Compare commits
46 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7d0d1be7bf | ||
![]() |
5d45ddbdd9 | ||
![]() |
573e381c4b | ||
![]() |
57b3842f62 | ||
![]() |
7136b95953 | ||
![]() |
c53bc5aae3 | ||
![]() |
b36bd43e17 | ||
![]() |
a3f871f8a7 | ||
![]() |
8592dd8fde | ||
![]() |
b3298d231a | ||
![]() |
a273deba77 | ||
![]() |
64107a5b13 | ||
![]() |
68a8c14305 | ||
![]() |
19fd034d79 | ||
![]() |
be96e0c0d5 | ||
![]() |
060b98775d | ||
![]() |
fc87c6c040 | ||
![]() |
d2bb14deae | ||
![]() |
dbc6cd724d | ||
![]() |
5cf97989ab | ||
![]() |
2aac0613d9 | ||
![]() |
93bf78c17f | ||
![]() |
e6e583b44a | ||
![]() |
f58185b947 | ||
![]() |
fe6587fdc7 | ||
![]() |
7db07b904c | ||
![]() |
80ce110950 | ||
![]() |
b29f436980 | ||
![]() |
f3c1e10482 | ||
![]() |
75ca294941 | ||
![]() |
43921b4de6 | ||
![]() |
3872cffe96 | ||
![]() |
3fce35d421 | ||
![]() |
412b1a7731 | ||
![]() |
24a004ef01 | ||
![]() |
14183d316e | ||
![]() |
844f13f119 | ||
![]() |
d37ea3972e | ||
![]() |
815554bb04 | ||
![]() |
d3ef1e5b83 | ||
![]() |
90b90c1d44 | ||
![]() |
3b30957e37 | ||
![]() |
c43ded4696 | ||
![]() |
78ccad1206 | ||
![]() |
4c8d3488f4 | ||
![]() |
bd7e0bea6b |
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -13,3 +13,9 @@
|
||||
[submodule "third_party/recastnavigation"]
|
||||
path = third_party/recastnavigation
|
||||
url = git@git.kingsome.cn:libs/recastnavigation.git
|
||||
[submodule "third_party/a8"]
|
||||
path = third_party/a8
|
||||
url = git@git.kingsome.cn:server_common/a8.git
|
||||
[submodule "third_party/f8"]
|
||||
path = third_party/f8
|
||||
url = git@git.kingsome.cn:server_common/f8.git
|
||||
|
@ -0,0 +1,12 @@
|
||||
[
|
||||
{
|
||||
"instance_id": 1,
|
||||
"ip": "127.0.0.1",
|
||||
"listen_port": 7621
|
||||
},
|
||||
{
|
||||
"instance_id": 2,
|
||||
"ip": "127.0.0.1",
|
||||
"listen_port": 7622
|
||||
}
|
||||
]
|
@ -0,0 +1,12 @@
|
||||
[
|
||||
{
|
||||
"instance_id": 1,
|
||||
"ip": "127.0.0.1",
|
||||
"listen_port": 7621
|
||||
},
|
||||
{
|
||||
"instance_id": 2,
|
||||
"ip": "127.0.0.1",
|
||||
"listen_port": 7622
|
||||
}
|
||||
]
|
@ -0,0 +1,7 @@
|
||||
[
|
||||
{
|
||||
"instance_id": 1,
|
||||
"ip": "127.0.0.1",
|
||||
"listen_port": 7627
|
||||
}
|
||||
]
|
@ -0,0 +1,7 @@
|
||||
[
|
||||
{
|
||||
"instance_id": 1,
|
||||
"ip": "127.0.0.1",
|
||||
"listen_port": 7628
|
||||
}
|
||||
]
|
@ -0,0 +1,7 @@
|
||||
[
|
||||
{
|
||||
"instance_id": 1,
|
||||
"ip": "127.0.0.1",
|
||||
"listen_port": 7629
|
||||
}
|
||||
]
|
1
server/bin/masterserver/bin/masterserver2006
Symbolic link
1
server/bin/masterserver/bin/masterserver2006
Symbolic link
@ -0,0 +1 @@
|
||||
masterserver
|
1
server/bin/masterserver/bin/masterserver9007
Symbolic link
1
server/bin/masterserver/bin/masterserver9007
Symbolic link
@ -0,0 +1 @@
|
||||
masterserver
|
1
server/bin/masterserver/bin/masterserver9008
Symbolic link
1
server/bin/masterserver/bin/masterserver9008
Symbolic link
@ -0,0 +1 @@
|
||||
masterserver
|
1
server/bin/masterserver/bin/masterserver9009
Symbolic link
1
server/bin/masterserver/bin/masterserver9009
Symbolic link
@ -0,0 +1 @@
|
||||
masterserver
|
@ -1,11 +0,0 @@
|
||||
path_arr=$(echo $PWD|tr '/' '\n')
|
||||
path_arr=(${path_arr})
|
||||
GAME_ID=${path_arr[-5]}
|
||||
|
||||
if echo $GAME_ID | grep -q '[^0-9]'
|
||||
then
|
||||
echo 'game_id参数必须为数字'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
python ../../third_party/tools/scripts/server/monitor.py masterserver${GAME_ID} '-n1 -i1'
|
@ -23,12 +23,13 @@ else()
|
||||
message(LIB_DIR: ${LIB_DIR} )
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g -std=gnu++1z -DGAME_ID=${GAME_ID} -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++1z -DGAME_ID=${GAME_ID} -DDEBUG")
|
||||
|
||||
include_directories(
|
||||
AFTER
|
||||
../../third_party/a8engine
|
||||
../../third_party/a8
|
||||
../../third_party/f8
|
||||
/usr/include/mysql
|
||||
/usr/include/jsoncpp
|
||||
/usr/include/hiredis
|
||||
@ -48,11 +49,11 @@ link_directories(
|
||||
../../third_party/behaviac/lib/${LIB_DIR}
|
||||
)
|
||||
|
||||
aux_source_directory(../../third_party/a8engine/a8
|
||||
aux_source_directory(../../third_party/a8/a8
|
||||
SRC_LIST
|
||||
)
|
||||
|
||||
aux_source_directory(../../third_party/framework/cpp
|
||||
aux_source_directory(../../third_party/f8/f8
|
||||
SRC_LIST
|
||||
)
|
||||
|
||||
@ -79,11 +80,11 @@ aux_source_directory(.
|
||||
)
|
||||
|
||||
set(EXECUTABLE_OUTPUT_PATH
|
||||
${PROJECT_BINARY_DIR}/../bin
|
||||
${PROJECT_BINARY_DIR}/../bin/masterserver/bin
|
||||
)
|
||||
|
||||
add_executable(
|
||||
masterserver${GAME_ID} ${SRC_LIST}
|
||||
masterserver ${SRC_LIST}
|
||||
)
|
||||
|
||||
add_custom_target(script_pb_protocol ALL)
|
||||
@ -91,12 +92,12 @@ add_custom_command(TARGET script_pb_protocol
|
||||
PRE_BUILD
|
||||
COMMAND python ../../third_party/tools/scripts/construct/build_pb.py --cpp_out=. --pb_files=ss_proto,ss_msgid --nohooks 1
|
||||
)
|
||||
add_dependencies(masterserver${GAME_ID} script_pb_protocol)
|
||||
add_dependencies(masterserver script_pb_protocol)
|
||||
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
target_link_libraries(
|
||||
masterserver${GAME_ID}
|
||||
masterserver
|
||||
pthread
|
||||
mysqlclient
|
||||
protobuf
|
||||
@ -110,11 +111,11 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
hiredis
|
||||
tinyxml2
|
||||
tcmalloc
|
||||
behaviac_gcc_release
|
||||
behaviac_gcc_debug
|
||||
)
|
||||
else()
|
||||
target_link_libraries(
|
||||
masterserver${GAME_ID}
|
||||
masterserver
|
||||
pthread
|
||||
mysqlclient
|
||||
protobuf
|
||||
@ -131,4 +132,3 @@ else()
|
||||
behaviac_gcc_release
|
||||
)
|
||||
endif()
|
||||
|
||||
|
@ -4,7 +4,8 @@
|
||||
#include <a8/mixedsession.h>
|
||||
#include <a8/tcplistener.h>
|
||||
|
||||
#include "framework/cpp/netmsghandler.h"
|
||||
#include <f8/netmsghandler.h>
|
||||
#include <f8/msgqueue.h>
|
||||
|
||||
#include "app.h"
|
||||
#include "GGListener.h"
|
||||
@ -27,13 +28,15 @@ public:
|
||||
if (buflen - offset < sizeof(f8::PackHead) + p->packlen) {
|
||||
break;
|
||||
}
|
||||
App::Instance()->AddSocketMsg(SF_GameGate,
|
||||
socket_handle,
|
||||
saddr,
|
||||
p->msgid,
|
||||
p->seqid,
|
||||
&buf[offset + sizeof(f8::PackHead)],
|
||||
p->packlen);
|
||||
f8::App::Instance()->AddSocketMsg
|
||||
(SF_GameGate,
|
||||
socket_handle,
|
||||
saddr,
|
||||
p->msgid,
|
||||
p->seqid,
|
||||
&buf[offset + sizeof(f8::PackHead)],
|
||||
p->packlen,
|
||||
0);
|
||||
offset += sizeof(f8::PackHead) + p->packlen;
|
||||
} else {
|
||||
warning = true;
|
||||
@ -43,46 +46,49 @@ public:
|
||||
}
|
||||
|
||||
if (warning) {
|
||||
a8::UdpLog::Instance()->Warning("收到client非法数据包", {});
|
||||
f8::UdpLog::Instance()->Warning("收到client非法数据包", {});
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnRawHttpGet(const std::string& url, const std::string& querystr,
|
||||
std::string& response) override
|
||||
{
|
||||
App::Instance()->AddIMMsg(IM_ExecGM,
|
||||
a8::XParams()
|
||||
.SetSender(socket_handle)
|
||||
.SetParam1(url)
|
||||
.SetParam2(querystr)
|
||||
.SetParam3(saddr)
|
||||
);
|
||||
f8::MsgQueue::Instance()->PostMsg
|
||||
(IM_ExecGM,
|
||||
a8::Args
|
||||
(
|
||||
{
|
||||
socket_handle,
|
||||
a8::XValue(url).GetString(),
|
||||
a8::XValue(querystr).GetString(),
|
||||
saddr
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
virtual void OnDisConnect() override
|
||||
{
|
||||
App::Instance()->AddIMMsg(IM_ClientSocketDisconnect,
|
||||
a8::XParams()
|
||||
.SetSender(socket_handle)
|
||||
.SetParam1(1));
|
||||
f8::MsgQueue::Instance()->PostMsg
|
||||
(IM_ClientSocketDisconnect,
|
||||
a8::Args
|
||||
(
|
||||
{
|
||||
socket_handle
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
static void CreateGameClientSocket(a8::TcpSession **p)
|
||||
{
|
||||
*p = new GGClientSession();
|
||||
}
|
||||
|
||||
static void GSListeneron_error(a8::TcpListener*, int type, int errorid)
|
||||
{
|
||||
a8::UdpLog::Instance()->Debug("GGListeneron_error %d %d", {type, errorid});
|
||||
f8::UdpLog::Instance()->Debug("GGListeneron_error %d %d", {type, errorid});
|
||||
}
|
||||
|
||||
void GGListener::Init()
|
||||
{
|
||||
tcp_listener_ = new a8::TcpListener();
|
||||
tcp_listener_->on_create_client_socket = CreateGameClientSocket;
|
||||
tcp_listener_ = std::make_shared<a8::TcpListener>();
|
||||
tcp_listener_->RegisterSessionClass<GGClientSession>(1024 * 64);
|
||||
tcp_listener_->on_error = GSListeneron_error;
|
||||
|
||||
tcp_listener_->bind_address = "0.0.0.0";
|
||||
@ -92,8 +98,6 @@ void GGListener::Init()
|
||||
|
||||
void GGListener::UnInit()
|
||||
{
|
||||
delete tcp_listener_;
|
||||
tcp_listener_ = nullptr;
|
||||
}
|
||||
|
||||
void GGListener::SendText(int sockhandle, const std::string& text)
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <f8/protoutils.h>
|
||||
|
||||
//game client listener
|
||||
namespace a8
|
||||
{
|
||||
@ -20,7 +22,7 @@ class GGListener : public a8::Singleton<GGListener>
|
||||
void SendMsg(int sockhandle, T& msg)
|
||||
{
|
||||
static int msgid = f8::Net_GetMessageId(msg);
|
||||
f8::Net_SendMsg(tcp_listener_, sockhandle, 0, msgid, msg);
|
||||
f8::Net_SendMsg(tcp_listener_.get(), sockhandle, 0, msgid, msg);
|
||||
}
|
||||
|
||||
void SendText(int sockhandle, const std::string& text);
|
||||
@ -29,5 +31,5 @@ class GGListener : public a8::Singleton<GGListener>
|
||||
void MarkClient(int sockhandle, bool is_active);
|
||||
|
||||
private:
|
||||
a8::TcpListener *tcp_listener_ = nullptr;
|
||||
std::shared_ptr<a8::TcpListener> tcp_listener_;
|
||||
};
|
||||
|
@ -1,16 +1,12 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
#include <a8/redis.h>
|
||||
#include <a8/timer.h>
|
||||
#include <a8/uuid.h>
|
||||
|
||||
#include "framework/cpp/netmsghandler.h"
|
||||
#include <f8/netmsghandler.h>
|
||||
#include <f8/msgqueue.h>
|
||||
#include <f8/tglog.h>
|
||||
#include <f8/timer.h>
|
||||
|
||||
#include "app.h"
|
||||
#include "jsondatamgr.h"
|
||||
@ -21,35 +17,9 @@
|
||||
#include "ss_msgid.pb.h"
|
||||
#include "ss_proto.pb.h"
|
||||
|
||||
#include "framework/cpp/msgqueue.h"
|
||||
#include "framework/cpp/tglog.h"
|
||||
|
||||
struct MsgNode
|
||||
{
|
||||
SocketFrom_e sockfrom;
|
||||
int sockhandle;
|
||||
unsigned short msgid;
|
||||
unsigned int seqid;
|
||||
long ip_saddr;
|
||||
char* buf;
|
||||
int buflen;
|
||||
MsgNode* next;
|
||||
};
|
||||
|
||||
struct IMMsgNode
|
||||
{
|
||||
unsigned short msgid;
|
||||
a8::XParams params;
|
||||
IMMsgNode* next = nullptr;
|
||||
|
||||
};
|
||||
|
||||
const char* const PROJ_LOG_ROOT_FMT = "/data/logs/%s/logs";
|
||||
const char* const PROJ_LOG_FILENAME_FMT = "log_$pid_%Y%m%d.log";
|
||||
|
||||
static void SavePerfLog()
|
||||
{
|
||||
a8::UdpLog::Instance()->Info("max_mainloop_rundelay:%d",
|
||||
f8::UdpLog::Instance()->Info("max_mainloop_rundelay:%d",
|
||||
{
|
||||
App::Instance()->perf.max_run_delay_time,
|
||||
});
|
||||
@ -57,291 +27,66 @@ static void SavePerfLog()
|
||||
App::Instance()->perf.max_timer_idle = 0;
|
||||
}
|
||||
|
||||
void App::Init(int argc, char* argv[])
|
||||
const std::string App::GetPkgName()
|
||||
{
|
||||
#if 0
|
||||
{
|
||||
Vector2D dir;
|
||||
dir.Normalize();
|
||||
}
|
||||
#endif
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
this->argc = argc;
|
||||
this->argv = argv;
|
||||
return a8::Format("game%d_masterserver", {App::Instance()->GetGameId()});
|
||||
}
|
||||
|
||||
if (!ParseOpt()) {
|
||||
terminated = true;
|
||||
if (node_id <= 0) {
|
||||
a8::XPrintf("gameserver启动失败,缺少-n参数\n", {});
|
||||
} else if (node_id > MAX_NODE_ID) {
|
||||
a8::XPrintf("gameserver启动失败,-n参数不能大于%d\n", {MAX_NODE_ID});
|
||||
} else if (instance_id <= 0) {
|
||||
a8::XPrintf("gameserver启动失败,缺少-i参数\n", {});
|
||||
} else if (instance_id > MAX_INSTANCE_ID) {
|
||||
a8::XPrintf("gameserver启动失败,-i参数不能大于%d\n", {MAX_INSTANCE_ID});
|
||||
}
|
||||
return;
|
||||
}
|
||||
a8::XPrintf("masterserver starting instance_id:%d pid:%d game_id:%d\n", {instance_id, getpid(), GAME_ID});
|
||||
|
||||
loop_mutex_ = new std::mutex();
|
||||
loop_cond_ = new std::condition_variable();
|
||||
msg_mutex_ = new std::mutex();
|
||||
im_msg_mutex_ = new std::mutex();
|
||||
|
||||
srand(time(nullptr));
|
||||
InitLog();
|
||||
void App::Init()
|
||||
{
|
||||
HandlerMgr::Instance()->Init();
|
||||
a8::Timer::Instance()->Init();
|
||||
f8::MsgQueue::Instance()->Init();
|
||||
f8::TGLog::Instance()->Init(a8::Format(PROJ_NAME_FMT, {GAME_ID}), false);
|
||||
JsonDataMgr::Instance()->Init();
|
||||
LoadSeparateChannelConfig();
|
||||
uuid.SetMachineId((node_id - 1) * MAX_NODE_ID + instance_id);
|
||||
GGListener::Instance()->Init();
|
||||
GSMgr::Instance()->Init();
|
||||
|
||||
a8::UdpLog::Instance()->Info("masterserver starting instance_id:%d pid:%d", {instance_id, getpid()});
|
||||
{
|
||||
int perf_log_time = 1000 * 60 * 5;
|
||||
if (getenv("is_dev_env")) {
|
||||
perf_log_time = 1000 * 10;
|
||||
}
|
||||
a8::Timer::Instance()->AddRepeatTimer(perf_log_time,
|
||||
a8::XParams(),
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
SavePerfLog();
|
||||
});
|
||||
}
|
||||
{
|
||||
a8::Timer::Instance()->AddRepeatTimer(1000 * 60 * 5,
|
||||
a8::XParams(),
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
App::Instance()->LoadSeparateChannelConfig();
|
||||
});
|
||||
f8::Timer::Instance()->SetInterval
|
||||
(perf_log_time,
|
||||
[] (int e, const a8::Args* args)
|
||||
{
|
||||
if (a8::TIMER_EXEC_EVENT == e) {
|
||||
SavePerfLog();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void App::UnInit()
|
||||
{
|
||||
if (terminated) {
|
||||
return;
|
||||
}
|
||||
GSMgr::Instance()->UnInit();
|
||||
GGListener::Instance()->UnInit();
|
||||
JsonDataMgr::Instance()->UnInit();
|
||||
f8::MsgQueue::Instance()->UnInit();
|
||||
a8::Timer::Instance()->UnInit();
|
||||
HandlerMgr::Instance()->UnInit();
|
||||
f8::TGLog::Instance()->UnInit();
|
||||
UnInitLog();
|
||||
|
||||
delete im_msg_mutex_;
|
||||
im_msg_mutex_ = nullptr;
|
||||
delete msg_mutex_;
|
||||
msg_mutex_ = nullptr;
|
||||
delete loop_cond_;
|
||||
loop_cond_ = nullptr;
|
||||
delete loop_mutex_;
|
||||
loop_mutex_ = nullptr;
|
||||
}
|
||||
|
||||
int App::Run()
|
||||
void App::Update(int delta_time)
|
||||
{
|
||||
if (terminated) {
|
||||
return 0;
|
||||
}
|
||||
int ret = 0;
|
||||
a8::UdpLog::Instance()->Info("masterserver running", {});
|
||||
last_run_tick_ = a8::XGetTickCount();
|
||||
int delta_time = 0;
|
||||
while (!terminated) {
|
||||
a8::tick_t begin_tick = a8::XGetTickCount();
|
||||
Global::g_nowtime = time(nullptr);
|
||||
QuickExecute(delta_time);
|
||||
SlowerExecute(delta_time);
|
||||
Schedule();
|
||||
a8::tick_t end_tick = a8::XGetTickCount();
|
||||
if (end_tick - begin_tick > perf.max_run_delay_time) {
|
||||
perf.max_run_delay_time = end_tick - begin_tick;
|
||||
}
|
||||
delta_time = end_tick - begin_tick;
|
||||
}
|
||||
return ret;
|
||||
QuickExecute();
|
||||
SlowerExecute();
|
||||
}
|
||||
|
||||
void App::AddSocketMsg(SocketFrom_e sockfrom,
|
||||
int sockhandle,
|
||||
long ip_saddr,
|
||||
unsigned short msgid,
|
||||
unsigned int seqid,
|
||||
const char *msgbody,
|
||||
int bodylen)
|
||||
{
|
||||
MsgNode *p = (MsgNode*) malloc(sizeof(MsgNode));
|
||||
memset(p, 0, sizeof(MsgNode));
|
||||
p->sockfrom = sockfrom;
|
||||
p->ip_saddr = ip_saddr;
|
||||
p->sockhandle = sockhandle;
|
||||
p->msgid = msgid;
|
||||
p->seqid = seqid;
|
||||
p->buf = nullptr;
|
||||
p->buflen = bodylen;
|
||||
if (bodylen > 0) {
|
||||
p->buf = (char*)malloc(bodylen);
|
||||
memmove(p->buf, msgbody, bodylen);
|
||||
}
|
||||
msg_mutex_->lock();
|
||||
if (bot_node_) {
|
||||
bot_node_->next = p;
|
||||
bot_node_ = p;
|
||||
} else {
|
||||
top_node_ = p;
|
||||
bot_node_ = p;
|
||||
}
|
||||
++msgnode_size_;
|
||||
msg_mutex_->unlock();
|
||||
NotifyLoopCond();
|
||||
}
|
||||
|
||||
void App::AddIMMsg(unsigned short imcmd, a8::XParams params)
|
||||
{
|
||||
IMMsgNode *p = new IMMsgNode;
|
||||
p->msgid = imcmd;
|
||||
p->params = params;
|
||||
p->next = nullptr;
|
||||
im_msg_mutex_->lock();
|
||||
if (im_bot_node_) {
|
||||
im_bot_node_->next = p;
|
||||
im_bot_node_ = p;
|
||||
} else {
|
||||
im_top_node_ = p;
|
||||
im_bot_node_ = p;
|
||||
}
|
||||
im_msg_mutex_->unlock();
|
||||
NotifyLoopCond();
|
||||
}
|
||||
|
||||
void App::QuickExecute(int delta_time)
|
||||
{
|
||||
ProcessIMMsg();
|
||||
DispatchMsg();
|
||||
a8::Timer::Instance()->Update();
|
||||
}
|
||||
|
||||
void App::SlowerExecute(int delta_time)
|
||||
void App::QuickExecute()
|
||||
{
|
||||
}
|
||||
|
||||
void App::NotifyLoopCond()
|
||||
void App::SlowerExecute()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(*loop_mutex_);
|
||||
loop_cond_->notify_all();
|
||||
}
|
||||
|
||||
void App::Schedule()
|
||||
{
|
||||
#if 1
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(*loop_mutex_);
|
||||
loop_cond_->wait_for(lk, std::chrono::milliseconds(1));
|
||||
}
|
||||
#else
|
||||
std::unique_lock<std::mutex> lk(*loop_mutex_);
|
||||
if (!HasTask()) {
|
||||
int sleep_time = a8::Timer::Instance()->GetIdleableMillSeconds();
|
||||
loop_cond_->wait_for(lk, std::chrono::milliseconds(sleep_time));
|
||||
if (sleep_time > perf.max_timer_idle) {
|
||||
perf.max_timer_idle = sleep_time;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool App::HasTask()
|
||||
{
|
||||
{
|
||||
if (!im_work_node_) {
|
||||
im_msg_mutex_->lock();
|
||||
if (!im_work_node_ && im_top_node_) {
|
||||
im_work_node_ = im_top_node_;
|
||||
im_top_node_ = nullptr;
|
||||
im_bot_node_ = nullptr;
|
||||
}
|
||||
im_msg_mutex_->unlock();
|
||||
}
|
||||
if (im_work_node_) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
{
|
||||
if (!work_node_) {
|
||||
msg_mutex_->lock();
|
||||
if (!work_node_ && top_node_) {
|
||||
work_node_ = top_node_;
|
||||
top_node_ = nullptr;
|
||||
bot_node_ = nullptr;
|
||||
}
|
||||
msg_mutex_->unlock();
|
||||
}
|
||||
if (work_node_) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void App::DispatchMsg()
|
||||
void App::ProcessGameGateMsg(f8::MsgHdr* hdr)
|
||||
{
|
||||
long long starttick = a8::XGetTickCount();
|
||||
if (!work_node_ && top_node_) {
|
||||
msg_mutex_->lock();
|
||||
work_node_ = top_node_;
|
||||
top_node_ = nullptr;
|
||||
bot_node_ = nullptr;
|
||||
working_msgnode_size_ = msgnode_size_;
|
||||
msg_mutex_->unlock();
|
||||
}
|
||||
|
||||
f8::MsgHdr hdr;
|
||||
while (work_node_) {
|
||||
MsgNode *pdelnode = work_node_;
|
||||
work_node_ = pdelnode->next;
|
||||
hdr.msgid = pdelnode->msgid;
|
||||
hdr.seqid = pdelnode->seqid;
|
||||
hdr.socket_handle = pdelnode->sockhandle;
|
||||
hdr.buf = pdelnode->buf;
|
||||
hdr.buflen = pdelnode->buflen;
|
||||
hdr.offset = 0;
|
||||
hdr.ip_saddr = pdelnode->ip_saddr;
|
||||
switch (pdelnode->sockfrom) {
|
||||
case SF_GameGate:
|
||||
{
|
||||
ProcessGameGateMsg(hdr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (pdelnode->buf) {
|
||||
free(pdelnode->buf);
|
||||
}
|
||||
free(pdelnode);
|
||||
working_msgnode_size_--;
|
||||
if (a8::XGetTickCount() - starttick > 200) {
|
||||
break;
|
||||
}
|
||||
}//end while
|
||||
|
||||
if (!work_node_) {
|
||||
working_msgnode_size_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void App::ProcessGameGateMsg(f8::MsgHdr& hdr)
|
||||
{
|
||||
f8::NetMsgHandler* handler = f8::GetNetMsgHandler(&HandlerMgr::Instance()->ggmsghandler,
|
||||
hdr.msgid);
|
||||
f8::NetMsgHandler* handler = f8::GetNetMsgHandler
|
||||
(&HandlerMgr::Instance()->ggmsghandler,
|
||||
hdr->msgid);
|
||||
if (handler) {
|
||||
switch (handler->handlerid) {
|
||||
case HID_GSMgr:
|
||||
@ -351,159 +96,28 @@ void App::ProcessGameGateMsg(f8::MsgHdr& hdr)
|
||||
}
|
||||
}
|
||||
|
||||
void App::ProcessIMMsg()
|
||||
void App::DispatchSocketMsg(f8::MsgHdr* hdr)
|
||||
{
|
||||
if (!im_work_node_ && im_top_node_) {
|
||||
im_msg_mutex_->lock();
|
||||
im_work_node_ = im_top_node_;
|
||||
im_top_node_ = nullptr;
|
||||
im_bot_node_ = nullptr;
|
||||
im_msg_mutex_->unlock();
|
||||
}
|
||||
while (im_work_node_) {
|
||||
IMMsgNode *pdelnode = im_work_node_;
|
||||
switch (im_work_node_->msgid) {
|
||||
case f8::IM_SysMsgQueue:
|
||||
{
|
||||
const a8::XParams* param = (const a8::XParams*)pdelnode->params.param1.GetUserData();
|
||||
f8::MsgQueue::Instance()->ProcessMsg(pdelnode->params.sender.GetInt(),
|
||||
*param
|
||||
);
|
||||
delete param;
|
||||
}
|
||||
break;
|
||||
case IM_ClientSocketDisconnect:
|
||||
{
|
||||
#if 0
|
||||
PlayerMgr::Instance()->OnClientDisconnect(pdelnode->params);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case IM_ExecGM:
|
||||
{
|
||||
HandlerMgr::Instance()->ProcGMMsg(pdelnode->params.param3,
|
||||
pdelnode->params.sender,
|
||||
pdelnode->params.param1.GetString(),
|
||||
pdelnode->params.param2.GetString()
|
||||
);
|
||||
}
|
||||
break;
|
||||
switch (hdr->sockfrom) {
|
||||
case SF_GameGate:
|
||||
{
|
||||
ProcessGameGateMsg(hdr);
|
||||
}
|
||||
im_work_node_ = im_work_node_->next;
|
||||
delete pdelnode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void App::InitLog()
|
||||
int App::GetGameId() const
|
||||
{
|
||||
std::string filename_fmt = PROJ_LOG_FILENAME_FMT;
|
||||
a8::ReplaceString(filename_fmt, "$pid", a8::XValue(getpid()));
|
||||
|
||||
std::string proj_root_dir = a8::Format(PROJ_ROOT_FMT, {a8::Format(PROJ_NAME_FMT,{GAME_ID})});
|
||||
std::string proj_log_root_dir = a8::Format(PROJ_LOG_ROOT_FMT, {a8::Format(PROJ_NAME_FMT, {GAME_ID})});
|
||||
std::string log_file_name = a8::Format(PROJ_LOG_ROOT_FMT,
|
||||
{a8::Format(PROJ_NAME_FMT, {GAME_ID})}) + "/" + filename_fmt;
|
||||
|
||||
a8::MkDir(proj_root_dir);
|
||||
a8::MkDir(proj_log_root_dir);
|
||||
a8::UdpLog::Instance()->SetLogFileName(log_file_name);
|
||||
a8::UdpLog::Instance()->Init();
|
||||
a8::UdpLog::Instance()->Info("proj_root_dir:%s", {proj_root_dir});
|
||||
a8::UdpLog::Instance()->Info("proj_log_root_dir:%s", {proj_log_root_dir});
|
||||
a8::UdpLog::Instance()->Info("log_file_name:%s", {log_file_name});
|
||||
}
|
||||
|
||||
void App::UnInitLog()
|
||||
{
|
||||
a8::UdpLog::Instance()->UnInit();
|
||||
}
|
||||
|
||||
bool App::ParseOpt()
|
||||
{
|
||||
int ch = 0;
|
||||
while ((ch = getopt(argc, argv, "n:i:t:r:f:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'n':
|
||||
{
|
||||
node_id = a8::XValue(optarg);
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
{
|
||||
instance_id = a8::XValue(optarg);
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
{
|
||||
is_test_mode = true;
|
||||
test_param = a8::XValue(optarg);
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
{
|
||||
std::vector<std::string> strings;
|
||||
a8::Split(optarg, strings, ',');
|
||||
for (auto& str : strings) {
|
||||
flags.insert(a8::XValue(str).GetInt());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return instance_id > 0 && node_id > 0;
|
||||
}
|
||||
|
||||
long long App::NewUuid()
|
||||
{
|
||||
return uuid.Generate();
|
||||
}
|
||||
|
||||
a8::XParams* App::AddContext(long long context_id)
|
||||
{
|
||||
context_hash_[context_id] = a8::XParams();
|
||||
return GetContext(context_id);
|
||||
}
|
||||
|
||||
void App::DelContext(long long context_id)
|
||||
{
|
||||
context_hash_.erase(context_id);
|
||||
}
|
||||
|
||||
a8::XParams* App::GetContext(long long context_id)
|
||||
{
|
||||
auto itr = context_hash_.find(context_id);
|
||||
return itr != context_hash_.end() ? &(itr->second) : nullptr;
|
||||
}
|
||||
|
||||
bool App::IsSeparateChannel(int channel)
|
||||
{
|
||||
return separate_channel_hash_.find(channel) != separate_channel_hash_.end();
|
||||
}
|
||||
|
||||
void App::LoadSeparateChannelConfig()
|
||||
{
|
||||
std::string data;
|
||||
a8::ReadStringFromFile("../config/separate_channels.csv", data);
|
||||
#ifdef DEBUG
|
||||
std::string game_id = a8::XValue((f8::App::Instance()->GetArgv())[0]).GetString();
|
||||
std::vector<std::string> strings;
|
||||
a8::Split(data, strings, ',');
|
||||
separate_channel_hash_.clear();
|
||||
for (std::string& str : strings) {
|
||||
int channel = a8::XValue(str);
|
||||
if (channel != 0) {
|
||||
separate_channel_hash_.insert(channel);
|
||||
}
|
||||
}
|
||||
a8::UdpLog::Instance()->Info("LoadSeparateChannelConfig channelids:%s",
|
||||
{
|
||||
GetSeparateChannelConfigData()
|
||||
});
|
||||
}
|
||||
|
||||
std::string App::GetSeparateChannelConfigData()
|
||||
{
|
||||
std::string data;
|
||||
for (int channel : separate_channel_hash_) {
|
||||
data += a8::XValue(channel).GetString() + ",";
|
||||
}
|
||||
return data;
|
||||
a8::Split(game_id, strings, '/');
|
||||
game_id = strings.at(strings.size() - 1);
|
||||
//a8::XPrintf("exe:%s\n", {game_id});
|
||||
a8::ReplaceString(game_id, "masterserver", "");
|
||||
return a8::XValue(game_id);
|
||||
#else
|
||||
return GAME_ID;
|
||||
#endif
|
||||
}
|
||||
|
@ -1,10 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <a8/uuid.h>
|
||||
#include <a8/singleton.h>
|
||||
|
||||
#include <f8/app.h>
|
||||
|
||||
namespace f8
|
||||
{
|
||||
struct MsgHdr;
|
||||
}
|
||||
|
||||
struct MsgNode;
|
||||
struct IMMsgNode;
|
||||
class App : public a8::Singleton<App>
|
||||
class App : public a8::Singleton<App>, public f8::UserApp
|
||||
{
|
||||
private:
|
||||
App() {};
|
||||
@ -12,80 +18,21 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
void Init(int argc, char* argv[]);
|
||||
void UnInit();
|
||||
virtual const std::string GetPkgName() override;
|
||||
virtual void Init() override;
|
||||
virtual void UnInit() override;
|
||||
virtual void Update(int delta_time) override;
|
||||
virtual bool HasTask() override;
|
||||
virtual void DispatchSocketMsg(f8::MsgHdr* hdr) override;
|
||||
|
||||
int Run();
|
||||
|
||||
void AddSocketMsg(SocketFrom_e sockfrom,
|
||||
int sockhandle,
|
||||
long ip_saddr,
|
||||
unsigned short msgid,
|
||||
unsigned int seqid,
|
||||
const char *msgbody,
|
||||
int bodylen);
|
||||
void AddIMMsg(unsigned short imcmd, a8::XParams params);
|
||||
|
||||
void NotifyLoopCond();
|
||||
|
||||
long long NewUuid();
|
||||
a8::XParams* AddContext(long long context_id);
|
||||
void DelContext(long long context_id);
|
||||
a8::XParams* GetContext(long long context_id);
|
||||
bool IsSeparateChannel(int channel);
|
||||
void LoadSeparateChannelConfig();
|
||||
std::string GetSeparateChannelConfigData();
|
||||
int GetGameId() const;
|
||||
|
||||
private:
|
||||
void QuickExecute(int delta_time);
|
||||
void SlowerExecute(int delta_time);
|
||||
void Schedule();
|
||||
bool HasTask();
|
||||
void QuickExecute();
|
||||
void SlowerExecute();
|
||||
|
||||
void DispatchMsg();
|
||||
void ProcessIMMsg();
|
||||
|
||||
void ProcessGameGateMsg(f8::MsgHdr& hdr);
|
||||
|
||||
void InitLog();
|
||||
void UnInitLog();
|
||||
|
||||
bool ParseOpt();
|
||||
void ProcessGameGateMsg(f8::MsgHdr* hdr);
|
||||
|
||||
public:
|
||||
int argc = 0;
|
||||
char** argv = nullptr;
|
||||
volatile bool terminated = false;
|
||||
PerfMonitor perf;
|
||||
a8::uuid::SnowFlake uuid;
|
||||
|
||||
public:
|
||||
int node_id = 0;
|
||||
int instance_id = 0;
|
||||
bool is_test_mode = false;
|
||||
int test_param = 0;
|
||||
std::set<int> flags;
|
||||
|
||||
private:
|
||||
long long last_run_tick_ = 0;
|
||||
std::mutex *loop_mutex_ = nullptr;
|
||||
std::condition_variable *loop_cond_ = nullptr;
|
||||
|
||||
std::mutex *msg_mutex_ = nullptr;
|
||||
MsgNode* top_node_ = nullptr;
|
||||
MsgNode* bot_node_ = nullptr;
|
||||
MsgNode* work_node_ = nullptr;
|
||||
|
||||
std::mutex* im_msg_mutex_ = nullptr;
|
||||
IMMsgNode* im_top_node_ = nullptr;
|
||||
IMMsgNode* im_bot_node_ = nullptr;
|
||||
IMMsgNode* im_work_node_ = nullptr;
|
||||
|
||||
std::set<int> separate_channel_hash_;
|
||||
std::map<long long, a8::XParams> context_hash_;
|
||||
|
||||
public:
|
||||
int msgnode_size_ = 0 ;
|
||||
int working_msgnode_size_ = 0;
|
||||
|
||||
};
|
||||
|
@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
类似http的错误码设计
|
||||
0:成功
|
||||
<400: 客户端的错
|
||||
>500: 服务器的错
|
||||
*/
|
||||
enum ErrorCode_e
|
||||
{
|
||||
ERRNO_OK = 0,
|
||||
|
||||
};
|
@ -1,37 +0,0 @@
|
||||
#include "precompile.h"
|
||||
#include "global.h"
|
||||
|
||||
int g_hint_flags = 0;
|
||||
|
||||
bool Global::IsVirtualItem(int itemid)
|
||||
{
|
||||
return (itemid == VID_Item_Exp ||
|
||||
itemid == VID_Item_Gold ||
|
||||
itemid == VID_Soul_Stone ||
|
||||
itemid == VID_Pickaxe);
|
||||
}
|
||||
|
||||
time_t Global::BetweenDays(time_t time1, time_t time2)
|
||||
{
|
||||
return (time1 + g_time_zone*3600)/3600/24 - (time2 + g_time_zone*3600)/3600/24;
|
||||
}
|
||||
|
||||
time_t Global::GetDaySeconds(time_t time, int incdays)
|
||||
{
|
||||
return time_t((time + g_time_zone * 3600)/3600/24 + incdays) * 3600 * 24 - 3600 * g_time_zone;
|
||||
}
|
||||
|
||||
bool Global::IsTimeToReset(int time)
|
||||
{
|
||||
return BetweenDays(g_nowtime - 60 * SYS_RESET_TIME, time - 60 * SYS_RESET_TIME) > 0;
|
||||
}
|
||||
|
||||
|
||||
int Global::g_nowtime = time(nullptr);
|
||||
int Global::g_time_zone = 8;
|
||||
bool Global::g_shutdown = false;
|
||||
|
||||
bool IsValidSlotId(int slot_id)
|
||||
{
|
||||
return slot_id >= 0 && slot_id < IS_END;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
extern int g_hint_flags;
|
||||
|
||||
class Global : public a8::Singleton<Global>
|
||||
{
|
||||
private:
|
||||
Global() {};
|
||||
friend class a8::Singleton<Global>;
|
||||
public:
|
||||
|
||||
static bool IsVirtualItem(int itemid);
|
||||
static bool IsTimeToReset(int time);
|
||||
static time_t BetweenDays(time_t time1, time_t time2);
|
||||
static time_t GetDaySeconds(time_t time, int incdays = 0);
|
||||
|
||||
static int g_nowtime;
|
||||
static int g_time_zone; // 默认东八区
|
||||
static bool g_shutdown;
|
||||
};
|
||||
|
||||
bool IsValidSlotId(int slot_id);
|
@ -1,22 +1,49 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <a8/mutable_xobject.h>
|
||||
#include <a8/timer.h>
|
||||
|
||||
#include <f8/utils.h>
|
||||
#include <f8/timer.h>
|
||||
#include <f8/jsonhttprequest.h>
|
||||
|
||||
#include "gsmgr.h"
|
||||
#include "app.h"
|
||||
#include "GGListener.h"
|
||||
|
||||
#include "framework/cpp/utils.h"
|
||||
#include "ss_proto.pb.h"
|
||||
|
||||
struct GSNode
|
||||
{
|
||||
std::string key;
|
||||
long long node_idx = 0;
|
||||
int node_id = 0;
|
||||
int instance_id = 0;
|
||||
int room_num = 0;
|
||||
int alive_count = 0;
|
||||
int online_num = 0;
|
||||
std::string ip;
|
||||
int port = 0;
|
||||
bool servicing = false;
|
||||
int version = 0;
|
||||
f8::TimerWp timer_wp;
|
||||
|
||||
std::string ToJson()
|
||||
{
|
||||
auto node = a8::MutableXObject::CreateObject();
|
||||
node->SetVal("node_id", node_id);
|
||||
node->SetVal("instance_id", instance_id);
|
||||
node->SetVal("room_num", room_num);
|
||||
node->SetVal("online_num", online_num);
|
||||
node->SetVal("ip", ip);
|
||||
node->SetVal("port", port);
|
||||
node->SetVal("servicing", servicing);
|
||||
node->SetVal("version", version);
|
||||
return node->ToJsonStr();
|
||||
}
|
||||
};
|
||||
|
||||
void GSMgr::Init()
|
||||
{
|
||||
a8::Timer::Instance()->AddRepeatTimer(1000 * 2,
|
||||
a8::XParams(),
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
GSMgr::Instance()->ClearTimeOutNode();
|
||||
});
|
||||
}
|
||||
|
||||
void GSMgr::UnInit()
|
||||
@ -24,143 +51,211 @@ void GSMgr::UnInit()
|
||||
|
||||
}
|
||||
|
||||
void GSMgr::_SS_WSP_RequestTargetServer(f8::MsgHdr& hdr, const ss::SS_WSP_RequestTargetServer& msg)
|
||||
void GSMgr::_SS_WSP_RequestTargetServer(f8::MsgHdr* hdr, const ss::SS_WSP_RequestTargetServer& msg)
|
||||
{
|
||||
int channel = f8::ExtractChannelIdFromAccountId(msg.account_id());
|
||||
if (!App::Instance()->IsSeparateChannel(channel)) {
|
||||
channel = 0;
|
||||
}
|
||||
#if 1
|
||||
int src_channel = f8::ExtractChannelIdFromAccountId(msg.account_id());
|
||||
if (channel == 0 &&
|
||||
src_channel == kTouTiaoChannelId &&
|
||||
msg.proto_version() == 2019071502) {
|
||||
channel = src_channel;
|
||||
}
|
||||
#endif
|
||||
ss::SS_MS_ResponseTargetServer respmsg;
|
||||
respmsg.set_context_id(msg.context_id());
|
||||
if (msg.is_reconnect()) {
|
||||
GSNode* node = GetNodeByNodeKey(msg.server_info());
|
||||
std::shared_ptr<GSNode> node = GetNodeByNodeKey(msg.server_info());
|
||||
if (node) {
|
||||
respmsg.set_host(node->ip);
|
||||
respmsg.set_port(node->port);
|
||||
} else {
|
||||
respmsg.set_error_code(1);
|
||||
respmsg.set_error_msg("无法分配节点");
|
||||
respmsg.set_error_msg("cant alloc node");
|
||||
}
|
||||
} else {
|
||||
GSNode* node = GetNodeByTeamId(msg.team_id());
|
||||
if (node && node->channel == channel) {
|
||||
std::shared_ptr<GSNode> node = GetNodeByTeamId(msg.team_id());
|
||||
#ifdef DEBUG
|
||||
{
|
||||
a8::XObject request;
|
||||
request.ReadFromUrlQueryString(msg.query_str());
|
||||
if (request.HasKey("server_id")) {
|
||||
node = GetNodeByInstanceId(request.At("server_id")->AsXValue());
|
||||
if (!node) {
|
||||
respmsg.set_error_code(1);
|
||||
respmsg.set_error_msg("cant alloc node1");
|
||||
GGListener::Instance()->SendMsg(hdr->socket_handle, respmsg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (node) {
|
||||
respmsg.set_host(node->ip);
|
||||
respmsg.set_port(node->port);
|
||||
} else {
|
||||
node = AllocNode(channel);
|
||||
node = AllocNode();
|
||||
if (node) {
|
||||
respmsg.set_host(node->ip);
|
||||
respmsg.set_port(node->port);
|
||||
team_hash_[msg.team_id()] = node;
|
||||
} else {
|
||||
respmsg.set_error_code(1);
|
||||
respmsg.set_error_msg("无法分配节点");
|
||||
respmsg.set_error_msg("cant alloc node");
|
||||
}
|
||||
}
|
||||
}
|
||||
GGListener::Instance()->SendMsg(hdr.socket_handle, respmsg);
|
||||
GGListener::Instance()->SendMsg(hdr->socket_handle, respmsg);
|
||||
}
|
||||
|
||||
void GSMgr::_SS_Ping(f8::MsgHdr& hdr, const ss::SS_Ping& msg)
|
||||
void GSMgr::_SS_WSP_HttpTunnelRequest(f8::MsgHdr* hdr, const ss::SS_WSP_HttpTunnelRequest& msg)
|
||||
{
|
||||
ss::SS_MS_HttpTunnelResponse rspmsg;
|
||||
a8::XObject request;
|
||||
request.ReadFromUrlQueryString(msg.query_str());
|
||||
std::string team_uuid = request.At("team_uuid")->AsXValue().GetString();
|
||||
|
||||
std::shared_ptr<GSNode> node = GetNodeByTeamId(team_uuid);
|
||||
#ifdef DEBUG
|
||||
a8::XPrintf("SS_WSP_HttpTunnelRequest %s\n" , {f8::PbToJson(&msg)});
|
||||
{
|
||||
if (request.HasKey("server_id")) {
|
||||
node = GetNodeByInstanceId(request.At("server_id")->AsXValue());
|
||||
if (!node) {
|
||||
rspmsg.set_error_code(1);
|
||||
rspmsg.set_error_msg("cant alloc node1");
|
||||
GGListener::Instance()->SendMsg(hdr->socket_handle, rspmsg);
|
||||
return;
|
||||
}
|
||||
rspmsg.set_error_code(0);
|
||||
rspmsg.set_error_msg("");
|
||||
rspmsg.set_context_id(msg.context_id());
|
||||
rspmsg.set_host(node->ip);
|
||||
rspmsg.set_port(node->port);
|
||||
GGListener::Instance()->SendMsg(hdr->socket_handle, rspmsg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (!node) {
|
||||
rspmsg.set_error_code(1);
|
||||
rspmsg.set_error_msg("cant alloc node1");
|
||||
GGListener::Instance()->SendMsg(hdr->socket_handle, rspmsg);
|
||||
return;
|
||||
}
|
||||
rspmsg.set_error_code(0);
|
||||
rspmsg.set_error_msg("");
|
||||
rspmsg.set_context_id(msg.context_id());
|
||||
rspmsg.set_host(node->ip);
|
||||
rspmsg.set_port(node->port);
|
||||
GGListener::Instance()->SendMsg(hdr->socket_handle, rspmsg);
|
||||
}
|
||||
|
||||
void GSMgr::_SS_Ping(f8::MsgHdr* hdr, const ss::SS_Ping& msg)
|
||||
{
|
||||
ss::SS_Pong pongmsg;
|
||||
GGListener::Instance()->SendMsg(hdr.socket_handle, pongmsg);
|
||||
GGListener::Instance()->SendMsg(hdr->socket_handle, pongmsg);
|
||||
}
|
||||
|
||||
void GSMgr::___GSReport(f8::JsonHttpRequest* request)
|
||||
void GSMgr::___GSReport(std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
{
|
||||
std::string ip = request->request.Get("ip");
|
||||
int port = request->request.Get("port");
|
||||
int alive_count = request->request.Get("alive_count");
|
||||
int online_num = request->request.Get("online_num");
|
||||
int room_num = request->request.Get("room_num");
|
||||
int instance_id = request->request.Get("instance_id");
|
||||
int node_id = request->request.Get("node_id");
|
||||
int channel = request->request.Get("channel");
|
||||
bool servicing = request->request.Get("servicing");
|
||||
std::string ip = request->GetParams()->Get("ip");
|
||||
int port = request->GetParams()->Get("port");
|
||||
int alive_count = request->GetParams()->Get("alive_count");
|
||||
int online_num = request->GetParams()->Get("online_num");
|
||||
int room_num = request->GetParams()->Get("room_num");
|
||||
int instance_id = request->GetParams()->Get("instance_id");
|
||||
int node_id = request->GetParams()->Get("node_id");
|
||||
int version = request->GetParams()->Get("version");
|
||||
bool servicing = request->GetParams()->Get("servicing");
|
||||
std::string key = ip + ":" + a8::XValue(port).GetString();
|
||||
|
||||
auto itr = node_key_hash_.find(key);
|
||||
if (itr != node_key_hash_.end()) {
|
||||
if (itr->second.online_num != online_num ||
|
||||
itr->second.room_num != room_num ||
|
||||
itr->second.alive_count != alive_count ||
|
||||
itr->second.servicing != servicing ||
|
||||
itr->second.channel != channel
|
||||
if (itr->second->online_num != online_num ||
|
||||
itr->second->room_num != room_num ||
|
||||
itr->second->alive_count != alive_count ||
|
||||
itr->second->servicing != servicing ||
|
||||
itr->second->version != version
|
||||
) {
|
||||
itr->second.online_num = online_num;
|
||||
itr->second.room_num = room_num;
|
||||
itr->second.servicing = servicing;
|
||||
if (itr->second.channel != channel) {
|
||||
itr->second.channel = channel;
|
||||
OnChannelChange(&itr->second);
|
||||
itr->second->online_num = online_num;
|
||||
itr->second->room_num = room_num;
|
||||
itr->second->servicing = servicing;
|
||||
if (itr->second->version != version) {
|
||||
itr->second->version = version;
|
||||
OnVersionChange(itr->second);
|
||||
}
|
||||
RearrangeNode();
|
||||
}
|
||||
itr->second.alive_count = alive_count;
|
||||
itr->second.last_active_tick = a8::XGetTickCount();
|
||||
itr->second->alive_count = alive_count;
|
||||
if (!itr->second->timer_wp.expired()) {
|
||||
f8::Timer::Instance()->ModifyTime(itr->second->timer_wp, 1000 * 5);
|
||||
}
|
||||
} else {
|
||||
GSNode gs;
|
||||
gs.key = key;
|
||||
gs.node_id = node_id;
|
||||
gs.node_idx = App::Instance()->NewUuid();
|
||||
gs.instance_id = instance_id;
|
||||
gs.alive_count = alive_count;
|
||||
gs.online_num = online_num;
|
||||
gs.room_num = room_num;
|
||||
gs.ip = ip;
|
||||
gs.port = port;
|
||||
gs.servicing = servicing;
|
||||
gs.channel = channel;
|
||||
gs.last_active_tick = a8::XGetTickCount();
|
||||
auto gs = std::make_shared<GSNode>();
|
||||
gs->key = key;
|
||||
gs->node_id = node_id;
|
||||
gs->node_idx = f8::App::Instance()->NewNodeUuid();
|
||||
gs->instance_id = instance_id;
|
||||
gs->alive_count = alive_count;
|
||||
gs->online_num = online_num;
|
||||
gs->room_num = room_num;
|
||||
gs->ip = ip;
|
||||
gs->port = port;
|
||||
gs->servicing = servicing;
|
||||
gs->version = version;
|
||||
gs->timer_wp = f8::Timer::Instance()->SetIntervalWp
|
||||
(
|
||||
1000 * 5,
|
||||
[this, gs] (int e, const a8::Args* args)
|
||||
{
|
||||
if (a8::TIMER_EXEC_EVENT == e) {
|
||||
RemoveNodeFromSortedNodes(gs);
|
||||
{
|
||||
std::vector<std::string> deleted_teams;
|
||||
for (auto& pair : team_hash_) {
|
||||
if (pair.second == gs) {
|
||||
deleted_teams.push_back(pair.first);
|
||||
}
|
||||
}
|
||||
for (const std::string& team_id : deleted_teams) {
|
||||
team_hash_.erase(team_id);
|
||||
}
|
||||
}
|
||||
node_key_hash_.erase(gs->key);
|
||||
RearrangeNode();
|
||||
f8::Timer::Instance()->DeleteCurrentTimer();
|
||||
}
|
||||
});
|
||||
node_key_hash_[key] = gs;
|
||||
AddNodeToSortedNodes(&node_key_hash_[key]);
|
||||
AddNodeToSortedNodes(gs);
|
||||
RearrangeNode();
|
||||
}
|
||||
|
||||
request->resp_xobj->SetVal("errcode", 0);
|
||||
request->resp_xobj->SetVal("errmsg", "");
|
||||
request->GetResp()->SetVal("errcode", 0);
|
||||
request->GetResp()->SetVal("errmsg", "");
|
||||
}
|
||||
|
||||
void GSMgr::___GSList(f8::JsonHttpRequest* request)
|
||||
void GSMgr::___GSList(std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
{
|
||||
{
|
||||
a8::MutableXObject* node_list = a8::MutableXObject::NewArray();
|
||||
auto node_list = a8::MutableXObject::CreateArray();
|
||||
|
||||
for (auto& pair : node_key_hash_) {
|
||||
a8::MutableXObject* node = a8::MutableXObject::NewObject();
|
||||
node->SetVal("node_id", pair.second.node_id);
|
||||
node->SetVal("instance_id", pair.second.instance_id);
|
||||
node->SetVal("room_num", pair.second.room_num);
|
||||
node->SetVal("alive_count", pair.second.alive_count);
|
||||
node->SetVal("online_num", pair.second.online_num);
|
||||
node->SetVal("ip", pair.second.ip);
|
||||
node->SetVal("port", pair.second.port);
|
||||
node->SetVal("servicing", pair.second.servicing);
|
||||
node->SetVal("channel", pair.second.channel);
|
||||
auto node = a8::MutableXObject::CreateObject();
|
||||
node->SetVal("node_id", pair.second->node_id);
|
||||
node->SetVal("instance_id", pair.second->instance_id);
|
||||
node->SetVal("room_num", pair.second->room_num);
|
||||
node->SetVal("alive_count", pair.second->alive_count);
|
||||
node->SetVal("online_num", pair.second->online_num);
|
||||
node->SetVal("ip", pair.second->ip);
|
||||
node->SetVal("port", pair.second->port);
|
||||
node->SetVal("servicing", pair.second->servicing);
|
||||
node->SetVal("version", pair.second->version);
|
||||
node_list->Push(*node);
|
||||
delete node;
|
||||
}
|
||||
|
||||
request->resp_xobj->SetVal("errcode", 0);
|
||||
request->resp_xobj->SetVal("errmsg", "");
|
||||
request->resp_xobj->SetVal("node_list", *node_list);
|
||||
delete node_list;
|
||||
request->GetResp()->SetVal("errcode", 0);
|
||||
request->GetResp()->SetVal("errmsg", "");
|
||||
request->GetResp()->SetVal("node_list", *node_list);
|
||||
}
|
||||
{
|
||||
a8::MutableXObject* node_list = a8::MutableXObject::NewArray();
|
||||
auto node_list = a8::MutableXObject::CreateArray();
|
||||
|
||||
for (auto& pair : sorted_node_hash_) {
|
||||
for (GSNode* gs_node : pair.second) {
|
||||
a8::MutableXObject* node = a8::MutableXObject::NewObject();
|
||||
for (auto itr = sorted_node_hash_.rbegin(); itr != sorted_node_hash_.rend(); ++itr) {
|
||||
for (std::shared_ptr<GSNode> gs_node : itr->second) {
|
||||
auto node = a8::MutableXObject::CreateObject();
|
||||
node->SetVal("node_id", gs_node->node_id);
|
||||
node->SetVal("instance_id", gs_node->instance_id);
|
||||
node->SetVal("room_num", gs_node->room_num);
|
||||
@ -168,39 +263,47 @@ void GSMgr::___GSList(f8::JsonHttpRequest* request)
|
||||
node->SetVal("ip", gs_node->ip);
|
||||
node->SetVal("port", gs_node->port);
|
||||
node->SetVal("servicing", gs_node->servicing);
|
||||
node->SetVal("channel", gs_node->channel);
|
||||
node->SetVal("version", gs_node->version);
|
||||
node_list->Push(*node);
|
||||
delete node;
|
||||
}
|
||||
}
|
||||
|
||||
request->resp_xobj->SetVal("errcode", 0);
|
||||
request->resp_xobj->SetVal("errmsg", "");
|
||||
request->resp_xobj->SetVal("sorted_node_list", *node_list);
|
||||
delete node_list;
|
||||
request->GetResp()->SetVal("errcode", 0);
|
||||
request->GetResp()->SetVal("errmsg", "");
|
||||
request->GetResp()->SetVal("sorted_node_list", *node_list);
|
||||
}
|
||||
}
|
||||
|
||||
GSNode* GSMgr::GetNodeByTeamId(const std::string& team_id)
|
||||
std::shared_ptr<GSNode> GSMgr::GetNodeByTeamId(const std::string& team_id)
|
||||
{
|
||||
auto itr = team_hash_.find(team_id);
|
||||
return itr != team_hash_.end() ? itr->second : nullptr;
|
||||
}
|
||||
|
||||
GSNode* GSMgr::GetNodeByNodeKey(const std::string& node_key)
|
||||
std::shared_ptr<GSNode> GSMgr::GetNodeByNodeKey(const std::string& node_key)
|
||||
{
|
||||
auto itr = node_key_hash_.find(node_key);
|
||||
return itr != node_key_hash_.end() ? &itr->second : nullptr;
|
||||
return itr != node_key_hash_.end() ? itr->second : nullptr;
|
||||
}
|
||||
|
||||
GSNode* GSMgr::AllocNode(int channel)
|
||||
std::shared_ptr<GSNode> GSMgr::GetNodeByInstanceId(int instance_id)
|
||||
{
|
||||
std::vector<GSNode*>* sorted_nodes = GetSortedNodesByChannel(channel);
|
||||
for (auto& pair : node_key_hash_) {
|
||||
if (pair.second->instance_id == instance_id) {
|
||||
return pair.second;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<GSNode> GSMgr::AllocNode()
|
||||
{
|
||||
std::vector<std::shared_ptr<GSNode>>* sorted_nodes = GetSortedNodes();
|
||||
if (sorted_nodes && !sorted_nodes->empty()) {
|
||||
size_t rnd = std::min((size_t)2, sorted_nodes->size());
|
||||
if (rnd >= 2) {
|
||||
GSNode* n1 = sorted_nodes->at(sorted_nodes->size() - 1);
|
||||
GSNode* n2 = sorted_nodes->at(sorted_nodes->size() - 2);
|
||||
std::shared_ptr<GSNode> n1 = sorted_nodes->at(sorted_nodes->size() - 1);
|
||||
std::shared_ptr<GSNode> n2 = sorted_nodes->at(sorted_nodes->size() - 2);
|
||||
if (n1->online_num < 100 && n2->online_num < 100) {
|
||||
if (n1->instance_id < n2->instance_id) {
|
||||
if (n1->servicing) {
|
||||
@ -221,13 +324,12 @@ GSNode* GSMgr::AllocNode(int channel)
|
||||
--idx;
|
||||
}
|
||||
}
|
||||
a8::UdpLog::Instance()->Warning
|
||||
("节点分配失败 sorted_node_hashlist.size:%d node_list.size:%d sorted_node.size:%d channel:%d",
|
||||
f8::UdpLog::Instance()->Warning
|
||||
("节点分配失败 sorted_node_hashlist.size:%d node_list.size:%d sorted_node.size:%d",
|
||||
{
|
||||
sorted_node_hash_.size(),
|
||||
node_key_hash_.size(),
|
||||
sorted_nodes ? sorted_nodes->size() : 0,
|
||||
channel
|
||||
});
|
||||
return nullptr;
|
||||
}
|
||||
@ -236,8 +338,11 @@ void GSMgr::RearrangeNode()
|
||||
{
|
||||
for (auto& pair : sorted_node_hash_) {
|
||||
std::sort(pair.second.begin(), pair.second.end(),
|
||||
[] (const GSNode* a, const GSNode* b)
|
||||
[] (const std::shared_ptr<GSNode> a, const std::shared_ptr<GSNode> b)
|
||||
{
|
||||
if (a->version > b->version) {
|
||||
return true;
|
||||
}
|
||||
if (a->servicing && b->servicing) {
|
||||
if (a->online_num < b->online_num) {
|
||||
return true;
|
||||
@ -265,66 +370,50 @@ void GSMgr::RearrangeNode()
|
||||
}
|
||||
}
|
||||
|
||||
void GSMgr::ClearTimeOutNode()
|
||||
void GSMgr::AddNodeToSortedNodes(std::shared_ptr<GSNode> node)
|
||||
{
|
||||
std::vector<GSNode*> time_out_nodes;
|
||||
for (auto& pair : node_key_hash_) {
|
||||
if (a8::XGetTickCount() - pair.second.last_active_tick > 1000 * 5) {
|
||||
time_out_nodes.push_back(&pair.second);
|
||||
}
|
||||
}
|
||||
for (GSNode* node : time_out_nodes) {
|
||||
RemoveNodeFromSortedNodes(node);
|
||||
{
|
||||
std::vector<std::string> deleted_teams;
|
||||
for (auto& pair : team_hash_) {
|
||||
if (pair.second == node) {
|
||||
deleted_teams.push_back(pair.first);
|
||||
}
|
||||
}
|
||||
for (const std::string& team_id : deleted_teams) {
|
||||
team_hash_.erase(team_id);
|
||||
}
|
||||
}
|
||||
node_key_hash_.erase(node->key);
|
||||
}
|
||||
RearrangeNode();
|
||||
}
|
||||
|
||||
void GSMgr::AddNodeToSortedNodes(GSNode* node)
|
||||
{
|
||||
auto itr = sorted_node_hash_.find(node->channel);
|
||||
#ifdef DEBUG
|
||||
a8::XPrintf("AddNodeToSortedNodes %s\n" , {node->ToJson()});
|
||||
#endif
|
||||
auto itr = sorted_node_hash_.find(node->version);
|
||||
if (itr != sorted_node_hash_.end()) {
|
||||
itr->second.push_back(node);
|
||||
} else {
|
||||
sorted_node_hash_[node->channel] = std::vector<GSNode*>({node});
|
||||
sorted_node_hash_[node->version] = std::vector<std::shared_ptr<GSNode>>({node});
|
||||
}
|
||||
}
|
||||
|
||||
void GSMgr::RemoveNodeFromSortedNodes(GSNode* node)
|
||||
void GSMgr::RemoveNodeFromSortedNodes(std::shared_ptr<GSNode> node)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
a8::XPrintf("RemoveNodeFromSortedNodes %s\n" , {node->ToJson()});
|
||||
#endif
|
||||
for (auto& pair : sorted_node_hash_) {
|
||||
std::vector<GSNode*>& node_list = pair.second;
|
||||
std::vector<std::shared_ptr<GSNode>>& node_list = pair.second;
|
||||
for (size_t i = 0; i < node_list.size(); ++i) {
|
||||
if (node_list[i] == node) {
|
||||
node_list.erase(node_list.begin() + i);
|
||||
#ifdef DEBUG
|
||||
a8::XPrintf("RemoveNodeFromSortedNodes ok %s\n" , {node->ToJson()});
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<GSNode*>* GSMgr::GetSortedNodesByChannel(int channel)
|
||||
std::vector<std::shared_ptr<GSNode>>* GSMgr::GetSortedNodes()
|
||||
{
|
||||
auto itr = sorted_node_hash_.find(channel);
|
||||
if (itr != sorted_node_hash_.end()) {
|
||||
return &itr->second;
|
||||
} else {
|
||||
if (sorted_node_hash_.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
for (auto itr = sorted_node_hash_.rbegin(); itr != sorted_node_hash_.rend(); ++itr) {
|
||||
return &itr->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void GSMgr::OnChannelChange(GSNode* node)
|
||||
void GSMgr::OnVersionChange(std::shared_ptr<GSNode> node)
|
||||
{
|
||||
RemoveNodeFromSortedNodes(node);
|
||||
AddNodeToSortedNodes(node);
|
||||
|
@ -1,23 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "ss_proto.pb.h"
|
||||
#include <f8/timer.h>
|
||||
|
||||
struct GSNode
|
||||
namespace ss
|
||||
{
|
||||
std::string key;
|
||||
long long node_idx = 0;
|
||||
int node_id = 0;
|
||||
int instance_id = 0;
|
||||
int room_num = 0;
|
||||
int alive_count = 0;
|
||||
int online_num = 0;
|
||||
std::string ip;
|
||||
int port = 0;
|
||||
bool servicing = false;
|
||||
int channel = 0;
|
||||
long long last_active_tick = 0;
|
||||
};
|
||||
class SS_WSP_RequestTargetServer;
|
||||
class SS_WSP_HttpTunnelRequest;
|
||||
class SS_Ping;
|
||||
}
|
||||
|
||||
struct GSNode;
|
||||
class GSMgr : public a8::Singleton<GSMgr>
|
||||
{
|
||||
public:
|
||||
@ -32,26 +24,27 @@ class GSMgr : public a8::Singleton<GSMgr>
|
||||
void Init();
|
||||
void UnInit();
|
||||
|
||||
void _SS_WSP_RequestTargetServer(f8::MsgHdr& hdr, const ss::SS_WSP_RequestTargetServer& msg);
|
||||
void _SS_Ping(f8::MsgHdr& hdr, const ss::SS_Ping& msg);
|
||||
void _SS_WSP_RequestTargetServer(f8::MsgHdr* hdr, const ss::SS_WSP_RequestTargetServer& msg);
|
||||
void _SS_WSP_HttpTunnelRequest(f8::MsgHdr* hdr, const ss::SS_WSP_HttpTunnelRequest& msg);
|
||||
void _SS_Ping(f8::MsgHdr* hdr, const ss::SS_Ping& msg);
|
||||
|
||||
void ___GSReport(f8::JsonHttpRequest* request);
|
||||
void ___GSList(f8::JsonHttpRequest* request);
|
||||
void ___GSReport(std::shared_ptr<f8::JsonHttpRequest> request);
|
||||
void ___GSList(std::shared_ptr<f8::JsonHttpRequest> request);
|
||||
|
||||
private:
|
||||
GSNode* GetNodeByTeamId(const std::string& team_id);
|
||||
GSNode* GetNodeByNodeKey(const std::string& node_key);
|
||||
GSNode* AllocNode(int channel);
|
||||
std::shared_ptr<GSNode> GetNodeByTeamId(const std::string& team_id);
|
||||
std::shared_ptr<GSNode> GetNodeByNodeKey(const std::string& node_key);
|
||||
std::shared_ptr<GSNode> GetNodeByInstanceId(int instance_id);
|
||||
std::shared_ptr<GSNode> AllocNode();
|
||||
void RearrangeNode();
|
||||
void ClearTimeOutNode();
|
||||
void AddNodeToSortedNodes(GSNode* node);
|
||||
void RemoveNodeFromSortedNodes(GSNode* node);
|
||||
std::vector<GSNode*>* GetSortedNodesByChannel(int channel);
|
||||
void OnChannelChange(GSNode* node);
|
||||
void AddNodeToSortedNodes(std::shared_ptr<GSNode> node);
|
||||
void RemoveNodeFromSortedNodes(std::shared_ptr<GSNode> node);
|
||||
std::vector<std::shared_ptr<GSNode>>* GetSortedNodes();
|
||||
void OnVersionChange(std::shared_ptr<GSNode> node);
|
||||
|
||||
private:
|
||||
|
||||
std::map<std::string, GSNode*> team_hash_;
|
||||
std::map<std::string, GSNode> node_key_hash_;
|
||||
std::map<int, std::vector<GSNode*>> sorted_node_hash_;
|
||||
f8::Attacher timer_attacher_;
|
||||
std::map<std::string, std::shared_ptr<GSNode>> team_hash_;
|
||||
std::map<std::string, std::shared_ptr<GSNode>> node_key_hash_;
|
||||
std::map<int, std::vector<std::shared_ptr<GSNode>>> sorted_node_hash_;
|
||||
};
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <a8/mutable_xobject.h>
|
||||
#include <f8/jsonhttprequest.h>
|
||||
#include <f8/msgqueue.h>
|
||||
|
||||
#include "handlermgr.h"
|
||||
|
||||
@ -8,44 +10,49 @@
|
||||
#include "app.h"
|
||||
#include "gsmgr.h"
|
||||
|
||||
static void _GMOpsSelfChecking(f8::JsonHttpRequest* request)
|
||||
{
|
||||
request->resp_xobj->SetVal("errcode", 0);
|
||||
request->resp_xobj->SetVal("errmsg", "");
|
||||
request->resp_xobj->SetVal("healthy", 1);
|
||||
request->resp_xobj->SetVal("max_rundelay", App::Instance()->perf.max_run_delay_time);
|
||||
request->resp_xobj->SetVal("max_timer_idle", App::Instance()->perf.max_timer_idle);
|
||||
}
|
||||
#include "ss_proto.pb.h"
|
||||
|
||||
static void _GMOpsReload(f8::JsonHttpRequest* request)
|
||||
static void _GMOpsSelfChecking(std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
{
|
||||
App::Instance()->LoadSeparateChannelConfig();
|
||||
request->resp_xobj->SetVal("errcode", 0);
|
||||
request->resp_xobj->SetVal("errmsg", "");
|
||||
a8::UdpLog::Instance()->Warning("reload config files", {});
|
||||
}
|
||||
|
||||
static void _GMOpsShowConfig(f8::JsonHttpRequest* request)
|
||||
{
|
||||
request->resp_xobj->SetVal("errcode", 0);
|
||||
request->resp_xobj->SetVal("errmsg", "");
|
||||
request->resp_xobj->SetVal("separate_channels", App::Instance()->GetSeparateChannelConfigData());
|
||||
request->GetResp()->SetVal("errcode", 0);
|
||||
request->GetResp()->SetVal("errmsg", "");
|
||||
request->GetResp()->SetVal("healthy", 1);
|
||||
request->GetResp()->SetVal("max_rundelay", App::Instance()->perf.max_run_delay_time);
|
||||
request->GetResp()->SetVal("max_timer_idle", App::Instance()->perf.max_timer_idle);
|
||||
}
|
||||
|
||||
void HandlerMgr::Init()
|
||||
{
|
||||
RegisterNetMsgHandlers();
|
||||
RegisterGMMsgHandler("Ops@selfChecking", _GMOpsSelfChecking);
|
||||
RegisterGMMsgHandler("Ops@reload", _GMOpsReload);
|
||||
RegisterGMMsgHandler("Ops@showConfig", _GMOpsShowConfig);
|
||||
RegisterGMMsgHandler("GS@report", [] (f8::JsonHttpRequest* request)
|
||||
{
|
||||
GSMgr::Instance()->___GSReport(request);
|
||||
});
|
||||
RegisterGMMsgHandler("GS@list", [] (f8::JsonHttpRequest* request)
|
||||
{
|
||||
GSMgr::Instance()->___GSList(request);
|
||||
});
|
||||
RegisterGMMsgHandler("GS@report",
|
||||
[] (std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
{
|
||||
GSMgr::Instance()->___GSReport(request);
|
||||
});
|
||||
RegisterGMMsgHandler("GS@list",
|
||||
[] (std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
{
|
||||
GSMgr::Instance()->___GSList(request);
|
||||
});
|
||||
f8::MsgQueue::Instance()->RegisterCallBack
|
||||
(
|
||||
IM_ExecGM,
|
||||
[] (const a8::Args& args)
|
||||
{
|
||||
int socket_handle = args.Get<int>(0);
|
||||
std::string url = args.Get<std::string>(1);
|
||||
std::string query_str = args.Get<std::string>(2);
|
||||
unsigned long saddr = args.Get<unsigned long>(3);
|
||||
|
||||
HandlerMgr::Instance()->ProcGMMsg
|
||||
(
|
||||
saddr,
|
||||
socket_handle,
|
||||
url,
|
||||
query_str
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void HandlerMgr::UnInit()
|
||||
@ -55,6 +62,7 @@ void HandlerMgr::UnInit()
|
||||
void HandlerMgr::RegisterNetMsgHandlers()
|
||||
{
|
||||
RegisterNetMsgHandler(&ggmsghandler, &GSMgr::_SS_WSP_RequestTargetServer);
|
||||
RegisterNetMsgHandler(&ggmsghandler, &GSMgr::_SS_WSP_HttpTunnelRequest);
|
||||
RegisterNetMsgHandler(&ggmsghandler, &GSMgr::_SS_Ping);
|
||||
}
|
||||
|
||||
@ -72,29 +80,24 @@ void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle,
|
||||
std::string msgname = a8::Get(request, "c").GetString() + "@" + a8::Get(request, "a").GetString();
|
||||
auto itr = gmhandlers_.find(msgname);
|
||||
if (itr != gmhandlers_.end()) {
|
||||
f8::JsonHttpRequest* request = new f8::JsonHttpRequest;
|
||||
request->saddr = saddr;
|
||||
request->socket_handle = sockhandle;
|
||||
request->query_str = querystr;
|
||||
request->request.ReadFromUrlQueryString(querystr);
|
||||
request->resp_xobj->SetVal("errcode", 0);
|
||||
request->resp_xobj->SetVal("errmsg", "");
|
||||
auto request = std::make_shared<f8::JsonHttpRequest>
|
||||
(
|
||||
saddr,
|
||||
url,
|
||||
querystr,
|
||||
[sockhandle] (const a8::Args& args)
|
||||
{
|
||||
std::string data = args.Get<std::string>(0);
|
||||
GGListener::Instance()->SendText(sockhandle, data);
|
||||
});
|
||||
itr->second(request);
|
||||
|
||||
if (!request->pending){
|
||||
std::string response;
|
||||
request->resp_xobj->ToJsonStr(response);
|
||||
GGListener::Instance()->SendText(sockhandle, a8::HttpResponse(response));
|
||||
|
||||
delete request;
|
||||
}
|
||||
} else {
|
||||
GGListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}"));
|
||||
}
|
||||
}
|
||||
|
||||
void HandlerMgr::RegisterGMMsgHandler(const std::string& msgname,
|
||||
void (*handler)(f8::JsonHttpRequest*))
|
||||
void (*handler)(std::shared_ptr<f8::JsonHttpRequest>))
|
||||
{
|
||||
gmhandlers_[msgname] = handler;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <a8/basehttpsession.h>
|
||||
|
||||
#include "framework/cpp/netmsghandler.h"
|
||||
#include <f8/netmsghandler.h>
|
||||
|
||||
namespace a8
|
||||
{
|
||||
@ -29,7 +29,7 @@ class HandlerMgr : public a8::Singleton<HandlerMgr>
|
||||
private:
|
||||
void RegisterNetMsgHandlers();
|
||||
void RegisterGMMsgHandler(const std::string& msgname,
|
||||
void (*)(f8::JsonHttpRequest*));
|
||||
void (*)(std::shared_ptr<f8::JsonHttpRequest>));
|
||||
|
||||
std::map<std::string, void (*)(f8::JsonHttpRequest*)> gmhandlers_;
|
||||
std::map<std::string, void (*)(std::shared_ptr<f8::JsonHttpRequest>)> gmhandlers_;
|
||||
};
|
||||
|
@ -1,36 +1,27 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <f8/utils.h>
|
||||
|
||||
#include "jsondatamgr.h"
|
||||
#include "app.h"
|
||||
|
||||
#include "framework/cpp/utils.h"
|
||||
|
||||
void JsonDataMgr::Init()
|
||||
{
|
||||
std::string masterserver_cluster_json_file;
|
||||
if (!f8::IsOnlineEnv()) {
|
||||
if (f8::IsTestEnv()) {
|
||||
work_path_ = a8::Format("/root/pub/%d/%d/conf_test/game%d/masterserver.test",
|
||||
{
|
||||
GAME_ID,
|
||||
App::Instance()->instance_id,
|
||||
GAME_ID
|
||||
});
|
||||
work_path_ = a8::Format("../%d_test_config", {App::Instance()->GetGameId()});
|
||||
} else {
|
||||
work_path_ = a8::Format("/root/pub/%d/%d/conf_test/game%d/masterserver.dev",
|
||||
{
|
||||
GAME_ID,
|
||||
App::Instance()->instance_id,
|
||||
GAME_ID
|
||||
});
|
||||
work_path_ = a8::Format("../%d_dev_config", {App::Instance()->GetGameId()});
|
||||
}
|
||||
}
|
||||
masterserver_cluster_json_file = a8::Format("%s/node%d/game%d.masterserver.cluster.json",
|
||||
{
|
||||
work_path_,
|
||||
App::Instance()->node_id,
|
||||
GAME_ID
|
||||
});
|
||||
|
||||
std::string masterserver_cluster_json_file = a8::Format
|
||||
("%s/zone%d/node%d/masterserver.cluster.json",
|
||||
{
|
||||
work_path_,
|
||||
f8::App::Instance()->GetZoneId(),
|
||||
f8::App::Instance()->GetNodeId(),
|
||||
});
|
||||
masterserver_cluster_json_.ReadFromFile(masterserver_cluster_json_file);
|
||||
}
|
||||
|
||||
@ -40,8 +31,11 @@ void JsonDataMgr::UnInit()
|
||||
|
||||
std::shared_ptr<a8::XObject> JsonDataMgr::GetConf()
|
||||
{
|
||||
if (App::Instance()->instance_id < 1 || App::Instance()->instance_id > masterserver_cluster_json_.Size()) {
|
||||
abort();
|
||||
for (int i = 0; i < masterserver_cluster_json_.Size(); ++i) {
|
||||
auto conf = masterserver_cluster_json_.At(i);
|
||||
if (conf->At("instance_id")->AsXValue().GetInt() == f8::App::Instance()->GetInstanceId()) {
|
||||
return conf;
|
||||
}
|
||||
}
|
||||
return masterserver_cluster_json_[App::Instance()->instance_id - 1];
|
||||
A8_ABORT();
|
||||
}
|
||||
|
@ -12,9 +12,6 @@ class JsonDataMgr : public a8::Singleton<JsonDataMgr>
|
||||
|
||||
std::shared_ptr<a8::XObject> GetConf();
|
||||
|
||||
std::string ip;
|
||||
int listen_port = 0;
|
||||
|
||||
private:
|
||||
std::string work_path_ = "../config";
|
||||
a8::XObject masterserver_cluster_json_;
|
||||
|
@ -1,11 +1,10 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <f8/app.h>
|
||||
|
||||
#include "app.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int exitcode = 0;
|
||||
App::Instance()->Init(argc, argv);
|
||||
exitcode = App::Instance()->Run();
|
||||
App::Instance()->UnInit();
|
||||
return exitcode;
|
||||
return f8::App::Instance()->Run(argc, argv, App::Instance());
|
||||
}
|
||||
|
@ -1,21 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <a8/a8.h>
|
||||
#include <a8/udplog.h>
|
||||
#include <f8/f8.h>
|
||||
#include <f8/udplog.h>
|
||||
|
||||
#include "constant.h"
|
||||
#include "types.h"
|
||||
#include "error_code.h"
|
||||
#include "global.h"
|
||||
|
||||
namespace google
|
||||
{
|
||||
namespace protobuf
|
||||
{
|
||||
class Message;
|
||||
}
|
||||
}
|
||||
|
||||
#include "framework/cpp/types.h"
|
||||
#include "framework/cpp/protoutils.h"
|
||||
|
||||
|
@ -10,5 +10,9 @@ enum SSMessageId_e
|
||||
_SS_WSP_RequestTargetServer = 11;
|
||||
_SS_MS_ResponseTargetServer = 12;
|
||||
_SS_ForceCloseSocket = 13;
|
||||
_SS_WSP_HttpTunnelRequest = 14;
|
||||
_SS_MS_HttpTunnelResponse = 15;
|
||||
_SS_HttpTunnelRequest = 16;
|
||||
_SS_HttpTunnelResponse = 17;
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ message SS_WSP_RequestTargetServer
|
||||
optional string server_info = 4;
|
||||
optional int32 is_reconnect = 5;
|
||||
optional int32 proto_version = 6; //协议版本号Constant_e.ProtoVersion
|
||||
optional string url = 7;
|
||||
optional string query_str = 8;
|
||||
optional string session_id = 9;
|
||||
}
|
||||
|
||||
message SS_MS_ResponseTargetServer
|
||||
@ -36,3 +39,36 @@ message SS_MS_ResponseTargetServer
|
||||
message SS_ForceCloseSocket
|
||||
{
|
||||
}
|
||||
|
||||
message SS_WSP_HttpTunnelRequest
|
||||
{
|
||||
optional int64 context_id = 1;
|
||||
optional string url = 7;
|
||||
optional string query_str = 8;
|
||||
}
|
||||
|
||||
message SS_MS_HttpTunnelResponse
|
||||
{
|
||||
optional int32 error_code = 1;
|
||||
optional string error_msg = 2;
|
||||
optional int64 context_id = 3;
|
||||
optional string host = 4;
|
||||
optional int32 port = 5;
|
||||
}
|
||||
|
||||
message SS_HttpTunnelRequest
|
||||
{
|
||||
optional int64 context_id = 1;
|
||||
optional int32 socket_handle = 2;
|
||||
optional string url = 3;
|
||||
optional string query_str = 4;
|
||||
}
|
||||
|
||||
message SS_HttpTunnelResponse
|
||||
{
|
||||
optional int32 error_code = 1;
|
||||
optional string error_msg = 2;
|
||||
optional int64 context_id = 3;
|
||||
optional int32 socket_handle = 4;
|
||||
optional string response = 5;
|
||||
}
|
||||
|
1
third_party/a8
vendored
Submodule
1
third_party/a8
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit af7a9093a0d6a9c7427e08c5ee042d692c94c70b
|
2
third_party/behaviac
vendored
2
third_party/behaviac
vendored
@ -1 +1 @@
|
||||
Subproject commit 5beca57f6555aa0d9e4de71c93653cade928a654
|
||||
Subproject commit 8cd7e2432785bf4027e89c5dc74cb4980e4cd3c1
|
1
third_party/f8
vendored
Submodule
1
third_party/f8
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 9d627653179015b73f4f21c285b065a50e98a59e
|
Loading…
x
Reference in New Issue
Block a user