From 1d28c061044057ab5a740417bae60a943cf1ce4c Mon Sep 17 00:00:00 2001 From: fallenoak Date: Thu, 23 Mar 2023 23:28:44 -0500 Subject: [PATCH] feat(net): invoke message handlers from NetClient --- src/net/connection/NetClient.cpp | 34 +++++++++++++++++++++++++++++++- src/net/connection/NetClient.hpp | 1 + 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/net/connection/NetClient.cpp b/src/net/connection/NetClient.cpp index 292e879..580e677 100644 --- a/src/net/connection/NetClient.cpp +++ b/src/net/connection/NetClient.cpp @@ -209,7 +209,18 @@ int32_t NetClient::HandleConnect() { } int32_t NetClient::HandleData(uint32_t timeReceived, void* data, int32_t size) { - // TODO + // TODO push obj mgr + + CDataStore msg; + msg.m_data = static_cast(data); + msg.m_size = size; + msg.m_alloc = -1; + msg.m_read = 0; + + this->ProcessMessage(timeReceived, &msg, 0); + + // TODO pop obj mgr + return 1; } @@ -259,6 +270,27 @@ void NetClient::PongHandler(WowConnection* conn, CDataStore* msg) { // TODO } +void NetClient::ProcessMessage(uint32_t timeReceived, CDataStore* msg, int32_t a4) { + // TODO s_stats.messagesReceived++ + + uint16_t msgId; + msg->Get(msgId); + + // TODO virtual function call on NetClient + + if (msgId >= NUM_MSG_TYPES || !this->m_handlers[msgId]) { + msg->Reset(); + return; + } + + this->m_handlers[msgId]( + this->m_handlerParams[msgId], + static_cast(msgId), + timeReceived, + msg + ); +} + void NetClient::Send(CDataStore* msg) { if (this->m_netState != NS_CONNECTED) { return; diff --git a/src/net/connection/NetClient.hpp b/src/net/connection/NetClient.hpp index 29f1429..7564e33 100644 --- a/src/net/connection/NetClient.hpp +++ b/src/net/connection/NetClient.hpp @@ -72,6 +72,7 @@ class NetClient : public WowConnectionResponse { int32_t Initialize(); void PollEventQueue(); void PongHandler(WowConnection* conn, CDataStore* msg); + void ProcessMessage(uint32_t timeReceived, CDataStore* msg, int32_t a4); void Send(CDataStore* msg); void SetDelete(); void SetLoginData(LoginData* loginData);