1
This commit is contained in:
parent
273b13b018
commit
3f79474667
@ -28,6 +28,7 @@ endif()
|
|||||||
include_directories(
|
include_directories(
|
||||||
AFTER
|
AFTER
|
||||||
../../third_party/a8
|
../../third_party/a8
|
||||||
|
../../third_party/f8
|
||||||
/usr/include/mysql
|
/usr/include/mysql
|
||||||
/usr/include/jsoncpp
|
/usr/include/jsoncpp
|
||||||
/usr/include/hiredis
|
/usr/include/hiredis
|
||||||
@ -87,43 +88,22 @@ add_custom_command(TARGET script_pb_protocol
|
|||||||
)
|
)
|
||||||
add_dependencies(wsproxy${GAME_ID} script_pb_protocol)
|
add_dependencies(wsproxy${GAME_ID} script_pb_protocol)
|
||||||
|
|
||||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
target_link_libraries(
|
||||||
target_link_libraries(
|
wsproxy${GAME_ID}
|
||||||
wsproxy${GAME_ID}
|
pthread
|
||||||
pthread
|
mysqlclient
|
||||||
mysqlclient
|
protobuf
|
||||||
protobuf
|
rt
|
||||||
rt
|
dl
|
||||||
dl
|
util
|
||||||
util
|
crypto
|
||||||
crypto
|
ssl
|
||||||
ssl
|
jsoncpp
|
||||||
jsoncpp
|
curl
|
||||||
curl
|
hiredis
|
||||||
hiredis
|
tinyxml2
|
||||||
tinyxml2
|
tcmalloc
|
||||||
tcmalloc
|
)
|
||||||
behaviac_gcc_release
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
target_link_libraries(
|
|
||||||
wsproxy${GAME_ID}
|
|
||||||
pthread
|
|
||||||
mysqlclient
|
|
||||||
protobuf
|
|
||||||
rt
|
|
||||||
dl
|
|
||||||
util
|
|
||||||
crypto
|
|
||||||
ssl
|
|
||||||
jsoncpp
|
|
||||||
curl
|
|
||||||
hiredis
|
|
||||||
tinyxml2
|
|
||||||
tcmalloc
|
|
||||||
behaviac_gcc_release
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
#include <a8/websocketsession.h>
|
#include <a8/websocketsession.h>
|
||||||
#include <a8/tcplistener.h>
|
#include <a8/tcplistener.h>
|
||||||
|
|
||||||
#include "framework/cpp/netmsghandler.h"
|
#include <f8/netmsghandler.h>
|
||||||
|
#include <f8/udplog.h>
|
||||||
|
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "GCListener.h"
|
#include "GCListener.h"
|
||||||
@ -43,19 +44,21 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (warning) {
|
if (warning) {
|
||||||
a8::UdpLog::Instance()->Warning("收到client非法数据包", {});
|
f8::UdpLog::Instance()->Warning("收到client非法数据包", {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnRawHttpGet(const std::string& url, const std::string& querystr,
|
virtual void OnRawHttpGet(const std::string& url, const std::string& querystr,
|
||||||
std::string& response) override
|
std::string& response) override
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
App::Instance()->AddIMMsg(IM_ExecGM,
|
App::Instance()->AddIMMsg(IM_ExecGM,
|
||||||
a8::XParams()
|
a8::XParams()
|
||||||
.SetSender(socket_handle)
|
.SetSender(socket_handle)
|
||||||
.SetParam1(url)
|
.SetParam1(url)
|
||||||
.SetParam2(querystr)
|
.SetParam2(querystr)
|
||||||
.SetParam3(saddr));
|
.SetParam3(saddr));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool HandleRedirect(const std::string& url, const std::string& querystr,
|
virtual bool HandleRedirect(const std::string& url, const std::string& querystr,
|
||||||
@ -90,10 +93,12 @@ public:
|
|||||||
|
|
||||||
virtual void OnDisConnect() override
|
virtual void OnDisConnect() override
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
App::Instance()->AddIMMsg(IM_ClientSocketDisconnect,
|
App::Instance()->AddIMMsg(IM_ClientSocketDisconnect,
|
||||||
a8::XParams()
|
a8::XParams()
|
||||||
.SetSender(socket_handle)
|
.SetSender(socket_handle)
|
||||||
.SetParam1(1));
|
.SetParam1(1));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -105,7 +110,7 @@ static void CreateGameClientSocket(a8::TcpSession **p)
|
|||||||
|
|
||||||
static void GSListeneron_error(a8::TcpListener*, int type, int errorid)
|
static void GSListeneron_error(a8::TcpListener*, int type, int errorid)
|
||||||
{
|
{
|
||||||
a8::UdpLog::Instance()->Debug("GCListeneron_error %d %d", {type, errorid});
|
f8::UdpLog::Instance()->Debug("GCListeneron_error %d %d", {type, errorid});
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCListener::Init()
|
void GCListener::Init()
|
||||||
|
@ -6,12 +6,11 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
|
||||||
#include <a8/redis.h>
|
#include <a8/xtimer.h>
|
||||||
#include <a8/timer.h>
|
|
||||||
#include <a8/uuid.h>
|
#include <a8/uuid.h>
|
||||||
#include <a8/ioloop.h>
|
|
||||||
|
|
||||||
#include "framework/cpp/netmsghandler.h"
|
#include <f8/netmsghandler.h>
|
||||||
|
#include <f8/udplog.h>
|
||||||
|
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "GCListener.h"
|
#include "GCListener.h"
|
||||||
@ -41,20 +40,12 @@ struct MsgNode
|
|||||||
MsgNode* next;
|
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_ROOT_FMT = "/data/logs/%s/logs";
|
||||||
const char* const PROJ_LOG_FILENAME_FMT = "log_$pid_%Y%m%d.log";
|
const char* const PROJ_LOG_FILENAME_FMT = "log_$pid_%Y%m%d.log";
|
||||||
|
|
||||||
static void SavePerfLog()
|
static void SavePerfLog()
|
||||||
{
|
{
|
||||||
a8::UdpLog::Instance()->Info(" max_run_delay_time:%d max_timer_idle:%d "
|
f8::UdpLog::Instance()->Info(" max_run_delay_time:%d max_timer_idle:%d "
|
||||||
"in_data_size:%d out_data_size:%d msgnode_size:%d read_count:%d max_login_time:%d "
|
"in_data_size:%d out_data_size:%d msgnode_size:%d read_count:%d max_login_time:%d "
|
||||||
"max_join_time:%d",
|
"max_join_time:%d",
|
||||||
{
|
{
|
||||||
@ -127,25 +118,21 @@ bool App::Init(int argc, char* argv[])
|
|||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
a8::XPrintf("wsproxy starting node_id:%d instance_id:%d pid:%d master_mode:%d async_tcpclient:%d\n",
|
a8::XPrintf("wsproxy starting node_id:%d instance_id:%d pid:%d\n",
|
||||||
{
|
{
|
||||||
node_id,
|
node_id,
|
||||||
instance_id,
|
instance_id,
|
||||||
getpid(),
|
getpid()
|
||||||
MASTER_MODE,
|
|
||||||
ASYNC_TCPCLIENT
|
|
||||||
});
|
});
|
||||||
|
|
||||||
loop_mutex_ = new std::mutex();
|
loop_mutex_ = new std::mutex();
|
||||||
loop_cond_ = new std::condition_variable();
|
loop_cond_ = new std::condition_variable();
|
||||||
msg_mutex_ = new std::mutex();
|
msg_mutex_ = new std::mutex();
|
||||||
im_msg_mutex_ = new std::mutex();
|
|
||||||
|
|
||||||
srand(time(nullptr));
|
srand(time(nullptr));
|
||||||
InitLog();
|
InitLog();
|
||||||
HandlerMgr::Instance()->Init();
|
HandlerMgr::Instance()->Init();
|
||||||
a8::Timer::Instance()->Init();
|
f8::Timer::Instance()->Init();
|
||||||
a8::IoLoop::Instance()->Init(1);
|
|
||||||
JsonDataMgr::Instance()->Init();
|
JsonDataMgr::Instance()->Init();
|
||||||
#if MASTER_MODE
|
#if MASTER_MODE
|
||||||
uuid.SetMachineId((node_id - 1) * MAX_NODE_ID + instance_id);
|
uuid.SetMachineId((node_id - 1) * MAX_NODE_ID + instance_id);
|
||||||
@ -159,26 +146,28 @@ bool App::Init(int argc, char* argv[])
|
|||||||
TargetConnMgr::Instance()->Init();
|
TargetConnMgr::Instance()->Init();
|
||||||
GCListener::Instance()->Init();
|
GCListener::Instance()->Init();
|
||||||
|
|
||||||
a8::UdpLog::Instance()->Info("wsproxy starting instance_id:%d pid:%d async_tcpclient:%d",
|
f8::UdpLog::Instance()->Info("wsproxy starting instance_id:%d pid:%d",
|
||||||
{
|
{
|
||||||
instance_id,
|
instance_id,
|
||||||
getpid(),
|
getpid(),
|
||||||
ASYNC_TCPCLIENT
|
|
||||||
});
|
});
|
||||||
{
|
{
|
||||||
int perf_log_time = 1000 * 60 * 5;
|
int perf_log_time = 1000 * 60 * 5;
|
||||||
if (getenv("is_dev_env")) {
|
if (getenv("is_dev_env")) {
|
||||||
perf_log_time = 1000 * 10;
|
perf_log_time = 1000 * 10;
|
||||||
}
|
}
|
||||||
a8::Timer::Instance()->AddRepeatTimer(perf_log_time,
|
#if 0
|
||||||
|
f8::Timer::Instance()->AddRepeatTimer(perf_log_time,
|
||||||
a8::XParams(),
|
a8::XParams(),
|
||||||
[] (const a8::XParams& param)
|
[] (const a8::XParams& param)
|
||||||
{
|
{
|
||||||
SavePerfLog();
|
SavePerfLog();
|
||||||
});
|
});
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (HasFlag(1)) {
|
if (HasFlag(1)) {
|
||||||
a8::Timer::Instance()->AddDeadLineTimer(
|
#if 0
|
||||||
|
f8::Timer::Instance()->AddDeadLineTimer(
|
||||||
1000 * 60,
|
1000 * 60,
|
||||||
a8::XParams(),
|
a8::XParams(),
|
||||||
[] (const a8::XParams& param)
|
[] (const a8::XParams& param)
|
||||||
@ -187,8 +176,10 @@ bool App::Init(int argc, char* argv[])
|
|||||||
App::Instance()->NotifyLoopCond();
|
App::Instance()->NotifyLoopCond();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (HasFlag(4)) {
|
if (HasFlag(4)) {
|
||||||
|
#if 0
|
||||||
a8::Timer::Instance()->AddDeadLineTimer(
|
a8::Timer::Instance()->AddDeadLineTimer(
|
||||||
1000 * 30,
|
1000 * 30,
|
||||||
a8::XParams(),
|
a8::XParams(),
|
||||||
@ -198,6 +189,7 @@ bool App::Init(int argc, char* argv[])
|
|||||||
a8::XPrintf("shutdowned\n", {});
|
a8::XPrintf("shutdowned\n", {});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -212,15 +204,11 @@ void App::UnInit()
|
|||||||
TargetConnMgr::Instance()->UnInit();
|
TargetConnMgr::Instance()->UnInit();
|
||||||
GameClientMgr::Instance()->UnInit();
|
GameClientMgr::Instance()->UnInit();
|
||||||
JsonDataMgr::Instance()->UnInit();
|
JsonDataMgr::Instance()->UnInit();
|
||||||
a8::IoLoop::Instance()->UnInit();
|
f8::Timer::Instance()->UnInit();
|
||||||
a8::Timer::Instance()->UnInit();
|
|
||||||
HandlerMgr::Instance()->UnInit();
|
HandlerMgr::Instance()->UnInit();
|
||||||
UnInitLog();
|
UnInitLog();
|
||||||
|
|
||||||
FreeSocketMsgQueue();
|
FreeSocketMsgQueue();
|
||||||
FreeIMMsgQueue();
|
|
||||||
delete im_msg_mutex_;
|
|
||||||
im_msg_mutex_ = nullptr;
|
|
||||||
delete msg_mutex_;
|
delete msg_mutex_;
|
||||||
msg_mutex_ = nullptr;
|
msg_mutex_ = nullptr;
|
||||||
delete loop_cond_;
|
delete loop_cond_;
|
||||||
@ -233,7 +221,7 @@ void App::UnInit()
|
|||||||
int App::Run()
|
int App::Run()
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
a8::UdpLog::Instance()->Info("wsproxy running", {});
|
f8::UdpLog::Instance()->Info("wsproxy running", {});
|
||||||
while (!terminated) {
|
while (!terminated) {
|
||||||
a8::tick_t begin_tick = a8::XGetTickCount();
|
a8::tick_t begin_tick = a8::XGetTickCount();
|
||||||
QuickExecute();
|
QuickExecute();
|
||||||
@ -281,29 +269,10 @@ void App::AddSocketMsg(SocketFrom_e sockfrom,
|
|||||||
NotifyLoopCond();
|
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()
|
void App::QuickExecute()
|
||||||
{
|
{
|
||||||
ProcessIMMsg();
|
|
||||||
DispatchMsg();
|
DispatchMsg();
|
||||||
a8::Timer::Instance()->Update();
|
f8::Timer::Instance()->Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::SlowerExecute()
|
void App::SlowerExecute()
|
||||||
@ -320,30 +289,18 @@ void App::Schedule()
|
|||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lk(*loop_mutex_);
|
std::unique_lock<std::mutex> lk(*loop_mutex_);
|
||||||
if (!HasTask()) {
|
if (!HasTask()) {
|
||||||
int sleep_time = a8::Timer::Instance()->GetIdleableMillSeconds();
|
#if 0
|
||||||
|
int sleep_time = f8::Timer::Instance()->GetIdleableMillSeconds();
|
||||||
loop_cond_->wait_for(lk, std::chrono::milliseconds(sleep_time));
|
loop_cond_->wait_for(lk, std::chrono::milliseconds(sleep_time));
|
||||||
if (sleep_time > perf.max_timer_idle) {
|
if (sleep_time > perf.max_timer_idle) {
|
||||||
perf.max_timer_idle = sleep_time;
|
perf.max_timer_idle = sleep_time;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool App::HasTask()
|
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_) {
|
if (!work_node_) {
|
||||||
msg_mutex_->lock();
|
msg_mutex_->lock();
|
||||||
@ -473,7 +430,7 @@ void App::ProcessClientMsg(f8::MsgHdr& hdr)
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
TargetConn* conn = nullptr;
|
TargetConn* conn = nullptr;
|
||||||
if (hdr.msgid == ss::_SS_CMLogin || hdr.msgid == ss::_SS_CMReConnect) {
|
if (hdr.msgid == ss::_SS_CMLogin || hdr.msgid == ss::_SS_CMReconnect) {
|
||||||
ss::SS_CMLogin_CMReConnect_CommonHead msg;
|
ss::SS_CMLogin_CMReConnect_CommonHead msg;
|
||||||
bool ok = msg.ParseFromArray(hdr.buf + hdr.offset, hdr.buflen - hdr.offset);
|
bool ok = msg.ParseFromArray(hdr.buf + hdr.offset, hdr.buflen - hdr.offset);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
@ -529,6 +486,7 @@ void App::ProcessTargetServerMsg(f8::MsgHdr& hdr)
|
|||||||
GCListener::Instance()->ForwardTargetConnMsg(hdr);
|
GCListener::Instance()->ForwardTargetConnMsg(hdr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
void App::ProcessIMMsg()
|
void App::ProcessIMMsg()
|
||||||
{
|
{
|
||||||
if (!im_work_node_ && im_top_node_) {
|
if (!im_work_node_ && im_top_node_) {
|
||||||
@ -577,6 +535,7 @@ void App::ProcessIMMsg()
|
|||||||
delete pdelnode;
|
delete pdelnode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void App::InitLog()
|
void App::InitLog()
|
||||||
{
|
{
|
||||||
@ -590,16 +549,16 @@ void App::InitLog()
|
|||||||
|
|
||||||
a8::MkDir(proj_root_dir);
|
a8::MkDir(proj_root_dir);
|
||||||
a8::MkDir(proj_log_root_dir);
|
a8::MkDir(proj_log_root_dir);
|
||||||
a8::UdpLog::Instance()->SetLogFileName(log_file_name);
|
f8::UdpLog::Instance()->SetLogFileName(log_file_name);
|
||||||
a8::UdpLog::Instance()->Init();
|
f8::UdpLog::Instance()->Init();
|
||||||
a8::UdpLog::Instance()->Info("proj_root_dir:%s", {proj_root_dir});
|
f8::UdpLog::Instance()->Info("proj_root_dir:%s", {proj_root_dir});
|
||||||
a8::UdpLog::Instance()->Info("proj_log_root_dir:%s", {proj_log_root_dir});
|
f8::UdpLog::Instance()->Info("proj_log_root_dir:%s", {proj_log_root_dir});
|
||||||
a8::UdpLog::Instance()->Info("log_file_name:%s", {log_file_name});
|
f8::UdpLog::Instance()->Info("log_file_name:%s", {log_file_name});
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::UnInitLog()
|
void App::UnInitLog()
|
||||||
{
|
{
|
||||||
a8::UdpLog::Instance()->UnInit();
|
f8::UdpLog::Instance()->UnInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool App::ParseOpt()
|
bool App::ParseOpt()
|
||||||
@ -635,23 +594,6 @@ bool App::ParseOpt()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
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::HasFlag(int flag)
|
bool App::HasFlag(int flag)
|
||||||
{
|
{
|
||||||
return flags.find(flag) != flags.end();
|
return flags.find(flag) != flags.end();
|
||||||
@ -680,28 +622,3 @@ void App::FreeSocketMsgQueue()
|
|||||||
}
|
}
|
||||||
msg_mutex_->unlock();
|
msg_mutex_->unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::FreeIMMsgQueue()
|
|
||||||
{
|
|
||||||
im_msg_mutex_->lock();
|
|
||||||
if (!im_work_node_) {
|
|
||||||
im_work_node_ = im_top_node_;
|
|
||||||
im_top_node_ = nullptr;
|
|
||||||
im_bot_node_ = nullptr;
|
|
||||||
}
|
|
||||||
while (im_work_node_) {
|
|
||||||
IMMsgNode* pdelnode = im_work_node_;
|
|
||||||
im_work_node_ = im_work_node_->next;
|
|
||||||
if (pdelnode->msgid == f8::IM_SysMsgQueue) {
|
|
||||||
a8::XParams* param = (a8::XParams*)pdelnode->params.param1.GetUserData();
|
|
||||||
delete param;
|
|
||||||
}
|
|
||||||
delete pdelnode;
|
|
||||||
if (!im_work_node_) {
|
|
||||||
im_work_node_ = im_top_node_;
|
|
||||||
im_top_node_ = nullptr;
|
|
||||||
im_bot_node_ = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
im_msg_mutex_->unlock();
|
|
||||||
}
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <a8/uuid.h>
|
#include <a8/uuid.h>
|
||||||
|
#include <a8/singleton.h>
|
||||||
|
|
||||||
struct MsgNode;
|
struct MsgNode;
|
||||||
struct IMMsgNode;
|
|
||||||
class App : public a8::Singleton<App>
|
class App : public a8::Singleton<App>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -24,13 +24,8 @@ class App : public a8::Singleton<App>
|
|||||||
unsigned int seqid,
|
unsigned int seqid,
|
||||||
const char *msgbody,
|
const char *msgbody,
|
||||||
int bodylen);
|
int bodylen);
|
||||||
void AddIMMsg(unsigned short imcmd, a8::XParams params);
|
|
||||||
|
|
||||||
void NotifyLoopCond();
|
void NotifyLoopCond();
|
||||||
|
|
||||||
a8::XParams* AddContext(long long context_id);
|
|
||||||
void DelContext(long long context_id);
|
|
||||||
a8::XParams* GetContext(long long context_id);
|
|
||||||
bool HasFlag(int flag);
|
bool HasFlag(int flag);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -40,7 +35,6 @@ private:
|
|||||||
bool HasTask();
|
bool HasTask();
|
||||||
|
|
||||||
void DispatchMsg();
|
void DispatchMsg();
|
||||||
void ProcessIMMsg();
|
|
||||||
|
|
||||||
void ProcessClientMsg(f8::MsgHdr& hdr);
|
void ProcessClientMsg(f8::MsgHdr& hdr);
|
||||||
void ProcessMasterServerMsg(f8::MsgHdr& hdr);
|
void ProcessMasterServerMsg(f8::MsgHdr& hdr);
|
||||||
@ -51,7 +45,6 @@ private:
|
|||||||
|
|
||||||
bool ParseOpt();
|
bool ParseOpt();
|
||||||
void FreeSocketMsgQueue();
|
void FreeSocketMsgQueue();
|
||||||
void FreeIMMsgQueue();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
@ -75,13 +68,6 @@ public:
|
|||||||
MsgNode* bot_node_ = nullptr;
|
MsgNode* bot_node_ = nullptr;
|
||||||
MsgNode* work_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::map<long long, a8::XParams> context_hash_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int msgnode_size_ = 0 ;
|
int msgnode_size_ = 0 ;
|
||||||
int working_msgnode_size_ = 0;
|
int working_msgnode_size_ = 0;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "precompile.h"
|
#include "precompile.h"
|
||||||
|
|
||||||
|
#include <f8/udplog.h>
|
||||||
|
|
||||||
#include "gameclientmgr.h"
|
#include "gameclientmgr.h"
|
||||||
#include "ss_proto.pb.h"
|
#include "ss_proto.pb.h"
|
||||||
|
|
||||||
@ -19,9 +21,12 @@ void GameClientMgr::UnInit()
|
|||||||
delete pair.second;
|
delete pair.second;
|
||||||
}
|
}
|
||||||
socket_hash_.clear();
|
socket_hash_.clear();
|
||||||
|
#if 0
|
||||||
pending_account_hash_.clear();
|
pending_account_hash_.clear();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
void GameClientMgr::OnClientDisconnect(a8::XParams& param)
|
void GameClientMgr::OnClientDisconnect(a8::XParams& param)
|
||||||
{
|
{
|
||||||
GameClient* client = GetGameClientBySocket(param.sender);
|
GameClient* client = GetGameClientBySocket(param.sender);
|
||||||
@ -35,7 +40,9 @@ void GameClientMgr::OnClientDisconnect(a8::XParams& param)
|
|||||||
}
|
}
|
||||||
RemovePendingAccount(param.sender);
|
RemovePendingAccount(param.sender);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
void GameClientMgr::OnTargetServerDisconnect(a8::XParams& param)
|
void GameClientMgr::OnTargetServerDisconnect(a8::XParams& param)
|
||||||
{
|
{
|
||||||
std::list<GameClient*> delete_client;
|
std::list<GameClient*> delete_client;
|
||||||
@ -51,11 +58,14 @@ void GameClientMgr::OnTargetServerDisconnect(a8::XParams& param)
|
|||||||
delete client;
|
delete client;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
void GameClientMgr::OnTargetServerConnect(a8::XParams& param)
|
void GameClientMgr::OnTargetServerConnect(a8::XParams& param)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
GameClient* GameClientMgr::GetGameClientBySocket(int sockhandle)
|
GameClient* GameClientMgr::GetGameClientBySocket(int sockhandle)
|
||||||
{
|
{
|
||||||
@ -75,8 +85,9 @@ void GameClientMgr::BindTargetConn(int socket_handle, int conn_instance_id)
|
|||||||
client->socket_handle = socket_handle;
|
client->socket_handle = socket_handle;
|
||||||
client->conn = conn;
|
client->conn = conn;
|
||||||
socket_hash_[client->socket_handle] = client;
|
socket_hash_[client->socket_handle] = client;
|
||||||
a8::UdpLog::Instance()->Info("BindTargetConn socket_handle:%d", {socket_handle});
|
f8::UdpLog::Instance()->Info("BindTargetConn socket_handle:%d", {socket_handle});
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
auto itr = pending_account_hash_.find(socket_handle);
|
auto itr = pending_account_hash_.find(socket_handle);
|
||||||
if (itr != pending_account_hash_.end()) {
|
if (itr != pending_account_hash_.end()) {
|
||||||
std::string account_id = std::get<0>(itr->second);
|
std::string account_id = std::get<0>(itr->second);
|
||||||
@ -86,15 +97,16 @@ void GameClientMgr::BindTargetConn(int socket_handle, int conn_instance_id)
|
|||||||
App::Instance()->perf.max_join_time = cur_tick - req_tick;
|
App::Instance()->perf.max_join_time = cur_tick - req_tick;
|
||||||
}
|
}
|
||||||
if (account_id == azw_account_id) {
|
if (account_id == azw_account_id) {
|
||||||
a8::UdpLog::Instance()->Info("%s join time:%d",
|
f8::UdpLog::Instance()->Info("%s join time:%d",
|
||||||
{
|
{
|
||||||
account_id,
|
account_id,
|
||||||
cur_tick - req_tick
|
cur_tick - req_tick
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
a8::UdpLog::Instance()->Info("BindTargetConn account_id:%s", {account_id});
|
f8::UdpLog::Instance()->Info("BindTargetConn account_id:%s", {account_id});
|
||||||
RemovePendingAccount(socket_handle);
|
RemovePendingAccount(socket_handle);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,7 +114,8 @@ void GameClientMgr::BindTargetConn(int socket_handle, int conn_instance_id)
|
|||||||
|
|
||||||
void GameClientMgr::AddPendingAccount(const std::string& account_id, int socket_handle, long long req_tick)
|
void GameClientMgr::AddPendingAccount(const std::string& account_id, int socket_handle, long long req_tick)
|
||||||
{
|
{
|
||||||
a8::UdpLog::Instance()->Info("AddPendingAccount %s %d", {account_id, socket_handle});
|
#if 0
|
||||||
|
f8::UdpLog::Instance()->Info("AddPendingAccount %s %d", {account_id, socket_handle});
|
||||||
auto itr = pending_account_hash_.find(socket_handle);
|
auto itr = pending_account_hash_.find(socket_handle);
|
||||||
if (itr == pending_account_hash_.end()){
|
if (itr == pending_account_hash_.end()){
|
||||||
timer_list* timer = a8::Timer::Instance()->AddDeadLineTimerAndAttach(1000 * 10,
|
timer_list* timer = a8::Timer::Instance()->AddDeadLineTimerAndAttach(1000 * 10,
|
||||||
@ -114,6 +127,7 @@ void GameClientMgr::AddPendingAccount(const std::string& account_id, int socket_
|
|||||||
App::Instance()->perf.max_join_time = std::max((long long)1000 * 10, App::Instance()->perf.max_join_time);
|
App::Instance()->perf.max_join_time = std::max((long long)1000 * 10, App::Instance()->perf.max_join_time);
|
||||||
},
|
},
|
||||||
&timer_attacher_.timer_list_
|
&timer_attacher_.timer_list_
|
||||||
|
|
||||||
);
|
);
|
||||||
pending_account_hash_[socket_handle] = std::make_tuple(
|
pending_account_hash_[socket_handle] = std::make_tuple(
|
||||||
account_id,
|
account_id,
|
||||||
@ -121,14 +135,19 @@ void GameClientMgr::AddPendingAccount(const std::string& account_id, int socket_
|
|||||||
timer
|
timer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameClientMgr::RemovePendingAccount(int socket_handle)
|
void GameClientMgr::RemovePendingAccount(int socket_handle)
|
||||||
{
|
{
|
||||||
a8::UdpLog::Instance()->Info("RemovePendingAccount %d", {socket_handle});
|
#if 0
|
||||||
|
f8::UdpLog::Instance()->Info("RemovePendingAccount %d", {socket_handle});
|
||||||
auto itr = pending_account_hash_.find(socket_handle);
|
auto itr = pending_account_hash_.find(socket_handle);
|
||||||
if (itr != pending_account_hash_.end()) {
|
if (itr != pending_account_hash_.end()) {
|
||||||
a8::Timer::Instance()->DeleteTimer(std::get<2>(itr->second));
|
#if 0
|
||||||
|
f8::Timer::Instance()->DeleteTimer(std::get<2>(itr->second));
|
||||||
pending_account_hash_.erase(itr);
|
pending_account_hash_.erase(itr);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <a8/timer.h>
|
#include <f8/timer.h>
|
||||||
|
|
||||||
class GameClient;
|
class GameClient;
|
||||||
class GameClientMgr : public a8::Singleton<GameClientMgr>
|
class GameClientMgr : public a8::Singleton<GameClientMgr>
|
||||||
@ -14,9 +14,11 @@ class GameClientMgr : public a8::Singleton<GameClientMgr>
|
|||||||
void Init();
|
void Init();
|
||||||
void UnInit();
|
void UnInit();
|
||||||
|
|
||||||
|
#if 0
|
||||||
void OnClientDisconnect(a8::XParams& param);
|
void OnClientDisconnect(a8::XParams& param);
|
||||||
void OnTargetServerDisconnect(a8::XParams& param);
|
void OnTargetServerDisconnect(a8::XParams& param);
|
||||||
void OnTargetServerConnect(a8::XParams& param);
|
void OnTargetServerConnect(a8::XParams& param);
|
||||||
|
#endif
|
||||||
GameClient* GetGameClientBySocket(int sockhande);
|
GameClient* GetGameClientBySocket(int sockhande);
|
||||||
void BindTargetConn(int socket_handle, int conn_instance_id);
|
void BindTargetConn(int socket_handle, int conn_instance_id);
|
||||||
void AddPendingAccount(const std::string& account_id, int socket_handle, long long req_tick);
|
void AddPendingAccount(const std::string& account_id, int socket_handle, long long req_tick);
|
||||||
@ -26,7 +28,9 @@ private:
|
|||||||
void RemovePendingAccount(int socket_handle);
|
void RemovePendingAccount(int socket_handle);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
a8::TimerAttacher timer_attacher_;
|
a8::Attacher timer_attacher_;
|
||||||
std::map<int, GameClient*> socket_hash_;
|
std::map<int, GameClient*> socket_hash_;
|
||||||
|
#if 0
|
||||||
std::map<int, std::tuple<std::string, long long, timer_list*>> pending_account_hash_;
|
std::map<int, std::tuple<std::string, long long, timer_list*>> pending_account_hash_;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
@ -12,17 +12,21 @@
|
|||||||
|
|
||||||
static void _GMOpsSelfChecking(f8::JsonHttpRequest* request)
|
static void _GMOpsSelfChecking(f8::JsonHttpRequest* request)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
request->resp_xobj->SetVal("errcode", 0);
|
request->resp_xobj->SetVal("errcode", 0);
|
||||||
request->resp_xobj->SetVal("errmsg", "");
|
request->resp_xobj->SetVal("errmsg", "");
|
||||||
request->resp_xobj->SetVal("healthy", 1);
|
request->resp_xobj->SetVal("healthy", 1);
|
||||||
request->resp_xobj->SetVal("max_rundelay", 10);
|
request->resp_xobj->SetVal("max_rundelay", 10);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _GMOpsGetNodeId(f8::JsonHttpRequest* request)
|
static void _GMOpsGetNodeId(f8::JsonHttpRequest* request)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
request->resp_xobj->SetVal("errcode", 0);
|
request->resp_xobj->SetVal("errcode", 0);
|
||||||
request->resp_xobj->SetVal("errmsg", "");
|
request->resp_xobj->SetVal("errmsg", "");
|
||||||
request->resp_xobj->SetVal("node_id", App::Instance()->node_id);
|
request->resp_xobj->SetVal("node_id", App::Instance()->node_id);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandlerMgr::Init()
|
void HandlerMgr::Init()
|
||||||
@ -55,6 +59,7 @@ 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
|
||||||
f8::JsonHttpRequest* request = new f8::JsonHttpRequest;
|
f8::JsonHttpRequest* request = new f8::JsonHttpRequest;
|
||||||
request->saddr = saddr;
|
request->saddr = saddr;
|
||||||
request->socket_handle = sockhandle;
|
request->socket_handle = sockhandle;
|
||||||
@ -69,6 +74,7 @@ void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle,
|
|||||||
|
|
||||||
delete request;
|
delete request;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
GCListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}"));
|
GCListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}"));
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <a8/basehttpsession.h>
|
#include <a8/basehttpsession.h>
|
||||||
|
|
||||||
#include "framework/cpp/netmsghandler.h"
|
#include <f8/netmsghandler.h>
|
||||||
|
|
||||||
namespace a8
|
namespace a8
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
|
#include <f8/utils.h>
|
||||||
|
|
||||||
#include "jsondatamgr.h"
|
#include "jsondatamgr.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <a8/singleton.h>
|
||||||
|
|
||||||
class JsonDataMgr : public a8::Singleton<JsonDataMgr>
|
class JsonDataMgr : public a8::Singleton<JsonDataMgr>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -2,14 +2,15 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <a8/tcpclient.h>
|
||||||
|
|
||||||
|
#include <f8/udplog.h>
|
||||||
|
#include <f8/timer.h>
|
||||||
|
|
||||||
#include "ss_proto.pb.h"
|
#include "ss_proto.pb.h"
|
||||||
#include "ss_msgid.pb.h"
|
#include "ss_msgid.pb.h"
|
||||||
#include "mastersvr.h"
|
#include "mastersvr.h"
|
||||||
#include <a8/tcpclient.h>
|
|
||||||
#include <a8/asynctcpclient.h>
|
|
||||||
#include <a8/ioloop.h>
|
|
||||||
#include <a8/udplog.h>
|
|
||||||
#include <a8/timer.h>
|
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
|
||||||
const int PACK_MAX = 1024 * 64;
|
const int PACK_MAX = 1024 * 64;
|
||||||
@ -34,6 +35,7 @@ void MasterSvr::Init(int instance_id, const std::string& remote_ip, int remote_p
|
|||||||
tcp_client_->on_connect = std::bind(&MasterSvr::on_connect, this, std::placeholders::_1);
|
tcp_client_->on_connect = std::bind(&MasterSvr::on_connect, this, std::placeholders::_1);
|
||||||
tcp_client_->on_disconnect = std::bind(&MasterSvr::on_disconnect, this, std::placeholders::_1);
|
tcp_client_->on_disconnect = std::bind(&MasterSvr::on_disconnect, this, std::placeholders::_1);
|
||||||
tcp_client_->on_socketread = std::bind(&MasterSvr::on_socketread, this ,std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
tcp_client_->on_socketread = std::bind(&MasterSvr::on_socketread, this ,std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||||
|
#if 0
|
||||||
timer_ = a8::Timer::Instance()->AddRepeatTimer(1000 * 9 + a8::RandEx(500, 150),
|
timer_ = a8::Timer::Instance()->AddRepeatTimer(1000 * 9 + a8::RandEx(500, 150),
|
||||||
a8::XParams().SetSender(this),
|
a8::XParams().SetSender(this),
|
||||||
[] (const a8::XParams& param)
|
[] (const a8::XParams& param)
|
||||||
@ -41,12 +43,15 @@ void MasterSvr::Init(int instance_id, const std::string& remote_ip, int remote_p
|
|||||||
MasterSvr* conn = (MasterSvr*)param.sender.GetUserData();
|
MasterSvr* conn = (MasterSvr*)param.sender.GetUserData();
|
||||||
conn->CheckAlive();
|
conn->CheckAlive();
|
||||||
});
|
});
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MasterSvr::UnInit()
|
void MasterSvr::UnInit()
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
a8::Timer::Instance()->DeleteTimer(timer_);
|
a8::Timer::Instance()->DeleteTimer(timer_);
|
||||||
timer_ = nullptr;
|
timer_ = nullptr;
|
||||||
|
#endif
|
||||||
tcp_client_->Close();
|
tcp_client_->Close();
|
||||||
#if ASYNC_TCPCLIENT
|
#if ASYNC_TCPCLIENT
|
||||||
a8::IoLoop::Instance()->DestoryAsyncTcpClient(tcp_client_);
|
a8::IoLoop::Instance()->DestoryAsyncTcpClient(tcp_client_);
|
||||||
@ -80,7 +85,7 @@ void MasterSvr::on_error(a8::AsyncTcpClient* sender, int errorId)
|
|||||||
void MasterSvr::on_error(a8::TcpClient* sender, int errorId)
|
void MasterSvr::on_error(a8::TcpClient* sender, int errorId)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
a8::UdpLog::Instance()->Error("MasterSvr errorid=%d remote_ip:%s remote_port:%d",
|
f8::UdpLog::Instance()->Error("MasterSvr errorid=%d remote_ip:%s remote_port:%d",
|
||||||
{
|
{
|
||||||
errorId,
|
errorId,
|
||||||
sender->remote_address,
|
sender->remote_address,
|
||||||
@ -95,7 +100,7 @@ void MasterSvr::on_connect(a8::TcpClient* sender)
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
recv_bufflen_ = 0;
|
recv_bufflen_ = 0;
|
||||||
a8::UdpLog::Instance()->Info("masterserver connected", {});
|
f8::UdpLog::Instance()->Info("masterserver connected", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ASYNC_TCPCLIENT
|
#if ASYNC_TCPCLIENT
|
||||||
@ -105,11 +110,13 @@ void MasterSvr::on_disconnect(a8::TcpClient* sender)
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
recv_bufflen_ = 0;
|
recv_bufflen_ = 0;
|
||||||
a8::UdpLog::Instance()->Info("masterserver %d disconnected after 10s later reconnect", {instance_id});
|
f8::UdpLog::Instance()->Info("masterserver %d disconnected after 10s later reconnect", {instance_id});
|
||||||
|
#if 0
|
||||||
App::Instance()->AddIMMsg(IM_MasterSvrDisconnect,
|
App::Instance()->AddIMMsg(IM_MasterSvrDisconnect,
|
||||||
a8::XParams()
|
a8::XParams()
|
||||||
.SetSender(instance_id)
|
.SetSender(instance_id)
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ASYNC_TCPCLIENT
|
#if ASYNC_TCPCLIENT
|
||||||
@ -123,7 +130,7 @@ void MasterSvr::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len
|
|||||||
#endif
|
#endif
|
||||||
if (recv_bufflen_ + len > 2 * PACK_MAX) {
|
if (recv_bufflen_ + len > 2 * PACK_MAX) {
|
||||||
recv_bufflen_ = 0;
|
recv_bufflen_ = 0;
|
||||||
a8::UdpLog::Instance()->Debug("recvied masterserver too long message", {});
|
f8::UdpLog::Instance()->Debug("recvied masterserver too long message", {});
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
memmove(&recv_buff_[recv_bufflen_], buf, len);
|
memmove(&recv_buff_[recv_bufflen_], buf, len);
|
||||||
@ -154,7 +161,7 @@ void MasterSvr::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (warning) {
|
if (warning) {
|
||||||
a8::UdpLog::Instance()->Debug("recvied bad package", {});
|
f8::UdpLog::Instance()->Debug("recvied bad package", {});
|
||||||
}
|
}
|
||||||
if (offset > 0 && offset < recv_bufflen_) {
|
if (offset > 0 && offset < recv_bufflen_) {
|
||||||
memmove(recv_buff_, recv_buff_ + offset, recv_bufflen_ - offset);
|
memmove(recv_buff_, recv_buff_ + offset, recv_bufflen_ - offset);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "framework/cpp/protoutils.h"
|
#include <f8/protoutils.h>
|
||||||
|
|
||||||
namespace a8
|
namespace a8
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,9 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <a8/openssl.h>
|
#include <a8/openssl.h>
|
||||||
#include <a8/timer.h>
|
|
||||||
|
#include <f8/timer.h>
|
||||||
|
#include <f8/netmsghandler.h>
|
||||||
|
|
||||||
#include "mastersvrmgr.h"
|
#include "mastersvrmgr.h"
|
||||||
#include "mastersvr.h"
|
#include "mastersvr.h"
|
||||||
@ -14,8 +16,6 @@
|
|||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "gameclientmgr.h"
|
#include "gameclientmgr.h"
|
||||||
|
|
||||||
#include "framework/cpp/netmsghandler.h"
|
|
||||||
|
|
||||||
void MasterSvrMgr::Init()
|
void MasterSvrMgr::Init()
|
||||||
{
|
{
|
||||||
curr_context_id_ = a8::MakeInt64(0, time(nullptr) + 1000 * 60 * 10);
|
curr_context_id_ = a8::MakeInt64(0, time(nullptr) + 1000 * 60 * 10);
|
||||||
@ -113,6 +113,7 @@ void MasterSvrMgr::RequestTargetServer(f8::MsgHdr& hdr,
|
|||||||
MasterSvr* svr = GetConnById(code % mastersvr_hash_.size() + 1);
|
MasterSvr* svr = GetConnById(code % mastersvr_hash_.size() + 1);
|
||||||
if (svr) {
|
if (svr) {
|
||||||
++curr_context_id_;
|
++curr_context_id_;
|
||||||
|
#if 0
|
||||||
a8::TimerAttacher* timer_attacher = new a8::TimerAttacher();
|
a8::TimerAttacher* timer_attacher = new a8::TimerAttacher();
|
||||||
f8::MsgHdr* new_hdr = hdr.Clone();
|
f8::MsgHdr* new_hdr = hdr.Clone();
|
||||||
new_hdr->user_data = timer_attacher;
|
new_hdr->user_data = timer_attacher;
|
||||||
@ -174,11 +175,13 @@ void MasterSvrMgr::RequestTargetServer(f8::MsgHdr& hdr,
|
|||||||
&timer_attacher->timer_list_,
|
&timer_attacher->timer_list_,
|
||||||
timer_after_func
|
timer_after_func
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MasterSvrMgr::RemoveRequest(int socket_handle, long long context_id, bool auto_free)
|
void MasterSvrMgr::RemoveRequest(int socket_handle, long long context_id, bool auto_free)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
if (context_id == GetContextIdBySocket(socket_handle)) {
|
if (context_id == GetContextIdBySocket(socket_handle)) {
|
||||||
f8::MsgHdr* hdr = GetHdrByContextId(context_id);
|
f8::MsgHdr* hdr = GetHdrByContextId(context_id);
|
||||||
if (hdr) {
|
if (hdr) {
|
||||||
@ -195,6 +198,7 @@ void MasterSvrMgr::RemoveRequest(int socket_handle, long long context_id, bool a
|
|||||||
pending_request_hash_.erase(context_id);
|
pending_request_hash_.erase(context_id);
|
||||||
pending_socket_hash_.erase(socket_handle);
|
pending_socket_hash_.erase(socket_handle);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
long long MasterSvrMgr::GetContextIdBySocket(int socket_handle)
|
long long MasterSvrMgr::GetContextIdBySocket(int socket_handle)
|
||||||
|
@ -1,20 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
#include <a8/a8.h>
|
#include <a8/a8.h>
|
||||||
#include <a8/udplog.h>
|
#include <f8/f8.h>
|
||||||
|
|
||||||
#include "constant.h"
|
#include "constant.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
namespace google
|
|
||||||
{
|
|
||||||
namespace protobuf
|
|
||||||
{
|
|
||||||
class Message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "framework/cpp/types.h"
|
|
||||||
#include "framework/cpp/utils.h"
|
|
||||||
#include "framework/cpp/protoutils.h"
|
|
||||||
|
@ -2,14 +2,15 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <a8/tcpclient.h>
|
||||||
|
|
||||||
|
#include <f8/udplog.h>
|
||||||
|
#include <f8/timer.h>
|
||||||
|
|
||||||
#include "ss_proto.pb.h"
|
#include "ss_proto.pb.h"
|
||||||
#include "ss_msgid.pb.h"
|
#include "ss_msgid.pb.h"
|
||||||
#include "target_conn.h"
|
#include "target_conn.h"
|
||||||
#include <a8/tcpclient.h>
|
|
||||||
#include <a8/udplog.h>
|
|
||||||
#include <a8/timer.h>
|
|
||||||
#include <a8/ioloop.h>
|
|
||||||
#include <a8/asynctcpclient.h>
|
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
|
||||||
const int PACK_MAX = 1024 * 64 * 2;
|
const int PACK_MAX = 1024 * 64 * 2;
|
||||||
@ -37,6 +38,7 @@ void TargetConn::Init(int instance_id, const std::string& remote_ip, int remote_
|
|||||||
tcp_client_->on_connect = std::bind(&TargetConn::on_connect, this, std::placeholders::_1);
|
tcp_client_->on_connect = std::bind(&TargetConn::on_connect, this, std::placeholders::_1);
|
||||||
tcp_client_->on_disconnect = std::bind(&TargetConn::on_disconnect, this, std::placeholders::_1);
|
tcp_client_->on_disconnect = std::bind(&TargetConn::on_disconnect, this, std::placeholders::_1);
|
||||||
tcp_client_->on_socketread = std::bind(&TargetConn::on_socketread, this ,std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
tcp_client_->on_socketread = std::bind(&TargetConn::on_socketread, this ,std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||||
|
#if 0
|
||||||
timer_ = a8::Timer::Instance()->AddRepeatTimer(1000 * 9 + a8::RandEx(500, 150),
|
timer_ = a8::Timer::Instance()->AddRepeatTimer(1000 * 9 + a8::RandEx(500, 150),
|
||||||
a8::XParams().SetSender(this),
|
a8::XParams().SetSender(this),
|
||||||
[] (const a8::XParams& param)
|
[] (const a8::XParams& param)
|
||||||
@ -44,6 +46,7 @@ void TargetConn::Init(int instance_id, const std::string& remote_ip, int remote_
|
|||||||
TargetConn* conn = (TargetConn*)param.sender.GetUserData();
|
TargetConn* conn = (TargetConn*)param.sender.GetUserData();
|
||||||
conn->CheckAlive();
|
conn->CheckAlive();
|
||||||
});
|
});
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void TargetConn::UnInit()
|
void TargetConn::UnInit()
|
||||||
@ -59,8 +62,10 @@ void TargetConn::UnInit()
|
|||||||
delete pdelnode;
|
delete pdelnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
a8::Timer::Instance()->DeleteTimer(timer_);
|
#if 0
|
||||||
|
f8::Timer::Instance()->DeleteTimer(timer_);
|
||||||
timer_ = nullptr;
|
timer_ = nullptr;
|
||||||
|
#endif
|
||||||
tcp_client_->Close();
|
tcp_client_->Close();
|
||||||
#if ASYNC_TCPCLIENT && GAME_ID == 2002
|
#if ASYNC_TCPCLIENT && GAME_ID == 2002
|
||||||
a8::IoLoop::Instance()->DestoryAsyncTcpClient(tcp_client_);
|
a8::IoLoop::Instance()->DestoryAsyncTcpClient(tcp_client_);
|
||||||
@ -158,7 +163,7 @@ void TargetConn::on_error(a8::AsyncTcpClient* sender, int errorId)
|
|||||||
void TargetConn::on_error(a8::TcpClient* sender, int errorId)
|
void TargetConn::on_error(a8::TcpClient* sender, int errorId)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
a8::UdpLog::Instance()->Error("target server errorid=%d remote_ip:%s remote_port:%d",
|
f8::UdpLog::Instance()->Error("target server errorid=%d remote_ip:%s remote_port:%d",
|
||||||
{
|
{
|
||||||
errorId,
|
errorId,
|
||||||
sender->remote_address,
|
sender->remote_address,
|
||||||
@ -173,15 +178,17 @@ void TargetConn::on_connect(a8::TcpClient* sender)
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
recv_bufflen_ = 0;
|
recv_bufflen_ = 0;
|
||||||
a8::UdpLog::Instance()->Info("target server connected remote_ip:%s remote_port:%d",
|
f8::UdpLog::Instance()->Info("target server connected remote_ip:%s remote_port:%d",
|
||||||
{
|
{
|
||||||
sender->remote_address,
|
sender->remote_address,
|
||||||
sender->remote_port
|
sender->remote_port
|
||||||
});
|
});
|
||||||
|
#if 0
|
||||||
App::Instance()->AddIMMsg(IM_TargetConnConnect,
|
App::Instance()->AddIMMsg(IM_TargetConnConnect,
|
||||||
a8::XParams()
|
a8::XParams()
|
||||||
.SetSender(instance_id)
|
.SetSender(instance_id)
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ASYNC_TCPCLIENT && GAME_ID == 2002
|
#if ASYNC_TCPCLIENT && GAME_ID == 2002
|
||||||
@ -191,17 +198,19 @@ void TargetConn::on_disconnect(a8::TcpClient* sender)
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
recv_bufflen_ = 0;
|
recv_bufflen_ = 0;
|
||||||
a8::UdpLog::Instance()->Info("target server %d disconnected after 10s later reconnect "
|
f8::UdpLog::Instance()->Info("target server %d disconnected after 10s later reconnect "
|
||||||
"remote_ip:%s remote_port:%d",
|
"remote_ip:%s remote_port:%d",
|
||||||
{
|
{
|
||||||
instance_id,
|
instance_id,
|
||||||
sender->remote_address,
|
sender->remote_address,
|
||||||
sender->remote_port
|
sender->remote_port
|
||||||
});
|
});
|
||||||
|
#if 0
|
||||||
App::Instance()->AddIMMsg(IM_TargetConnDisconnect,
|
App::Instance()->AddIMMsg(IM_TargetConnDisconnect,
|
||||||
a8::XParams()
|
a8::XParams()
|
||||||
.SetSender(instance_id)
|
.SetSender(instance_id)
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ASYNC_TCPCLIENT && GAME_ID == 2002
|
#if ASYNC_TCPCLIENT && GAME_ID == 2002
|
||||||
@ -215,7 +224,7 @@ void TargetConn::on_socketread(a8::TcpClient* sender, char* buf, unsigned int le
|
|||||||
#endif
|
#endif
|
||||||
if (recv_bufflen_ + len > 2 * PACK_MAX) {
|
if (recv_bufflen_ + len > 2 * PACK_MAX) {
|
||||||
recv_bufflen_ = 0;
|
recv_bufflen_ = 0;
|
||||||
a8::UdpLog::Instance()->Debug("recvied target server too long message", {});
|
f8::UdpLog::Instance()->Debug("recvied target server too long message", {});
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
memmove(&recv_buff_[recv_bufflen_], buf, len);
|
memmove(&recv_buff_[recv_bufflen_], buf, len);
|
||||||
@ -247,7 +256,7 @@ void TargetConn::on_socketread(a8::TcpClient* sender, char* buf, unsigned int le
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (warning) {
|
if (warning) {
|
||||||
a8::UdpLog::Instance()->Debug("recvied bad package", {});
|
f8::UdpLog::Instance()->Debug("recvied bad package", {});
|
||||||
}
|
}
|
||||||
if (offset > 0 && offset < recv_bufflen_) {
|
if (offset > 0 && offset < recv_bufflen_) {
|
||||||
memmove(recv_buff_, recv_buff_ + offset, recv_bufflen_ - offset);
|
memmove(recv_buff_, recv_buff_ + offset, recv_bufflen_ - offset);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "framework/cpp/protoutils.h"
|
#include <f8/protoutils.h>
|
||||||
|
|
||||||
namespace a8
|
namespace a8
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <a8/singleton.h>
|
||||||
|
|
||||||
class TargetConn;
|
class TargetConn;
|
||||||
class TargetConnMgr : public a8::Singleton<TargetConnMgr>
|
class TargetConnMgr : public a8::Singleton<TargetConnMgr>
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user