Skip to content

Commit 5a51ea0

Browse files
committed
commit
1 parent bf978c2 commit 5a51ea0

File tree

13 files changed

+65
-31
lines changed

13 files changed

+65
-31
lines changed

Server/Src/AccountServer/Main.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ int main(int argc, char* argv[])
1313

1414
CCommandLine cmdLine(argc, argv);
1515

16-
//设置被监视索引,用于和监控程通信
17-
CWatcherClient::GetInstancePtr()->SetWatchIndex(cmdLine.GetIntValue("windex"));
18-
1916
if (CGameService::GetInstancePtr()->Init())
2017
{
2118
CGameService::GetInstancePtr()->Run();

Server/Src/CenterServer/CenterMsgHandler.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ BOOL CCenterMsgHandler::OnMsgLogicSvrRegReq(NetPacket* pPacket)
4343
SvrRegToSvrReq Req;
4444
Req.ParsePartialFromArray(pPacket->m_pDataBuffer->GetData(), pPacket->m_pDataBuffer->GetBodyLenth());
4545
LogicSvrMgr::GetInstancePtr()->RegisterLogicServer(pPacket->m_dwConnID, Req.serverid(), Req.servername());
46-
46+
CLog::GetInstancePtr()->LogInfo("ServerID:%d Register Successed!", Req.serverid());
4747

4848
SvrRegToSvrAck Ack;
4949
Ack.set_retcode(MRC_SUCCESSED);
50-
ServiceBase::GetInstancePtr()->SendMsgProtoBuf(pPacket->m_dwConnID, MSG_LOGIC_REGTO_LOGIN_ACK, 0, 0, Ack);
50+
ServiceBase::GetInstancePtr()->SendMsgProtoBuf(pPacket->m_dwConnID, MSG_LOGIC_REGTO_CENTER_ACK, 0, 0, Ack);
5151
return TRUE;
5252
}
5353

Server/Src/CenterServer/CenterServer.vcxproj

+4-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
<PrecompiledHeader>Use</PrecompiledHeader>
6868
<WarningLevel>Level3</WarningLevel>
6969
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
70-
<DisableSpecificWarnings>4996;4800;%(DisableSpecificWarnings)</DisableSpecificWarnings>
70+
<DisableSpecificWarnings>4996;4800;4244;%(DisableSpecificWarnings)</DisableSpecificWarnings>
71+
<MultiProcessorCompilation>true</MultiProcessorCompilation>
7172
</ClCompile>
7273
<Link>
7374
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
@@ -88,7 +89,8 @@
8889
<PrecompiledHeader>Use</PrecompiledHeader>
8990
<WarningLevel>Level3</WarningLevel>
9091
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
91-
<DisableSpecificWarnings>4996;4800;</DisableSpecificWarnings>
92+
<DisableSpecificWarnings>4996;4800;4244;</DisableSpecificWarnings>
93+
<MultiProcessorCompilation>true</MultiProcessorCompilation>
9294
</ClCompile>
9395
<Link>
9496
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>

Server/Src/CenterServer/GameService.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "../Message/Msg_RetCode.pb.h"
55
#include "../Message/Msg_ID.pb.h"
66
#include "WatcherClient.h"
7+
#include "LogicSvrMgr.h"
78

89
CGameService::CGameService(void)
910
{
@@ -38,21 +39,27 @@ BOOL CGameService::Init()
3839

3940
if (CommonFunc::IsAlreadyRun("CenterServer"))
4041
{
42+
CLog::GetInstancePtr()->LogError("CenterServer己经在运行!");
4143
return FALSE;
4244
}
4345

4446
CLog::GetInstancePtr()->SetLogLevel(CConfigFile::GetInstancePtr()->GetIntValue("center_log_level"));
4547

4648

4749
UINT16 nPort = CConfigFile::GetInstancePtr()->GetIntValue("center_svr_port");
50+
if (nPort <= 0)
51+
{
52+
CLog::GetInstancePtr()->LogError("配制文件center_svr_port配制错误!");
53+
return FALSE;
54+
}
4855
INT32 nMaxConn = CConfigFile::GetInstancePtr()->GetIntValue("center_svr_max_con");
4956
if(!ServiceBase::GetInstancePtr()->StartNetwork(nPort, nMaxConn, this))
5057
{
5158
CLog::GetInstancePtr()->LogError("启动服务失败!");
5259
return FALSE;
5360
}
5461

55-
m_CenterMsgHandler.Init(0);
62+
ERROR_RETURN_FALSE(m_CenterMsgHandler.Init(0));
5663
CLog::GetInstancePtr()->LogError("---------服务器启动成功!--------");
5764
return TRUE;
5865
}
@@ -69,6 +76,8 @@ BOOL CGameService::OnCloseConnect(UINT32 nConnID)
6976
{
7077
CWatcherClient::GetInstancePtr()->OnCloseConnect(nConnID);
7178

79+
LogicSvrMgr::GetInstancePtr()->OnCloseConnect(nConnID);
80+
7281
return TRUE;
7382
}
7483

@@ -96,8 +105,16 @@ BOOL CGameService::DispatchPacket(NetPacket* pNetPacket)
96105

97106
BOOL CGameService::Uninit()
98107
{
108+
CLog::GetInstancePtr()->LogError("==========服务器开始关闭=======================");
109+
99110
ServiceBase::GetInstancePtr()->StopNetwork();
111+
112+
m_CenterMsgHandler.Uninit();
113+
100114
google::protobuf::ShutdownProtobufLibrary();
115+
116+
CLog::GetInstancePtr()->LogError("==========服务器关闭完成=======================");
117+
101118
return TRUE;
102119
}
103120

Server/Src/CenterServer/LogicSvrMgr.cpp

+36-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ BOOL LogicSvrMgr::RegisterLogicServer(UINT32 dwConnID, UINT32 dwServerID, std::s
4545
return TRUE;
4646
}
4747

48-
BOOL LogicSvrMgr::UnregisterLogicServer(UINT32 dwConnID, UINT32 dwServerID)
48+
BOOL LogicSvrMgr::UnregisterLogicServer(UINT32 dwServerID)
4949
{
5050
LogicServerNode* pNode = GetLogicServerInfo(dwServerID);
5151
if(pNode == NULL)
@@ -58,6 +58,23 @@ BOOL LogicSvrMgr::UnregisterLogicServer(UINT32 dwConnID, UINT32 dwServerID)
5858
return TRUE;
5959
}
6060

61+
BOOL LogicSvrMgr::OnCloseConnect(UINT32 dwConnID)
62+
{
63+
for (auto itor = m_mapServer.begin(); itor != m_mapServer.end(); ++itor)
64+
{
65+
LogicServerNode* pNode = itor->second;
66+
ERROR_CONTINUE_EX(pNode != NULL);
67+
68+
if (pNode->m_dwConnID == dwConnID)
69+
{
70+
pNode->m_dwConnID = 0;
71+
}
72+
73+
}
74+
75+
return TRUE;
76+
}
77+
6178
UINT32 LogicSvrMgr::GetLogicConnID(UINT32 dwServerID)
6279
{
6380
LogicServerNode* pNode = GetLogicServerInfo(dwServerID);
@@ -85,6 +102,24 @@ BOOL LogicSvrMgr::SendMsgProtoBuf(UINT32 dwServerID, UINT32 dwMsgID, const googl
85102
return ServiceBase::GetInstancePtr()->SendMsgProtoBuf(GetLogicConnID(dwServerID), dwMsgID, 0, 0, pdata);
86103
}
87104

105+
BOOL LogicSvrMgr::BroadMsgToAll(UINT32 dwMsgID, const google::protobuf::Message& pdata, UINT32 nNoConnID)
106+
{
107+
for (auto itor = m_mapServer.begin(); itor != m_mapServer.end(); ++itor)
108+
{
109+
LogicServerNode* pServerNode = itor->second;
110+
ERROR_CONTINUE_EX(pServerNode != NULL);
111+
112+
if (pServerNode->m_dwConnID == nNoConnID)
113+
{
114+
continue;
115+
}
116+
117+
ServiceBase::GetInstancePtr()->SendMsgProtoBuf(pServerNode->m_dwConnID, dwMsgID, 0, 0, pdata);
118+
}
119+
120+
return TRUE;
121+
}
122+
88123
BOOL LogicSvrMgr::SendMsgRawData(UINT32 dwServerID, UINT32 dwMsgID, const char* pdata, UINT32 dwLen)
89124
{
90125
return ServiceBase::GetInstancePtr()->SendMsgRawData(GetLogicConnID(dwServerID), dwMsgID, 0, 0, pdata, dwLen);

Server/Src/CenterServer/LogicSvrMgr.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ class LogicSvrMgr
2525

2626
BOOL RegisterLogicServer(UINT32 dwConnID, UINT32 dwServerID, std::string strSvrName);
2727

28-
BOOL UnregisterLogicServer(UINT32 dwConnID, UINT32 dwServerID);
28+
BOOL UnregisterLogicServer(UINT32 dwServerID);
29+
30+
BOOL OnCloseConnect(UINT32 dwConnID);
2931

3032
UINT32 GetLogicConnID(UINT32 dwServerID);
3133

3234
BOOL SendMsgProtoBuf(UINT32 dwServerID, UINT32 dwMsgID, const google::protobuf::Message& pdata);
3335

36+
BOOL BroadMsgToAll(UINT32 dwMsgID, const google::protobuf::Message& pdata, UINT32 nNoConnID = 0);
37+
3438
BOOL SendMsgRawData(UINT32 dwServerID, UINT32 dwMsgID, const char* pdata, UINT32 dwLen);
3539

3640
LogicServerNode* GetLogicServerInfo(UINT32 dwServerID);

Server/Src/CenterServer/Main.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ int main(int argc, char* argv[])
1313

1414
CCommandLine cmdLine(argc, argv);
1515

16-
//设置被监视索引,用于和监控程通信
17-
CWatcherClient::GetInstancePtr()->SetWatchIndex(cmdLine.GetIntValue("windex"));
18-
1916
if (!CGameService::GetInstancePtr()->Init())
2017
{
2118
return 0;

Server/Src/DBServer/Main.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ int main(int argc, char* argv[])
1313

1414
CCommandLine cmdLine(argc, argv);
1515

16-
//设置被监视索引,用于和监控程通信
17-
CWatcherClient::GetInstancePtr()->SetWatchIndex(cmdLine.GetIntValue("windex"));
18-
1916
if (!CGameService::GetInstancePtr()->Init())
2017
{
2118
return 0;

Server/Src/GameServer/Main.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ int main(int argc, char* argv[])
2323

2424
SetCrashReport("GameServer");
2525

26-
//设置被监视索引,用于和监控程通信
27-
CWatcherClient::GetInstancePtr()->SetWatchIndex(cmdLine.GetIntValue("windex"));
28-
2926
if (!CGameService::GetInstancePtr()->Init(dwSvrID, dwPort))
3027
{
3128
return 0;

Server/Src/LogServer/Main.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ int main(int argc, char* argv[])
1313

1414
CCommandLine cmdLine(argc, argv);
1515

16-
//设置被监视索引,用于和监控程通信
17-
CWatcherClient::GetInstancePtr()->SetWatchIndex(cmdLine.GetIntValue("windex"));
18-
1916
if (!CGameService::GetInstancePtr()->Init())
2017
{
2118
return 0;

Server/Src/LogicServer/Main.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ int main(int argc, char* argv[])
1313

1414
CCommandLine cmdLine(argc, argv);
1515

16-
//设置被监视索引,用于和监控程通信
17-
CWatcherClient::GetInstancePtr()->SetWatchIndex(cmdLine.GetIntValue("windex"));
18-
1916
if (!CGameService::GetInstancePtr()->Init())
2017
{
2118
return 0;

Server/Src/LoginServer/Main.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ int main(int argc, char* argv[])
1313

1414
CCommandLine cmdLine(argc, argv);
1515

16-
//设置被监视索引,用于和监控程通信
17-
CWatcherClient::GetInstancePtr()->SetWatchIndex(cmdLine.GetIntValue("windex"));
18-
1916
if (CGameService::GetInstancePtr()->Init())
2017
{
2118
CGameService::GetInstancePtr()->Run();

Server/Src/ProxyServer/Main.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ int main(int argc, char* argv[])
1313

1414
CCommandLine cmdLine(argc, argv);
1515

16-
//设置被监视索引,用于和监控程通信
17-
CWatcherClient::GetInstancePtr()->SetWatchIndex(cmdLine.GetIntValue("windex"));
18-
1916
if (!CGameService::GetInstancePtr()->Init())
2017
{
2118
return 0;

0 commit comments

Comments
 (0)