From d6f90cd4cb1b6c513375669f4521dc777b3b0587 Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 19 Aug 2023 15:03:23 +0800 Subject: [PATCH] 1 --- server/robotserver/player.cc | 76 ++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/server/robotserver/player.cc b/server/robotserver/player.cc index 6225e47f..138f791e 100644 --- a/server/robotserver/player.cc +++ b/server/robotserver/player.cc @@ -9,6 +9,7 @@ #include #include "player.h" +#include "app.h" #include "cs_proto.pb.h" @@ -26,32 +27,57 @@ void Player::Init(int idx, account_id_ = account_id; session_id_ = session_id; web_socket_ = socket; - { - web_socket_->on_error = - [this] (a8::WebSocketClient*,int err_code) - { - f8::UdpLog::Instance()->Warning - ("WebSocketClient on_error %d", {err_code}); - }; - web_socket_->on_connect = - [this] (a8::WebSocketClient* ) - { - net_connected_ = true; - f8::UdpLog::Instance()->Info - ("WebSocketClient on_connect", {}); - }; - web_socket_->on_disconnect = - [this] (a8::WebSocketClient* ) - { - f8::UdpLog::Instance()->Warning - ("WebSocketClient on_disconnect", {}); - }; - web_socket_->on_decode_userpacket = - [this] (char* buf, int& offset, unsigned int buflen) - { + web_socket_->on_error = + [this] (a8::WebSocketClient*,int err_code) + { + f8::UdpLog::Instance()->Warning + ("WebSocketClient on_error %d", {err_code}); + }; + web_socket_->on_connect = + [this] (a8::WebSocketClient* ) + { + net_connected_ = true; + f8::UdpLog::Instance()->Info + ("WebSocketClient on_connect", {}); + }; + web_socket_->on_disconnect = + [this] (a8::WebSocketClient* ) + { + f8::UdpLog::Instance()->Warning + ("WebSocketClient on_disconnect", {}); + }; + web_socket_->on_decode_userpacket = + [this, socket_handle = GetSocketId()] + (char* buf, int& offset, unsigned int buflen) + { + bool warning = false; + while (buflen - offset >= sizeof(f8::PackHead)) { + f8::PackHead* p = (f8::PackHead*)&buf[offset]; + if (p->magic_code == f8::MAGIC_CODE) { + if (buflen - offset < sizeof(f8::PackHead) + p->packlen) { + break; + } + App::Instance()->AddSocketMsg + (SF_GameServer, + socket_handle, + //p->ip_saddr, + 0, + p->msgid, + p->seqid, + &buf[offset + sizeof(f8::PackHead)], + p->packlen); + offset += sizeof(f8::PackHead) + p->packlen; + } else { + warning = true; + offset++; + continue; + } + } - }; - } + if (warning) { + f8::UdpLog::Instance()->Warning("收到client非法数据包", {}); + } + }; f8::CoMgr::Instance()->CreateCo ( [this] (f8::Coroutine* co)