1
This commit is contained in:
parent
1c141d8817
commit
e6570ff2d3
@ -236,7 +236,8 @@ namespace f8
|
|||||||
unsigned short msgid,
|
unsigned short msgid,
|
||||||
unsigned int seqid,
|
unsigned int seqid,
|
||||||
const char *msgbody,
|
const char *msgbody,
|
||||||
int bodylen)
|
int bodylen,
|
||||||
|
int tag)
|
||||||
{
|
{
|
||||||
char *p = (char*)malloc(sizeof(MsgHdr) + bodylen);
|
char *p = (char*)malloc(sizeof(MsgHdr) + bodylen);
|
||||||
MsgHdr* hdr = (MsgHdr*)p;
|
MsgHdr* hdr = (MsgHdr*)p;
|
||||||
@ -250,6 +251,7 @@ namespace f8
|
|||||||
hdr->offset = 0;
|
hdr->offset = 0;
|
||||||
hdr->hum = nullptr;
|
hdr->hum = nullptr;
|
||||||
hdr->user_data = nullptr;
|
hdr->user_data = nullptr;
|
||||||
|
hdr->tag = tag;
|
||||||
if (bodylen > 0) {
|
if (bodylen > 0) {
|
||||||
memmove((void*)hdr->buf, msgbody, bodylen);
|
memmove((void*)hdr->buf, msgbody, bodylen);
|
||||||
}
|
}
|
||||||
|
3
f8/app.h
3
f8/app.h
@ -55,7 +55,8 @@ namespace f8
|
|||||||
unsigned short msgid,
|
unsigned short msgid,
|
||||||
unsigned int seqid,
|
unsigned int seqid,
|
||||||
const char *msgbody,
|
const char *msgbody,
|
||||||
int bodylen);
|
int bodylen,
|
||||||
|
int tag);
|
||||||
void FreeSocketMsg(MsgHdr* hdr);
|
void FreeSocketMsg(MsgHdr* hdr);
|
||||||
char** GetArgv() { return argv_; }
|
char** GetArgv() { return argv_; }
|
||||||
int GetArgc() { return argc_; }
|
int GetArgc() { return argc_; }
|
||||||
|
@ -15,7 +15,7 @@ namespace f8
|
|||||||
const unsigned short MAX_MSG_ID = 2000;
|
const unsigned short MAX_MSG_ID = 2000;
|
||||||
|
|
||||||
struct MsgHdr;
|
struct MsgHdr;
|
||||||
typedef bool (*CUSTOM_PARSER)(MsgHdr&, google::protobuf::Message*);
|
typedef bool (*CUSTOM_PARSER)(MsgHdr*, google::protobuf::Message*);
|
||||||
|
|
||||||
struct NetMsgHandler
|
struct NetMsgHandler
|
||||||
{
|
{
|
||||||
@ -45,21 +45,21 @@ namespace f8
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename InstanceType, typename MsgType>
|
template<typename InstanceType, typename MsgType>
|
||||||
static void NetMsgHandlerWrapper(InstanceType* instance, MsgHdr& hdr, NetMsgHandler* handler)
|
static void NetMsgHandlerWrapper(InstanceType* instance, MsgHdr* hdr, NetMsgHandler* handler)
|
||||||
{
|
{
|
||||||
MsgType msg;
|
MsgType msg;
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
if (handler->custom_parser) {
|
if (handler->custom_parser) {
|
||||||
ok = handler->custom_parser(hdr, &msg);
|
ok = handler->custom_parser(hdr, &msg);
|
||||||
} else {
|
} 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);
|
assert(ok);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
struct Invoker: public NetMsgHandler
|
struct Invoker: public NetMsgHandler
|
||||||
{
|
{
|
||||||
void (*wrapper)(InstanceType*, MsgHdr&, NetMsgHandler*);
|
void (*wrapper)(InstanceType*, MsgHdr*, NetMsgHandler*);
|
||||||
void (InstanceType::*func)(MsgHdr&, const MsgType&);
|
void (InstanceType::*func)(MsgHdr*, const MsgType&);
|
||||||
};
|
};
|
||||||
Invoker* invoker = (Invoker*)handler;
|
Invoker* invoker = (Invoker*)handler;
|
||||||
auto ptr = invoker->func;
|
auto ptr = invoker->func;
|
||||||
@ -69,7 +69,7 @@ namespace f8
|
|||||||
|
|
||||||
template<typename InstanceType, typename MsgType>
|
template<typename InstanceType, typename MsgType>
|
||||||
static void RegisterNetMsgHandler(NetMsgHandlerObject* msghandler,
|
static void RegisterNetMsgHandler(NetMsgHandlerObject* msghandler,
|
||||||
void (InstanceType::*ptr)(MsgHdr&, const MsgType&),
|
void (InstanceType::*ptr)(MsgHdr*, const MsgType&),
|
||||||
CUSTOM_PARSER custom_parser = nullptr
|
CUSTOM_PARSER custom_parser = nullptr
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -81,8 +81,8 @@ namespace f8
|
|||||||
}
|
}
|
||||||
struct Invoker: public NetMsgHandler
|
struct Invoker: public NetMsgHandler
|
||||||
{
|
{
|
||||||
void (*wrapper)(InstanceType*, MsgHdr&, NetMsgHandler*);
|
void (*wrapper)(InstanceType*, MsgHdr*, NetMsgHandler*);
|
||||||
void (InstanceType::*func)(MsgHdr&, const MsgType&);
|
void (InstanceType::*func)(MsgHdr*, const MsgType&);
|
||||||
};
|
};
|
||||||
Invoker *p = new Invoker();
|
Invoker *p = new Invoker();
|
||||||
p->wrapper = &NetMsgHandlerWrapper<InstanceType, MsgType>;
|
p->wrapper = &NetMsgHandlerWrapper<InstanceType, MsgType>;
|
||||||
@ -96,12 +96,12 @@ namespace f8
|
|||||||
template<typename InstanceType>
|
template<typename InstanceType>
|
||||||
static bool ProcessNetMsg(NetMsgHandler* handler,
|
static bool ProcessNetMsg(NetMsgHandler* handler,
|
||||||
InstanceType* instance,
|
InstanceType* instance,
|
||||||
MsgHdr& hdr)
|
MsgHdr* hdr)
|
||||||
{
|
{
|
||||||
if(handler){
|
if(handler){
|
||||||
struct Invoker: public NetMsgHandler
|
struct Invoker: public NetMsgHandler
|
||||||
{
|
{
|
||||||
void (*wrapper)(InstanceType*, MsgHdr&, NetMsgHandler*);
|
void (*wrapper)(InstanceType*, MsgHdr*, NetMsgHandler*);
|
||||||
void* func;
|
void* func;
|
||||||
};
|
};
|
||||||
Invoker *p = (Invoker*)handler;
|
Invoker *p = (Invoker*)handler;
|
||||||
@ -115,6 +115,6 @@ namespace f8
|
|||||||
NetMsgHandler* GetNetMsgHandler(NetMsgHandlerObject* handlers,
|
NetMsgHandler* GetNetMsgHandler(NetMsgHandlerObject* handlers,
|
||||||
unsigned short msgid);
|
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);
|
void DumpMsgToLog(const ::google::protobuf::Message& msg, const char* prefix);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ namespace f8
|
|||||||
int offset;
|
int offset;
|
||||||
Player *hum = nullptr;
|
Player *hum = nullptr;
|
||||||
const void* user_data = nullptr;
|
const void* user_data = nullptr;
|
||||||
|
int tag;
|
||||||
list_head entry;
|
list_head entry;
|
||||||
|
|
||||||
MsgHdr* Clone();
|
MsgHdr* Clone();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user