1
This commit is contained in:
parent
0a640cd6a5
commit
4ebe45d2f1
@ -48,6 +48,7 @@ void HandlerMgr::RegisterNetMsgHandlers()
|
|||||||
RegisterNetMsgHandler(&ggmsghandler, &GGListener::_SS_Ping);
|
RegisterNetMsgHandler(&ggmsghandler, &GGListener::_SS_Ping);
|
||||||
|
|
||||||
RegisterNetMsgHandler(&immsghandler, &IMSMgr::_SS_Ping);
|
RegisterNetMsgHandler(&immsghandler, &IMSMgr::_SS_Ping);
|
||||||
|
RegisterNetMsgHandler(&immsghandler, &SvrMgr::_SS_IM_ReportServerInfo);
|
||||||
RegisterNetMsgHandler(&immsghandler, &CacheMgr::_SS_IM_UserOnline);
|
RegisterNetMsgHandler(&immsghandler, &CacheMgr::_SS_IM_UserOnline);
|
||||||
RegisterNetMsgHandler(&immsghandler, &CacheMgr::_SS_IM_UserOffline);
|
RegisterNetMsgHandler(&immsghandler, &CacheMgr::_SS_IM_UserOffline);
|
||||||
RegisterNetMsgHandler(&immsghandler, &CacheMgr::_SS_IM_PullUserList);
|
RegisterNetMsgHandler(&immsghandler, &CacheMgr::_SS_IM_PullUserList);
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "svrmgr.h"
|
#include "svrmgr.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "GGListener.h"
|
#include "GGListener.h"
|
||||||
|
#include "IMListener.h"
|
||||||
|
|
||||||
void SvrMgr::Init()
|
void SvrMgr::Init()
|
||||||
{
|
{
|
||||||
@ -38,6 +39,39 @@ void SvrMgr::_SS_WSP_RequestTargetServer(f8::MsgHdr& hdr, const ss::SS_WSP_Reque
|
|||||||
GGListener::Instance()->SendMsg(hdr.socket_handle, respmsg);
|
GGListener::Instance()->SendMsg(hdr.socket_handle, respmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SvrMgr::_SS_IM_ReportServerInfo(f8::MsgHdr& hdr, const ss::SS_IM_ReportServerInfo& msg)
|
||||||
|
{
|
||||||
|
std::string key = msg.ip() + ":" + a8::XValue(msg.port()).GetString();
|
||||||
|
|
||||||
|
auto itr = node_key_hash_.find(key);
|
||||||
|
if (itr != node_key_hash_.end()) {
|
||||||
|
if (itr->second.online_num != msg.online_num() ||
|
||||||
|
itr->second.servicing != msg.servicing()
|
||||||
|
) {
|
||||||
|
itr->second.online_num = msg.online_num();
|
||||||
|
itr->second.servicing = msg.servicing();
|
||||||
|
RearrangeNode();
|
||||||
|
}
|
||||||
|
itr->second.last_active_tick = a8::XGetTickCount();
|
||||||
|
} else {
|
||||||
|
SvrNode svr;
|
||||||
|
svr.key = key;
|
||||||
|
svr.node_idx = App::Instance()->NewUuid();
|
||||||
|
svr.instance_id = msg.instance_id();
|
||||||
|
svr.online_num = msg.online_num();
|
||||||
|
svr.ip = msg.ip();
|
||||||
|
svr.port = msg.port();
|
||||||
|
svr.servicing = msg.servicing();
|
||||||
|
svr.last_active_tick = a8::XGetTickCount();
|
||||||
|
node_key_hash_[key] = svr;
|
||||||
|
node_sorted_list_.push_back(&node_key_hash_[key]);
|
||||||
|
RearrangeNode();
|
||||||
|
}
|
||||||
|
|
||||||
|
ss::SS_MS_ConfirmedServerInfo respmsg;
|
||||||
|
IMListener::Instance()->SendMsg(hdr.socket_handle, respmsg);
|
||||||
|
}
|
||||||
|
|
||||||
void SvrMgr::___GSList(f8::JsonHttpRequest* request)
|
void SvrMgr::___GSList(f8::JsonHttpRequest* request)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@ -45,7 +79,6 @@ void SvrMgr::___GSList(f8::JsonHttpRequest* request)
|
|||||||
|
|
||||||
for (auto& pair : node_key_hash_) {
|
for (auto& pair : node_key_hash_) {
|
||||||
a8::MutableXObject* node = a8::MutableXObject::NewObject();
|
a8::MutableXObject* node = a8::MutableXObject::NewObject();
|
||||||
node->SetVal("node_id", pair.second.node_id);
|
|
||||||
node->SetVal("instance_id", pair.second.instance_id);
|
node->SetVal("instance_id", pair.second.instance_id);
|
||||||
node->SetVal("online_num", pair.second.online_num);
|
node->SetVal("online_num", pair.second.online_num);
|
||||||
node->SetVal("ip", pair.second.ip);
|
node->SetVal("ip", pair.second.ip);
|
||||||
@ -65,7 +98,6 @@ void SvrMgr::___GSList(f8::JsonHttpRequest* request)
|
|||||||
|
|
||||||
for (SvrNode* 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("instance_id", gs_node->instance_id);
|
node->SetVal("instance_id", gs_node->instance_id);
|
||||||
node->SetVal("online_num", gs_node->online_num);
|
node->SetVal("online_num", gs_node->online_num);
|
||||||
node->SetVal("ip", gs_node->ip);
|
node->SetVal("ip", gs_node->ip);
|
||||||
@ -135,7 +167,7 @@ void SvrMgr::ClearTimeOutNode()
|
|||||||
{
|
{
|
||||||
std::vector<SvrNode*> 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 * 3) {
|
||||||
time_out_nodes.push_back(&pair.second);
|
time_out_nodes.push_back(&pair.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ struct SvrNode
|
|||||||
{
|
{
|
||||||
std::string key;
|
std::string key;
|
||||||
long long node_idx = 0;
|
long long node_idx = 0;
|
||||||
int node_id = 0;
|
|
||||||
int instance_id = 0;
|
int instance_id = 0;
|
||||||
int online_num = 0;
|
int online_num = 0;
|
||||||
std::string ip;
|
std::string ip;
|
||||||
@ -30,6 +29,7 @@ class SvrMgr : public a8::Singleton<SvrMgr>
|
|||||||
void UnInit();
|
void UnInit();
|
||||||
|
|
||||||
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_IM_ReportServerInfo(f8::MsgHdr& hdr, const ss::SS_IM_ReportServerInfo& msg);
|
||||||
|
|
||||||
void ___GSList(f8::JsonHttpRequest* request);
|
void ___GSList(f8::JsonHttpRequest* request);
|
||||||
|
|
||||||
|
@ -132,6 +132,21 @@ message SS_MS_LoadGroup
|
|||||||
optional int64 group_id = 1;
|
optional int64 group_id = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message SS_IM_ReportServerInfo
|
||||||
|
{
|
||||||
|
optional int32 instance_id = 1;
|
||||||
|
optional int32 online_num = 2;
|
||||||
|
optional string ip = 3;
|
||||||
|
optional int32 port = 4;
|
||||||
|
optional bool servicing = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SS_MS_ConfirmedServerInfo
|
||||||
|
{
|
||||||
|
optional int32 errcode = 1;
|
||||||
|
optional string errmsg = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message SS_IM_UserOnline
|
message SS_IM_UserOnline
|
||||||
{
|
{
|
||||||
optional string account_id = 1;
|
optional string account_id = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user