From acb71d7e6248dff7162f4fad6740b95181a3814c Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 24 Aug 2020 21:01:09 +0800 Subject: [PATCH] 1 --- server/wsproxy/CMakeLists.txt | 10 ++++ server/wsproxy/GCListener.cc | 92 +++++++++++++++++++++++++++++---- server/wsproxy/GCListener.h | 16 ++++++ server/wsproxy/app.cc | 19 ++++--- server/wsproxy/constant.h | 5 +- server/wsproxy/gameclientmgr.cc | 10 ++-- server/wsproxy/gameclientmgr.h | 2 +- server/wsproxy/handlermgr.cc | 6 +++ server/wsproxy/handlermgr.h | 1 + server/wsproxy/mastersvrmgr.cc | 18 +++++++ server/wsproxy/mastersvrmgr.h | 2 + third_party/a8engine | 2 +- third_party/framework | 2 +- 13 files changed, 155 insertions(+), 30 deletions(-) diff --git a/server/wsproxy/CMakeLists.txt b/server/wsproxy/CMakeLists.txt index 536a6fa..ead666c 100644 --- a/server/wsproxy/CMakeLists.txt +++ b/server/wsproxy/CMakeLists.txt @@ -42,6 +42,8 @@ include_directories( /usr/include/glm ../../third_party ../../third_party/behaviac/inc + ../../third_party/recastnavigation/Recast/Include + ../../third_party/recastnavigation/Detour/Include ../../third_party/recastnavigation/Detour/Include ../../third_party/recastnavigation/DetourTileCache/Include . @@ -61,6 +63,14 @@ aux_source_directory(../../third_party/framework/cpp SRC_LIST ) +aux_source_directory(../../third_party/recastnavigation/Recast/Source + SRC_LIST +) + +aux_source_directory(../../third_party/recastnavigation/RecastDemo/Contrib/fastlz + SRC_LIST +) + aux_source_directory(../../third_party/recastnavigation/Detour/Source SRC_LIST ) diff --git a/server/wsproxy/GCListener.cc b/server/wsproxy/GCListener.cc index 7ae6e92..ebd7ada 100644 --- a/server/wsproxy/GCListener.cc +++ b/server/wsproxy/GCListener.cc @@ -5,12 +5,18 @@ #include #include "framework/cpp/netmsghandler.h" +#include "framework/cpp/im_msgid.pb.h" +#include "framework/cpp/im_proto.pb.h" #include "app.h" #include "GCListener.h" #include "jsondatamgr.h" #include "ss_proto.pb.h" #include "handlermgr.h" +#include "gameclientmgr.h" +#if MASTER_MODE +#include "mastersvrmgr.h" +#endif class GCClientSession: public a8::WebSocketSession { @@ -27,13 +33,15 @@ public: if (buflen - offset < sizeof(f8::PackHead) + p->packlen) { break; } - App::Instance()->AddSocketMsg(SF_Client, - socket_handle, - saddr, - p->msgid, - p->seqid, - &buf[offset + sizeof(f8::PackHead)], - p->packlen); + if (p->msgid > im::MaxIMMsgId) { + App::Instance()->AddSocketMsg(SF_Client, + socket_handle, + saddr, + p->msgid, + p->seqid, + &buf[offset + sizeof(f8::PackHead)], + p->packlen); + } offset += sizeof(f8::PackHead) + p->packlen; } else { warning = true; @@ -61,6 +69,20 @@ public: virtual bool HandleRedirect(const std::string& url, const std::string& querystr, std::string& location) override { + im::IMSocketConnect msg; + msg.set_is_websocket(true); + msg.set_url(url); + msg.set_query_str(querystr); + + std::string data; + msg.SerializeToString(&data); + App::Instance()->AddSocketMsg(SF_Client, + socket_handle, + saddr, + im::_IMSocketConnect, + 0, + data.data(), + data.size()); #if MASTER_MODE a8::HTTPRequest request; a8::ParserUrlQueryString(querystr.c_str(), request); @@ -90,10 +112,16 @@ public: virtual void OnDisConnect() override { - App::Instance()->AddIMMsg(IM_ClientSocketDisconnect, - a8::XParams() - .SetSender(socket_handle) - .SetParam1(1)); + im::IMSocketDisconnect msg; + std::string data; + msg.SerializeToString(&data); + App::Instance()->AddSocketMsg(SF_Client, + socket_handle, + saddr, + im::_IMSocketDisconnect, + 0, + data.data(), + data.size()); } }; @@ -125,6 +153,36 @@ void GCListener::UnInit() tcp_listener_ = nullptr; } +void GCListener::_F8_IMSocketConnect(f8::MsgHdr& hdr, const im::IMSocketConnect& msg) +{ + if (msg.url().size() > 1024) { + a8::UdpLog::Instance()->Warning("websokcet connect url to long %s %s", + { + msg.url(), + msg.query_str() + }); + return; + } + if (msg.query_str().size() > 1024) { + a8::UdpLog::Instance()->Warning("websokcet connect query_str to long %s %s", + { + msg.url(), + msg.query_str() + }); + return; + } + websocket_url_hash_[hdr.socket_handle] = std::make_tuple(msg.url(), msg.query_str()); +} + +void GCListener::_F8_IMSocketDisconnect(f8::MsgHdr& hdr, const im::IMSocketDisconnect& msg) +{ + GameClientMgr::Instance()->OnClientDisconnect(hdr.socket_handle); +#if MASTER_MODE + MasterSvrMgr::Instance()->RemoveRequestBySocketHandle(hdr.socket_handle, true); +#endif + websocket_url_hash_.erase(hdr.socket_handle); +} + void GCListener::ForwardTargetConnMsg(f8::MsgHdr& hdr) { char* buff = (char*)malloc(sizeof(f8::PackHead) + hdr.buflen); @@ -166,3 +224,15 @@ long long GCListener::GetSentBytesNum() { return tcp_listener_->sent_bytes_num; } + +bool GCListener::GetWebSocketUrl(int socket_handle, std::string& url, std::string& query_str) +{ + auto itr = websocket_url_hash_.find(socket_handle); + if (itr != websocket_url_hash_.end()) { + url = std::get<0>(itr->second); + query_str = std::get<1>(itr->second); + return true; + } else { + return false; + } +} diff --git a/server/wsproxy/GCListener.h b/server/wsproxy/GCListener.h index 962c333..e6f4ff6 100644 --- a/server/wsproxy/GCListener.h +++ b/server/wsproxy/GCListener.h @@ -6,6 +6,17 @@ namespace a8 class TcpListener; } +namespace f8 +{ + struct MsgHdr; +} + +namespace im +{ + class IMSocketConnect; + class IMSocketDisconnect; +} + class GCListener : public a8::Singleton { private: @@ -26,6 +37,9 @@ class GCListener : public a8::Singleton f8::Net_SendMsg(tcp_listener_, socket_handle, 0, msgid, msg); } + void _F8_IMSocketConnect(f8::MsgHdr& hdr, const im::IMSocketConnect& msg); + void _F8_IMSocketDisconnect(f8::MsgHdr& hdr, const im::IMSocketDisconnect& msg); + void ForwardTargetConnMsg(f8::MsgHdr& hdr); void SendText(unsigned short sockhandle, const std::string& text); @@ -33,7 +47,9 @@ class GCListener : public a8::Singleton void MarkClient(unsigned short sockhandle, bool is_active); long long GetSendNodeNum(); long long GetSentBytesNum(); + bool GetWebSocketUrl(int socket_handle, std::string& url, std::string& query_str); private: + std::map> websocket_url_hash_; a8::TcpListener *tcp_listener_ = nullptr; }; diff --git a/server/wsproxy/app.cc b/server/wsproxy/app.cc index 2a5107e..99cfa25 100644 --- a/server/wsproxy/app.cc +++ b/server/wsproxy/app.cc @@ -419,6 +419,15 @@ void App::DispatchMsg() void App::ProcessClientMsg(f8::MsgHdr& hdr) { if (hdr.msgid < 100) { + f8::NetMsgHandler* handler = f8::GetNetMsgHandler(&HandlerMgr::Instance()->immsghandler, + hdr.msgid); + if (handler) { + switch (handler->handlerid) { + case HID_GCListener: + ProcessNetMsg(handler, GCListener::Instance(), hdr); + break; + } + } return; } #if MASTER_MODE @@ -434,6 +443,7 @@ void App::ProcessClientMsg(f8::MsgHdr& hdr) MasterSvrMgr::Instance()->RequestTargetServer(hdr, msg.team_uuid(), msg.account_id(), + msg.session_id(), "", 0, msg.proto_version()); @@ -448,6 +458,7 @@ void App::ProcessClientMsg(f8::MsgHdr& hdr) MasterSvrMgr::Instance()->RequestTargetServer(hdr, msg.team_uuid(), msg.account_id(), + msg.session_id(), msg.server_info(), 1, 0); @@ -541,14 +552,6 @@ void App::ProcessIMMsg() while (im_work_node_) { IMMsgNode *pdelnode = im_work_node_; switch (im_work_node_->msgid) { - case IM_ClientSocketDisconnect: - { - GameClientMgr::Instance()->OnClientDisconnect(pdelnode->params); -#if MASTER_MODE - MasterSvrMgr::Instance()->RemoveRequest(pdelnode->params.param1, pdelnode->params.sender, true); -#endif - } - break; case IM_TargetConnConnect: { GameClientMgr::Instance()->OnTargetServerConnect(pdelnode->params); diff --git a/server/wsproxy/constant.h b/server/wsproxy/constant.h index 3165ef0..a4b2516 100644 --- a/server/wsproxy/constant.h +++ b/server/wsproxy/constant.h @@ -1,4 +1,4 @@ -#pragma once + #pragma once enum SocketFrom_e { @@ -9,8 +9,7 @@ enum SocketFrom_e enum InnerMesssage_e { - IM_ClientSocketDisconnect = 100, - IM_PlayerOffline, + IM_PlayerOffline = 100, IM_ExecGM, IM_TargetConnDisconnect, IM_MasterSvrDisconnect, diff --git a/server/wsproxy/gameclientmgr.cc b/server/wsproxy/gameclientmgr.cc index 340caa9..a1c4c9a 100644 --- a/server/wsproxy/gameclientmgr.cc +++ b/server/wsproxy/gameclientmgr.cc @@ -22,18 +22,18 @@ void GameClientMgr::UnInit() pending_account_hash_.clear(); } -void GameClientMgr::OnClientDisconnect(a8::XParams& param) +void GameClientMgr::OnClientDisconnect(int socket_handle) { - GameClient* client = GetGameClientBySocket(param.sender); + GameClient* client = GetGameClientBySocket(socket_handle); if (client) { if (client->conn) { ss::SS_WSP_SocketDisconnect msg; - client->conn->SendMsg(param.sender, msg); + client->conn->SendMsg(socket_handle, msg); } - socket_hash_.erase(param.sender); + socket_hash_.erase(socket_handle); delete client; } - RemovePendingAccount(param.sender); + RemovePendingAccount(socket_handle); } void GameClientMgr::OnTargetServerDisconnect(a8::XParams& param) diff --git a/server/wsproxy/gameclientmgr.h b/server/wsproxy/gameclientmgr.h index 6144316..b272bf3 100644 --- a/server/wsproxy/gameclientmgr.h +++ b/server/wsproxy/gameclientmgr.h @@ -14,7 +14,7 @@ class GameClientMgr : public a8::Singleton void Init(); void UnInit(); - void OnClientDisconnect(a8::XParams& param); + void OnClientDisconnect(int socket_handle); void OnTargetServerDisconnect(a8::XParams& param); void OnTargetServerConnect(a8::XParams& param); GameClient* GetGameClientBySocket(int sockhande); diff --git a/server/wsproxy/handlermgr.cc b/server/wsproxy/handlermgr.cc index 2be6d42..8d15413 100644 --- a/server/wsproxy/handlermgr.cc +++ b/server/wsproxy/handlermgr.cc @@ -10,6 +10,9 @@ #include "ss_proto.pb.h" +#include "framework/cpp/im_msgid.pb.h" +#include "framework/cpp/im_proto.pb.h" + static void _GMOpsSelfChecking(f8::JsonHttpRequest* request) { request->resp_xobj->SetVal("errcode", 0); @@ -38,6 +41,9 @@ void HandlerMgr::UnInit() void HandlerMgr::RegisterNetMsgHandlers() { + RegisterNetMsgHandler(&immsghandler, &GCListener::_F8_IMSocketConnect); + RegisterNetMsgHandler(&immsghandler, &GCListener::_F8_IMSocketDisconnect); + RegisterNetMsgHandler(&msmsghandler, &MasterSvrMgr::_SS_MS_ResponseTargetServer); } diff --git a/server/wsproxy/handlermgr.h b/server/wsproxy/handlermgr.h index 6f5fab6..3197b0d 100644 --- a/server/wsproxy/handlermgr.h +++ b/server/wsproxy/handlermgr.h @@ -21,6 +21,7 @@ class HandlerMgr : public a8::Singleton void Init(); void UnInit(); + f8::NetMsgHandlerObject immsghandler; f8::NetMsgHandlerObject gcmsghandler; f8::NetMsgHandlerObject msmsghandler; diff --git a/server/wsproxy/mastersvrmgr.cc b/server/wsproxy/mastersvrmgr.cc index 0930318..56ca365 100644 --- a/server/wsproxy/mastersvrmgr.cc +++ b/server/wsproxy/mastersvrmgr.cc @@ -13,6 +13,7 @@ #include "target_conn_mgr.h" #include "app.h" #include "gameclientmgr.h" +#include "GCListener.h" #include "framework/cpp/netmsghandler.h" @@ -71,6 +72,7 @@ MasterSvr* MasterSvrMgr::GetConnById(int instance_id) void MasterSvrMgr::RequestTargetServer(f8::MsgHdr& hdr, const std::string& team_id, const std::string& account_id, + const std::string& session_id, const std::string& server_info, int is_reconnect, int proto_version) @@ -118,10 +120,18 @@ void MasterSvrMgr::RequestTargetServer(f8::MsgHdr& hdr, ss::SS_WSP_RequestTargetServer msg; msg.set_context_id(curr_context_id_); msg.set_account_id(account_id); + msg.set_session_id(session_id); msg.set_team_id(team_uuid); msg.set_server_info(server_info); msg.set_is_reconnect(is_reconnect); msg.set_proto_version(proto_version); + std::string url; + std::string query_str; + { + GCListener::Instance()->GetWebSocketUrl(hdr.socket_handle, url, query_str); + } + msg.set_url(url); + msg.set_query_str(query_str); svr->SendMsg(msg); pending_socket_hash_[hdr.socket_handle] = curr_context_id_; @@ -195,6 +205,14 @@ void MasterSvrMgr::RemoveRequest(int socket_handle, long long context_id, bool a } } +void MasterSvrMgr::RemoveRequestBySocketHandle(int socket_handle, bool auto_free) +{ + long long context_id = GetContextIdBySocket(socket_handle); + if (context_id != 0) { + RemoveRequest(socket_handle, context_id, auto_free); + } +} + long long MasterSvrMgr::GetContextIdBySocket(int socket_handle) { auto itr = pending_socket_hash_.find(socket_handle); diff --git a/server/wsproxy/mastersvrmgr.h b/server/wsproxy/mastersvrmgr.h index 6588771..4c8cda2 100644 --- a/server/wsproxy/mastersvrmgr.h +++ b/server/wsproxy/mastersvrmgr.h @@ -29,10 +29,12 @@ class MasterSvrMgr : public a8::Singleton void RequestTargetServer(f8::MsgHdr& hdr, const std::string& team_id, const std::string& account_id, + const std::string& session_id, const std::string& server_info, int is_reconnect, int proto_version); void RemoveRequest(int socket_handle, long long context_id, bool auto_free); + void RemoveRequestBySocketHandle(int socket_handle, bool auto_free); private: long long GetContextIdBySocket(int socket_handle); diff --git a/third_party/a8engine b/third_party/a8engine index a369c48..a25550d 160000 --- a/third_party/a8engine +++ b/third_party/a8engine @@ -1 +1 @@ -Subproject commit a369c484113b240f042c62cba80afd26df91e4ca +Subproject commit a25550d418277048506bb2815a192e15802dd19e diff --git a/third_party/framework b/third_party/framework index 9ba2696..4523d88 160000 --- a/third_party/framework +++ b/third_party/framework @@ -1 +1 @@ -Subproject commit 9ba2696e52664c9f5b7a1e09a4a5516359d330b0 +Subproject commit 4523d8845cbf2098d8b8274e5cbe976cc639c78a