1
This commit is contained in:
parent
c33414a82d
commit
0bed23cde9
@ -57,21 +57,30 @@ public:
|
||||
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,
|
||||
url,
|
||||
querystr,
|
||||
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,
|
||||
1
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
};
|
||||
@ -85,10 +94,14 @@ static void CreateGameClientSocket(a8::TcpSession **p)
|
||||
static void GSListeneron_error(a8::TcpListener*, int type, int errorid)
|
||||
{
|
||||
f8::UdpLog::Instance()->Debug("GGListeneron_error %d %d", {type, errorid});
|
||||
f8::MsgQueue::Instance()->PostMsg_r(IM_GGListenerError,
|
||||
a8::XParams()
|
||||
.SetParam1(errorid)
|
||||
);
|
||||
f8::MsgQueue::Instance()->PostMsg
|
||||
(IM_GGListenerError,
|
||||
a8::Args
|
||||
(
|
||||
{
|
||||
errorid
|
||||
}
|
||||
));
|
||||
abort();
|
||||
}
|
||||
|
||||
@ -102,11 +115,15 @@ void GGListener::Init()
|
||||
tcp_listener_->bind_port = JsonDataMgr::Instance()->GetConf()->At("listen_port")->AsXValue();
|
||||
tcp_listener_->Open();
|
||||
|
||||
f8::MsgQueue::Instance()->RegisterCallBack(IM_GGListenerError,
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
GGListener::Instance()->OnListenError(param.param1);
|
||||
});
|
||||
f8::MsgQueue::Instance()->RegisterCallBack
|
||||
(IM_GGListenerError,
|
||||
[] (const a8::Args& args)
|
||||
{
|
||||
// 777
|
||||
#if 0
|
||||
GGListener::Instance()->OnListenError(param.param1);
|
||||
#endif
|
||||
});
|
||||
}
|
||||
|
||||
void GGListener::UnInit()
|
||||
|
@ -54,14 +54,6 @@ 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";
|
||||
|
||||
@ -217,7 +209,6 @@ bool App::Init(int argc, char* argv[])
|
||||
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();
|
||||
@ -301,8 +292,6 @@ void App::UnInit()
|
||||
UnInitLog();
|
||||
|
||||
FreeSocketMsgQueue();
|
||||
FreeIMMsgQueue();
|
||||
A8_SAFE_DELETE(im_msg_mutex_);
|
||||
A8_SAFE_DELETE(msg_mutex_);
|
||||
A8_SAFE_DELETE(loop_cond_);
|
||||
A8_SAFE_DELETE(loop_mutex_);
|
||||
@ -363,27 +352,9 @@ 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(int delta_time)
|
||||
{
|
||||
ProcessIMMsg();
|
||||
f8::MsgQueue::Instance()->Update();
|
||||
DispatchMsg();
|
||||
RoomMgr::Instance()->Update(delta_time);
|
||||
a8::Timer::Instance()->Update();
|
||||
@ -407,20 +378,6 @@ void App::Schedule()
|
||||
|
||||
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();
|
||||
@ -525,47 +482,6 @@ void App::ProcessGameGateMsg(f8::MsgHdr& hdr)
|
||||
}
|
||||
}
|
||||
|
||||
void App::ProcessIMMsg()
|
||||
{
|
||||
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:
|
||||
{
|
||||
PlayerMgr::Instance()->OnClientDisconnect(pdelnode->params);
|
||||
}
|
||||
break;
|
||||
case IM_ExecGM:
|
||||
{
|
||||
HandlerMgr::Instance()->ProcGMMsg(pdelnode->params.param3,
|
||||
pdelnode->params.sender,
|
||||
pdelnode->params.param1.GetString(),
|
||||
pdelnode->params.param2.GetString()
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
im_work_node_ = im_work_node_->next;
|
||||
delete pdelnode;
|
||||
}
|
||||
}
|
||||
|
||||
void App::InitLog()
|
||||
{
|
||||
std::string filename_fmt = PROJ_LOG_FILENAME_FMT;
|
||||
@ -686,31 +602,6 @@ 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();
|
||||
}
|
||||
|
||||
long long App::AllocTempHeroUniId()
|
||||
{
|
||||
if (curr_uniid_ < 1000) {
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <f8/protoutils.h>
|
||||
|
||||
struct MsgNode;
|
||||
struct IMMsgNode;
|
||||
class App : public a8::Singleton<App>
|
||||
{
|
||||
private:
|
||||
@ -30,7 +29,6 @@ public:
|
||||
unsigned int seqid,
|
||||
const char *msgbody,
|
||||
int bodylen);
|
||||
void AddIMMsg(unsigned short imcmd, a8::XParams params);
|
||||
|
||||
void NotifyLoopCond();
|
||||
|
||||
@ -51,7 +49,6 @@ private:
|
||||
bool HasTask();
|
||||
|
||||
void DispatchMsg();
|
||||
void ProcessIMMsg();
|
||||
|
||||
void ProcessGameGateMsg(f8::MsgHdr& hdr);
|
||||
|
||||
@ -60,7 +57,6 @@ private:
|
||||
|
||||
bool ParseOpt();
|
||||
void FreeSocketMsgQueue();
|
||||
void FreeIMMsgQueue();
|
||||
|
||||
public:
|
||||
int argc = 0;
|
||||
@ -98,11 +94,6 @@ private:
|
||||
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_;
|
||||
|
||||
long long curr_uniid_ = 0;
|
||||
|
2
third_party/f8
vendored
2
third_party/f8
vendored
@ -1 +1 @@
|
||||
Subproject commit 5d7153a5e5404f6cd428fe5644d0c6e046611ab5
|
||||
Subproject commit db10c37c68a30f1e9d6cbddafa8721e4bccb9676
|
Loading…
x
Reference in New Issue
Block a user