feat(net): invoke message handlers from NetClient

This commit is contained in:
fallenoak 2023-03-23 23:28:44 -05:00
parent 5d11881372
commit 1d28c06104
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
2 changed files with 34 additions and 1 deletions
src/net/connection

View File

@ -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<uint8_t*>(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<NETMESSAGE>(msgId),
timeReceived,
msg
);
}
void NetClient::Send(CDataStore* msg) {
if (this->m_netState != NS_CONNECTED) {
return;

View File

@ -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);