feat(网络): 重构网关socket连接与消息处理逻辑
- 重构Client类,使用事件队列管理连接和消息事件 - 增加消息队列大小限制和错误处理 - 优化数据包处理流程,减少内存拷贝 - 添加nullptr检查防止空指针访问 - 更新版本号至1.4 - 新增TimerQueue_GetTimerMess函数声明和hook
This commit is contained in:
@@ -16,6 +16,7 @@ SUBHOOK_INIT(doDispatch, 0x08594922);
|
||||
SUBHOOK_INIT(Inter_LoadGeolocation_dispatch_sig, 0x0816088A);
|
||||
SUBHOOK_INIT(History_Log, 0x854F990);
|
||||
SUBHOOK_INIT(Neof_startupGlobalInstances, 0x0829F7C5);
|
||||
SUBHOOK_INIT(TimerQueue_GetTimerMess, 0x08630ECC);
|
||||
|
||||
int checkGame(const char *pName) {
|
||||
char path[256];
|
||||
@@ -308,15 +309,6 @@ int _Inter_LoadGeolocation_dispatch_sig(void *pThis, void *pUser, char *a3) {
|
||||
}
|
||||
sq_settop(v, top); // restores the original stack size
|
||||
|
||||
sq_pushroottable(v); // pushes the global table
|
||||
sq_pushstring(v, _SC("main"), -1);
|
||||
if (SQ_SUCCEEDED(
|
||||
sq_get(v, -2))) { // gets the field 'foo' from the global table
|
||||
sq_pushroottable(v); // push the 'this' (in this case is the global table)
|
||||
sq_call(v, 1, SQFalse, SQTrue); // calls the function
|
||||
}
|
||||
sq_settop(v, top); // restores the original stack size
|
||||
|
||||
int Ret = Inter_LoadGeolocation_dispatch_sig(pThis, pUser, a3);
|
||||
|
||||
return Ret;
|
||||
@@ -366,6 +358,12 @@ int _Neof_startupGlobalInstances() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int _TimerQueue_GetTimerMess(void *thisC, void *timerEntry) {
|
||||
int ret = TimerQueue_GetTimerMess(thisC, timerEntry);
|
||||
l_socket::getInstance().Logic();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Lenheart() {
|
||||
// 主程序才加载插件
|
||||
if (!checkGame("df_game_r")) {
|
||||
@@ -374,7 +372,8 @@ void Lenheart() {
|
||||
SUBHOOK_SETUP(Inter_LoadGeolocation_dispatch_sig);
|
||||
SUBHOOK_SETUP(History_Log);
|
||||
|
||||
SUBHOOK_SETUP(doDispatch); // 收包注册
|
||||
SUBHOOK_SETUP(doDispatch);
|
||||
SUBHOOK_SETUP(TimerQueue_GetTimerMess); // 收包注册
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,6 +110,8 @@ typedef void (*fnCUserWorkPerFiveMin)(void *CUser);
|
||||
// 线程执行
|
||||
typedef int (*fnTimerDispatcher_dispatch)(void *A, void *B);
|
||||
|
||||
typedef int (*fnTimerQueue_GetTimerMess)(void *thisC, void *timerEntry);
|
||||
|
||||
// 线程执行
|
||||
typedef void *(*fnSetUserMaxLevel)(void *CUser, int level);
|
||||
|
||||
@@ -121,4 +123,4 @@ typedef int (*fncusermake_basic_info)(void *a1, void *a2, char a3);
|
||||
|
||||
typedef int (*fnNeof_startupGlobalInstances)();
|
||||
|
||||
__END_DECLS
|
||||
__END_DECLS
|
||||
|
||||
@@ -64,7 +64,7 @@ void l_socket::IntToByteLittle(unsigned char *b, int Count)
|
||||
|
||||
void l_socket::Send(const SQChar *Pck)
|
||||
{
|
||||
if (ClientObj->ConnectState == false)
|
||||
if (ClientObj == nullptr || ClientObj->ConnectState == false)
|
||||
return;
|
||||
int Length = strlen(Pck);
|
||||
unsigned char *PckData = new unsigned char[Length + 4];
|
||||
@@ -76,7 +76,7 @@ void l_socket::Send(const SQChar *Pck)
|
||||
|
||||
void l_socket::Logic()
|
||||
{
|
||||
if (ClientObj->ConnectState == false)
|
||||
if (ClientObj == nullptr)
|
||||
return;
|
||||
ClientObj->PackLogic();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user