This commit is contained in:
aozhiwei 2020-06-16 10:39:03 +08:00
parent 4399b8c65a
commit ff86f230a4
5 changed files with 41 additions and 45 deletions

View File

@ -15,7 +15,7 @@
#include "app.h"
#include "jsondatamgr.h"
#include "handlermgr.h"
#include "gsmgr.h"
#include "svrmgr.h"
#include "imsmgr.h"
#include "GGListener.h"
#include "IMListener.h"
@ -92,7 +92,7 @@ void App::Init(int argc, char* argv[])
uuid.SetMachineId(instance_id);
GGListener::Instance()->Init();
IMListener::Instance()->Init();
GSMgr::Instance()->Init();
SvrMgr::Instance()->Init();
IMSMgr::Instance()->Init();
CacheMgr::Instance()->Init();
@ -118,7 +118,7 @@ void App::UnInit()
}
CacheMgr::Instance()->UnInit();
IMSMgr::Instance()->UnInit();
GSMgr::Instance()->UnInit();
SvrMgr::Instance()->UnInit();
IMListener::Instance()->UnInit();
GGListener::Instance()->UnInit();
JsonDataMgr::Instance()->UnInit();
@ -335,8 +335,8 @@ void App::ProcessGameGateMsg(f8::MsgHdr& hdr)
hdr.msgid);
if (handler) {
switch (handler->handlerid) {
case HID_GSMgr:
ProcessNetMsg(handler, GSMgr::Instance(), hdr);
case HID_SvrMgr:
ProcessNetMsg(handler, SvrMgr::Instance(), hdr);
break;
}
}

View File

@ -17,7 +17,7 @@ enum InnerMesssage_e
//网络处理对象
enum NetHandler_e
{
HID_GSMgr,
HID_SvrMgr,
HID_IMSMgr,
HID_CacheMgr,
};

View File

@ -6,7 +6,7 @@
#include "GGListener.h"
#include "app.h"
#include "gsmgr.h"
#include "svrmgr.h"
#include "imsmgr.h"
static void _GMOpsSelfChecking(f8::JsonHttpRequest* request)
@ -30,13 +30,9 @@ void HandlerMgr::Init()
RegisterNetMsgHandlers();
RegisterGMMsgHandler("Ops@selfChecking", _GMOpsSelfChecking);
RegisterGMMsgHandler("Ops@reload", _GMOpsReload);
RegisterGMMsgHandler("GS@report", [] (f8::JsonHttpRequest* request)
RegisterGMMsgHandler("SvrMgr@list", [] (f8::JsonHttpRequest* request)
{
GSMgr::Instance()->___GSReport(request);
});
RegisterGMMsgHandler("GS@list", [] (f8::JsonHttpRequest* request)
{
GSMgr::Instance()->___GSList(request);
SvrMgr::Instance()->___GSList(request);
});
}
@ -46,8 +42,8 @@ void HandlerMgr::UnInit()
void HandlerMgr::RegisterNetMsgHandlers()
{
RegisterNetMsgHandler(&ggmsghandler, &GSMgr::_SS_WSP_RequestTargetServer);
RegisterNetMsgHandler(&ggmsghandler, &GSMgr::_SS_Ping);
RegisterNetMsgHandler(&ggmsghandler, &SvrMgr::_SS_WSP_RequestTargetServer);
RegisterNetMsgHandler(&ggmsghandler, &SvrMgr::_SS_Ping);
RegisterNetMsgHandler(&immsghandler, &IMSMgr::_SS_Ping);
}

View File

@ -3,30 +3,30 @@
#include <a8/mutable_xobject.h>
#include <a8/timer.h>
#include "gsmgr.h"
#include "svrmgr.h"
#include "app.h"
#include "GGListener.h"
void GSMgr::Init()
void SvrMgr::Init()
{
a8::Timer::Instance()->AddRepeatTimer(1000 * 2,
a8::XParams(),
[] (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;
respmsg.set_context_id(msg.context_id());
GSNode* node = GetNodeByTeamId(msg.team_id());
SvrNode* node = GetNodeByTeamId(msg.team_id());
if (node) {
respmsg.set_host(node->ip);
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);
}
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;
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");
int port = request->request.Get("port");
@ -77,7 +77,7 @@ void GSMgr::___GSReport(f8::JsonHttpRequest* request)
itr->second.alive_count = alive_count;
itr->second.last_active_tick = a8::XGetTickCount();
} else {
GSNode gs;
SvrNode gs;
gs.key = key;
gs.node_id = node_id;
gs.node_idx = App::Instance()->NewUuid();
@ -98,7 +98,7 @@ void GSMgr::___GSReport(f8::JsonHttpRequest* request)
request->resp_xobj->SetVal("errmsg", "");
}
void GSMgr::___GSList(f8::JsonHttpRequest* request)
void SvrMgr::___GSList(f8::JsonHttpRequest* request)
{
{
a8::MutableXObject* node_list = a8::MutableXObject::NewArray();
@ -125,7 +125,7 @@ void GSMgr::___GSList(f8::JsonHttpRequest* request)
{
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();
node->SetVal("node_id", gs_node->node_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);
return itr != team_hash_.end() ? itr->second : nullptr;
}
GSNode* GSMgr::AllocNode()
SvrNode* SvrMgr::AllocNode()
{
if (node_sorted_list_.empty()) {
return nullptr;
@ -172,10 +172,10 @@ GSNode* GSMgr::AllocNode()
return nullptr;
}
void GSMgr::RearrangeNode()
void SvrMgr::RearrangeNode()
{
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->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_) {
if (a8::XGetTickCount() - pair.second.last_active_tick > 1000 * 5) {
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) {
if (node_sorted_list_[i] == node) {

View File

@ -2,7 +2,7 @@
#include "ss_proto.pb.h"
struct GSNode
struct SvrNode
{
std::string key;
long long node_idx = 0;
@ -17,14 +17,14 @@ struct GSNode
long long last_active_tick = 0;
};
class GSMgr : public a8::Singleton<GSMgr>
class SvrMgr : public a8::Singleton<SvrMgr>
{
public:
enum { HID = HID_GSMgr };
enum { HID = HID_SvrMgr };
private:
GSMgr() {};
friend class a8::Singleton<GSMgr>;
SvrMgr() {};
friend class a8::Singleton<SvrMgr>;
public:
@ -38,14 +38,14 @@ class GSMgr : public a8::Singleton<GSMgr>
void ___GSList(f8::JsonHttpRequest* request);
private:
GSNode* GetNodeByTeamId(const std::string& team_id);
GSNode* AllocNode();
SvrNode* GetNodeByTeamId(const std::string& team_id);
SvrNode* AllocNode();
void RearrangeNode();
void ClearTimeOutNode();
private:
std::map<std::string, GSNode*> team_hash_;
std::map<std::string, GSNode> node_key_hash_;
std::vector<GSNode*> node_sorted_list_;
std::map<std::string, SvrNode*> team_hash_;
std::map<std::string, SvrNode> node_key_hash_;
std::vector<SvrNode*> node_sorted_list_;
};