mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-12-12 11:12:29 +00:00
93 lines
2.7 KiB
C++
93 lines
2.7 KiB
C++
|
|
#include "client/ClientServices.hpp"
|
||
|
|
#include "client/ClientRealmResponseAdapter.hpp"
|
||
|
|
#include "net/Connection.hpp"
|
||
|
|
#include "net/Login.hpp"
|
||
|
|
#include <storm/Memory.hpp>
|
||
|
|
#include <storm/String.hpp>
|
||
|
|
#include <new>
|
||
|
|
|
||
|
|
ClientConnection* g_clientConnection;
|
||
|
|
|
||
|
|
RealmResponse* ClientServices::s_clientRealmResponse;
|
||
|
|
ClientConnection* ClientServices::s_currentConnection;
|
||
|
|
ClientServices* ClientServices::s_instance;
|
||
|
|
Login* ClientServices::s_loginObj;
|
||
|
|
bool ClientServices::s_newLogin;
|
||
|
|
|
||
|
|
ClientConnection* ClientServices::Connection() {
|
||
|
|
// TODO assertion?
|
||
|
|
|
||
|
|
return ClientServices::s_currentConnection;
|
||
|
|
}
|
||
|
|
|
||
|
|
ClientServices* ClientServices::GetInstance() {
|
||
|
|
if (ClientServices::s_instance) {
|
||
|
|
return ClientServices::s_instance;
|
||
|
|
}
|
||
|
|
|
||
|
|
auto instanceMem = SMemAlloc(sizeof(ClientServices), __FILE__, __LINE__, 0x0);
|
||
|
|
auto instance = new (instanceMem) ClientServices();
|
||
|
|
ClientServices::s_instance = instance;
|
||
|
|
|
||
|
|
return ClientServices::s_instance;
|
||
|
|
}
|
||
|
|
|
||
|
|
void ClientServices::Initialize() {
|
||
|
|
if (!g_clientConnection) {
|
||
|
|
auto adapterMem = SMemAlloc(sizeof(ClientRealmResponseAdapter), __FILE__, __LINE__, 0x0);
|
||
|
|
auto clientRealmResponse = new (adapterMem) ClientRealmResponseAdapter();
|
||
|
|
ClientServices::s_clientRealmResponse = clientRealmResponse;
|
||
|
|
|
||
|
|
auto connectionMem = SMemAlloc(sizeof(ClientConnection), __FILE__, __LINE__, 0x0);
|
||
|
|
auto clientConnection = new (connectionMem) ClientConnection(ClientServices::s_clientRealmResponse);
|
||
|
|
g_clientConnection = clientConnection;
|
||
|
|
}
|
||
|
|
|
||
|
|
ClientServices::s_currentConnection = g_clientConnection;
|
||
|
|
|
||
|
|
// TODO ConsoleCommandRegister("logout", &Sub6B2030, 5, nullptr);
|
||
|
|
}
|
||
|
|
|
||
|
|
Login* ClientServices::LoginConnection() {
|
||
|
|
return ClientServices::s_loginObj;
|
||
|
|
}
|
||
|
|
|
||
|
|
void ClientServices::Logon(const char* accountName, const char* password) {
|
||
|
|
if (ClientServices::s_newLogin) {
|
||
|
|
if (ClientServices::s_loginObj) {
|
||
|
|
// TODO
|
||
|
|
// ClientServices::s_loginObj->Vfunc48(1);
|
||
|
|
|
||
|
|
ClientServices::s_loginObj = nullptr;
|
||
|
|
}
|
||
|
|
|
||
|
|
ClientServices::s_newLogin = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
auto useBattlenet = SStrChr(accountName, '@') != 0;
|
||
|
|
|
||
|
|
Login* loginObj;
|
||
|
|
|
||
|
|
if (useBattlenet) {
|
||
|
|
// TODO
|
||
|
|
} else {
|
||
|
|
auto loginMem = SMemAlloc(sizeof(GruntLogin), __FILE__, __LINE__, 0x0);
|
||
|
|
loginObj = new (loginMem) GruntLogin();
|
||
|
|
}
|
||
|
|
|
||
|
|
ClientServices::s_loginObj = loginObj;
|
||
|
|
ClientServices::s_loginObj->Init(ClientServices::GetInstance());
|
||
|
|
|
||
|
|
// TODO
|
||
|
|
|
||
|
|
ClientServices::s_loginObj->SetLogonCreds(accountName, password);
|
||
|
|
|
||
|
|
// TODO
|
||
|
|
|
||
|
|
ClientServices::s_loginObj->Logon(nullptr, nullptr);
|
||
|
|
}
|
||
|
|
|
||
|
|
void ClientServices::LoginServerStatus(LOGIN_STATE state, LOGIN_RESULT result, const char* addrStr, const char* stateStr, const char* resultStr, uint16_t a7) {
|
||
|
|
// TODO
|
||
|
|
}
|