Skip to content

Commit

Permalink
Update: Use cmd args to set node connection info.
Browse files Browse the repository at this point in the history
  • Loading branch information
i0gan committed Mar 30, 2024
1 parent c4437c2 commit 33fc1db
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 83 deletions.
24 changes: 24 additions & 0 deletions config/node/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"DB" : {
"Mysql" : {
"Account" : [
{ "ip":"127.0.0.1", "port":10400, "user":"root", "auth":"pwnsky_squick", "database":"player"}
]
},
"Mongo" : {
"Player" : [
{ "ip":"127.0.0.1", "port":10410, "user":"admin", "auth":"pwnsky_squick", "database":"game"}
]
},
"Redis" : {
"Cache" : [
{ "ip":"127.0.0.1", "port":10420, "user":"root", "auth":"pwnsky_squick", "database":""}
]
},
"Clickhouse" : {
"Log" : [
{ "ip":"127.0.0.1", "port":10431, "user":"default", "auth":"pwnsky_squick", "database":"squick"}
]
}
}
}
14 changes: 7 additions & 7 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,27 @@ void PrintLogo() {

// Just for debug or dev
void DefaultStartUp(std::string strArgvList, std::vector<std::shared_ptr<PluginServer>> &serverList) {
serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=master id=1")));
serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=master id=1 area=0 ip=127.0.0.1 port=10001 web_port=8888")));

serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=world id=100")));
serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=world id=100 area=0 ip=127.0.0.1 port=10101 master=127.0.0.1:10001")));
//serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=world id=101"))); // 区服2
serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=db_proxy id=300")));
serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=db_proxy id=300 area=0 ip=127.0.0.1 port=10201 master=127.0.0.1:10001")));

//serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=db_proxy id=301"))); // 区服2

serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=login id=2")));
serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=login id=2 area=0 ip=127.0.0.1 port=10301 web_port=80 master=127.0.0.1:10001")));

// Lobby
serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=lobby id=1000")));
serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=lobby id=1001")));
serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=lobby id=1000 area=0 ip=127.0.0.1 port=10401 master=127.0.0.1:10001")));
serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=lobby id=1001 area=0 ip=127.0.0.1 port=10402 master=127.0.0.1:10001")));
//serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=lobby id=1002")));

// Game
//serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=game id=3000")));
//serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=game id=3001")));
//serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=game_mgr id=2000")));

serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=proxy id=500")));
serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=proxy id=500 area=0 ip=127.0.0.1 port=10501 master=127.0.0.1:10001")));
//serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=proxy id=501")));

//serverList.push_back(std::shared_ptr<PluginServer>(new PluginServer(strArgvList + " type=proxy id=502"))); // 区服2
Expand Down
16 changes: 1 addition & 15 deletions src/node/login/http/http_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,7 @@ bool HttpModule::AfterStart() {
//m_http_server_->AddNetFilter("/area/list", this, &HttpModule::OnFilter);
//m_http_server_->AddNetFilter("/area/enter", this, &HttpModule::OnFilter);

std::shared_ptr<IClass> xLogicClass = m_class_->GetElement(excel::Server::ThisName());
if (xLogicClass) {
const std::vector<std::string> &strIdList = xLogicClass->GetIDList();
for (int i = 0; i < strIdList.size(); ++i) {
const std::string &strId = strIdList[i];

int web_port = m_element_->GetPropertyInt32(strId, excel::Server::WebPort());
int nWebServerAppID = m_element_->GetPropertyInt32(strId, excel::Server::ServerID());
// webserver only run one instance in each server
if (pm_->GetAppID() == nWebServerAppID && web_port > 0) {
m_http_server_->StartServer(web_port);
break;
}
}
}
m_http_server_->StartServer(pm_->GetArg("web_port=", 80));

return true;
}
Expand Down
19 changes: 1 addition & 18 deletions src/node/master/http/http_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,7 @@ bool HttpModule::AfterStart() {
m_http_server_->AddRequestHandler("/status", HttpType::SQUICK_HTTP_REQ_GET, this, &HttpModule::OnCommandQuery);

//m_http_server_->AddNetFilter("/status", this, &HttpModule::OnFilter);

std::shared_ptr<IClass> xLogicClass = m_class_->GetElement(excel::Server::ThisName());
if (xLogicClass) {
const std::vector<std::string> &strIdList = xLogicClass->GetIDList();
for (int i = 0; i < strIdList.size(); ++i) {
const std::string &strId = strIdList[i];

int nJsonPort = m_element_->GetPropertyInt32(strId, excel::Server::WebPort());
int nWebServerAppID = m_element_->GetPropertyInt32(strId, excel::Server::ServerID());

// webserver only run one instance in each server
if (pm_->GetAppID() == nWebServerAppID) {
m_http_server_->StartServer(nJsonPort);

break;
}
}
}
m_http_server_->StartServer(pm_->GetArg("web_port=", 8888));

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/squick/core/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "i_plugin_manager.h"
#include <iostream>

#define SQUICK_VERSION "1.0.1"
#define SQUICK_VERSION "1.0.2"
#define SERVER_NAME "Squick/" SQUICK_VERSION

enum ServerType {
Expand Down
22 changes: 22 additions & 0 deletions src/squick/core/i_plugin_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,28 @@ class IPluginManager {
virtual void SetArgs(const std::vector<std::string>& id) = 0;

virtual std::string FindParameterValue(const std::string& header) = 0;

int GetArg(const std::string& header, int default_value) {
std::string value = FindParameterValue(header);
int ret_value;
if (value.empty()) {
ret_value = default_value;
} else {
ret_value = atoi(value.c_str());
}
return ret_value;
}

std::string GetArg(const std::string& header, const std::string &default_value) {
std::string value = FindParameterValue(header);
std::string ret_value;
if (value.empty()) {
ret_value = default_value;
} else {
ret_value = value;
}
return ret_value;
}

virtual int GetAppType() const = 0;
virtual void SetAppType(const int type) = 0;
Expand Down
2 changes: 0 additions & 2 deletions src/squick/core/plugin_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,8 @@ class PluginManager : public IPluginManager {
virtual std::vector<ReplaceContent> GetFileReplaceContents(const std::string &fileName) override;

protected:
bool CheckStaticPlugin();
bool LoadPluginLibrary(const std::string &pluginDLLName);
bool UnLoadPluginLibrary(const std::string &pluginDLLName);
bool UnLoadStaticPlugin(const std::string &pluginDLLName);

private:
int appID = 0;
Expand Down
92 changes: 52 additions & 40 deletions src/squick/imodule/i_node_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ class INodeBaseModule : public IModule {
return true;
}

static std::string EnumNodeTypeToString(ServerType type)
{
return "";
}

static ServerType StringNodeTypeToEnum(const std::string& type)
{
if (type == "master") return ServerType::ST_MASTER;
else if (type == "login") return ServerType::ST_LOGIN;
else if (type == "world") return ServerType::ST_WORLD;
else if (type == "db_proxy") return ServerType::ST_DB_PROXY;
else if (type == "proxy") return ServerType::ST_PROXY;
else if (type == "lobby") return ServerType::ST_LOBBY;
else if (type == "game_mgr") return ServerType::ST_GAME_MGR;
else if (type == "game") return ServerType::ST_GAME;
else if (type == "micro") return ServerType::ST_MICRO;
else if (type == "cdn") return ServerType::ST_CDN;
else if (type == "robot") return ServerType::ST_ROBOT;
return ServerType::ST_NONE;
}

virtual bool Listen() {

m_net_->AddReceiveCallBack(rpc::ServerRPC::REQ_REGISTER, this, &INodeBaseModule::OnReqRegister);
Expand All @@ -41,46 +62,37 @@ class INodeBaseModule : public IModule {
m_net_->AddEventCallBack(this, &INodeBaseModule::OnServerSocketEvent);
m_net_->ExpandBufferSize();

std::shared_ptr<IClass> xLogicClass = m_class_->GetElement(excel::Server::ThisName());
if (xLogicClass) {
const std::vector<std::string> &strIdList = xLogicClass->GetIDList();
for (int i = 0; i < strIdList.size(); ++i) {
const std::string &strId = strIdList[i];
const int id = m_element_->GetPropertyInt32(strId, excel::Server::ServerID());
if (pm_->GetAppID() == id) {
ServerInfo s;
s.info->set_id(id);
s.info->set_key(m_element_->GetPropertyString(strId, excel::Server::Key()));
s.info->set_type(m_element_->GetPropertyInt32(strId, excel::Server::Type()));
s.info->set_port(m_element_->GetPropertyInt32(strId, excel::Server::Port()));
s.info->set_max_online(m_element_->GetPropertyInt32(strId, excel::Server::MaxOnline()));
s.info->set_cpu_count(m_element_->GetPropertyInt32(strId, excel::Server::CpuCount()));
s.info->set_name(m_element_->GetPropertyString(strId, excel::Server::ID()));
s.info->set_ip(m_element_->GetPropertyString(strId, excel::Server::IP()));
s.info->set_public_ip(m_element_->GetPropertyString(strId, excel::Server::PublicIP()));
s.info->set_area(m_element_->GetPropertyInt32(strId, excel::Server::Area()));
s.info->set_cpu_count(m_element_->GetPropertyInt32(strId, excel::Server::CpuCount()));
s.type = ServerInfo::Type::Self;
s.info->set_update_time(SquickGetTimeS());
pm_->SetAppType(s.info->type());
pm_->SetArea(s.info->area());
servers_[pm_->GetAppID()] = s;

int nRet = m_net_->Startialization(s.info->max_online(), s.info->port(), s.info->cpu_count());

std::ostringstream log;
log << "Node Listen at 0.0.0.0:" << s.info->port() << " Name: " << s.info->name();
m_log_->LogDebug(NULL_OBJECT, log, __FUNCTION__, __LINE__);

if (nRet < 0) {
std::ostringstream strLog;
strLog << "Cannot init server net, Port = " << s.info->port();
m_log_->LogError(NULL_OBJECT, strLog, __FUNCTION__, __LINE__);
SQUICK_ASSERT(nRet, "Cannot init server net", __FILE__, __FUNCTION__);
exit(0);
}
}
}
ServerInfo s;
s.info->set_id(pm_->GetArg("id=", 0));
//s.info->set_key("key");
std::string name = pm_->GetArg("type=", "squick_node") + pm_->GetArg("id=", "0");
s.info->set_type(StringNodeTypeToEnum(pm_->GetArg("type=", "squick_node")));
s.info->set_port(pm_->GetArg("port=", 10000));
//s.info->set_max_online(m_element_->GetPropertyInt32(strId, excel::Server::MaxOnline()));
//s.info->set_cpu_count(m_element_->GetPropertyInt32(strId, excel::Server::CpuCount()));
s.info->set_name(name);
s.info->set_ip(pm_->GetArg("ip=", "127.0.0.1"));
s.info->set_public_ip(pm_->GetArg("public_ip=", "127.0.0.1"));
s.info->set_area(pm_->GetArg("area=", 0));
//s.info->set_cpu_count(m_element_->GetPropertyInt32(strId, excel::Server::CpuCount()));
s.type = ServerInfo::Type::Self;
s.info->set_update_time(SquickGetTimeS());
pm_->SetAppType(s.info->type());
pm_->SetArea(s.info->area());
servers_[pm_->GetAppID()] = s;

int nRet = m_net_->Startialization(s.info->max_online(), s.info->port(), s.info->cpu_count());

std::ostringstream log;
log << "Node Listen at 0.0.0.0:" << s.info->port() << " Name: " << s.info->name();
m_log_->LogDebug(NULL_OBJECT, log, __FUNCTION__, __LINE__);

if (nRet < 0) {
std::ostringstream strLog;
strLog << "Cannot init server net, Port = " << s.info->port();
m_log_->LogError(NULL_OBJECT, strLog, __FUNCTION__, __LINE__);
SQUICK_ASSERT(nRet, "Cannot init server net", __FILE__, __FUNCTION__);
exit(0);
}
return true;
}
Expand Down

0 comments on commit 33fc1db

Please sign in to comment.