mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-12-12 03:02:30 +00:00
feat(net): implement message ready callback in NetClient
This commit is contained in:
parent
af2a47ae15
commit
8e03d9e5dd
3 changed files with 44 additions and 4 deletions
|
|
@ -31,7 +31,7 @@ enum EVENTID {
|
||||||
EVENT_ID_21 = 21,
|
EVENT_ID_21 = 21,
|
||||||
EVENT_ID_22 = 22,
|
EVENT_ID_22 = 22,
|
||||||
EVENT_ID_PAINT = 23,
|
EVENT_ID_PAINT = 23,
|
||||||
EVENT_ID_24 = 24,
|
EVENT_ID_NET_DATA = 24,
|
||||||
EVENT_ID_NET_CONNECT = 25,
|
EVENT_ID_NET_CONNECT = 25,
|
||||||
EVENT_ID_26 = 26,
|
EVENT_ID_26 = 26,
|
||||||
EVENT_ID_27 = 27,
|
EVENT_ID_27 = 27,
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
#include <common/DataStore.hpp>
|
||||||
#include <common/Prop.hpp>
|
#include <common/Prop.hpp>
|
||||||
#include <common/Time.hpp>
|
#include <common/Time.hpp>
|
||||||
#include <storm/Error.hpp>
|
#include <storm/Error.hpp>
|
||||||
|
|
@ -22,6 +23,10 @@ void NETEVENTQUEUE::AddEvent(EVENTID eventId, void* conn, NetClient* client, con
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NetClient::AuthChallengeHandler(WowConnection* conn, CDataStore* msg) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
void NetClient::Connect(const char* addrStr) {
|
void NetClient::Connect(const char* addrStr) {
|
||||||
if (this->m_netState != NS_INITIALIZED) {
|
if (this->m_netState != NS_INITIALIZED) {
|
||||||
SErrDisplayAppFatal("Expected (m_netState == NS_INITIALIZED), got %d", this->m_netState);
|
SErrDisplayAppFatal("Expected (m_netState == NS_INITIALIZED), got %d", this->m_netState);
|
||||||
|
|
@ -85,6 +90,10 @@ int32_t NetClient::Initialize() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NetClient::PongHandler(WowConnection* conn, CDataStore* msg) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
void NetClient::SetLoginData(LoginData* loginData) {
|
void NetClient::SetLoginData(LoginData* loginData) {
|
||||||
memcpy(&this->m_loginData, loginData, sizeof(this->m_loginData));
|
memcpy(&this->m_loginData, loginData, sizeof(this->m_loginData));
|
||||||
}
|
}
|
||||||
|
|
@ -121,5 +130,33 @@ void NetClient::WCDisconnected(WowConnection* conn, uint32_t timeStamp, NETCONNA
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetClient::WCMessageReady(WowConnection* conn, uint32_t timeStamp, CDataStore* msg) {
|
void NetClient::WCMessageReady(WowConnection* conn, uint32_t timeStamp, CDataStore* msg) {
|
||||||
// TODO
|
uint8_t* data;
|
||||||
|
msg->GetDataInSitu(reinterpret_cast<void*&>(data), msg->m_size);
|
||||||
|
|
||||||
|
// TODO increment byte counter
|
||||||
|
// SInterlockedExchangeAdd(this->m_bytesReceived, msg->m_size);
|
||||||
|
|
||||||
|
msg->m_read = 0;
|
||||||
|
|
||||||
|
uint16_t msgId;
|
||||||
|
msg->Get(msgId);
|
||||||
|
|
||||||
|
// TODO SMSG_SUSPEND_COMMS (0x50F)
|
||||||
|
// TODO SMSG_FORCE_SEND_QUEUED_PACKETS (0x511)
|
||||||
|
// TODO SMSG_REDIRECT_CLIENT (0x50D)
|
||||||
|
|
||||||
|
if (msgId == SMSG_PONG) {
|
||||||
|
this->PongHandler(conn, msg);
|
||||||
|
return;
|
||||||
|
} else if (msgId == SMSG_AUTH_CHALLENGE) {
|
||||||
|
this->AuthChallengeHandler(conn, msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conn == this->m_serverConnection && !this->m_suspended) {
|
||||||
|
msg->m_read = msg->m_size;
|
||||||
|
this->m_netEventQueue->AddEvent(EVENT_ID_NET_DATA, conn, this, data, msg->m_size);
|
||||||
|
} else {
|
||||||
|
conn->Disconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ class NetClient : public WowConnectionResponse {
|
||||||
// Member variables
|
// Member variables
|
||||||
LoginData m_loginData;
|
LoginData m_loginData;
|
||||||
NETSTATE m_netState = NS_UNINITIALIZED;
|
NETSTATE m_netState = NS_UNINITIALIZED;
|
||||||
|
bool m_suspended = false;
|
||||||
MESSAGE_HANDLER m_handlers[NUM_MSG_TYPES];
|
MESSAGE_HANDLER m_handlers[NUM_MSG_TYPES];
|
||||||
void* m_handlerParams[NUM_MSG_TYPES];
|
void* m_handlerParams[NUM_MSG_TYPES];
|
||||||
NETEVENTQUEUE* m_netEventQueue = nullptr;
|
NETEVENTQUEUE* m_netEventQueue = nullptr;
|
||||||
|
|
@ -58,9 +59,11 @@ class NetClient : public WowConnectionResponse {
|
||||||
virtual void WCDisconnected(WowConnection* conn, uint32_t timeStamp, NETCONNADDR* addr);
|
virtual void WCDisconnected(WowConnection* conn, uint32_t timeStamp, NETCONNADDR* addr);
|
||||||
|
|
||||||
// Member functions
|
// Member functions
|
||||||
|
void AuthChallengeHandler(WowConnection* conn, CDataStore* msg);
|
||||||
void Connect(const char* addrStr);
|
void Connect(const char* addrStr);
|
||||||
int32_t ConnectInternal(const char* host, uint16_t port);
|
int32_t ConnectInternal(const char* host, uint16_t port);
|
||||||
int32_t Initialize();
|
int32_t Initialize();
|
||||||
|
void PongHandler(WowConnection* conn, CDataStore* msg);
|
||||||
void SetLoginData(LoginData* loginData);
|
void SetLoginData(LoginData* loginData);
|
||||||
void SetMessageHandler(NETMESSAGE msgId, MESSAGE_HANDLER handler, void* param);
|
void SetMessageHandler(NETMESSAGE msgId, MESSAGE_HANDLER handler, void* param);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue