1
This commit is contained in:
parent
b1e5346fbb
commit
c68363b07b
@ -383,6 +383,11 @@ void App::ProcessIMMsg()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case IM_IMSSocketDisconnect:
|
||||||
|
{
|
||||||
|
SvrMgr::Instance()->OnIMServerDisconnect(pdelnode->params);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case IM_ExecGM:
|
case IM_ExecGM:
|
||||||
{
|
{
|
||||||
HandlerMgr::Instance()->ProcGMMsg(pdelnode->params.param3,
|
HandlerMgr::Instance()->ProcGMMsg(pdelnode->params.param3,
|
||||||
|
@ -31,3 +31,9 @@ void CacheMgr::_SS_IM_IMServerList(f8::MsgHdr& hdr, const ss::SS_IM_IMServerList
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Friend* CacheMgr::GetFriendData(const std::string& account_id)
|
||||||
|
{
|
||||||
|
auto itr = friend_hash_.find(account_id);
|
||||||
|
return itr != friend_hash_.end() ? itr->second : nullptr;
|
||||||
|
}
|
||||||
|
@ -21,8 +21,9 @@ class CacheMgr : public a8::Singleton<CacheMgr>
|
|||||||
void _SS_IM_PullUserList(f8::MsgHdr& hdr, const ss::SS_IM_PullUserList& msg);
|
void _SS_IM_PullUserList(f8::MsgHdr& hdr, const ss::SS_IM_PullUserList& msg);
|
||||||
void _SS_IM_IMServerList(f8::MsgHdr& hdr, const ss::SS_IM_IMServerList& msg);
|
void _SS_IM_IMServerList(f8::MsgHdr& hdr, const ss::SS_IM_IMServerList& msg);
|
||||||
|
|
||||||
private:
|
Friend* GetFriendData(const std::string& account_id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
std::map<std::string, Friend*> friend_hash_;
|
||||||
};
|
};
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "GGListener.h"
|
#include "GGListener.h"
|
||||||
#include "IMListener.h"
|
#include "IMListener.h"
|
||||||
|
#include "cachemgr.h"
|
||||||
|
|
||||||
void SvrMgr::Init()
|
void SvrMgr::Init()
|
||||||
{
|
{
|
||||||
@ -29,7 +30,7 @@ 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 = AllocNode();
|
SvrNode* node = AllocNode(msg.account_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);
|
||||||
@ -43,10 +44,25 @@ void SvrMgr::_SS_WSP_RequestTargetServer(f8::MsgHdr& hdr, const ss::SS_WSP_Reque
|
|||||||
void SvrMgr::_SS_IM_ReportServerInfo(f8::MsgHdr& hdr, const ss::SS_IM_ReportServerInfo& msg)
|
void SvrMgr::_SS_IM_ReportServerInfo(f8::MsgHdr& hdr, const ss::SS_IM_ReportServerInfo& msg)
|
||||||
{
|
{
|
||||||
SvrNode* svr = GetNodeBySocket(hdr.socket_handle);
|
SvrNode* svr = GetNodeBySocket(hdr.socket_handle);
|
||||||
std::string key = msg.ip() + ":" + a8::XValue(msg.port()).GetString();
|
|
||||||
|
|
||||||
svr = GetNodeByKey(key);
|
|
||||||
if (svr) {
|
if (svr) {
|
||||||
|
if (svr->instance_id != msg.instance_id() ||
|
||||||
|
svr->ip != msg.ip() ||
|
||||||
|
svr->port != msg.port()
|
||||||
|
) {
|
||||||
|
a8::UdpLog::Instance()->Warning
|
||||||
|
(
|
||||||
|
"serverA %s:%d-%d serverB %s:%d-%d",
|
||||||
|
{
|
||||||
|
svr->ip,
|
||||||
|
svr->port,
|
||||||
|
svr->instance_id,
|
||||||
|
msg.ip(),
|
||||||
|
msg.port(),
|
||||||
|
msg.instance_id()
|
||||||
|
});
|
||||||
|
IMListener::Instance()->ForceCloseClient(hdr.socket_handle);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (svr->online_num != msg.online_num() ||
|
if (svr->online_num != msg.online_num() ||
|
||||||
svr->servicing != msg.servicing()
|
svr->servicing != msg.servicing()
|
||||||
) {
|
) {
|
||||||
@ -55,17 +71,19 @@ void SvrMgr::_SS_IM_ReportServerInfo(f8::MsgHdr& hdr, const ss::SS_IM_ReportServ
|
|||||||
RearrangeNode();
|
RearrangeNode();
|
||||||
}
|
}
|
||||||
svr->last_active_tick = a8::XGetTickCount();
|
svr->last_active_tick = a8::XGetTickCount();
|
||||||
if (svr->instance_id != msg.instance_id()) {
|
} else {
|
||||||
|
std::string key = msg.ip() + ":" + a8::XValue(msg.port()).GetString();
|
||||||
|
if (GetNodeByKey(key)) {
|
||||||
a8::UdpLog::Instance()->Warning
|
a8::UdpLog::Instance()->Warning
|
||||||
(
|
(
|
||||||
"report server info %s %d %d",
|
"server %s:%d registered",
|
||||||
{
|
{
|
||||||
key,
|
msg.ip(),
|
||||||
svr->instance_id,
|
msg.port()
|
||||||
msg.instance_id()
|
|
||||||
});
|
});
|
||||||
|
IMListener::Instance()->ForceCloseClient(hdr.socket_handle);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
svr = new SvrNode;
|
svr = new SvrNode;
|
||||||
svr->socket_handle = hdr.socket_handle;
|
svr->socket_handle = hdr.socket_handle;
|
||||||
svr->key = key;
|
svr->key = key;
|
||||||
@ -128,8 +146,21 @@ void SvrMgr::___GSList(f8::JsonHttpRequest* request)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SvrNode* SvrMgr::AllocNode()
|
void SvrMgr::OnIMServerDisconnect(a8::XParams& param)
|
||||||
{
|
{
|
||||||
|
SvrNode* svr = GetNodeBySocket(param.sender);
|
||||||
|
if (svr) {
|
||||||
|
RemoveNode(svr);
|
||||||
|
RearrangeNode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SvrNode* SvrMgr::AllocNode(const std::string& account_id)
|
||||||
|
{
|
||||||
|
Friend* friend_data = CacheMgr::Instance()->GetFriendData(account_id);
|
||||||
|
if (friend_data && friend_data->svr_node) {
|
||||||
|
return friend_data->svr_node;
|
||||||
|
}
|
||||||
if (node_sorted_list_.empty()) {
|
if (node_sorted_list_.empty()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -186,17 +217,7 @@ void SvrMgr::ClearTimeOutNode()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (SvrNode* node : time_out_nodes) {
|
for (SvrNode* node : time_out_nodes) {
|
||||||
{
|
RemoveNode(node);
|
||||||
for (size_t i = 0; i < node_sorted_list_.size(); ++i) {
|
|
||||||
if (node_sorted_list_[i] == node) {
|
|
||||||
node_sorted_list_.erase(node_sorted_list_.begin() + i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
node_key_hash_.erase(node->key);
|
|
||||||
socket_hash_.erase(node->socket_handle);
|
|
||||||
delete node;
|
|
||||||
}
|
}
|
||||||
RearrangeNode();
|
RearrangeNode();
|
||||||
}
|
}
|
||||||
@ -212,3 +233,20 @@ SvrNode* SvrMgr::GetNodeBySocket(int socket_handle)
|
|||||||
auto itr = socket_hash_.find(socket_handle);
|
auto itr = socket_hash_.find(socket_handle);
|
||||||
return itr != socket_hash_.end() ? itr->second : nullptr;
|
return itr != socket_hash_.end() ? itr->second : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SvrMgr::RemoveNode(SvrNode* node)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < node_sorted_list_.size(); ++i) {
|
||||||
|
if (node_sorted_list_[i] == node) {
|
||||||
|
node_sorted_list_.erase(node_sorted_list_.begin() + i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
node_key_hash_.erase(node->key);
|
||||||
|
socket_hash_.erase(node->socket_handle);
|
||||||
|
}
|
||||||
|
delete node;
|
||||||
|
}
|
||||||
|
@ -41,12 +41,15 @@ class SvrMgr : public a8::Singleton<SvrMgr>
|
|||||||
|
|
||||||
void ___GSList(f8::JsonHttpRequest* request);
|
void ___GSList(f8::JsonHttpRequest* request);
|
||||||
|
|
||||||
|
void OnIMServerDisconnect(a8::XParams& param);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SvrNode* AllocNode();
|
SvrNode* AllocNode(const std::string& account_id);
|
||||||
void RearrangeNode();
|
void RearrangeNode();
|
||||||
void ClearTimeOutNode();
|
void ClearTimeOutNode();
|
||||||
SvrNode* GetNodeByKey(const std::string& key);
|
SvrNode* GetNodeByKey(const std::string& key);
|
||||||
SvrNode* GetNodeBySocket(int socket_handle);
|
SvrNode* GetNodeBySocket(int socket_handle);
|
||||||
|
void RemoveNode(SvrNode* node);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user