1
This commit is contained in:
parent
273b13b018
commit
3f79474667
@ -28,6 +28,7 @@ endif()
|
||||
include_directories(
|
||||
AFTER
|
||||
../../third_party/a8
|
||||
../../third_party/f8
|
||||
/usr/include/mysql
|
||||
/usr/include/jsoncpp
|
||||
/usr/include/hiredis
|
||||
@ -87,43 +88,22 @@ add_custom_command(TARGET script_pb_protocol
|
||||
)
|
||||
add_dependencies(wsproxy${GAME_ID} script_pb_protocol)
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
target_link_libraries(
|
||||
wsproxy${GAME_ID}
|
||||
pthread
|
||||
mysqlclient
|
||||
protobuf
|
||||
rt
|
||||
dl
|
||||
util
|
||||
crypto
|
||||
ssl
|
||||
jsoncpp
|
||||
curl
|
||||
hiredis
|
||||
tinyxml2
|
||||
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()
|
||||
target_link_libraries(
|
||||
wsproxy${GAME_ID}
|
||||
pthread
|
||||
mysqlclient
|
||||
protobuf
|
||||
rt
|
||||
dl
|
||||
util
|
||||
crypto
|
||||
ssl
|
||||
jsoncpp
|
||||
curl
|
||||
hiredis
|
||||
tinyxml2
|
||||
tcmalloc
|
||||
)
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
target_link_libraries(
|
||||
|
@ -4,7 +4,8 @@
|
||||
#include <a8/websocketsession.h>
|
||||
#include <a8/tcplistener.h>
|
||||
|
||||
#include "framework/cpp/netmsghandler.h"
|
||||
#include <f8/netmsghandler.h>
|
||||
#include <f8/udplog.h>
|
||||
|
||||
#include "app.h"
|
||||
#include "GCListener.h"
|
||||
@ -43,19 +44,21 @@ 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
|
||||
{
|
||||
#if 0
|
||||
App::Instance()->AddIMMsg(IM_ExecGM,
|
||||
a8::XParams()
|
||||
.SetSender(socket_handle)
|
||||
.SetParam1(url)
|
||||
.SetParam2(querystr)
|
||||
.SetParam3(saddr));
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual bool HandleRedirect(const std::string& url, const std::string& querystr,
|
||||
@ -90,10 +93,12 @@ public:
|
||||
|
||||
virtual void OnDisConnect() override
|
||||
{
|
||||
#if 0
|
||||
App::Instance()->AddIMMsg(IM_ClientSocketDisconnect,
|
||||
a8::XParams()
|
||||
.SetSender(socket_handle)
|
||||
.SetParam1(1));
|
||||
#endif
|
||||
}
|
||||
|
||||
};
|
||||
@ -105,7 +110,7 @@ static void CreateGameClientSocket(a8::TcpSession **p)
|
||||
|
||||
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()
|
||||
|
@ -6,12 +6,11 @@
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
#include <a8/redis.h>
|
||||
#include <a8/timer.h>
|
||||
#include <a8/xtimer.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 "GCListener.h"
|
||||
@ -41,20 +40,12 @@ struct MsgNode
|
||||
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_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 "
|
||||
"max_join_time:%d",
|
||||
{
|
||||
@ -127,25 +118,21 @@ bool App::Init(int argc, char* argv[])
|
||||
#endif
|
||||
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,
|
||||
instance_id,
|
||||
getpid(),
|
||||
MASTER_MODE,
|
||||
ASYNC_TCPCLIENT
|
||||
getpid()
|
||||
});
|
||||
|
||||
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();
|
||||
HandlerMgr::Instance()->Init();
|
||||
a8::Timer::Instance()->Init();
|
||||
a8::IoLoop::Instance()->Init(1);
|
||||
f8::Timer::Instance()->Init();
|
||||
JsonDataMgr::Instance()->Init();
|
||||
#if MASTER_MODE
|
||||
uuid.SetMachineId((node_id - 1) * MAX_NODE_ID + instance_id);
|
||||
@ -159,26 +146,28 @@ bool App::Init(int argc, char* argv[])
|
||||
TargetConnMgr::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,
|
||||
getpid(),
|
||||
ASYNC_TCPCLIENT
|
||||
});
|
||||
{
|
||||
int perf_log_time = 1000 * 60 * 5;
|
||||
if (getenv("is_dev_env")) {
|
||||
perf_log_time = 1000 * 10;
|
||||
}
|
||||
a8::Timer::Instance()->AddRepeatTimer(perf_log_time,
|
||||
#if 0
|
||||
f8::Timer::Instance()->AddRepeatTimer(perf_log_time,
|
||||
a8::XParams(),
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
SavePerfLog();
|
||||
});
|
||||
#endif
|
||||
}
|
||||
if (HasFlag(1)) {
|
||||
a8::Timer::Instance()->AddDeadLineTimer(
|
||||
#if 0
|
||||
f8::Timer::Instance()->AddDeadLineTimer(
|
||||
1000 * 60,
|
||||
a8::XParams(),
|
||||
[] (const a8::XParams& param)
|
||||
@ -187,8 +176,10 @@ bool App::Init(int argc, char* argv[])
|
||||
App::Instance()->NotifyLoopCond();
|
||||
}
|
||||
);
|
||||
#endif
|
||||
}
|
||||
if (HasFlag(4)) {
|
||||
#if 0
|
||||
a8::Timer::Instance()->AddDeadLineTimer(
|
||||
1000 * 30,
|
||||
a8::XParams(),
|
||||
@ -198,6 +189,7 @@ bool App::Init(int argc, char* argv[])
|
||||
a8::XPrintf("shutdowned\n", {});
|
||||
}
|
||||
);
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -212,15 +204,11 @@ void App::UnInit()
|
||||
TargetConnMgr::Instance()->UnInit();
|
||||
GameClientMgr::Instance()->UnInit();
|
||||
JsonDataMgr::Instance()->UnInit();
|
||||
a8::IoLoop::Instance()->UnInit();
|
||||
a8::Timer::Instance()->UnInit();
|
||||
f8::Timer::Instance()->UnInit();
|
||||
HandlerMgr::Instance()->UnInit();
|
||||
UnInitLog();
|
||||
|
||||
FreeSocketMsgQueue();
|
||||
FreeIMMsgQueue();
|
||||
delete im_msg_mutex_;
|
||||
im_msg_mutex_ = nullptr;
|
||||
delete msg_mutex_;
|
||||
msg_mutex_ = nullptr;
|
||||
delete loop_cond_;
|
||||
@ -233,7 +221,7 @@ void App::UnInit()
|
||||
int App::Run()
|
||||
{
|
||||
int ret = 0;
|
||||
a8::UdpLog::Instance()->Info("wsproxy running", {});
|
||||
f8::UdpLog::Instance()->Info("wsproxy running", {});
|
||||
while (!terminated) {
|
||||
a8::tick_t begin_tick = a8::XGetTickCount();
|
||||
QuickExecute();
|
||||
@ -281,29 +269,10 @@ void App::AddSocketMsg(SocketFrom_e sockfrom,
|
||||
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()
|
||||
{
|
||||
ProcessIMMsg();
|
||||
DispatchMsg();
|
||||
a8::Timer::Instance()->Update();
|
||||
f8::Timer::Instance()->Update();
|
||||
}
|
||||
|
||||
void App::SlowerExecute()
|
||||
@ -320,30 +289,18 @@ void App::Schedule()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(*loop_mutex_);
|
||||
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));
|
||||
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();
|
||||
@ -473,7 +430,7 @@ void App::ProcessClientMsg(f8::MsgHdr& hdr)
|
||||
}
|
||||
#else
|
||||
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;
|
||||
bool ok = msg.ParseFromArray(hdr.buf + hdr.offset, hdr.buflen - hdr.offset);
|
||||
if (ok) {
|
||||
@ -529,6 +486,7 @@ void App::ProcessTargetServerMsg(f8::MsgHdr& hdr)
|
||||
GCListener::Instance()->ForwardTargetConnMsg(hdr);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void App::ProcessIMMsg()
|
||||
{
|
||||
if (!im_work_node_ && im_top_node_) {
|
||||
@ -577,6 +535,7 @@ void App::ProcessIMMsg()
|
||||
delete pdelnode;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void App::InitLog()
|
||||
{
|
||||
@ -590,16 +549,16 @@ void App::InitLog()
|
||||
|
||||
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});
|
||||
f8::UdpLog::Instance()->SetLogFileName(log_file_name);
|
||||
f8::UdpLog::Instance()->Init();
|
||||
f8::UdpLog::Instance()->Info("proj_root_dir:%s", {proj_root_dir});
|
||||
f8::UdpLog::Instance()->Info("proj_log_root_dir:%s", {proj_log_root_dir});
|
||||
f8::UdpLog::Instance()->Info("log_file_name:%s", {log_file_name});
|
||||
}
|
||||
|
||||
void App::UnInitLog()
|
||||
{
|
||||
a8::UdpLog::Instance()->UnInit();
|
||||
f8::UdpLog::Instance()->UnInit();
|
||||
}
|
||||
|
||||
bool App::ParseOpt()
|
||||
@ -635,23 +594,6 @@ bool App::ParseOpt()
|
||||
#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)
|
||||
{
|
||||
return flags.find(flag) != flags.end();
|
||||
@ -680,28 +622,3 @@ void App::FreeSocketMsgQueue()
|
||||
}
|
||||
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
|
||||
|
||||
#include <a8/uuid.h>
|
||||
#include <a8/singleton.h>
|
||||
|
||||
struct MsgNode;
|
||||
struct IMMsgNode;
|
||||
class App : public a8::Singleton<App>
|
||||
{
|
||||
private:
|
||||
@ -24,13 +24,8 @@ class App : public a8::Singleton<App>
|
||||
unsigned int seqid,
|
||||
const char *msgbody,
|
||||
int bodylen);
|
||||
void AddIMMsg(unsigned short imcmd, a8::XParams params);
|
||||
|
||||
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);
|
||||
|
||||
private:
|
||||
@ -40,7 +35,6 @@ private:
|
||||
bool HasTask();
|
||||
|
||||
void DispatchMsg();
|
||||
void ProcessIMMsg();
|
||||
|
||||
void ProcessClientMsg(f8::MsgHdr& hdr);
|
||||
void ProcessMasterServerMsg(f8::MsgHdr& hdr);
|
||||
@ -51,7 +45,6 @@ private:
|
||||
|
||||
bool ParseOpt();
|
||||
void FreeSocketMsgQueue();
|
||||
void FreeIMMsgQueue();
|
||||
|
||||
public:
|
||||
int argc = 0;
|
||||
@ -75,13 +68,6 @@ public:
|
||||
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::map<long long, a8::XParams> context_hash_;
|
||||
|
||||
public:
|
||||
int msgnode_size_ = 0 ;
|
||||
int working_msgnode_size_ = 0;
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <f8/udplog.h>
|
||||
|
||||
#include "gameclientmgr.h"
|
||||
#include "ss_proto.pb.h"
|
||||
|
||||
@ -19,9 +21,12 @@ void GameClientMgr::UnInit()
|
||||
delete pair.second;
|
||||
}
|
||||
socket_hash_.clear();
|
||||
#if 0
|
||||
pending_account_hash_.clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
void GameClientMgr::OnClientDisconnect(a8::XParams& param)
|
||||
{
|
||||
GameClient* client = GetGameClientBySocket(param.sender);
|
||||
@ -35,7 +40,9 @@ void GameClientMgr::OnClientDisconnect(a8::XParams& param)
|
||||
}
|
||||
RemovePendingAccount(param.sender);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
void GameClientMgr::OnTargetServerDisconnect(a8::XParams& param)
|
||||
{
|
||||
std::list<GameClient*> delete_client;
|
||||
@ -51,11 +58,14 @@ void GameClientMgr::OnTargetServerDisconnect(a8::XParams& param)
|
||||
delete client;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
void GameClientMgr::OnTargetServerConnect(a8::XParams& param)
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
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->conn = conn;
|
||||
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);
|
||||
if (itr != pending_account_hash_.end()) {
|
||||
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;
|
||||
}
|
||||
if (account_id == azw_account_id) {
|
||||
a8::UdpLog::Instance()->Info("%s join time:%d",
|
||||
f8::UdpLog::Instance()->Info("%s join time:%d",
|
||||
{
|
||||
account_id,
|
||||
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);
|
||||
}
|
||||
#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)
|
||||
{
|
||||
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);
|
||||
if (itr == pending_account_hash_.end()){
|
||||
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);
|
||||
},
|
||||
&timer_attacher_.timer_list_
|
||||
|
||||
);
|
||||
pending_account_hash_[socket_handle] = std::make_tuple(
|
||||
account_id,
|
||||
@ -121,14 +135,19 @@ void GameClientMgr::AddPendingAccount(const std::string& account_id, int socket_
|
||||
timer
|
||||
);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <a8/timer.h>
|
||||
#include <f8/timer.h>
|
||||
|
||||
class GameClient;
|
||||
class GameClientMgr : public a8::Singleton<GameClientMgr>
|
||||
@ -14,9 +14,11 @@ class GameClientMgr : public a8::Singleton<GameClientMgr>
|
||||
void Init();
|
||||
void UnInit();
|
||||
|
||||
#if 0
|
||||
void OnClientDisconnect(a8::XParams& param);
|
||||
void OnTargetServerDisconnect(a8::XParams& param);
|
||||
void OnTargetServerConnect(a8::XParams& param);
|
||||
#endif
|
||||
GameClient* GetGameClientBySocket(int sockhande);
|
||||
void BindTargetConn(int socket_handle, int conn_instance_id);
|
||||
void AddPendingAccount(const std::string& account_id, int socket_handle, long long req_tick);
|
||||
@ -26,7 +28,9 @@ private:
|
||||
void RemovePendingAccount(int socket_handle);
|
||||
|
||||
private:
|
||||
a8::TimerAttacher timer_attacher_;
|
||||
a8::Attacher timer_attacher_;
|
||||
std::map<int, GameClient*> socket_hash_;
|
||||
#if 0
|
||||
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)
|
||||
{
|
||||
#if 0
|
||||
request->resp_xobj->SetVal("errcode", 0);
|
||||
request->resp_xobj->SetVal("errmsg", "");
|
||||
request->resp_xobj->SetVal("healthy", 1);
|
||||
request->resp_xobj->SetVal("max_rundelay", 10);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void _GMOpsGetNodeId(f8::JsonHttpRequest* request)
|
||||
{
|
||||
#if 0
|
||||
request->resp_xobj->SetVal("errcode", 0);
|
||||
request->resp_xobj->SetVal("errmsg", "");
|
||||
request->resp_xobj->SetVal("node_id", App::Instance()->node_id);
|
||||
#endif
|
||||
}
|
||||
|
||||
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();
|
||||
auto itr = gmhandlers_.find(msgname);
|
||||
if (itr != gmhandlers_.end()) {
|
||||
#if 0
|
||||
f8::JsonHttpRequest* request = new f8::JsonHttpRequest;
|
||||
request->saddr = saddr;
|
||||
request->socket_handle = sockhandle;
|
||||
@ -69,6 +74,7 @@ void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle,
|
||||
|
||||
delete request;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
GCListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}"));
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <a8/basehttpsession.h>
|
||||
|
||||
#include "framework/cpp/netmsghandler.h"
|
||||
#include <f8/netmsghandler.h>
|
||||
|
||||
namespace a8
|
||||
{
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include <f8/utils.h>
|
||||
|
||||
#include "jsondatamgr.h"
|
||||
#include "app.h"
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <a8/singleton.h>
|
||||
|
||||
class JsonDataMgr : public a8::Singleton<JsonDataMgr>
|
||||
{
|
||||
private:
|
||||
|
@ -2,14 +2,15 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <a8/tcpclient.h>
|
||||
|
||||
#include <f8/udplog.h>
|
||||
#include <f8/timer.h>
|
||||
|
||||
#include "ss_proto.pb.h"
|
||||
#include "ss_msgid.pb.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"
|
||||
|
||||
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_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);
|
||||
#if 0
|
||||
timer_ = a8::Timer::Instance()->AddRepeatTimer(1000 * 9 + a8::RandEx(500, 150),
|
||||
a8::XParams().SetSender(this),
|
||||
[] (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();
|
||||
conn->CheckAlive();
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
void MasterSvr::UnInit()
|
||||
{
|
||||
#if 0
|
||||
a8::Timer::Instance()->DeleteTimer(timer_);
|
||||
timer_ = nullptr;
|
||||
#endif
|
||||
tcp_client_->Close();
|
||||
#if ASYNC_TCPCLIENT
|
||||
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)
|
||||
#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,
|
||||
sender->remote_address,
|
||||
@ -95,7 +100,7 @@ void MasterSvr::on_connect(a8::TcpClient* sender)
|
||||
#endif
|
||||
{
|
||||
recv_bufflen_ = 0;
|
||||
a8::UdpLog::Instance()->Info("masterserver connected", {});
|
||||
f8::UdpLog::Instance()->Info("masterserver connected", {});
|
||||
}
|
||||
|
||||
#if ASYNC_TCPCLIENT
|
||||
@ -105,11 +110,13 @@ void MasterSvr::on_disconnect(a8::TcpClient* sender)
|
||||
#endif
|
||||
{
|
||||
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,
|
||||
a8::XParams()
|
||||
.SetSender(instance_id)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ASYNC_TCPCLIENT
|
||||
@ -123,7 +130,7 @@ void MasterSvr::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len
|
||||
#endif
|
||||
if (recv_bufflen_ + len > 2 * PACK_MAX) {
|
||||
recv_bufflen_ = 0;
|
||||
a8::UdpLog::Instance()->Debug("recvied masterserver too long message", {});
|
||||
f8::UdpLog::Instance()->Debug("recvied masterserver too long message", {});
|
||||
return;
|
||||
} else {
|
||||
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) {
|
||||
a8::UdpLog::Instance()->Debug("recvied bad package", {});
|
||||
f8::UdpLog::Instance()->Debug("recvied bad package", {});
|
||||
}
|
||||
if (offset > 0 && offset < recv_bufflen_) {
|
||||
memmove(recv_buff_, recv_buff_ + offset, recv_bufflen_ - offset);
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "framework/cpp/protoutils.h"
|
||||
#include <f8/protoutils.h>
|
||||
|
||||
namespace a8
|
||||
{
|
||||
|
@ -3,7 +3,9 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <a8/openssl.h>
|
||||
#include <a8/timer.h>
|
||||
|
||||
#include <f8/timer.h>
|
||||
#include <f8/netmsghandler.h>
|
||||
|
||||
#include "mastersvrmgr.h"
|
||||
#include "mastersvr.h"
|
||||
@ -14,8 +16,6 @@
|
||||
#include "app.h"
|
||||
#include "gameclientmgr.h"
|
||||
|
||||
#include "framework/cpp/netmsghandler.h"
|
||||
|
||||
void MasterSvrMgr::Init()
|
||||
{
|
||||
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);
|
||||
if (svr) {
|
||||
++curr_context_id_;
|
||||
#if 0
|
||||
a8::TimerAttacher* timer_attacher = new a8::TimerAttacher();
|
||||
f8::MsgHdr* new_hdr = hdr.Clone();
|
||||
new_hdr->user_data = timer_attacher;
|
||||
@ -174,11 +175,13 @@ void MasterSvrMgr::RequestTargetServer(f8::MsgHdr& hdr,
|
||||
&timer_attacher->timer_list_,
|
||||
timer_after_func
|
||||
);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void MasterSvrMgr::RemoveRequest(int socket_handle, long long context_id, bool auto_free)
|
||||
{
|
||||
#if 0
|
||||
if (context_id == GetContextIdBySocket(socket_handle)) {
|
||||
f8::MsgHdr* hdr = GetHdrByContextId(context_id);
|
||||
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_socket_hash_.erase(socket_handle);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
long long MasterSvrMgr::GetContextIdBySocket(int socket_handle)
|
||||
|
@ -1,20 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <a8/a8.h>
|
||||
#include <a8/udplog.h>
|
||||
#include <f8/f8.h>
|
||||
|
||||
#include "constant.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 <a8/tcpclient.h>
|
||||
|
||||
#include <f8/udplog.h>
|
||||
#include <f8/timer.h>
|
||||
|
||||
#include "ss_proto.pb.h"
|
||||
#include "ss_msgid.pb.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"
|
||||
|
||||
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_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);
|
||||
#if 0
|
||||
timer_ = a8::Timer::Instance()->AddRepeatTimer(1000 * 9 + a8::RandEx(500, 150),
|
||||
a8::XParams().SetSender(this),
|
||||
[] (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();
|
||||
conn->CheckAlive();
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
void TargetConn::UnInit()
|
||||
@ -59,8 +62,10 @@ void TargetConn::UnInit()
|
||||
delete pdelnode;
|
||||
}
|
||||
|
||||
a8::Timer::Instance()->DeleteTimer(timer_);
|
||||
#if 0
|
||||
f8::Timer::Instance()->DeleteTimer(timer_);
|
||||
timer_ = nullptr;
|
||||
#endif
|
||||
tcp_client_->Close();
|
||||
#if ASYNC_TCPCLIENT && GAME_ID == 2002
|
||||
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)
|
||||
#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,
|
||||
sender->remote_address,
|
||||
@ -173,15 +178,17 @@ void TargetConn::on_connect(a8::TcpClient* sender)
|
||||
#endif
|
||||
{
|
||||
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_port
|
||||
});
|
||||
#if 0
|
||||
App::Instance()->AddIMMsg(IM_TargetConnConnect,
|
||||
a8::XParams()
|
||||
.SetSender(instance_id)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ASYNC_TCPCLIENT && GAME_ID == 2002
|
||||
@ -191,17 +198,19 @@ void TargetConn::on_disconnect(a8::TcpClient* sender)
|
||||
#endif
|
||||
{
|
||||
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",
|
||||
{
|
||||
instance_id,
|
||||
sender->remote_address,
|
||||
sender->remote_port
|
||||
});
|
||||
#if 0
|
||||
App::Instance()->AddIMMsg(IM_TargetConnDisconnect,
|
||||
a8::XParams()
|
||||
.SetSender(instance_id)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ASYNC_TCPCLIENT && GAME_ID == 2002
|
||||
@ -215,7 +224,7 @@ void TargetConn::on_socketread(a8::TcpClient* sender, char* buf, unsigned int le
|
||||
#endif
|
||||
if (recv_bufflen_ + len > 2 * PACK_MAX) {
|
||||
recv_bufflen_ = 0;
|
||||
a8::UdpLog::Instance()->Debug("recvied target server too long message", {});
|
||||
f8::UdpLog::Instance()->Debug("recvied target server too long message", {});
|
||||
return;
|
||||
} else {
|
||||
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) {
|
||||
a8::UdpLog::Instance()->Debug("recvied bad package", {});
|
||||
f8::UdpLog::Instance()->Debug("recvied bad package", {});
|
||||
}
|
||||
if (offset > 0 && offset < recv_bufflen_) {
|
||||
memmove(recv_buff_, recv_buff_ + offset, recv_bufflen_ - offset);
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "framework/cpp/protoutils.h"
|
||||
#include <f8/protoutils.h>
|
||||
|
||||
namespace a8
|
||||
{
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <a8/singleton.h>
|
||||
|
||||
class TargetConn;
|
||||
class TargetConnMgr : public a8::Singleton<TargetConnMgr>
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user