Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ylmbtm committed Sep 4, 2021
1 parent e28acad commit bf978c2
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 184 deletions.
176 changes: 89 additions & 87 deletions Server/Src/AccountServer/GameService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

CGameService::CGameService(void)
{
m_dwLogSvrConnID = 0;
m_dwLogSvrConnID = 0;
}

CGameService::~CGameService(void)
Expand All @@ -16,141 +16,143 @@ CGameService::~CGameService(void)

CGameService* CGameService::GetInstancePtr()
{
static CGameService _GameService;
static CGameService _GameService;

return &_GameService;
return &_GameService;
}

UINT32 CGameService::GetLogSvrConnID()
{
return m_dwLogSvrConnID;
return m_dwLogSvrConnID;
}

BOOL CGameService::Init()
{
CommonFunc::SetCurrentWorkDir("");

if(!CLog::GetInstancePtr()->Start("AccountServer", "log"))
{
return FALSE;
}

CLog::GetInstancePtr()->LogInfo("---------服务器开始启动-----------");

if(!CConfigFile::GetInstancePtr()->Load("servercfg.ini"))
{
CLog::GetInstancePtr()->LogError("配制文件加载失败!");
return FALSE;
}

if (CommonFunc::IsAlreadyRun("AccountServer"))
{
CLog::GetInstancePtr()->LogError("AccountServer己经在运行!");
return FALSE;
}

CLog::GetInstancePtr()->SetLogLevel(CConfigFile::GetInstancePtr()->GetIntValue("account_log_level"));

UINT16 nPort = CConfigFile::GetInstancePtr()->GetIntValue("account_svr_port");
if (nPort <= 0)
{
CLog::GetInstancePtr()->LogError("配制文件account_svr_port配制错误!");
return FALSE;
}

INT32 nMaxConn = CConfigFile::GetInstancePtr()->GetIntValue("account_svr_max_con");
if(!ServiceBase::GetInstancePtr()->StartNetwork(nPort, nMaxConn, this, "127.0.0.1"))
{
CLog::GetInstancePtr()->LogError("启动服务失败!");
return FALSE;
}

m_AccountMsgHandler.Init(0);
CLog::GetInstancePtr()->LogError("---------服务器启动成功!--------");
return TRUE;
CommonFunc::SetCurrentWorkDir("");

if(!CLog::GetInstancePtr()->Start("AccountServer", "log"))
{
return FALSE;
}

CLog::GetInstancePtr()->LogInfo("---------服务器开始启动-----------");

if(!CConfigFile::GetInstancePtr()->Load("servercfg.ini"))
{
CLog::GetInstancePtr()->LogError("配制文件加载失败!");
return FALSE;
}

if (CommonFunc::IsAlreadyRun("AccountServer"))
{
CLog::GetInstancePtr()->LogError("AccountServer己经在运行!");
return FALSE;
}

CLog::GetInstancePtr()->SetLogLevel(CConfigFile::GetInstancePtr()->GetIntValue("account_log_level"));

UINT16 nPort = CConfigFile::GetInstancePtr()->GetIntValue("account_svr_port");
if (nPort <= 0)
{
CLog::GetInstancePtr()->LogError("配制文件account_svr_port配制错误!");
return FALSE;
}

INT32 nMaxConn = CConfigFile::GetInstancePtr()->GetIntValue("account_svr_max_con");
if(!ServiceBase::GetInstancePtr()->StartNetwork(nPort, nMaxConn, this, "127.0.0.1"))
{
CLog::GetInstancePtr()->LogError("启动服务失败!");
return FALSE;
}

ERROR_RETURN_FALSE(m_AccountMsgHandler.Init(0));

CLog::GetInstancePtr()->LogError("---------服务器启动成功!--------");

return TRUE;
}

BOOL CGameService::OnNewConnect(UINT32 nConnID)
{
CWatcherClient::GetInstancePtr()->OnNewConnect(nConnID);
CWatcherClient::GetInstancePtr()->OnNewConnect(nConnID);

return TRUE;
return TRUE;
}

BOOL CGameService::OnCloseConnect(UINT32 nConnID)
{
if (nConnID == m_dwLogSvrConnID)
{
m_dwLogSvrConnID = 0;
}
if (nConnID == m_dwLogSvrConnID)
{
m_dwLogSvrConnID = 0;
}

CWatcherClient::GetInstancePtr()->OnCloseConnect(nConnID);
CWatcherClient::GetInstancePtr()->OnCloseConnect(nConnID);

return TRUE;
return TRUE;
}

BOOL CGameService::OnSecondTimer()
{
ConnectToLogServer();
ConnectToLogServer();

CWatcherClient::GetInstancePtr()->OnSecondTimer();
CWatcherClient::GetInstancePtr()->OnSecondTimer();

return TRUE;
return TRUE;
}

BOOL CGameService::DispatchPacket(NetPacket* pNetPacket)
{
if (CWatcherClient::GetInstancePtr()->DispatchPacket(pNetPacket))
{
return TRUE;
}
if (CWatcherClient::GetInstancePtr()->DispatchPacket(pNetPacket))
{
return TRUE;
}

if (m_AccountMsgHandler.DispatchPacket(pNetPacket))
{
return TRUE;
}
if (m_AccountMsgHandler.DispatchPacket(pNetPacket))
{
return TRUE;
}

return FALSE;
return FALSE;
}

BOOL CGameService::Uninit()
{
CLog::GetInstancePtr()->LogError("==========服务器开始关闭=======================");
CLog::GetInstancePtr()->LogError("==========服务器开始关闭=======================");

ServiceBase::GetInstancePtr()->StopNetwork();
ServiceBase::GetInstancePtr()->StopNetwork();

m_AccountMsgHandler.Uninit();
m_AccountMsgHandler.Uninit();

google::protobuf::ShutdownProtobufLibrary();
google::protobuf::ShutdownProtobufLibrary();

CLog::GetInstancePtr()->LogError("==========服务器关闭完成=======================");
CLog::GetInstancePtr()->LogError("==========服务器关闭完成=======================");

return TRUE;
return TRUE;
}

BOOL CGameService::Run()
{
while (CWatcherClient::GetInstancePtr()->IsRun())
{
ServiceBase::GetInstancePtr()->Update();
while (CWatcherClient::GetInstancePtr()->IsRun())
{
ServiceBase::GetInstancePtr()->Update();

CommonFunc::Sleep(1);
}
ServiceBase::GetInstancePtr()->FixFrameNum(200);
}

return TRUE;
return TRUE;
}

BOOL CGameService::ConnectToLogServer()
{
if (m_dwLogSvrConnID != 0)
{
return TRUE;
}
UINT32 nLogPort = CConfigFile::GetInstancePtr()->GetRealNetPort("log_svr_port");
ERROR_RETURN_FALSE(nLogPort > 0);
std::string strStatIp = CConfigFile::GetInstancePtr()->GetStringValue("log_svr_ip");
CConnection* pConnection = ServiceBase::GetInstancePtr()->ConnectTo(strStatIp, nLogPort);
ERROR_RETURN_FALSE(pConnection != NULL);
m_dwLogSvrConnID = pConnection->GetConnectionID();
return TRUE;
if (m_dwLogSvrConnID != 0)
{
return TRUE;
}
UINT32 nLogPort = CConfigFile::GetInstancePtr()->GetRealNetPort("log_svr_port");
ERROR_RETURN_FALSE(nLogPort > 0);
std::string strStatIp = CConfigFile::GetInstancePtr()->GetStringValue("log_svr_ip");
CConnection* pConnection = ServiceBase::GetInstancePtr()->ConnectTo(strStatIp, nLogPort);
ERROR_RETURN_FALSE(pConnection != NULL);
m_dwLogSvrConnID = pConnection->GetConnectionID();
return TRUE;
}
3 changes: 2 additions & 1 deletion Server/Src/DBServer/GameService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ BOOL CGameService::Uninit()

ServiceBase::GetInstancePtr()->StopNetwork();

m_DBMsgHandler.Uninit();
m_DBWriterManger.Uninit();

google::protobuf::ShutdownProtobufLibrary();
Expand All @@ -173,7 +174,7 @@ BOOL CGameService::Run()

m_DBWriterManger.Update();

CommonFunc::Sleep(1);
ServiceBase::GetInstancePtr()->FixFrameNum(200);
}

return TRUE;
Expand Down
2 changes: 1 addition & 1 deletion Server/Src/GameServer/GameService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ BOOL CGameService::Run()

m_SceneManager.OnUpdate(CommonFunc::GetTickCount());

CommonFunc::Sleep(1);
ServiceBase::GetInstancePtr()->FixFrameNum(200);
}

return TRUE;
Expand Down
4 changes: 2 additions & 2 deletions Server/Src/LogServer/GameService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ BOOL CGameService::Init()
return FALSE;
}

m_LogMsgHandler.Init(0);
ERROR_RETURN_FALSE(m_LogMsgHandler.Init(0));
CLog::GetInstancePtr()->LogError("---------服务器启动成功!--------");
return TRUE;
}
Expand Down Expand Up @@ -122,7 +122,7 @@ BOOL CGameService::Run()

m_LogMsgHandler.OnUpdate(CommonFunc::GetTickCount());

CommonFunc::Sleep(1);
ServiceBase::GetInstancePtr()->FixFrameNum(30);
}

return TRUE;
Expand Down
2 changes: 1 addition & 1 deletion Server/Src/LoginServer/GameService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ BOOL CGameService::Run()

GiftCodeManager::GetInstancePtr()->Update();

CommonFunc::Sleep(1);
ServiceBase::GetInstancePtr()->FixFrameNum(200);
}

return TRUE;
Expand Down
Loading

0 comments on commit bf978c2

Please sign in to comment.