add c
This commit is contained in:
parent
3043f2986d
commit
845a51eb5e
@ -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:
|
||||
|
@ -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);
|
||||
|
@ -22,9 +22,6 @@ class HandlerMgr : public a8::Singleton<HandlerMgr>
|
||||
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);
|
||||
|
@ -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<a8::XObject> JsonDataMgr::GetConf()
|
||||
}
|
||||
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_);
|
||||
}
|
||||
|
@ -11,7 +11,12 @@ class JsonDataMgr : public a8::Singleton<JsonDataMgr>
|
||||
void UnInit();
|
||||
|
||||
std::shared_ptr<a8::XObject> GetConf();
|
||||
std::shared_ptr<a8::XObject> GetMasterServerClusterConf();
|
||||
|
||||
std::string ip;
|
||||
int listen_port = 0;
|
||||
|
||||
private:
|
||||
a8::XObject gameserver_cluster_json_;
|
||||
a8::XObject masterserver_cluster_json_;
|
||||
};
|
||||
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,11 @@ namespace cs
|
||||
class CMJoin;
|
||||
}
|
||||
|
||||
namespace ss
|
||||
{
|
||||
class SS_WSP_SocketDisconnect;
|
||||
}
|
||||
|
||||
class Player;
|
||||
class PlayerMgr : public a8::Singleton<PlayerMgr>
|
||||
{
|
||||
@ -19,8 +24,12 @@ class PlayerMgr : public a8::Singleton<PlayerMgr>
|
||||
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<int, Player*> socket_hash_;
|
||||
|
@ -1,5 +1,8 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <a8/timer.h>
|
||||
#include <a8/mutable_xobject.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
@ -23,12 +23,15 @@ class RoomMgr : public a8::Singleton<RoomMgr>
|
||||
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<long long, Room*> inactive_room_hash_;
|
||||
std::map<long long, Room*> room_hash_;
|
||||
std::map<long long, Room*> over_room_hash_;
|
||||
};
|
||||
|
@ -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();
|
||||
|
@ -12,6 +12,8 @@ class JsonDataMgr : public a8::Singleton<JsonDataMgr>
|
||||
|
||||
std::shared_ptr<a8::XObject> GetConf();
|
||||
|
||||
std::string ip;
|
||||
int listen_port = 0;
|
||||
private:
|
||||
a8::XObject masterserver_cluster_json_;
|
||||
};
|
||||
|
@ -1,5 +1,9 @@
|
||||
package ss;
|
||||
|
||||
message SS_WSP_SocketDisconnect
|
||||
{
|
||||
}
|
||||
|
||||
message SS_WSP_RequestTargetServer
|
||||
{
|
||||
optional int64 context_id = 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user