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