aozhiwei 473be3a9f1 1
2023-12-08 11:32:01 +08:00

259 lines
7.9 KiB
C++

#include "precompile.h"
#include <unistd.h>
#include <f8/udplog.h>
#include <f8/btmgr.h>
#include <f8/timer.h>
#include "app.h"
#include "jsondatamgr.h"
#include "handlermgr.h"
#include "roommgr.h"
#include "player.h"
#include "playermgr.h"
#include "mapmgr.h"
#include "entityfactory.h"
#include "perfmonitor.h"
#include "killmgr.h"
#include "httpproxy.h"
#include "lispenv.h"
#include "perf.h"
#include "tracemgr.h"
#include "matchmgr.h"
#include "selfchecker.h"
#include "hero_agent.h"
#include "android_agent.h"
#include "skillhelper.h"
#include "mt/MetaMgr.h"
#include "mt/Skill.h"
static void SavePerfLog()
{
f8::UdpLog::Instance()->Info
("max_rundelay:%d room_num:%d player_num:%d online_num:%d alive_count:%d "
"sys_request_delay:%d user_request_delay:%d http_pending_num:%d real_alive_count:%d "
"account_num:%d level0_num:%d level1_num:%d "
"max_full_obj:%d max_part_obj:%d max_bullet:%d max_packet:%d "
"his_max_full_obj:%d his_max_part_obj:%d his_max_bullet:%d his_max_packet:%d",
{
f8::App::Instance()->GetMaxRunDelayTime(),
RoomMgr::Instance()->RoomNum(),
PerfMonitor::Instance()->entity_num[ET_Player],
PlayerMgr::Instance()->OnlineNum(),
PerfMonitor::Instance()->alive_count,
f8::HttpClientPool::Instance()->max_sys_request_delay,
f8::HttpClientPool::Instance()->max_user_request_delay,
f8::HttpClientPool::Instance()->GetPendingNum(),
PerfMonitor::Instance()->real_alive_count,
PlayerMgr::Instance()->GetAccountNum(),
PerfMonitor::Instance()->room_num[RoomType_NewBrid],
PerfMonitor::Instance()->room_num[RoomType_MidBrid],
PerfMonitor::Instance()->max_full_objects_num,
PerfMonitor::Instance()->max_part_objects_num,
PerfMonitor::Instance()->max_bullet_num,
GGListener::Instance()->max_packet_size,
PerfMonitor::Instance()->his_max_full_objects_num,
PerfMonitor::Instance()->his_max_part_objects_num,
PerfMonitor::Instance()->his_max_bullet_num,
GGListener::Instance()->his_max_packet_size
});
{
PerfMonitor::Instance()->his_max_full_objects_num = std::max
(PerfMonitor::Instance()->his_max_full_objects_num, PerfMonitor::Instance()->max_full_objects_num);
PerfMonitor::Instance()->his_max_part_objects_num = std::max
(PerfMonitor::Instance()->his_max_part_objects_num, PerfMonitor::Instance()->max_part_objects_num);
PerfMonitor::Instance()->his_max_bullet_num = std::max
(PerfMonitor::Instance()->his_max_bullet_num, PerfMonitor::Instance()->max_bullet_num);
GGListener::Instance()->his_max_packet_size = std::max
(GGListener::Instance()->his_max_packet_size, GGListener::Instance()->max_packet_size);
}
f8::App::Instance()->ResetMaxRunDelayTime();
PerfMonitor::Instance()->max_timer_idle = 0;
PerfMonitor::Instance()->grid_chg_times = 0;
PerfMonitor::Instance()->max_full_objects_num = 0;
PerfMonitor::Instance()->max_part_objects_num = 0;
PerfMonitor::Instance()->max_bullet_num = 0;
GGListener::Instance()->max_packet_size = 0;
f8::HttpClientPool::Instance()->max_sys_request_delay = 0;
f8::HttpClientPool::Instance()->max_user_request_delay = 0;
}
void App::Init()
{
#ifdef MYDEBUG
TraceMgr::Instance()->Init("gameserver2006");
#endif
PerfMonitor::Instance()->Init();
HandlerMgr::Instance()->Init();
Perf::Instance()->Init();
f8::BtMgr::Instance()->Init("exported");
#ifdef MYDEBUG1
f8::BtMgr::Instance()->SetLogging(true);
#endif
SkillHelper::Init();
JsonDataMgr::Instance()->Init();
LispEnv::Instance()->Init();
mt::MetaMgr::Instance()->Init();
SelfChecker::Init();
EntityFactory::Instance()->Init();
KillMgr::Instance()->Init();
RoomMgr::Instance()->Init();
MatchMgr::Instance()->Init();
MapMgr::Instance()->Init();
PlayerMgr::Instance()->Init();
GGListener::Instance()->Init();
HttpProxy::Instance()->Init();
{
int perf_log_time = 1000 * 30;
f8::Timer::Instance()->SetInterval
(perf_log_time,
[] (int event, const a8::Args* args)
{
if (a8::TIMER_EXEC_EVENT == event) {
SavePerfLog();
}
});
}
}
void App::UnInit()
{
PlayerMgr::Instance()->UnInit();
RoomMgr::Instance()->UnInit();
HttpProxy::Instance()->UnInit();
GGListener::Instance()->UnInit();
MapMgr::Instance()->UnInit();
MatchMgr::Instance()->UnInit();
KillMgr::Instance()->UnInit();
EntityFactory::Instance()->UnInit();
SelfChecker::UnInit();
mt::MetaMgr::Instance()->UnInit();
LispEnv::Instance()->UnInit();
JsonDataMgr::Instance()->UnInit();
f8::BtMgr::Instance()->UnInit();
HandlerMgr::Instance()->UnInit();
PerfMonitor::Instance()->UnInit();
Perf::Instance()->UnInit();
#ifdef MYDEBUG
TraceMgr::Instance()->UnInit();
#endif
}
bool App::HasTask()
{
return RoomMgr::Instance()->HasTask();
}
void App::ProcessGameGateMsg(f8::MsgHdr* hdr)
{
f8::NetMsgHandler* handler = f8::GetNetMsgHandler
(&HandlerMgr::Instance()->ggmsghandler,
hdr->msgid);
if (handler) {
switch (handler->handlerid) {
case HID_RoomMgr:
ProcessNetMsg(handler, RoomMgr::Instance(), hdr);
break;
case HID_MatchTeam:
{
auto match_info = MatchMgr::Instance()->GetMatchInfo(hdr->socket_handle);
if (match_info) {
ProcessNetMsg(handler, std::get<1>(*match_info).get(), hdr);
}
}
break;
case HID_PlayerMgr:
ProcessNetMsg(handler, PlayerMgr::Instance(), hdr);
break;
case HID_Player:
{
Player* hum = PlayerMgr::Instance()->GetPlayerBySocket(hdr->socket_handle);
if (hum) {
hdr->hum = hum;
ProcessNetMsg(handler, hum, hdr);
}
}
break;
}
}
}
long long App::AllocTempHeroUniId()
{
if (curr_uniid_ < 1000) {
curr_uniid_ = 1000;
}
if (curr_uniid_ > 100000000) {
curr_uniid_ = 1001;
}
++curr_uniid_;
return -curr_uniid_;
}
long long App::AllocTempWeaponUniId()
{
if (curr_uniid_ < 1000) {
curr_uniid_ = 1000;
}
if (curr_uniid_ > 100000000) {
curr_uniid_ = 1000;
}
++curr_uniid_;
return -curr_uniid_;
}
static std::string GetSelfPath()
{
char self[PATH_MAX] = { 0 };
int nchar = readlink("/proc/self/exe", self, sizeof self);
if (nchar < 0) {
A8_ABORT();
}
std::string path((char*)self);
a8::XPrintf("exe:%s path:%s\n", {self, path});
return path;
}
int App::GetVersion()
{
const char* current_file_name = __FILE__;
if (!version_) {
std::string self_path = GetSelfPath();
//self_path = "/data/backups_app/b_game2006_gameserver_ty_z9.1.0.0.1.20231124R2/bin/gameserver2006";
std::vector<std::string> strings;
a8::Split(self_path, strings, '/');
std::string tag = strings.at(strings.size() - 3);
std::vector<std::string> strings2;
a8::Split(tag, strings2, '.');
std::string version_str = strings2.at(strings2.size() - 1);
a8::ReplaceString(version_str, "R", "0");
version_ = std::make_shared<int>(a8::XValue(version_str).GetInt());
a8::XPrintf("%s %s %s\n", {self_path, *version_, version_str});
}
return *version_;
}
const std::string App::GetPkgName()
{
return a8::Format("gameserver2006", {});
}
void App::Update(int delta_time)
{
RoomMgr::Instance()->Update(delta_time);
}
void App::DispatchSocketMsg(f8::MsgHdr* hdr)
{
switch (hdr->sockfrom) {
case SF_GameGate:
{
ProcessGameGateMsg(hdr);
}
break;
}
}