From e6570ff2d38b71d20328d875d02237a3a908512d Mon Sep 17 00:00:00 2001 From: azw Date: Mon, 13 Nov 2023 06:31:18 +0000 Subject: [PATCH] 1 --- f8/app.cc | 4 +++- f8/app.h | 3 ++- f8/netmsghandler.h | 22 +++++++++++----------- f8/protoutils.h | 1 + 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/f8/app.cc b/f8/app.cc index 625ac02..3d377c4 100644 --- a/f8/app.cc +++ b/f8/app.cc @@ -236,7 +236,8 @@ namespace f8 unsigned short msgid, unsigned int seqid, const char *msgbody, - int bodylen) + int bodylen, + int tag) { char *p = (char*)malloc(sizeof(MsgHdr) + bodylen); MsgHdr* hdr = (MsgHdr*)p; @@ -250,6 +251,7 @@ namespace f8 hdr->offset = 0; hdr->hum = nullptr; hdr->user_data = nullptr; + hdr->tag = tag; if (bodylen > 0) { memmove((void*)hdr->buf, msgbody, bodylen); } diff --git a/f8/app.h b/f8/app.h index f2fc734..0f23829 100644 --- a/f8/app.h +++ b/f8/app.h @@ -55,7 +55,8 @@ namespace f8 unsigned short msgid, unsigned int seqid, const char *msgbody, - int bodylen); + int bodylen, + int tag); void FreeSocketMsg(MsgHdr* hdr); char** GetArgv() { return argv_; } int GetArgc() { return argc_; } diff --git a/f8/netmsghandler.h b/f8/netmsghandler.h index 474bfb7..3cf18cf 100644 --- a/f8/netmsghandler.h +++ b/f8/netmsghandler.h @@ -15,7 +15,7 @@ namespace f8 const unsigned short MAX_MSG_ID = 2000; struct MsgHdr; - typedef bool (*CUSTOM_PARSER)(MsgHdr&, google::protobuf::Message*); + typedef bool (*CUSTOM_PARSER)(MsgHdr*, google::protobuf::Message*); struct NetMsgHandler { @@ -45,21 +45,21 @@ namespace f8 }; template - static void NetMsgHandlerWrapper(InstanceType* instance, MsgHdr& hdr, NetMsgHandler* handler) + static void NetMsgHandlerWrapper(InstanceType* instance, MsgHdr* hdr, NetMsgHandler* handler) { MsgType msg; bool ok = false; if (handler->custom_parser) { ok = handler->custom_parser(hdr, &msg); } else { - ok = msg.ParseFromArray(hdr.buf + hdr.offset, hdr.buflen - hdr.offset); + ok = msg.ParseFromArray(hdr->buf + hdr->offset, hdr->buflen - hdr->offset); } assert(ok); if (ok) { struct Invoker: public NetMsgHandler { - void (*wrapper)(InstanceType*, MsgHdr&, NetMsgHandler*); - void (InstanceType::*func)(MsgHdr&, const MsgType&); + void (*wrapper)(InstanceType*, MsgHdr*, NetMsgHandler*); + void (InstanceType::*func)(MsgHdr*, const MsgType&); }; Invoker* invoker = (Invoker*)handler; auto ptr = invoker->func; @@ -69,7 +69,7 @@ namespace f8 template static void RegisterNetMsgHandler(NetMsgHandlerObject* msghandler, - void (InstanceType::*ptr)(MsgHdr&, const MsgType&), + void (InstanceType::*ptr)(MsgHdr*, const MsgType&), CUSTOM_PARSER custom_parser = nullptr ) { @@ -81,8 +81,8 @@ namespace f8 } struct Invoker: public NetMsgHandler { - void (*wrapper)(InstanceType*, MsgHdr&, NetMsgHandler*); - void (InstanceType::*func)(MsgHdr&, const MsgType&); + void (*wrapper)(InstanceType*, MsgHdr*, NetMsgHandler*); + void (InstanceType::*func)(MsgHdr*, const MsgType&); }; Invoker *p = new Invoker(); p->wrapper = &NetMsgHandlerWrapper; @@ -96,12 +96,12 @@ namespace f8 template static bool ProcessNetMsg(NetMsgHandler* handler, InstanceType* instance, - MsgHdr& hdr) + MsgHdr* hdr) { if(handler){ struct Invoker: public NetMsgHandler { - void (*wrapper)(InstanceType*, MsgHdr&, NetMsgHandler*); + void (*wrapper)(InstanceType*, MsgHdr*, NetMsgHandler*); void* func; }; Invoker *p = (Invoker*)handler; @@ -115,6 +115,6 @@ namespace f8 NetMsgHandler* GetNetMsgHandler(NetMsgHandlerObject* handlers, unsigned short msgid); - void DumpMsgToLog(f8::MsgHdr& hdr, f8::NetMsgHandler* handler, const char* prefix); + void DumpMsgToLog(f8::MsgHdr* hdr, f8::NetMsgHandler* handler, const char* prefix); void DumpMsgToLog(const ::google::protobuf::Message& msg, const char* prefix); } diff --git a/f8/protoutils.h b/f8/protoutils.h index 99ec287..89c613b 100644 --- a/f8/protoutils.h +++ b/f8/protoutils.h @@ -23,6 +23,7 @@ namespace f8 int offset; Player *hum = nullptr; const void* user_data = nullptr; + int tag; list_head entry; MsgHdr* Clone();