diff --git a/server/gameserver/app.cc b/server/gameserver/app.cc index af250ee..a636a0a 100755 --- a/server/gameserver/app.cc +++ b/server/gameserver/app.cc @@ -347,19 +347,12 @@ void App::ProcessGameGateMsg(f8::MsgHdr& hdr) hdr.msgid); if (handler) { switch (handler->handlerid) { - case HID_GGListener: - #if 0 - ProcessNetMsg(handler, GGListener::Instance(), hdr); - #endif - break; - case HID_PlayerMgr: - #if 0 - ProcessNetMsg(handler, PlayerMgr::Instance(), hdr); - #endif - break; case HID_RoomMgr: ProcessNetMsg(handler, RoomMgr::Instance(), hdr); break; + case HID_PlayerMgr: + ProcessNetMsg(handler, PlayerMgr::Instance(), hdr); + break; case HID_Player: { Player* hum = PlayerMgr::Instance()->GetPlayerBySocket(hdr.socket_handle); @@ -396,9 +389,7 @@ void App::ProcessIMMsg() break; case IM_ClientSocketDisconnect: { - #if 0 PlayerMgr::Instance()->OnClientDisconnect(pdelnode->params); - #endif } break; case IM_ExecGM: diff --git a/server/gameserver/handlermgr.cc b/server/gameserver/handlermgr.cc index d829c81..043bd6e 100644 --- a/server/gameserver/handlermgr.cc +++ b/server/gameserver/handlermgr.cc @@ -8,8 +8,10 @@ #include "metamgr.h" #include "app.h" #include "player.h" +#include "playermgr.h" #include "roommgr.h" #include "cs_proto.pb.h" +#include "ss_proto.pb.h" static void _GMOpsSelfChecking(f8::JsonHttpRequest* request) { @@ -42,7 +44,7 @@ void HandlerMgr::UnInit() void HandlerMgr::RegisterNetMsgHandlers() { - //RegisterNetMsgHandler(&ggmsghandler, &PlayerMgr::_SS_WSP_SocketDisconnect); + RegisterNetMsgHandler(&ggmsghandler, &PlayerMgr::_SS_WSP_SocketDisconnect); RegisterNetMsgHandler(&ggmsghandler, &RoomMgr::_CMJoin); RegisterNetMsgHandler(&ggmsghandler, &Player::_CMMove); diff --git a/server/gameserver/handlermgr.h b/server/gameserver/handlermgr.h index bcbbdd8..2bf21b8 100644 --- a/server/gameserver/handlermgr.h +++ b/server/gameserver/handlermgr.h @@ -22,9 +22,6 @@ class HandlerMgr : public a8::Singleton void UnInit(); f8::NetMsgHandlerObject ggmsghandler; - f8::NetMsgHandlerObject dbmsghandler; - f8::NetMsgHandlerObject dpmsghandler; - f8::NetMsgHandlerObject bsmsghandler; void ProcGMMsg(unsigned long saddr, int sockhandle, const std::string& url, const std::string& quyerstr); diff --git a/server/gameserver/jsondatamgr.cc b/server/gameserver/jsondatamgr.cc index 6ee9dfd..c6c23bc 100644 --- a/server/gameserver/jsondatamgr.cc +++ b/server/gameserver/jsondatamgr.cc @@ -8,6 +8,7 @@ void JsonDataMgr::Init() { std::string gameserver_cluster_json_file; + std::string masterserver_cluster_json_file; if (!f8::IsOnlineEnv()) { if (App::Instance()->flags.find(2) != App::Instance()->flags.end()) { gameserver_cluster_json_file = a8::Format("/root/pub/%d/%d/conf_test/game%d/gameserver/" @@ -18,15 +19,30 @@ void JsonDataMgr::Init() GAME_ID, GAME_ID }); + masterserver_cluster_json_file = a8::Format("/root/pub/%d/%d/conf_test/game%d/masterserver/" + "game%d.masterserver.cluster.json", + { + GAME_ID, + App::Instance()->instance_id, + GAME_ID, + GAME_ID + }); } else { gameserver_cluster_json_file = a8::Format("/var/data/conf_test/game%d/gameserver/" "game%d.gameserver.cluster.json", {GAME_ID, GAME_ID}); + masterserver_cluster_json_file = a8::Format("/var/data/conf_test/game%d/mastererver/" + "game%d.masterserver.cluster.json", + {GAME_ID, GAME_ID}); } } else { gameserver_cluster_json_file = a8::Format("../config/game%d.gameserver.cluster.json", {GAME_ID}); + masterserver_cluster_json_file = a8::Format("../config/game%d.masterserver.cluster.json", {GAME_ID}); } gameserver_cluster_json_.ReadFromFile(gameserver_cluster_json_file); + masterserver_cluster_json_.ReadFromFile(masterserver_cluster_json_file); + ip = GetConf()->At("ip")->AsXValue().GetString(); + listen_port = GetConf()->At("listen_port")->AsXValue(); } void JsonDataMgr::UnInit() @@ -40,3 +56,8 @@ std::shared_ptr JsonDataMgr::GetConf() } return gameserver_cluster_json_[App::Instance()->instance_id - 1]; } + +std::shared_ptr JsonDataMgr::GetMasterServerClusterConf() +{ + return std::make_shared(masterserver_cluster_json_); +} diff --git a/server/gameserver/jsondatamgr.h b/server/gameserver/jsondatamgr.h index 71f432d..390233c 100644 --- a/server/gameserver/jsondatamgr.h +++ b/server/gameserver/jsondatamgr.h @@ -11,7 +11,12 @@ class JsonDataMgr : public a8::Singleton void UnInit(); std::shared_ptr GetConf(); + std::shared_ptr GetMasterServerClusterConf(); + + std::string ip; + int listen_port = 0; private: a8::XObject gameserver_cluster_json_; + a8::XObject masterserver_cluster_json_; }; diff --git a/server/gameserver/playermgr.cc b/server/gameserver/playermgr.cc index 0b4439e..f27def5 100644 --- a/server/gameserver/playermgr.cc +++ b/server/gameserver/playermgr.cc @@ -12,6 +12,15 @@ void PlayerMgr::UnInit() { } +void PlayerMgr::_SS_WSP_SocketDisconnect(f8::MsgHdr& hdr, const ss::SS_WSP_SocketDisconnect& msg) +{ +} + +int PlayerMgr::OnlineNum() +{ + return socket_hash_.size(); +} + Player* PlayerMgr::GetPlayerBySocket(int socket) { auto itr = socket_hash_.find(socket); @@ -39,3 +48,8 @@ Player* PlayerMgr::CreatePlayerByCMJoin(int socket, const cs::CMJoin& msg) socket_hash_[socket] = hum; return hum; } + +void PlayerMgr::OnClientDisconnect(a8::XParams& param) +{ + +} diff --git a/server/gameserver/playermgr.h b/server/gameserver/playermgr.h index d763b22..e93bf51 100644 --- a/server/gameserver/playermgr.h +++ b/server/gameserver/playermgr.h @@ -5,6 +5,11 @@ namespace cs class CMJoin; } +namespace ss +{ + class SS_WSP_SocketDisconnect; +} + class Player; class PlayerMgr : public a8::Singleton { @@ -19,8 +24,12 @@ class PlayerMgr : public a8::Singleton void Init(); void UnInit(); + void _SS_WSP_SocketDisconnect(f8::MsgHdr& hdr, const ss::SS_WSP_SocketDisconnect& msg); + + int OnlineNum(); Player* GetPlayerBySocket(int socket); Player* CreatePlayerByCMJoin(int socket, const cs::CMJoin& msg); + void OnClientDisconnect(a8::XParams& param); private: std::map socket_hash_; diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index 3daaa7d..875a686 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -1,5 +1,8 @@ #include "precompile.h" +#include +#include + #include "roommgr.h" #include "room.h" #include "cs_proto.pb.h" @@ -8,9 +11,34 @@ #include "playermgr.h" #include "app.h" #include "metamgr.h" +#include "jsondatamgr.h" +#include "playermgr.h" + +#include "framework/cpp/httpclientpool.h" void RoomMgr::Init() { + auto master_svr_cluster_conf = JsonDataMgr::Instance()->GetMasterServerClusterConf(); + for (int i = 0; i < master_svr_cluster_conf->Size(); ++i) { + auto master_svr_conf = master_svr_cluster_conf->At(i); + int instance_id = master_svr_conf->At("instance_id")->AsXValue(); + std::string remote_ip = master_svr_conf->At("ip")->AsXValue(); + int remote_port = master_svr_conf->At("port")->AsXValue(); + + a8::Timer::Instance()->AddDeadLineTimer(1000 + (i + 1), + a8::XParams() + .SetSender(instance_id) + .SetParam1(remote_ip) + .SetParam2(remote_port), + [] (const a8::XParams& param) + { + RoomMgr::Instance()->ReportServerState( + param.sender, + param.param1, + param.param2 + ); + }); + } } void RoomMgr::UnInit() @@ -103,6 +131,11 @@ int RoomMgr::RoomNum() return room_hash_.size(); } +int RoomMgr::ActiveRoomNum() +{ + return room_hash_.size() - over_room_hash_.size(); +} + Room* RoomMgr::GetJoinableRoom(const std::string& account_id) { for (auto& pair : inactive_room_hash_) { @@ -123,3 +156,32 @@ void RoomMgr::RemoveFromInactiveRoomHash(long long room_uuid) { inactive_room_hash_.erase(room_uuid); } + +void RoomMgr::ReportServerState(int instanc_id, const std::string& host, int port) +{ + std::string url = a8::Format("http://%s:%d/webapp/index.php?", + { + host, + port + }); + a8::MutableXObject* url_params = a8::MutableXObject::NewObject(); + url_params->SetVal("instance_id", App::Instance()->instance_id); + url_params->SetVal("ip", JsonDataMgr::Instance()->ip); + url_params->SetVal("port", JsonDataMgr::Instance()->listen_port); + url_params->SetVal("online_num", PlayerMgr::Instance()->OnlineNum()); + url_params->SetVal("room_num", ActiveRoomNum()); + f8::HttpClientPool::Instance()->HttpGet(a8::XParams(), + [] (a8::XParams& param, a8::XObject& data) + { + + }, + [] (a8::XParams& param, const std::string& response) + { + + }, + url.c_str(), + *url_params, + rand() + ); + delete url_params; +} diff --git a/server/gameserver/roommgr.h b/server/gameserver/roommgr.h index 5f8f5d5..9478223 100644 --- a/server/gameserver/roommgr.h +++ b/server/gameserver/roommgr.h @@ -23,12 +23,15 @@ class RoomMgr : public a8::Singleton void _CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg); void RemoveFromInactiveRoomHash(long long room_uuid); int RoomNum(); + int ActiveRoomNum(); Room* GetRoomByUuid(long long uuid); private: Room* GetJoinableRoom(const std::string& account_id); + void ReportServerState(int instanc_id, const std::string& host, int port); private: std::map inactive_room_hash_; std::map room_hash_; + std::map over_room_hash_; }; diff --git a/server/masterserver/app.cc b/server/masterserver/app.cc index 2ea5139..50fc456 100755 --- a/server/masterserver/app.cc +++ b/server/masterserver/app.cc @@ -16,6 +16,7 @@ #include "jsondatamgr.h" #include "handlermgr.h" #include "gsmgr.h" +#include "GGListener.h" #include "ss_msgid.pb.h" #include "ss_proto.pb.h" @@ -49,7 +50,7 @@ const char* const PROJ_LOG_FILENAME_FMT = "log_$pid_%Y%m%d.log"; static void SavePerfLog() { - a8::UdpLog::Instance()->Info("max_mainloop_rundelay:%d room_num:%d", + a8::UdpLog::Instance()->Info("max_mainloop_rundelay:%d", { App::Instance()->perf.max_run_delay_time, }); @@ -91,9 +92,7 @@ void App::Init(int argc, char* argv[]) f8::HttpClientPool::Instance()->Init(10); JsonDataMgr::Instance()->Init(); uuid.SetMachineId(instance_id); - #if 0 GGListener::Instance()->Init(); - #endif a8::UdpLog::Instance()->Info("masterserver starting instance_id:%d pid:%d", {instance_id, getpid()}); { @@ -115,9 +114,7 @@ void App::UnInit() if (terminated) { return; } - #if 0 GGListener::Instance()->Init(); - #endif JsonDataMgr::Instance()->UnInit(); f8::HttpClientPool::Instance()->UnInit(); f8::MsgQueue::Instance()->UnInit(); diff --git a/server/masterserver/jsondatamgr.h b/server/masterserver/jsondatamgr.h index 10a3f34..ce10f2e 100644 --- a/server/masterserver/jsondatamgr.h +++ b/server/masterserver/jsondatamgr.h @@ -12,6 +12,8 @@ class JsonDataMgr : public a8::Singleton std::shared_ptr GetConf(); + std::string ip; + int listen_port = 0; private: a8::XObject masterserver_cluster_json_; }; diff --git a/server/tools/protobuild/ss_proto.proto b/server/tools/protobuild/ss_proto.proto index de1cb9c..54f0df7 100755 --- a/server/tools/protobuild/ss_proto.proto +++ b/server/tools/protobuild/ss_proto.proto @@ -1,5 +1,9 @@ package ss; +message SS_WSP_SocketDisconnect +{ +} + message SS_WSP_RequestTargetServer { optional int64 context_id = 1;