From e8e6a85b8f00a248eea7aea80276c6f1afd98ef9 Mon Sep 17 00:00:00 2001 From: azw Date: Fri, 5 May 2023 23:20:20 +0000 Subject: [PATCH] 1 --- f8/protoutils.cc | 30 ++++++++++++++++++++++++++++++ f8/protoutils.h | 3 +++ 2 files changed, 33 insertions(+) diff --git a/f8/protoutils.cc b/f8/protoutils.cc index c5fb086..24397fd 100644 --- a/f8/protoutils.cc +++ b/f8/protoutils.cc @@ -7,6 +7,10 @@ #include #include +#ifdef USE_ASIO +#include +#endif + #include #include @@ -202,6 +206,32 @@ namespace f8 return sizeof(WSProxyPackHead_C) + packlen; } +#ifdef USE_ASIO + int Net_SendProxyCMsg(a8::AsioTcpClient* tcp_client, unsigned short socket_handle, + unsigned short msgid, ::google::protobuf::Message& msg) + { + int packlen = msg.ByteSize(); + assert(packlen < 1024 * 60); + + char* buff = (char*)malloc(sizeof(WSProxyPackHead_C) + packlen); + memset(buff, 0, sizeof(WSProxyPackHead_C)); + WSProxyPackHead_C* head = (WSProxyPackHead_C*)buff; + head->packlen = packlen; + head->msgid = msgid; + head->seqid = 0; + head->magic_code = MAGIC_CODE; + head->ip_saddr = 0; + head->socket_handle = socket_handle; + + if (packlen > 0) { + msg.SerializeToArray(buff + sizeof(WSProxyPackHead_C), packlen); + } + tcp_client->SendBuff(buff, sizeof(WSProxyPackHead_C) + packlen); + free(buff); + return sizeof(WSProxyPackHead_C) + packlen; + } +#endif + int Net_SendProxyMsg(a8::TcpListener* tcp_listener, int socket_handle, unsigned int seqid, unsigned short error_code, unsigned short msgid, ::google::protobuf::Message& msg) diff --git a/f8/protoutils.h b/f8/protoutils.h index 34490d9..19664ea 100644 --- a/f8/protoutils.h +++ b/f8/protoutils.h @@ -4,6 +4,7 @@ namespace a8 { class TcpClient; class TcpListener; + class AsioTcpClient; } class Player; @@ -103,6 +104,8 @@ namespace f8 int Net_SendProxyCMsg(a8::TcpClient* tcp_client, unsigned short socket_handle, unsigned short msgid, ::google::protobuf::Message& msg); + int Net_SendProxyCMsg(a8::AsioTcpClient* tcp_client, unsigned short socket_handle, + unsigned short msgid, ::google::protobuf::Message& msg); int Net_SendProxyMsg(a8::TcpListener* tcp_tlistener, int socket_handle, unsigned int seqid, unsigned short error_code,