This commit is contained in:
aozhiwei 2023-11-18 13:07:52 +08:00
parent 0733e51ec9
commit 3723810667
6 changed files with 66 additions and 39 deletions

View File

@ -123,8 +123,9 @@ static void SavePerfLog()
f8::HttpClientPool::Instance()->max_user_request_delay = 0; f8::HttpClientPool::Instance()->max_user_request_delay = 0;
} }
bool App::Init(int argc, char* argv[]) void App::Init()
{ {
#if 0
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
this->argc_ = argc; this->argc_ = argc;
this->argv_ = argv; this->argv_ = argv;
@ -227,6 +228,7 @@ bool App::Init(int argc, char* argv[])
); );
} }
return true; return true;
#endif
} }
void App::UnInit() void App::UnInit()
@ -423,25 +425,25 @@ void App::ProcessGameGateMsg(f8::MsgHdr& hdr)
if (handler) { if (handler) {
switch (handler->handlerid) { switch (handler->handlerid) {
case HID_RoomMgr: case HID_RoomMgr:
ProcessNetMsg(handler, RoomMgr::Instance(), hdr); ProcessNetMsg(handler, RoomMgr::Instance(), &hdr);
break; break;
case HID_MatchTeam: case HID_MatchTeam:
{ {
auto match_info = MatchMgr::Instance()->GetMatchInfo(hdr.socket_handle); auto match_info = MatchMgr::Instance()->GetMatchInfo(hdr.socket_handle);
if (match_info) { if (match_info) {
ProcessNetMsg(handler, std::get<1>(*match_info).get(), hdr); ProcessNetMsg(handler, std::get<1>(*match_info).get(), &hdr);
} }
} }
break; break;
case HID_PlayerMgr: case HID_PlayerMgr:
ProcessNetMsg(handler, PlayerMgr::Instance(), hdr); ProcessNetMsg(handler, PlayerMgr::Instance(), &hdr);
break; break;
case HID_Player: case HID_Player:
{ {
Player* hum = PlayerMgr::Instance()->GetPlayerBySocket(hdr.socket_handle); Player* hum = PlayerMgr::Instance()->GetPlayerBySocket(hdr.socket_handle);
if (hum) { if (hum) {
hdr.hum = hum; hdr.hum = hum;
ProcessNetMsg(handler, hum, hdr); ProcessNetMsg(handler, hum, &hdr);
} }
} }
break; break;
@ -581,3 +583,18 @@ long long App::AllocTempWeaponUniId()
++curr_uniid_; ++curr_uniid_;
return -curr_uniid_; return -curr_uniid_;
} }
const std::string App::GetPkgName()
{
return a8::Format("gameserver2006", {});
}
void App::Update()
{
}
void App::DispatchSocketMsg(f8::MsgHdr* hdr)
{
}

View File

@ -4,9 +4,10 @@
#include <a8/singleton.h> #include <a8/singleton.h>
#include <f8/protoutils.h> #include <f8/protoutils.h>
#include <f8/app.h>
struct MsgNode; struct MsgNode;
class App : public a8::Singleton<App> class App : public f8::UserApp, public a8::Singleton<App>
{ {
private: private:
App() {}; App() {};
@ -17,8 +18,12 @@ public:
std::map<int, int> debug_params; std::map<int, int> debug_params;
#endif #endif
bool Init(int argc, char* argv[]); virtual const std::string GetPkgName() override;
void UnInit(); virtual void Init() override;
virtual void UnInit() override;
virtual void Update() override;
virtual bool HasTask() override;
virtual void DispatchSocketMsg(f8::MsgHdr* hdr) override;
int Run(); int Run();
@ -51,7 +56,6 @@ private:
void QuickExecute(int delta_time); void QuickExecute(int delta_time);
void SlowerExecute(int delta_time); void SlowerExecute(int delta_time);
void Schedule(); void Schedule();
bool HasTask();
void DispatchMsg(); void DispatchMsg();

View File

@ -22,50 +22,50 @@
static void _GMOpsSelfChecking(std::shared_ptr<f8::JsonHttpRequest> request) static void _GMOpsSelfChecking(std::shared_ptr<f8::JsonHttpRequest> request)
{ {
request->resp_xobj->SetVal("errcode", 0); request->GetResp()->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", ""); request->GetResp()->SetVal("errmsg", "");
request->resp_xobj->SetVal("healthy", 1); request->GetResp()->SetVal("healthy", 1);
request->resp_xobj->SetVal("servicing", App::Instance()->IsServicing() ? 1 : 0); request->GetResp()->SetVal("servicing", App::Instance()->IsServicing() ? 1 : 0);
request->resp_xobj->SetVal("max_rundelay", PerfMonitor::Instance()->max_run_delay_time); request->GetResp()->SetVal("max_rundelay", PerfMonitor::Instance()->max_run_delay_time);
request->resp_xobj->SetVal("max_timer_idle", PerfMonitor::Instance()->max_timer_idle); request->GetResp()->SetVal("max_timer_idle", PerfMonitor::Instance()->max_timer_idle);
} }
static void _GMOpsStopService(std::shared_ptr<f8::JsonHttpRequest> request) static void _GMOpsStopService(std::shared_ptr<f8::JsonHttpRequest> request)
{ {
request->resp_xobj->SetVal("errcode", 0); request->GetResp()->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", ""); request->GetResp()->SetVal("errmsg", "");
App::Instance()->SetServicing(false); App::Instance()->SetServicing(false);
} }
static void _GMOpsStartService(std::shared_ptr<f8::JsonHttpRequest> request) static void _GMOpsStartService(std::shared_ptr<f8::JsonHttpRequest> request)
{ {
request->resp_xobj->SetVal("errcode", 0); request->GetResp()->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", ""); request->GetResp()->SetVal("errmsg", "");
App::Instance()->SetServicing(true); App::Instance()->SetServicing(true);
} }
static void _GMOpsServerInfo(std::shared_ptr<f8::JsonHttpRequest> request) static void _GMOpsServerInfo(std::shared_ptr<f8::JsonHttpRequest> request)
{ {
request->resp_xobj->SetVal("errcode", 0); request->GetResp()->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", ""); request->GetResp()->SetVal("errmsg", "");
request->resp_xobj->SetVal("node_id", App::Instance()->GetNodeId()); request->GetResp()->SetVal("node_id", App::Instance()->GetNodeId());
request->resp_xobj->SetVal("instance_id", App::Instance()->GetInstanceId()); request->GetResp()->SetVal("instance_id", App::Instance()->GetInstanceId());
} }
static void _GMOpsTerminate(std::shared_ptr<f8::JsonHttpRequest> request) static void _GMOpsTerminate(std::shared_ptr<f8::JsonHttpRequest> request)
{ {
request->resp_xobj->SetVal("errcode", 0); request->GetResp()->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", ""); request->GetResp()->SetVal("errmsg", "");
App::Instance()->Terminate(); App::Instance()->Terminate();
} }
static void _GMStatGetRealTimeOnline(std::shared_ptr<f8::JsonHttpRequest> request) static void _GMStatGetRealTimeOnline(std::shared_ptr<f8::JsonHttpRequest> request)
{ {
request->resp_xobj->SetVal("errcode", 0); request->GetResp()->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", ""); request->GetResp()->SetVal("errmsg", "");
request->resp_xobj->SetVal("num", PerfMonitor::Instance()->entity_num[ET_Player]); request->GetResp()->SetVal("num", PerfMonitor::Instance()->entity_num[ET_Player]);
request->resp_xobj->SetVal("room_num", RoomMgr::Instance()->RoomNum()); request->GetResp()->SetVal("room_num", RoomMgr::Instance()->RoomNum());
} }
void HandlerMgr::Init() void HandlerMgr::Init()
@ -103,6 +103,7 @@ void HandlerMgr::UnInit()
void HandlerMgr::RegisterNetMsgHandlers() void HandlerMgr::RegisterNetMsgHandlers()
{ {
#if 0
RegisterNetMsgHandler(&ggmsghandler, &PlayerMgr::_SS_WSP_SocketDisconnect); RegisterNetMsgHandler(&ggmsghandler, &PlayerMgr::_SS_WSP_SocketDisconnect);
RegisterNetMsgHandler(&ggmsghandler, &PlayerMgr::_SS_Ping); RegisterNetMsgHandler(&ggmsghandler, &PlayerMgr::_SS_Ping);
RegisterNetMsgHandler(&ggmsghandler, &RoomMgr::_CMJoin); RegisterNetMsgHandler(&ggmsghandler, &RoomMgr::_CMJoin);
@ -132,6 +133,7 @@ void HandlerMgr::RegisterNetMsgHandlers()
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMTeamMarkTargetPos); RegisterNetMsgHandler(&ggmsghandler, &Player::_CMTeamMarkTargetPos);
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMSetRevivePosition); RegisterNetMsgHandler(&ggmsghandler, &Player::_CMSetRevivePosition);
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMGetSettlementTeamList); RegisterNetMsgHandler(&ggmsghandler, &Player::_CMGetSettlementTeamList);
#endif
} }
void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle, void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle,
@ -148,20 +150,22 @@ void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle,
std::string msgname = a8::Get(request, "c").GetString() + "@" + a8::Get(request, "a").GetString(); std::string msgname = a8::Get(request, "c").GetString() + "@" + a8::Get(request, "a").GetString();
auto itr = gmhandlers_.find(msgname); auto itr = gmhandlers_.find(msgname);
if (itr != gmhandlers_.end()) { if (itr != gmhandlers_.end()) {
#if 0
auto request = std::make_shared<f8::JsonHttpRequest>(); auto request = std::make_shared<f8::JsonHttpRequest>();
request->saddr = saddr; request->saddr = saddr;
request->socket_handle = sockhandle; request->socket_handle = sockhandle;
request->query_str = querystr; request->query_str = querystr;
request->params->ReadFromUrlQueryString(querystr); request->params->ReadFromUrlQueryString(querystr);
request->resp_xobj->SetVal("errcode", 0); request->GetResp()->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", ""); request->GetResp()->SetVal("errmsg", "");
itr->second(request); itr->second(request);
if (!request->pending){ if (!request->pending){
std::string response; std::string response;
request->resp_xobj->ToJsonStr(response); request->GetResp()->ToJsonStr(response);
GGListener::Instance()->SendText(sockhandle, a8::HttpResponse(response)); GGListener::Instance()->SendText(sockhandle, a8::HttpResponse(response));
} }
#endif
} else { } else {
GGListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}")); GGListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}"));
} }

View File

@ -27,24 +27,24 @@ static void _ProxyCallback(std::shared_ptr<f8::JsonHttpRequest> request)
#ifdef DEBUG #ifdef DEBUG
f8::UdpLog::Instance()->Debug("ProxyCallbBack request:%s", f8::UdpLog::Instance()->Debug("ProxyCallbBack request:%s",
{ {
request->params->ToJsonStr() request->GetParams()->ToJsonStr()
}); });
#endif #endif
std::string seq_id = request->params->Get("seq_id"); std::string seq_id = request->GetParams()->Get("seq_id");
std::shared_ptr<HttpProxyRequest> req = HttpProxy::Instance()->GetRequest(seq_id); std::shared_ptr<HttpProxyRequest> req = HttpProxy::Instance()->GetRequest(seq_id);
if (req) { if (req) {
a8::XObject data; a8::XObject data;
data.ReadFromJsonString(request->params->Get("data").GetString()); data.ReadFromJsonString(request->GetParams()->Get("data").GetString());
if (data.GetType() == a8::XOT_SIMPLE) { if (data.GetType() == a8::XOT_SIMPLE) {
data.ReadFromJsonString("{}"); data.ReadFromJsonString("{}");
} }
f8::HttpContext ctx; f8::HttpContext ctx;
if (request->params->HasKey("errcode") && if (request->GetParams()->HasKey("errcode") &&
request->params->Get("errcode").GetInt() == 0) { request->GetParams()->Get("errcode").GetInt() == 0) {
req->cb(true, &data, &ctx); req->cb(true, &data, &ctx);
} else { } else {
req->cb(false, request->params.get(), &ctx); req->cb(false, request->GetParams().get(), &ctx);
} }
HttpProxy::Instance()->DestoryRequest(req); HttpProxy::Instance()->DestoryRequest(req);
} }

View File

@ -4,9 +4,11 @@
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
int exitcode = 0; int exitcode = 0;
#if 0
if (App::Instance()->Init(argc, argv)) { if (App::Instance()->Init(argc, argv)) {
exitcode = App::Instance()->Run(); exitcode = App::Instance()->Run();
App::Instance()->UnInit(); App::Instance()->UnInit();
} }
#endif
return exitcode; return exitcode;
} }

2
third_party/f8 vendored

@ -1 +1 @@
Subproject commit 7fb9c9083275fd35c2bb4456999673444dcfe986 Subproject commit 39cf53ed693b0c6e6d9119c38b894013ac9716e6