1
This commit is contained in:
parent
d20e2dcf5a
commit
42ca63e9a2
@ -14,7 +14,7 @@
|
||||
|
||||
#include "ss_proto.pb.h"
|
||||
|
||||
static void _GMOpsSelfChecking(std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
static void _GMOpsSelfChecking(int socket_handle, std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
{
|
||||
request->GetResp()->SetVal("errcode", 0);
|
||||
request->GetResp()->SetVal("errmsg", "");
|
||||
@ -22,14 +22,14 @@ static void _GMOpsSelfChecking(std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
request->GetResp()->SetVal("max_rundelay", 10);
|
||||
}
|
||||
|
||||
static void _GMOpsGetNodeId(std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
static void _GMOpsGetNodeId(int socket_handle, std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
{
|
||||
request->GetResp()->SetVal("errcode", 0);
|
||||
request->GetResp()->SetVal("errmsg", "");
|
||||
request->GetResp()->SetVal("node_id", f8::App::Instance()->GetNodeId());
|
||||
}
|
||||
|
||||
static void _GMOpsSetKcpSwitch(std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
static void _GMOpsSetKcpSwitch(int socket_handle, std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
{
|
||||
request->GetResp()->SetVal("errcode", 0);
|
||||
request->GetResp()->SetVal("errmsg", "");
|
||||
@ -39,13 +39,23 @@ static void _GMOpsSetKcpSwitch(std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
request->GetResp()->SetVal("is_open", JsonDataMgr::Instance()->GetKcpConf().open);
|
||||
}
|
||||
|
||||
static void _GMOpsGetKcpSwitch(std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
static void _GMOpsGetKcpSwitch(int socket_handle, std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
{
|
||||
request->GetResp()->SetVal("errcode", 0);
|
||||
request->GetResp()->SetVal("errmsg", "");
|
||||
request->GetResp()->SetVal("is_open", JsonDataMgr::Instance()->GetKcpConf().open);
|
||||
}
|
||||
|
||||
static void _GMHttpTunnelTeamRequest(int socket_handle, std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
{
|
||||
MasterMgr::Instance()->AddHttpTunnelRequest(socket_handle, request);
|
||||
}
|
||||
|
||||
static void _GMHttpTunnelOnlineTeamRequest(int socket_handle, std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
{
|
||||
MasterMgr::Instance()->AddHttpTunnelRequest(socket_handle, request);
|
||||
}
|
||||
|
||||
void HandlerMgr::Init()
|
||||
{
|
||||
RegisterNetMsgHandlers();
|
||||
@ -53,6 +63,8 @@ void HandlerMgr::Init()
|
||||
RegisterGMMsgHandler("Ops$getNodeId", _GMOpsGetNodeId);
|
||||
RegisterGMMsgHandler("Ops$setKcpSwitch", _GMOpsSetKcpSwitch);
|
||||
RegisterGMMsgHandler("Ops$getKcpSwitch", _GMOpsGetKcpSwitch);
|
||||
RegisterGMMsgHandler("HttpTunnel$teamRequest", _GMHttpTunnelTeamRequest);
|
||||
RegisterGMMsgHandler("HttpTunnel$onlineTeamRequest", _GMHttpTunnelOnlineTeamRequest);
|
||||
f8::MsgQueue::Instance()->RegisterCallBack
|
||||
(
|
||||
IM_ExecGM,
|
||||
@ -99,14 +111,14 @@ void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle,
|
||||
std::string data = args.Get<std::string>(0);
|
||||
GCListener::Instance()->SendText(sockhandle, data);
|
||||
});
|
||||
itr->second(request);
|
||||
itr->second(sockhandle, request);
|
||||
} else {
|
||||
GCListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}"));
|
||||
}
|
||||
}
|
||||
|
||||
void HandlerMgr::RegisterGMMsgHandler(const std::string& msgname,
|
||||
void (*handler)(std::shared_ptr<f8::JsonHttpRequest>))
|
||||
void (*handler)(int, std::shared_ptr<f8::JsonHttpRequest>))
|
||||
{
|
||||
gmhandlers_[msgname] = handler;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class HandlerMgr : public a8::Singleton<HandlerMgr>
|
||||
private:
|
||||
void RegisterNetMsgHandlers();
|
||||
void RegisterGMMsgHandler(const std::string& msgname,
|
||||
void (*)(std::shared_ptr<f8::JsonHttpRequest>));
|
||||
void (*)(int, std::shared_ptr<f8::JsonHttpRequest>));
|
||||
|
||||
std::map<std::string, void (*)(std::shared_ptr<f8::JsonHttpRequest>)> gmhandlers_;
|
||||
std::map<std::string, void (*)(int, std::shared_ptr<f8::JsonHttpRequest>)> gmhandlers_;
|
||||
};
|
||||
|
@ -198,6 +198,7 @@ void MasterMgr::RequestTargetServer(f8::MsgHdr* hdr,
|
||||
}
|
||||
|
||||
void MasterMgr::RemoveRequest(int socket_handle)
|
||||
{
|
||||
{
|
||||
auto req = GetRequestBySocket(socket_handle);
|
||||
if (req) {
|
||||
@ -209,6 +210,10 @@ void MasterMgr::RemoveRequest(int socket_handle)
|
||||
pending_socket_hash_.erase(socket_handle);
|
||||
}
|
||||
}
|
||||
{
|
||||
RemoveHttpTunnelRequest(socket_handle);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<RequestTarget> MasterMgr::GetRequestBySocket(int socket_handle)
|
||||
{
|
||||
@ -221,3 +226,22 @@ std::shared_ptr<RequestTarget> MasterMgr::GetRequestByContextId(long long contex
|
||||
auto itr = pending_context_hash_.find(context_id);
|
||||
return itr != pending_context_hash_.end() ? itr->second : nullptr;
|
||||
}
|
||||
|
||||
void MasterMgr::AddHttpTunnelRequest(int socket_handle, std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
{
|
||||
pending_http_tunnel_hash_[socket_handle] = request;
|
||||
}
|
||||
|
||||
void MasterMgr::RemoveHttpTunnelRequest(int socket_handle)
|
||||
{
|
||||
auto req = GetHttpTunnelRequest(socket_handle);
|
||||
if (req) {
|
||||
pending_http_tunnel_hash_.end();
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<f8::JsonHttpRequest> MasterMgr::GetHttpTunnelRequest(int socket_handle)
|
||||
{
|
||||
auto itr = pending_http_tunnel_hash_.find(socket_handle);
|
||||
return itr != pending_http_tunnel_hash_.end() ? itr->second : nullptr;
|
||||
}
|
||||
|
@ -35,8 +35,11 @@ class MasterMgr : public a8::Singleton<MasterMgr>
|
||||
int is_reconnect,
|
||||
int proto_version);
|
||||
void RemoveRequest(int socket_handle);
|
||||
void AddHttpTunnelRequest(int socket_handle, std::shared_ptr<f8::JsonHttpRequest> request);
|
||||
void RemoveHttpTunnelRequest(int socket_handle);
|
||||
|
||||
private:
|
||||
std::shared_ptr<f8::JsonHttpRequest> GetHttpTunnelRequest(int socket_handle);
|
||||
std::shared_ptr<RequestTarget> GetRequestBySocket(int socket_handle);
|
||||
std::shared_ptr<RequestTarget> GetRequestByContextId(long long context_id);
|
||||
std::shared_ptr<Master> GetConnById(int instance_id);
|
||||
@ -46,5 +49,5 @@ class MasterMgr : public a8::Singleton<MasterMgr>
|
||||
std::map<int, std::shared_ptr<Master>> mastersvr_hash_;
|
||||
std::map<int, std::shared_ptr<RequestTarget>> pending_socket_hash_;
|
||||
std::map<long long, std::shared_ptr<RequestTarget>> pending_context_hash_;
|
||||
|
||||
std::map<int, std::shared_ptr<f8::JsonHttpRequest>> pending_http_tunnel_hash_;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user