This commit is contained in:
aozhiwei 2019-05-15 11:40:00 +08:00
parent 268f62cff4
commit 37d7c529f4
7 changed files with 50 additions and 31 deletions

View File

@ -22,6 +22,8 @@
#include "gameclientmgr.h"
#include "ss_msgid.pb.h"
#include "ss_proto.pb.h"
#include "mastersvr.h"
#include "mastersvrmgr.h"
struct MsgNode
{
@ -93,6 +95,7 @@ void App::Init(int argc, char* argv[])
uuid.SetMachineId(instance_id);
GameClientMgr::Instance()->Init();
TargetConnMgr::Instance()->Init();
MasterSvrMgr::Instance()->Init();
a8::UdpLog::Instance()->Info("masterserver starting instance_id:%d pid:%d", {instance_id, getpid()});
{
@ -114,6 +117,7 @@ void App::UnInit()
if (terminated) {
return;
}
MasterSvrMgr::Instance()->UnInit();
TargetConnMgr::Instance()->UnInit();
GameClientMgr::Instance()->UnInit();
GCListener::Instance()->UnInit();
@ -300,6 +304,11 @@ void App::DispatchMsg()
ProcessTargetServerMsg(hdr);
}
break;
case SF_MasterServer:
{
ProcessMasterServerMsg(hdr);
}
break;
}
if (pdelnode->buf) {
free(pdelnode->buf);
@ -358,6 +367,11 @@ void App::ProcessTargetServerMsg(f8::MsgHdr& hdr)
GCListener::Instance()->ForwardTargetConnMsg(hdr);
}
void App::ProcessMasterServerMsg(f8::MsgHdr& hdr)
{
}
void App::ProcessIMMsg()
{
if (!im_work_node_ && im_top_node_) {

View File

@ -43,6 +43,7 @@ private:
void ProcessClientMsg(f8::MsgHdr& hdr);
void ProcessTargetServerMsg(f8::MsgHdr& hdr);
void ProcessMasterServerMsg(f8::MsgHdr& hdr);
void InitLog();
void UnInitLog();

View File

@ -4,6 +4,7 @@ enum SocketFrom_e
{
SF_Client,
SF_TargetServer,
SF_MasterServer,
};
enum InnerMesssage_e

View File

@ -64,28 +64,6 @@ bool MasterSvr::Connected()
return tcp_client_->Connected();
}
void MasterSvr::ForwardClientMsg(f8::MsgHdr& hdr)
{
char* buff = (char*)malloc(sizeof(f8::WSProxyPackHead_C) + hdr.buflen);
f8::WSProxyPackHead_C* head = (f8::WSProxyPackHead_C*)buff;
head->packlen = hdr.buflen;
head->msgid = hdr.msgid;
head->seqid = hdr.seqid;
head->magic_code = f8::MAGIC_CODE;
#if 0
head->rpc_error_code = 0;
#endif
head->socket_handle = hdr.socket_handle;
head->ip_saddr = hdr.ip_saddr;
if (hdr.buflen > 0) {
memmove(buff + sizeof(f8::WSProxyPackHead_C), hdr.buf, hdr.buflen);
}
tcp_client_->SendBuff(buff, sizeof(f8::WSProxyPackHead_C) + head->packlen);
free(buff);
}
void MasterSvr::on_error(a8::TcpClient* sender, int errorId)
{
a8::UdpLog::Instance()->Error("MasterSvr errorid=%d", {errorId});
@ -129,7 +107,7 @@ void MasterSvr::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len
if (recv_bufflen_ - offset < sizeof(f8::WSProxyPackHead_S) + p->packlen) {
break;
}
App::Instance()->AddSocketMsg(SF_TargetServer,
App::Instance()->AddSocketMsg(SF_MasterServer,
p->socket_handle,
instance_id,
p->msgid,

View File

@ -14,7 +14,6 @@ class MasterSvr
int instance_id = 0;
std::string remote_ip;
int remote_port = 0;
int matching_player_num = 0;
a8::tick_t last_pong_tick = 0;
public:
@ -29,15 +28,9 @@ class MasterSvr
void SendMsg(T& msg)
{
static int msgid = f8::Net_GetMessageId(msg);
#if 1
f8::Net_SendProxyCMsg(tcp_client_, msgid, msg);
#else
f8::Net_SendMsg(tcp_client_, 0, msgid, msg);
#endif
}
void ForwardClientMsg(f8::MsgHdr& hdr);
private:
void on_error(a8::TcpClient* sender, int errorId);
void on_connect(a8::TcpClient* sender);

View File

@ -0,0 +1,32 @@
#include "precompile.h"
#include "mastersvrmgr.h"
#include "mastersvr.h"
#include "jsondatamgr.h"
void MasterSvrMgr::Init()
{
auto master_svr_cluster_conf = JsonDataMgr::Instance()->GetTargetServerClusterConf();
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();
{
MasterSvr* conn = new MasterSvr();
conn->Init(instance_id, remote_ip, remote_port);
mastersvr_hash_[conn->instance_id] = conn;
conn->Open();
}
}
}
void MasterSvrMgr::UnInit()
{
}
MasterSvr* MasterSvrMgr::GetConnByInstanceId(int instance_id)
{
auto itr = mastersvr_hash_.find(instance_id);
return itr != mastersvr_hash_.end() ? itr->second : nullptr;
}

View File

@ -15,5 +15,5 @@ class MasterSvrMgr : public a8::Singleton<MasterSvrMgr>
MasterSvr* GetConnByInstanceId(int instance_id);
private:
std::map<int, MasterSvr*> target_conn_hash_;
std::map<int, MasterSvr*> mastersvr_hash_;
};