1
This commit is contained in:
parent
ff86f230a4
commit
ade654bf0e
@ -9,12 +9,13 @@
|
|||||||
|
|
||||||
void SvrMgr::Init()
|
void SvrMgr::Init()
|
||||||
{
|
{
|
||||||
a8::Timer::Instance()->AddRepeatTimer(1000 * 2,
|
a8::Timer::Instance()->AddRepeatTimer
|
||||||
a8::XParams(),
|
(1000 * 2,
|
||||||
[] (const a8::XParams& param)
|
a8::XParams(),
|
||||||
{
|
[] (const a8::XParams& param)
|
||||||
SvrMgr::Instance()->ClearTimeOutNode();
|
{
|
||||||
});
|
SvrMgr::Instance()->ClearTimeOutNode();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void SvrMgr::UnInit()
|
void SvrMgr::UnInit()
|
||||||
@ -26,20 +27,13 @@ void SvrMgr::_SS_WSP_RequestTargetServer(f8::MsgHdr& hdr, const ss::SS_WSP_Reque
|
|||||||
{
|
{
|
||||||
ss::SS_MS_ResponseTargetServer respmsg;
|
ss::SS_MS_ResponseTargetServer respmsg;
|
||||||
respmsg.set_context_id(msg.context_id());
|
respmsg.set_context_id(msg.context_id());
|
||||||
SvrNode* node = GetNodeByTeamId(msg.team_id());
|
SvrNode* node = AllocNode();
|
||||||
if (node) {
|
if (node) {
|
||||||
respmsg.set_host(node->ip);
|
respmsg.set_host(node->ip);
|
||||||
respmsg.set_port(node->port);
|
respmsg.set_port(node->port);
|
||||||
} else {
|
} else {
|
||||||
node = AllocNode();
|
respmsg.set_error_code(1);
|
||||||
if (node) {
|
respmsg.set_error_msg("无法分配节点");
|
||||||
respmsg.set_host(node->ip);
|
|
||||||
respmsg.set_port(node->port);
|
|
||||||
team_hash_[msg.team_id()] = node;
|
|
||||||
} else {
|
|
||||||
respmsg.set_error_code(1);
|
|
||||||
respmsg.set_error_msg("无法分配节点");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
GGListener::Instance()->SendMsg(hdr.socket_handle, respmsg);
|
GGListener::Instance()->SendMsg(hdr.socket_handle, respmsg);
|
||||||
}
|
}
|
||||||
@ -50,54 +44,6 @@ void SvrMgr::_SS_Ping(f8::MsgHdr& hdr, const ss::SS_Ping& msg)
|
|||||||
GGListener::Instance()->SendMsg(hdr.socket_handle, pongmsg);
|
GGListener::Instance()->SendMsg(hdr.socket_handle, pongmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SvrMgr::___GSReport(f8::JsonHttpRequest* request)
|
|
||||||
{
|
|
||||||
std::string ip = request->request.Get("ip");
|
|
||||||
int port = request->request.Get("port");
|
|
||||||
int alive_count = request->request.Get("alive_count");
|
|
||||||
int online_num = request->request.Get("online_num");
|
|
||||||
int room_num = request->request.Get("room_num");
|
|
||||||
int instance_id = request->request.Get("instance_id");
|
|
||||||
int node_id = request->request.Get("node_id");
|
|
||||||
bool servicing = request->request.Get("servicing");
|
|
||||||
std::string key = ip + ":" + a8::XValue(port).GetString();
|
|
||||||
|
|
||||||
auto itr = node_key_hash_.find(key);
|
|
||||||
if (itr != node_key_hash_.end()) {
|
|
||||||
if (itr->second.online_num != online_num ||
|
|
||||||
itr->second.room_num != room_num ||
|
|
||||||
itr->second.alive_count != alive_count ||
|
|
||||||
itr->second.servicing != servicing
|
|
||||||
) {
|
|
||||||
itr->second.online_num = online_num;
|
|
||||||
itr->second.room_num = room_num;
|
|
||||||
itr->second.servicing = servicing;
|
|
||||||
RearrangeNode();
|
|
||||||
}
|
|
||||||
itr->second.alive_count = alive_count;
|
|
||||||
itr->second.last_active_tick = a8::XGetTickCount();
|
|
||||||
} else {
|
|
||||||
SvrNode gs;
|
|
||||||
gs.key = key;
|
|
||||||
gs.node_id = node_id;
|
|
||||||
gs.node_idx = App::Instance()->NewUuid();
|
|
||||||
gs.instance_id = instance_id;
|
|
||||||
gs.alive_count = alive_count;
|
|
||||||
gs.online_num = online_num;
|
|
||||||
gs.room_num = room_num;
|
|
||||||
gs.ip = ip;
|
|
||||||
gs.port = port;
|
|
||||||
gs.servicing = servicing;
|
|
||||||
gs.last_active_tick = a8::XGetTickCount();
|
|
||||||
node_key_hash_[key] = gs;
|
|
||||||
node_sorted_list_.push_back(&node_key_hash_[key]);
|
|
||||||
RearrangeNode();
|
|
||||||
}
|
|
||||||
|
|
||||||
request->resp_xobj->SetVal("errcode", 0);
|
|
||||||
request->resp_xobj->SetVal("errmsg", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
void SvrMgr::___GSList(f8::JsonHttpRequest* request)
|
void SvrMgr::___GSList(f8::JsonHttpRequest* request)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@ -145,12 +91,6 @@ void SvrMgr::___GSList(f8::JsonHttpRequest* request)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SvrNode* SvrMgr::GetNodeByTeamId(const std::string& team_id)
|
|
||||||
{
|
|
||||||
auto itr = team_hash_.find(team_id);
|
|
||||||
return itr != team_hash_.end() ? itr->second : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
SvrNode* SvrMgr::AllocNode()
|
SvrNode* SvrMgr::AllocNode()
|
||||||
{
|
{
|
||||||
if (node_sorted_list_.empty()) {
|
if (node_sorted_list_.empty()) {
|
||||||
@ -220,17 +160,6 @@ void SvrMgr::ClearTimeOutNode()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
|
||||||
std::vector<std::string> deleted_teams;
|
|
||||||
for (auto& pair : team_hash_) {
|
|
||||||
if (pair.second == node) {
|
|
||||||
deleted_teams.push_back(pair.first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const std::string& team_id : deleted_teams) {
|
|
||||||
team_hash_.erase(team_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
node_key_hash_.erase(node->key);
|
node_key_hash_.erase(node->key);
|
||||||
}
|
}
|
||||||
RearrangeNode();
|
RearrangeNode();
|
||||||
|
@ -34,18 +34,15 @@ class SvrMgr : public a8::Singleton<SvrMgr>
|
|||||||
void _SS_WSP_RequestTargetServer(f8::MsgHdr& hdr, const ss::SS_WSP_RequestTargetServer& msg);
|
void _SS_WSP_RequestTargetServer(f8::MsgHdr& hdr, const ss::SS_WSP_RequestTargetServer& msg);
|
||||||
void _SS_Ping(f8::MsgHdr& hdr, const ss::SS_Ping& msg);
|
void _SS_Ping(f8::MsgHdr& hdr, const ss::SS_Ping& msg);
|
||||||
|
|
||||||
void ___GSReport(f8::JsonHttpRequest* request);
|
|
||||||
void ___GSList(f8::JsonHttpRequest* request);
|
void ___GSList(f8::JsonHttpRequest* request);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SvrNode* GetNodeByTeamId(const std::string& team_id);
|
|
||||||
SvrNode* AllocNode();
|
SvrNode* AllocNode();
|
||||||
void RearrangeNode();
|
void RearrangeNode();
|
||||||
void ClearTimeOutNode();
|
void ClearTimeOutNode();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::map<std::string, SvrNode*> team_hash_;
|
|
||||||
std::map<std::string, SvrNode> node_key_hash_;
|
std::map<std::string, SvrNode> node_key_hash_;
|
||||||
std::vector<SvrNode*> node_sorted_list_;
|
std::vector<SvrNode*> node_sorted_list_;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user