1
This commit is contained in:
parent
4399b8c65a
commit
ff86f230a4
@ -15,7 +15,7 @@
|
|||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "jsondatamgr.h"
|
#include "jsondatamgr.h"
|
||||||
#include "handlermgr.h"
|
#include "handlermgr.h"
|
||||||
#include "gsmgr.h"
|
#include "svrmgr.h"
|
||||||
#include "imsmgr.h"
|
#include "imsmgr.h"
|
||||||
#include "GGListener.h"
|
#include "GGListener.h"
|
||||||
#include "IMListener.h"
|
#include "IMListener.h"
|
||||||
@ -92,7 +92,7 @@ void App::Init(int argc, char* argv[])
|
|||||||
uuid.SetMachineId(instance_id);
|
uuid.SetMachineId(instance_id);
|
||||||
GGListener::Instance()->Init();
|
GGListener::Instance()->Init();
|
||||||
IMListener::Instance()->Init();
|
IMListener::Instance()->Init();
|
||||||
GSMgr::Instance()->Init();
|
SvrMgr::Instance()->Init();
|
||||||
IMSMgr::Instance()->Init();
|
IMSMgr::Instance()->Init();
|
||||||
CacheMgr::Instance()->Init();
|
CacheMgr::Instance()->Init();
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ void App::UnInit()
|
|||||||
}
|
}
|
||||||
CacheMgr::Instance()->UnInit();
|
CacheMgr::Instance()->UnInit();
|
||||||
IMSMgr::Instance()->UnInit();
|
IMSMgr::Instance()->UnInit();
|
||||||
GSMgr::Instance()->UnInit();
|
SvrMgr::Instance()->UnInit();
|
||||||
IMListener::Instance()->UnInit();
|
IMListener::Instance()->UnInit();
|
||||||
GGListener::Instance()->UnInit();
|
GGListener::Instance()->UnInit();
|
||||||
JsonDataMgr::Instance()->UnInit();
|
JsonDataMgr::Instance()->UnInit();
|
||||||
@ -335,8 +335,8 @@ void App::ProcessGameGateMsg(f8::MsgHdr& hdr)
|
|||||||
hdr.msgid);
|
hdr.msgid);
|
||||||
if (handler) {
|
if (handler) {
|
||||||
switch (handler->handlerid) {
|
switch (handler->handlerid) {
|
||||||
case HID_GSMgr:
|
case HID_SvrMgr:
|
||||||
ProcessNetMsg(handler, GSMgr::Instance(), hdr);
|
ProcessNetMsg(handler, SvrMgr::Instance(), hdr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ enum InnerMesssage_e
|
|||||||
//网络处理对象
|
//网络处理对象
|
||||||
enum NetHandler_e
|
enum NetHandler_e
|
||||||
{
|
{
|
||||||
HID_GSMgr,
|
HID_SvrMgr,
|
||||||
HID_IMSMgr,
|
HID_IMSMgr,
|
||||||
HID_CacheMgr,
|
HID_CacheMgr,
|
||||||
};
|
};
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include "GGListener.h"
|
#include "GGListener.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "gsmgr.h"
|
#include "svrmgr.h"
|
||||||
#include "imsmgr.h"
|
#include "imsmgr.h"
|
||||||
|
|
||||||
static void _GMOpsSelfChecking(f8::JsonHttpRequest* request)
|
static void _GMOpsSelfChecking(f8::JsonHttpRequest* request)
|
||||||
@ -30,14 +30,10 @@ void HandlerMgr::Init()
|
|||||||
RegisterNetMsgHandlers();
|
RegisterNetMsgHandlers();
|
||||||
RegisterGMMsgHandler("Ops@selfChecking", _GMOpsSelfChecking);
|
RegisterGMMsgHandler("Ops@selfChecking", _GMOpsSelfChecking);
|
||||||
RegisterGMMsgHandler("Ops@reload", _GMOpsReload);
|
RegisterGMMsgHandler("Ops@reload", _GMOpsReload);
|
||||||
RegisterGMMsgHandler("GS@report", [] (f8::JsonHttpRequest* request)
|
RegisterGMMsgHandler("SvrMgr@list", [] (f8::JsonHttpRequest* request)
|
||||||
{
|
{
|
||||||
GSMgr::Instance()->___GSReport(request);
|
SvrMgr::Instance()->___GSList(request);
|
||||||
});
|
});
|
||||||
RegisterGMMsgHandler("GS@list", [] (f8::JsonHttpRequest* request)
|
|
||||||
{
|
|
||||||
GSMgr::Instance()->___GSList(request);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandlerMgr::UnInit()
|
void HandlerMgr::UnInit()
|
||||||
@ -46,8 +42,8 @@ void HandlerMgr::UnInit()
|
|||||||
|
|
||||||
void HandlerMgr::RegisterNetMsgHandlers()
|
void HandlerMgr::RegisterNetMsgHandlers()
|
||||||
{
|
{
|
||||||
RegisterNetMsgHandler(&ggmsghandler, &GSMgr::_SS_WSP_RequestTargetServer);
|
RegisterNetMsgHandler(&ggmsghandler, &SvrMgr::_SS_WSP_RequestTargetServer);
|
||||||
RegisterNetMsgHandler(&ggmsghandler, &GSMgr::_SS_Ping);
|
RegisterNetMsgHandler(&ggmsghandler, &SvrMgr::_SS_Ping);
|
||||||
|
|
||||||
RegisterNetMsgHandler(&immsghandler, &IMSMgr::_SS_Ping);
|
RegisterNetMsgHandler(&immsghandler, &IMSMgr::_SS_Ping);
|
||||||
}
|
}
|
||||||
|
@ -3,30 +3,30 @@
|
|||||||
#include <a8/mutable_xobject.h>
|
#include <a8/mutable_xobject.h>
|
||||||
#include <a8/timer.h>
|
#include <a8/timer.h>
|
||||||
|
|
||||||
#include "gsmgr.h"
|
#include "svrmgr.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "GGListener.h"
|
#include "GGListener.h"
|
||||||
|
|
||||||
void GSMgr::Init()
|
void SvrMgr::Init()
|
||||||
{
|
{
|
||||||
a8::Timer::Instance()->AddRepeatTimer(1000 * 2,
|
a8::Timer::Instance()->AddRepeatTimer(1000 * 2,
|
||||||
a8::XParams(),
|
a8::XParams(),
|
||||||
[] (const a8::XParams& param)
|
[] (const a8::XParams& param)
|
||||||
{
|
{
|
||||||
GSMgr::Instance()->ClearTimeOutNode();
|
SvrMgr::Instance()->ClearTimeOutNode();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSMgr::UnInit()
|
void SvrMgr::UnInit()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSMgr::_SS_WSP_RequestTargetServer(f8::MsgHdr& hdr, const ss::SS_WSP_RequestTargetServer& msg)
|
void SvrMgr::_SS_WSP_RequestTargetServer(f8::MsgHdr& hdr, const ss::SS_WSP_RequestTargetServer& msg)
|
||||||
{
|
{
|
||||||
ss::SS_MS_ResponseTargetServer respmsg;
|
ss::SS_MS_ResponseTargetServer respmsg;
|
||||||
respmsg.set_context_id(msg.context_id());
|
respmsg.set_context_id(msg.context_id());
|
||||||
GSNode* node = GetNodeByTeamId(msg.team_id());
|
SvrNode* node = GetNodeByTeamId(msg.team_id());
|
||||||
if (node) {
|
if (node) {
|
||||||
respmsg.set_host(node->ip);
|
respmsg.set_host(node->ip);
|
||||||
respmsg.set_port(node->port);
|
respmsg.set_port(node->port);
|
||||||
@ -44,13 +44,13 @@ void GSMgr::_SS_WSP_RequestTargetServer(f8::MsgHdr& hdr, const ss::SS_WSP_Reques
|
|||||||
GGListener::Instance()->SendMsg(hdr.socket_handle, respmsg);
|
GGListener::Instance()->SendMsg(hdr.socket_handle, respmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSMgr::_SS_Ping(f8::MsgHdr& hdr, const ss::SS_Ping& msg)
|
void SvrMgr::_SS_Ping(f8::MsgHdr& hdr, const ss::SS_Ping& msg)
|
||||||
{
|
{
|
||||||
ss::SS_Pong pongmsg;
|
ss::SS_Pong pongmsg;
|
||||||
GGListener::Instance()->SendMsg(hdr.socket_handle, pongmsg);
|
GGListener::Instance()->SendMsg(hdr.socket_handle, pongmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSMgr::___GSReport(f8::JsonHttpRequest* request)
|
void SvrMgr::___GSReport(f8::JsonHttpRequest* request)
|
||||||
{
|
{
|
||||||
std::string ip = request->request.Get("ip");
|
std::string ip = request->request.Get("ip");
|
||||||
int port = request->request.Get("port");
|
int port = request->request.Get("port");
|
||||||
@ -77,7 +77,7 @@ void GSMgr::___GSReport(f8::JsonHttpRequest* request)
|
|||||||
itr->second.alive_count = alive_count;
|
itr->second.alive_count = alive_count;
|
||||||
itr->second.last_active_tick = a8::XGetTickCount();
|
itr->second.last_active_tick = a8::XGetTickCount();
|
||||||
} else {
|
} else {
|
||||||
GSNode gs;
|
SvrNode gs;
|
||||||
gs.key = key;
|
gs.key = key;
|
||||||
gs.node_id = node_id;
|
gs.node_id = node_id;
|
||||||
gs.node_idx = App::Instance()->NewUuid();
|
gs.node_idx = App::Instance()->NewUuid();
|
||||||
@ -98,7 +98,7 @@ void GSMgr::___GSReport(f8::JsonHttpRequest* request)
|
|||||||
request->resp_xobj->SetVal("errmsg", "");
|
request->resp_xobj->SetVal("errmsg", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSMgr::___GSList(f8::JsonHttpRequest* request)
|
void SvrMgr::___GSList(f8::JsonHttpRequest* request)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
a8::MutableXObject* node_list = a8::MutableXObject::NewArray();
|
a8::MutableXObject* node_list = a8::MutableXObject::NewArray();
|
||||||
@ -125,7 +125,7 @@ void GSMgr::___GSList(f8::JsonHttpRequest* request)
|
|||||||
{
|
{
|
||||||
a8::MutableXObject* node_list = a8::MutableXObject::NewArray();
|
a8::MutableXObject* node_list = a8::MutableXObject::NewArray();
|
||||||
|
|
||||||
for (GSNode* gs_node : node_sorted_list_) {
|
for (SvrNode* gs_node : node_sorted_list_) {
|
||||||
a8::MutableXObject* node = a8::MutableXObject::NewObject();
|
a8::MutableXObject* node = a8::MutableXObject::NewObject();
|
||||||
node->SetVal("node_id", gs_node->node_id);
|
node->SetVal("node_id", gs_node->node_id);
|
||||||
node->SetVal("instance_id", gs_node->instance_id);
|
node->SetVal("instance_id", gs_node->instance_id);
|
||||||
@ -145,13 +145,13 @@ void GSMgr::___GSList(f8::JsonHttpRequest* request)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GSNode* GSMgr::GetNodeByTeamId(const std::string& team_id)
|
SvrNode* SvrMgr::GetNodeByTeamId(const std::string& team_id)
|
||||||
{
|
{
|
||||||
auto itr = team_hash_.find(team_id);
|
auto itr = team_hash_.find(team_id);
|
||||||
return itr != team_hash_.end() ? itr->second : nullptr;
|
return itr != team_hash_.end() ? itr->second : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GSNode* GSMgr::AllocNode()
|
SvrNode* SvrMgr::AllocNode()
|
||||||
{
|
{
|
||||||
if (node_sorted_list_.empty()) {
|
if (node_sorted_list_.empty()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -172,10 +172,10 @@ GSNode* GSMgr::AllocNode()
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSMgr::RearrangeNode()
|
void SvrMgr::RearrangeNode()
|
||||||
{
|
{
|
||||||
std::sort(node_sorted_list_.begin(), node_sorted_list_.end(),
|
std::sort(node_sorted_list_.begin(), node_sorted_list_.end(),
|
||||||
[] (const GSNode* a, const GSNode* b)
|
[] (const SvrNode* a, const SvrNode* b)
|
||||||
{
|
{
|
||||||
if (a->servicing && b->servicing) {
|
if (a->servicing && b->servicing) {
|
||||||
if (a->room_num < b->room_num) {
|
if (a->room_num < b->room_num) {
|
||||||
@ -203,15 +203,15 @@ void GSMgr::RearrangeNode()
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSMgr::ClearTimeOutNode()
|
void SvrMgr::ClearTimeOutNode()
|
||||||
{
|
{
|
||||||
std::vector<GSNode*> time_out_nodes;
|
std::vector<SvrNode*> time_out_nodes;
|
||||||
for (auto& pair : node_key_hash_) {
|
for (auto& pair : node_key_hash_) {
|
||||||
if (a8::XGetTickCount() - pair.second.last_active_tick > 1000 * 5) {
|
if (a8::XGetTickCount() - pair.second.last_active_tick > 1000 * 5) {
|
||||||
time_out_nodes.push_back(&pair.second);
|
time_out_nodes.push_back(&pair.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (GSNode* node : time_out_nodes) {
|
for (SvrNode* node : time_out_nodes) {
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < node_sorted_list_.size(); ++i) {
|
for (size_t i = 0; i < node_sorted_list_.size(); ++i) {
|
||||||
if (node_sorted_list_[i] == node) {
|
if (node_sorted_list_[i] == node) {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "ss_proto.pb.h"
|
#include "ss_proto.pb.h"
|
||||||
|
|
||||||
struct GSNode
|
struct SvrNode
|
||||||
{
|
{
|
||||||
std::string key;
|
std::string key;
|
||||||
long long node_idx = 0;
|
long long node_idx = 0;
|
||||||
@ -17,14 +17,14 @@ struct GSNode
|
|||||||
long long last_active_tick = 0;
|
long long last_active_tick = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GSMgr : public a8::Singleton<GSMgr>
|
class SvrMgr : public a8::Singleton<SvrMgr>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum { HID = HID_GSMgr };
|
enum { HID = HID_SvrMgr };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GSMgr() {};
|
SvrMgr() {};
|
||||||
friend class a8::Singleton<GSMgr>;
|
friend class a8::Singleton<SvrMgr>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -38,14 +38,14 @@ class GSMgr : public a8::Singleton<GSMgr>
|
|||||||
void ___GSList(f8::JsonHttpRequest* request);
|
void ___GSList(f8::JsonHttpRequest* request);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GSNode* GetNodeByTeamId(const std::string& team_id);
|
SvrNode* GetNodeByTeamId(const std::string& team_id);
|
||||||
GSNode* AllocNode();
|
SvrNode* AllocNode();
|
||||||
void RearrangeNode();
|
void RearrangeNode();
|
||||||
void ClearTimeOutNode();
|
void ClearTimeOutNode();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::map<std::string, GSNode*> team_hash_;
|
std::map<std::string, SvrNode*> team_hash_;
|
||||||
std::map<std::string, GSNode> node_key_hash_;
|
std::map<std::string, SvrNode> node_key_hash_;
|
||||||
std::vector<GSNode*> node_sorted_list_;
|
std::vector<SvrNode*> node_sorted_list_;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user