121 lines
2.4 KiB
C++
Executable File
121 lines
2.4 KiB
C++
Executable File
#include "precompile.h"
|
|
|
|
#include <unistd.h>
|
|
#include <a8/uuid.h>
|
|
|
|
#include <f8/netmsghandler.h>
|
|
#include <f8/msgqueue.h>
|
|
#include <f8/tglog.h>
|
|
#include <f8/timer.h>
|
|
|
|
#include "app.h"
|
|
#include "jsondatamgr.h"
|
|
#include "handlermgr.h"
|
|
#include "gsmgr.h"
|
|
#include "GGListener.h"
|
|
|
|
#include "ss_msgid.pb.h"
|
|
#include "ss_proto.pb.h"
|
|
|
|
static void SavePerfLog()
|
|
{
|
|
f8::UdpLog::Instance()->Info("max_mainloop_rundelay:%d",
|
|
{
|
|
App::Instance()->perf.max_run_delay_time,
|
|
});
|
|
App::Instance()->perf.max_run_delay_time = 0;
|
|
App::Instance()->perf.max_timer_idle = 0;
|
|
}
|
|
|
|
const std::string App::GetPkgName()
|
|
{
|
|
return a8::Format("game%d_masterserver", {App::Instance()->GetGameId()});
|
|
}
|
|
|
|
void App::Init()
|
|
{
|
|
HandlerMgr::Instance()->Init();
|
|
JsonDataMgr::Instance()->Init();
|
|
GGListener::Instance()->Init();
|
|
GSMgr::Instance()->Init();
|
|
|
|
{
|
|
int perf_log_time = 1000 * 60 * 5;
|
|
if (getenv("is_dev_env")) {
|
|
perf_log_time = 1000 * 10;
|
|
}
|
|
f8::Timer::Instance()->SetInterval
|
|
(perf_log_time,
|
|
[] (int e, const a8::Args* args)
|
|
{
|
|
if (a8::TIMER_EXEC_EVENT == e) {
|
|
SavePerfLog();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
void App::UnInit()
|
|
{
|
|
GSMgr::Instance()->UnInit();
|
|
GGListener::Instance()->UnInit();
|
|
JsonDataMgr::Instance()->UnInit();
|
|
HandlerMgr::Instance()->UnInit();
|
|
}
|
|
|
|
void App::Update()
|
|
{
|
|
QuickExecute();
|
|
SlowerExecute();
|
|
}
|
|
|
|
void App::QuickExecute()
|
|
{
|
|
}
|
|
|
|
void App::SlowerExecute()
|
|
{
|
|
}
|
|
|
|
bool App::HasTask()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
void App::ProcessGameGateMsg(f8::MsgHdr* hdr)
|
|
{
|
|
f8::NetMsgHandler* handler = f8::GetNetMsgHandler
|
|
(&HandlerMgr::Instance()->ggmsghandler,
|
|
hdr->msgid);
|
|
if (handler) {
|
|
switch (handler->handlerid) {
|
|
case HID_GSMgr:
|
|
ProcessNetMsg(handler, GSMgr::Instance(), *hdr);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void App::DispatchSocketMsg(f8::MsgHdr* hdr)
|
|
{
|
|
switch (hdr->sockfrom) {
|
|
case SF_GameGate:
|
|
{
|
|
ProcessGameGateMsg(hdr);
|
|
}
|
|
break;
|
|
}
|
|
f8::App::Instance()->FreeSocketMsg(hdr);
|
|
}
|
|
|
|
int App::GetGameId() const
|
|
{
|
|
#ifdef DEBUG
|
|
std::string game_id = a8::XValue((f8::App::Instance()->GetArgv())[0]).GetString();
|
|
a8::ReplaceString(game_id, "./masterserver", "");
|
|
return a8::XValue(game_id);
|
|
#else
|
|
return GAME_ID;
|
|
#endif
|
|
}
|