This commit is contained in:
aozhiwei 2019-05-15 09:54:21 +08:00
parent 6223f2f4e5
commit b0c4341c04
4 changed files with 80 additions and 4 deletions

View File

@ -1,5 +1,7 @@
#include "precompile.h"
#include <a8/mutable_xobject.h>
#include "gsmgr.h"
#include "GGListener.h"
@ -16,5 +18,55 @@ void GSMgr::UnInit()
void GSMgr::_SS_WSP_RequestTargetServer(f8::MsgHdr& hdr, const ss::SS_WSP_RequestTargetServer& msg)
{
ss::SS_MS_ResponseTargetServer respmsg;
GSNode* node = GetNodeByTeamId(msg.team_id());
if (!node) {
respmsg.set_host(node->ip);
respmsg.set_port(node->port);
} else {
node = AllocNode();
if (node) {
team_hash_[msg.team_id()] = node;
} else {
respmsg.set_error_code(1);
respmsg.set_error_msg("无法分配节点");
}
}
GGListener::Instance()->SendProxyMsg(hdr.socket_handle, respmsg);
}
void GSMgr::___GSReport(f8::JsonHttpRequest* request)
{
std::string ip = request->request.Get("ip");
int port = request->request.Get("port");
int online_num = request->request.Get("online_num");
int room_num = request->request.Get("room_num");
std::string key = ip + a8::XValue(port).GetString();
auto itr = node_hash_.find(key);
if (itr != node_hash_.end()) {
itr->second.online_num = online_num;
itr->second.room_num = room_num;
} else {
GSNode gs;
gs.key = key;
gs.online_num = online_num;
gs.room_num = room_num;
gs.ip = ip;
gs.port = port;
node_hash_[key] = gs;
}
request->resp_xobj->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", "");
}
GSNode* GSMgr::GetNodeByTeamId(const std::string& team_id)
{
auto itr = team_hash_.find(team_id);
return itr != team_hash_.end() ? itr->second : nullptr;
}
GSNode* GSMgr::AllocNode()
{
}

View File

@ -2,6 +2,15 @@
#include "ss_proto.pb.h"
struct GSNode
{
std::string key;
int room_num = 0;
int online_num = 0;
std::string ip;
int port = 0;
};
class GSMgr : public a8::Singleton<GSMgr>
{
public:
@ -18,4 +27,14 @@ class GSMgr : public a8::Singleton<GSMgr>
void _SS_WSP_RequestTargetServer(f8::MsgHdr& hdr, const ss::SS_WSP_RequestTargetServer& msg);
void ___GSReport(f8::JsonHttpRequest* request);
private:
GSNode* GetNodeByTeamId(const std::string& team_id);
GSNode* AllocNode();
private:
std::map<std::string, GSNode*> team_hash_;
std::map<std::string, GSNode> node_hash_;
};

View File

@ -30,6 +30,10 @@ void HandlerMgr::Init()
RegisterNetMsgHandlers();
RegisterGMMsgHandler("Ops@selfChecking", _GMOpsSelfChecking);
RegisterGMMsgHandler("Ops@reload", _GMOpsReload);
RegisterGMMsgHandler("GS@report", [] (f8::JsonHttpRequest* request)
{
GSMgr::Instance()->___GSReport(request);
});
}
void HandlerMgr::UnInit()

View File

@ -9,8 +9,9 @@ message SS_WSP_RequestTargetServer
message SS_MS_ResponseTargetServer
{
optional int64 context_id = 1;
optional int32 instance_id = 2;
optional string host = 3;
optional int32 port = 4;
optional int32 error_code = 1;
optional string error_msg = 2;
optional int64 context_id = 3;
optional string host = 4;
optional int32 port = 5;
}