mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-04-16 10:04:42 +03:00
feat(net): implement message ready callback in NetClient
This commit is contained in:
parent
af2a47ae15
commit
8e03d9e5dd
@ -31,7 +31,7 @@ enum EVENTID {
|
||||
EVENT_ID_21 = 21,
|
||||
EVENT_ID_22 = 22,
|
||||
EVENT_ID_PAINT = 23,
|
||||
EVENT_ID_24 = 24,
|
||||
EVENT_ID_NET_DATA = 24,
|
||||
EVENT_ID_NET_CONNECT = 25,
|
||||
EVENT_ID_26 = 26,
|
||||
EVENT_ID_27 = 27,
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <new>
|
||||
#include <common/DataStore.hpp>
|
||||
#include <common/Prop.hpp>
|
||||
#include <common/Time.hpp>
|
||||
#include <storm/Error.hpp>
|
||||
@ -22,6 +23,10 @@ void NETEVENTQUEUE::AddEvent(EVENTID eventId, void* conn, NetClient* client, con
|
||||
// TODO
|
||||
}
|
||||
|
||||
void NetClient::AuthChallengeHandler(WowConnection* conn, CDataStore* msg) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void NetClient::Connect(const char* addrStr) {
|
||||
if (this->m_netState != NS_INITIALIZED) {
|
||||
SErrDisplayAppFatal("Expected (m_netState == NS_INITIALIZED), got %d", this->m_netState);
|
||||
@ -85,6 +90,10 @@ int32_t NetClient::Initialize() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void NetClient::PongHandler(WowConnection* conn, CDataStore* msg) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void NetClient::SetLoginData(LoginData* loginData) {
|
||||
memcpy(&this->m_loginData, loginData, sizeof(this->m_loginData));
|
||||
}
|
||||
@ -120,6 +129,34 @@ void NetClient::WCDisconnected(WowConnection* conn, uint32_t timeStamp, NETCONNA
|
||||
// TODO
|
||||
}
|
||||
|
||||
void NetClient::WCMessageReady(WowConnection *conn, uint32_t timeStamp, CDataStore* msg) {
|
||||
// TODO
|
||||
void NetClient::WCMessageReady(WowConnection* conn, uint32_t timeStamp, CDataStore* msg) {
|
||||
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
|
||||
LoginData m_loginData;
|
||||
NETSTATE m_netState = NS_UNINITIALIZED;
|
||||
bool m_suspended = false;
|
||||
MESSAGE_HANDLER m_handlers[NUM_MSG_TYPES];
|
||||
void* m_handlerParams[NUM_MSG_TYPES];
|
||||
NETEVENTQUEUE* m_netEventQueue = nullptr;
|
||||
@ -52,15 +53,17 @@ class NetClient : public WowConnectionResponse {
|
||||
SCritSect m_pingLock;
|
||||
|
||||
// Virtual member functions
|
||||
virtual void WCMessageReady(WowConnection *conn, uint32_t timeStamp, CDataStore* msg);
|
||||
virtual void WCMessageReady(WowConnection* conn, uint32_t timeStamp, CDataStore* msg);
|
||||
virtual void WCConnected(WowConnection* conn, WowConnection* inbound, uint32_t timeStamp, const NETCONNADDR* addr);
|
||||
virtual void WCCantConnect(WowConnection* conn, uint32_t timeStamp, NETCONNADDR* addr);
|
||||
virtual void WCDisconnected(WowConnection* conn, uint32_t timeStamp, NETCONNADDR* addr);
|
||||
|
||||
// Member functions
|
||||
void AuthChallengeHandler(WowConnection* conn, CDataStore* msg);
|
||||
void Connect(const char* addrStr);
|
||||
int32_t ConnectInternal(const char* host, uint16_t port);
|
||||
int32_t Initialize();
|
||||
void PongHandler(WowConnection* conn, CDataStore* msg);
|
||||
void SetLoginData(LoginData* loginData);
|
||||
void SetMessageHandler(NETMESSAGE msgId, MESSAGE_HANDLER handler, void* param);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user