This commit is contained in:
aozhiwei 2019-05-18 14:50:42 +08:00
parent 3043f2986d
commit 845a51eb5e
12 changed files with 128 additions and 21 deletions

View File

@ -347,19 +347,12 @@ void App::ProcessGameGateMsg(f8::MsgHdr& hdr)
hdr.msgid); hdr.msgid);
if (handler) { if (handler) {
switch (handler->handlerid) { 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: case HID_RoomMgr:
ProcessNetMsg(handler, RoomMgr::Instance(), hdr); ProcessNetMsg(handler, RoomMgr::Instance(), hdr);
break; break;
case HID_PlayerMgr:
ProcessNetMsg(handler, PlayerMgr::Instance(), hdr);
break;
case HID_Player: case HID_Player:
{ {
Player* hum = PlayerMgr::Instance()->GetPlayerBySocket(hdr.socket_handle); Player* hum = PlayerMgr::Instance()->GetPlayerBySocket(hdr.socket_handle);
@ -396,9 +389,7 @@ void App::ProcessIMMsg()
break; break;
case IM_ClientSocketDisconnect: case IM_ClientSocketDisconnect:
{ {
#if 0
PlayerMgr::Instance()->OnClientDisconnect(pdelnode->params); PlayerMgr::Instance()->OnClientDisconnect(pdelnode->params);
#endif
} }
break; break;
case IM_ExecGM: case IM_ExecGM:

View File

@ -8,8 +8,10 @@
#include "metamgr.h" #include "metamgr.h"
#include "app.h" #include "app.h"
#include "player.h" #include "player.h"
#include "playermgr.h"
#include "roommgr.h" #include "roommgr.h"
#include "cs_proto.pb.h" #include "cs_proto.pb.h"
#include "ss_proto.pb.h"
static void _GMOpsSelfChecking(f8::JsonHttpRequest* request) static void _GMOpsSelfChecking(f8::JsonHttpRequest* request)
{ {
@ -42,7 +44,7 @@ void HandlerMgr::UnInit()
void HandlerMgr::RegisterNetMsgHandlers() void HandlerMgr::RegisterNetMsgHandlers()
{ {
//RegisterNetMsgHandler(&ggmsghandler, &PlayerMgr::_SS_WSP_SocketDisconnect); RegisterNetMsgHandler(&ggmsghandler, &PlayerMgr::_SS_WSP_SocketDisconnect);
RegisterNetMsgHandler(&ggmsghandler, &RoomMgr::_CMJoin); RegisterNetMsgHandler(&ggmsghandler, &RoomMgr::_CMJoin);
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMMove); RegisterNetMsgHandler(&ggmsghandler, &Player::_CMMove);

View File

@ -22,9 +22,6 @@ class HandlerMgr : public a8::Singleton<HandlerMgr>
void UnInit(); void UnInit();
f8::NetMsgHandlerObject ggmsghandler; f8::NetMsgHandlerObject ggmsghandler;
f8::NetMsgHandlerObject dbmsghandler;
f8::NetMsgHandlerObject dpmsghandler;
f8::NetMsgHandlerObject bsmsghandler;
void ProcGMMsg(unsigned long saddr, int sockhandle, void ProcGMMsg(unsigned long saddr, int sockhandle,
const std::string& url, const std::string& quyerstr); const std::string& url, const std::string& quyerstr);

View File

@ -8,6 +8,7 @@
void JsonDataMgr::Init() void JsonDataMgr::Init()
{ {
std::string gameserver_cluster_json_file; std::string gameserver_cluster_json_file;
std::string masterserver_cluster_json_file;
if (!f8::IsOnlineEnv()) { if (!f8::IsOnlineEnv()) {
if (App::Instance()->flags.find(2) != App::Instance()->flags.end()) { 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/" 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,
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 { } else {
gameserver_cluster_json_file = a8::Format("/var/data/conf_test/game%d/gameserver/" gameserver_cluster_json_file = a8::Format("/var/data/conf_test/game%d/gameserver/"
"game%d.gameserver.cluster.json", "game%d.gameserver.cluster.json",
{GAME_ID, GAME_ID}); {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 { } else {
gameserver_cluster_json_file = a8::Format("../config/game%d.gameserver.cluster.json", {GAME_ID}); 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); 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() void JsonDataMgr::UnInit()
@ -40,3 +56,8 @@ std::shared_ptr<a8::XObject> JsonDataMgr::GetConf()
} }
return gameserver_cluster_json_[App::Instance()->instance_id - 1]; return gameserver_cluster_json_[App::Instance()->instance_id - 1];
} }
std::shared_ptr<a8::XObject> JsonDataMgr::GetMasterServerClusterConf()
{
return std::make_shared<a8::XObject>(masterserver_cluster_json_);
}

View File

@ -11,7 +11,12 @@ class JsonDataMgr : public a8::Singleton<JsonDataMgr>
void UnInit(); void UnInit();
std::shared_ptr<a8::XObject> GetConf(); std::shared_ptr<a8::XObject> GetConf();
std::shared_ptr<a8::XObject> GetMasterServerClusterConf();
std::string ip;
int listen_port = 0;
private: private:
a8::XObject gameserver_cluster_json_; a8::XObject gameserver_cluster_json_;
a8::XObject masterserver_cluster_json_;
}; };

View File

@ -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) Player* PlayerMgr::GetPlayerBySocket(int socket)
{ {
auto itr = socket_hash_.find(socket); auto itr = socket_hash_.find(socket);
@ -39,3 +48,8 @@ Player* PlayerMgr::CreatePlayerByCMJoin(int socket, const cs::CMJoin& msg)
socket_hash_[socket] = hum; socket_hash_[socket] = hum;
return hum; return hum;
} }
void PlayerMgr::OnClientDisconnect(a8::XParams& param)
{
}

View File

@ -5,6 +5,11 @@ namespace cs
class CMJoin; class CMJoin;
} }
namespace ss
{
class SS_WSP_SocketDisconnect;
}
class Player; class Player;
class PlayerMgr : public a8::Singleton<PlayerMgr> class PlayerMgr : public a8::Singleton<PlayerMgr>
{ {
@ -19,8 +24,12 @@ class PlayerMgr : public a8::Singleton<PlayerMgr>
void Init(); void Init();
void UnInit(); void UnInit();
void _SS_WSP_SocketDisconnect(f8::MsgHdr& hdr, const ss::SS_WSP_SocketDisconnect& msg);
int OnlineNum();
Player* GetPlayerBySocket(int socket); Player* GetPlayerBySocket(int socket);
Player* CreatePlayerByCMJoin(int socket, const cs::CMJoin& msg); Player* CreatePlayerByCMJoin(int socket, const cs::CMJoin& msg);
void OnClientDisconnect(a8::XParams& param);
private: private:
std::map<int, Player*> socket_hash_; std::map<int, Player*> socket_hash_;

View File

@ -1,5 +1,8 @@
#include "precompile.h" #include "precompile.h"
#include <a8/timer.h>
#include <a8/mutable_xobject.h>
#include "roommgr.h" #include "roommgr.h"
#include "room.h" #include "room.h"
#include "cs_proto.pb.h" #include "cs_proto.pb.h"
@ -8,9 +11,34 @@
#include "playermgr.h" #include "playermgr.h"
#include "app.h" #include "app.h"
#include "metamgr.h" #include "metamgr.h"
#include "jsondatamgr.h"
#include "playermgr.h"
#include "framework/cpp/httpclientpool.h"
void RoomMgr::Init() 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() void RoomMgr::UnInit()
@ -103,6 +131,11 @@ int RoomMgr::RoomNum()
return room_hash_.size(); return room_hash_.size();
} }
int RoomMgr::ActiveRoomNum()
{
return room_hash_.size() - over_room_hash_.size();
}
Room* RoomMgr::GetJoinableRoom(const std::string& account_id) Room* RoomMgr::GetJoinableRoom(const std::string& account_id)
{ {
for (auto& pair : inactive_room_hash_) { for (auto& pair : inactive_room_hash_) {
@ -123,3 +156,32 @@ void RoomMgr::RemoveFromInactiveRoomHash(long long room_uuid)
{ {
inactive_room_hash_.erase(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;
}

View File

@ -23,12 +23,15 @@ class RoomMgr : public a8::Singleton<RoomMgr>
void _CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg); void _CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg);
void RemoveFromInactiveRoomHash(long long room_uuid); void RemoveFromInactiveRoomHash(long long room_uuid);
int RoomNum(); int RoomNum();
int ActiveRoomNum();
Room* GetRoomByUuid(long long uuid); Room* GetRoomByUuid(long long uuid);
private: private:
Room* GetJoinableRoom(const std::string& account_id); Room* GetJoinableRoom(const std::string& account_id);
void ReportServerState(int instanc_id, const std::string& host, int port);
private: private:
std::map<long long, Room*> inactive_room_hash_; std::map<long long, Room*> inactive_room_hash_;
std::map<long long, Room*> room_hash_; std::map<long long, Room*> room_hash_;
std::map<long long, Room*> over_room_hash_;
}; };

View File

@ -16,6 +16,7 @@
#include "jsondatamgr.h" #include "jsondatamgr.h"
#include "handlermgr.h" #include "handlermgr.h"
#include "gsmgr.h" #include "gsmgr.h"
#include "GGListener.h"
#include "ss_msgid.pb.h" #include "ss_msgid.pb.h"
#include "ss_proto.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() 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, App::Instance()->perf.max_run_delay_time,
}); });
@ -91,9 +92,7 @@ void App::Init(int argc, char* argv[])
f8::HttpClientPool::Instance()->Init(10); f8::HttpClientPool::Instance()->Init(10);
JsonDataMgr::Instance()->Init(); JsonDataMgr::Instance()->Init();
uuid.SetMachineId(instance_id); uuid.SetMachineId(instance_id);
#if 0
GGListener::Instance()->Init(); GGListener::Instance()->Init();
#endif
a8::UdpLog::Instance()->Info("masterserver starting instance_id:%d pid:%d", {instance_id, getpid()}); a8::UdpLog::Instance()->Info("masterserver starting instance_id:%d pid:%d", {instance_id, getpid()});
{ {
@ -115,9 +114,7 @@ void App::UnInit()
if (terminated) { if (terminated) {
return; return;
} }
#if 0
GGListener::Instance()->Init(); GGListener::Instance()->Init();
#endif
JsonDataMgr::Instance()->UnInit(); JsonDataMgr::Instance()->UnInit();
f8::HttpClientPool::Instance()->UnInit(); f8::HttpClientPool::Instance()->UnInit();
f8::MsgQueue::Instance()->UnInit(); f8::MsgQueue::Instance()->UnInit();

View File

@ -12,6 +12,8 @@ class JsonDataMgr : public a8::Singleton<JsonDataMgr>
std::shared_ptr<a8::XObject> GetConf(); std::shared_ptr<a8::XObject> GetConf();
std::string ip;
int listen_port = 0;
private: private:
a8::XObject masterserver_cluster_json_; a8::XObject masterserver_cluster_json_;
}; };

View File

@ -1,5 +1,9 @@
package ss; package ss;
message SS_WSP_SocketDisconnect
{
}
message SS_WSP_RequestTargetServer message SS_WSP_RequestTargetServer
{ {
optional int64 context_id = 1; optional int64 context_id = 1;