From e18afec28dffc4cc85bbdb3ea698ee45409f1190 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Mon, 3 Apr 2023 18:00:18 -0500 Subject: [PATCH] feat(net): handle SMSG_AUTH_RESPONSE --- src/client/ClientRealmResponseAdapter.cpp | 5 ++ src/client/ClientRealmResponseAdapter.hpp | 3 + src/net/connection/RealmConnection.cpp | 98 ++++++++++++++++++++++- src/net/connection/RealmConnection.hpp | 8 ++ src/net/connection/RealmResponse.hpp | 3 + 5 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 src/client/ClientRealmResponseAdapter.cpp diff --git a/src/client/ClientRealmResponseAdapter.cpp b/src/client/ClientRealmResponseAdapter.cpp new file mode 100644 index 0000000..d32fbfd --- /dev/null +++ b/src/client/ClientRealmResponseAdapter.cpp @@ -0,0 +1,5 @@ +#include "client/ClientRealmResponseAdapter.hpp" + +void ClientRealmResponseAdapter::HandleAuthResponse(RealmConnection* connection, uint8_t authResult) { + // TODO +} diff --git a/src/client/ClientRealmResponseAdapter.hpp b/src/client/ClientRealmResponseAdapter.hpp index 8386310..0f0cda8 100644 --- a/src/client/ClientRealmResponseAdapter.hpp +++ b/src/client/ClientRealmResponseAdapter.hpp @@ -5,6 +5,9 @@ class ClientRealmResponseAdapter : public RealmResponse { public: + // Virtual member functions + virtual void HandleAuthResponse(RealmConnection* connection, uint8_t authResult); + virtual void GameServerResult(RealmConnection* connection, const char* a2, const char* a3, const char* a4) {}; }; #endif diff --git a/src/net/connection/RealmConnection.cpp b/src/net/connection/RealmConnection.cpp index 5fe5fe5..64d5c48 100644 --- a/src/net/connection/RealmConnection.cpp +++ b/src/net/connection/RealmConnection.cpp @@ -1,4 +1,5 @@ #include "net/connection/RealmConnection.hpp" +#include "net/connection/RealmResponse.hpp" #include "net/Types.hpp" #include #include @@ -8,8 +9,64 @@ SCritSect RealmConnection::s_AllRealmConnectionsCrit; STORM_LIST(RealmConnection::REALMCONNECTIONNODE) RealmConnection::s_AllRealmConnections; int32_t RealmConnection::MessageHandler(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { - // TODO - return 0; + auto connection = static_cast(param); + int32_t result = 0; + + switch (msgId) { + case SMSG_AUTH_RESPONSE: { + result = connection->HandleAuthResponse(msgId, time, msg); + break; + } + + case SMSG_CREATE_CHAR: { + // TODO + break; + } + + case SMSG_ENUM_CHARACTERS_RESULT: { + // TODO + break; + } + + case SMSG_DELETE_CHAR: { + // TODO + break; + } + + case SMSG_CHARACTER_LOGIN_FAILED: { + // TODO + break; + } + + case SMSG_ADDON_INFO: { + // TODO + break; + } + + case SMSG_LOGOUT_CANCEL_ACK: { + // TODO + break; + } + + case SMSG_LOGOUT_COMPLETE: { + // TODO + break; + } + + case SMSG_LOGOUT_RESPONSE: { + // TODO + break; + } + + default: + break; + } + + if (!msg->IsRead()) { + // TODO + } + + return result; } void RealmConnection::PollNet() { @@ -99,6 +156,43 @@ int32_t RealmConnection::HandleAuthChallenge(AuthenticationChallenge* challenge) return 1; } +int32_t RealmConnection::HandleAuthResponse(uint32_t msgId, uint32_t time, CDataStore* msg) { + if (this->m_realmResponse) { + this->m_realmResponse->GameServerResult(this, "SMSG_AUTH_RESPONSE", nullptr, nullptr); + } + + uint8_t authResult; + msg->Get(authResult); + + // AUTH_OK or AUTH_WAIT_QUEUE + if (authResult == 12 || authResult == 27) { + // AUTH_OK + if (authResult == 12) { + this->m_authenticated = 1; + } + + if (msg->Size() - msg->m_read >= 10 + (authResult == 27 ? 5 : 0)) { + msg->Get(this->m_billingTimeRemaining); + msg->Get(this->m_billingFlags); + msg->Get(this->m_billingTimeRested); + msg->Get(this->m_accountExpansion); + } + + // AUTH_WAIT_QUEUE + if (authResult == 27) { + msg->Get(this->m_queuePosition); + + uint8_t freeCharacterMigration; + msg->Get(freeCharacterMigration); + this->m_freeCharacterMigration = freeCharacterMigration; + } + } + + this->m_realmResponse->HandleAuthResponse(this, authResult); + + return 1; +} + void RealmConnection::SetSelectedRealm(uint32_t a2, uint32_t a3, uint32_t a4) { // TODO } diff --git a/src/net/connection/RealmConnection.hpp b/src/net/connection/RealmConnection.hpp index a471710..5414dc2 100644 --- a/src/net/connection/RealmConnection.hpp +++ b/src/net/connection/RealmConnection.hpp @@ -24,12 +24,20 @@ class RealmConnection : public NetClient { // Member variables RealmResponse* m_realmResponse; + uint8_t m_authenticated = 0; + uint32_t m_queuePosition = 0; + uint32_t m_freeCharacterMigration = 0; + uint32_t m_billingTimeRemaining = 0; + uint32_t m_billingTimeRested = 0; + uint8_t m_billingFlags = 0; + uint8_t m_accountExpansion = 0; // Virtual member functions virtual int32_t HandleAuthChallenge(AuthenticationChallenge* challenge); // Member functions RealmConnection(RealmResponse* realmResponse); + int32_t HandleAuthResponse(uint32_t msgId, uint32_t time, CDataStore* msg); void SetSelectedRealm(uint32_t a2, uint32_t a3, uint32_t a4); }; diff --git a/src/net/connection/RealmResponse.hpp b/src/net/connection/RealmResponse.hpp index e4b6eb6..6600312 100644 --- a/src/net/connection/RealmResponse.hpp +++ b/src/net/connection/RealmResponse.hpp @@ -3,6 +3,9 @@ class RealmResponse { public: + // Virtual member functions + virtual void HandleAuthResponse(RealmConnection* connection, uint8_t authResult) = 0; + virtual void GameServerResult(RealmConnection* connection, const char* a3, const char* a4, const char* a5) = 0; }; #endif