1
This commit is contained in:
parent
62b4b5829b
commit
b038b27c40
@ -63,7 +63,7 @@ static void SavePerfLog()
|
||||
App::Instance()->perf.max_timer_idle,
|
||||
App::Instance()->perf.in_data_size,
|
||||
App::Instance()->perf.out_data_size,
|
||||
App::Instance()->msgnode_size_,
|
||||
//App::Instance()->msgnode_size_,
|
||||
App::Instance()->perf.read_count,
|
||||
App::Instance()->perf.max_login_time,
|
||||
App::Instance()->perf.max_join_time,
|
||||
@ -91,24 +91,25 @@ bool App::Init(int argc, char* argv[])
|
||||
|
||||
if (!ParseOpt()) {
|
||||
terminated = true;
|
||||
if (node_id <= 0) {
|
||||
if (node_id_ <= 0) {
|
||||
a8::XPrintf("gameserver启动失败,缺少-n参数\n", {});
|
||||
} else if (node_id > MAX_NODE_ID) {
|
||||
} else if (node_id_ > MAX_NODE_ID) {
|
||||
a8::XPrintf("gameserver启动失败,-n参数不能大于%d\n", {MAX_NODE_ID});
|
||||
} else if (instance_id <= 0) {
|
||||
} else if (instance_id_ <= 0) {
|
||||
a8::XPrintf("gameserver启动失败,缺少-i参数\n", {});
|
||||
} else if (instance_id > MAX_INSTANCE_ID) {
|
||||
} else if (instance_id_ > MAX_INSTANCE_ID) {
|
||||
a8::XPrintf("gameserver启动失败,-i参数不能大于%d\n", {MAX_INSTANCE_ID});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
a8::XPrintf("wsproxy starting node_id:%d instance_id:%d pid:%d\n",
|
||||
{
|
||||
node_id,
|
||||
instance_id,
|
||||
node_id_,
|
||||
instance_id_,
|
||||
getpid()
|
||||
});
|
||||
|
||||
uuid_ = std::make_shared<a8::uuid::SnowFlake>();
|
||||
loop_mutex_ = new std::mutex();
|
||||
loop_cond_ = new std::condition_variable();
|
||||
msg_mutex_ = new std::mutex();
|
||||
@ -120,7 +121,7 @@ bool App::Init(int argc, char* argv[])
|
||||
HandlerMgr::Instance()->Init();
|
||||
f8::Timer::Instance()->Init();
|
||||
JsonDataMgr::Instance()->Init();
|
||||
uuid.SetMachineId((node_id - 1) * MAX_NODE_ID + instance_id);
|
||||
uuid_->SetMachineId((node_id_ - 1) * MAX_NODE_ID + instance_id_);
|
||||
DownStreamMgr::Instance()->Init();
|
||||
MasterMgr::Instance()->Init();
|
||||
UpStreamMgr::Instance()->Init();
|
||||
@ -129,7 +130,7 @@ bool App::Init(int argc, char* argv[])
|
||||
|
||||
f8::UdpLog::Instance()->Info("wsproxy starting instance_id:%d pid:%d",
|
||||
{
|
||||
instance_id,
|
||||
instance_id_,
|
||||
getpid(),
|
||||
});
|
||||
{
|
||||
@ -177,7 +178,7 @@ bool App::Init(int argc, char* argv[])
|
||||
|
||||
void App::UnInit()
|
||||
{
|
||||
a8::XPrintf("wsproxy terminating instance_id:%d pid:%d\n", {instance_id, getpid()});
|
||||
a8::XPrintf("wsproxy terminating instance_id:%d pid:%d\n", {instance_id_, getpid()});
|
||||
GCListener::Instance()->UnInit();
|
||||
LongSessionMgr::Instance()->UnInit();
|
||||
MasterMgr::Instance()->UnInit();
|
||||
@ -199,7 +200,7 @@ void App::UnInit()
|
||||
loop_cond_ = nullptr;
|
||||
delete loop_mutex_;
|
||||
loop_mutex_ = nullptr;
|
||||
a8::XPrintf("wsproxy terminated instance_id:%d pid:%d\n", {instance_id, getpid()});
|
||||
a8::XPrintf("wsproxy terminated instance_id:%d pid:%d\n", {instance_id_, getpid()});
|
||||
}
|
||||
|
||||
int App::Run()
|
||||
@ -489,12 +490,12 @@ bool App::ParseOpt()
|
||||
switch (ch) {
|
||||
case 'n':
|
||||
{
|
||||
node_id = a8::XValue(optarg);
|
||||
node_id_ = a8::XValue(optarg);
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
{
|
||||
instance_id = a8::XValue(optarg);
|
||||
instance_id_ = a8::XValue(optarg);
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
@ -508,7 +509,7 @@ bool App::ParseOpt()
|
||||
break;
|
||||
}
|
||||
}
|
||||
return instance_id > 0 && node_id > 0;
|
||||
return instance_id_ > 0 && node_id_ > 0;
|
||||
}
|
||||
|
||||
bool App::HasFlag(int flag)
|
||||
@ -608,5 +609,5 @@ void App::DispatchUdpMsg()
|
||||
|
||||
long long App::NewUuid()
|
||||
{
|
||||
return uuid.Generate();
|
||||
return uuid_->Generate();
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <a8/uuid.h>
|
||||
#include <a8/singleton.h>
|
||||
|
||||
namespace a8
|
||||
{
|
||||
struct UdpPacket;
|
||||
namespace uuid
|
||||
{
|
||||
class SnowFlake;
|
||||
}
|
||||
}
|
||||
|
||||
struct MsgNode;
|
||||
@ -36,6 +39,8 @@ class App : public a8::Singleton<App>
|
||||
void NotifyLoopCond();
|
||||
bool HasFlag(int flag);
|
||||
long long NewUuid();
|
||||
int GetNodeId() { return node_id_; }
|
||||
int GetInstanceId() { return instance_id_; }
|
||||
|
||||
private:
|
||||
void QuickExecute();
|
||||
@ -64,13 +69,12 @@ private:
|
||||
volatile bool shutdowned = false;
|
||||
std::set<int> flags;
|
||||
PerfMonitor perf;
|
||||
a8::uuid::SnowFlake uuid;
|
||||
|
||||
public:
|
||||
int node_id = 0;
|
||||
int instance_id = 0;
|
||||
|
||||
private:
|
||||
int node_id_ = 0;
|
||||
int instance_id_ = 0;
|
||||
|
||||
std::shared_ptr<a8::uuid::SnowFlake> uuid_;
|
||||
std::mutex *loop_mutex_ = nullptr;
|
||||
std::condition_variable *loop_cond_ = nullptr;
|
||||
|
||||
@ -84,7 +88,6 @@ public:
|
||||
UdpMsgNode* udp_bot_node_ = nullptr;
|
||||
UdpMsgNode* udp_work_node_ = nullptr;
|
||||
|
||||
public:
|
||||
int msgnode_size_ = 0 ;
|
||||
int udp_msgnode_size_ = 0 ;
|
||||
int working_msgnode_size_ = 0;
|
||||
|
@ -24,7 +24,7 @@ static void _GMOpsGetNodeId(std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
{
|
||||
request->resp_xobj->SetVal("errcode", 0);
|
||||
request->resp_xobj->SetVal("errmsg", "");
|
||||
request->resp_xobj->SetVal("node_id", App::Instance()->node_id);
|
||||
request->resp_xobj->SetVal("node_id", App::Instance()->GetNodeId());
|
||||
}
|
||||
|
||||
void HandlerMgr::Init()
|
||||
|
@ -31,13 +31,13 @@ void JsonDataMgr::Init()
|
||||
wsproxyserver_cluster_json_file = a8::Format("%s/node%d/game%d.wsproxy.cluster.json",
|
||||
{
|
||||
work_path_,
|
||||
App::Instance()->node_id,
|
||||
App::Instance()->GetNodeId(),
|
||||
GAME_ID
|
||||
});
|
||||
masterserver_cluster_json_file = a8::Format("%s/node%d/game%d.masterserver.cluster.json",
|
||||
{
|
||||
work_path_,
|
||||
App::Instance()->node_id,
|
||||
App::Instance()->GetNodeId(),
|
||||
GAME_ID
|
||||
});
|
||||
routing_tables_json_file = a8::Format("%s/routing_tables.json",
|
||||
@ -71,10 +71,11 @@ void JsonDataMgr::UnInit()
|
||||
|
||||
std::shared_ptr<a8::XObject> JsonDataMgr::GetConf()
|
||||
{
|
||||
if (App::Instance()->instance_id < 1 || App::Instance()->instance_id > wsproxyserver_cluster_json_.Size()) {
|
||||
if (App::Instance()->GetInstanceId() < 1 ||
|
||||
App::Instance()->GetInstanceId() > wsproxyserver_cluster_json_.Size()) {
|
||||
abort();
|
||||
}
|
||||
return wsproxyserver_cluster_json_[App::Instance()->instance_id - 1];
|
||||
return wsproxyserver_cluster_json_[App::Instance()->GetInstanceId() - 1];
|
||||
}
|
||||
|
||||
std::shared_ptr<a8::XObject> JsonDataMgr::GetMasterServerClusterConf()
|
||||
|
@ -110,7 +110,7 @@ void MasterMgr::RequestTargetServer(f8::MsgHdr& hdr,
|
||||
std::string data = a8::Format("!%s_%s_%d_%d",
|
||||
{
|
||||
account_id,
|
||||
App::Instance()->uuid.Generate(),
|
||||
App::Instance()->NewUuid(),
|
||||
getpid(),
|
||||
rand()
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user