feat(net): make Grunt::ClientLink state an enum (#21)

Co-authored-by: fallenoak <git@fallenoak.me>
This commit is contained in:
Tristan 'Natrist' Cormier 2025-09-25 12:20:57 -04:00 committed by GitHub
parent 1d1398ed4f
commit b95d725018
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 17 deletions

View File

@ -28,7 +28,7 @@ Grunt::ClientLink::ClientLink(Grunt::ClientResponse& clientResponse) {
this->m_clientResponse = &clientResponse; this->m_clientResponse = &clientResponse;
this->SetState(0); this->SetState(STATE_NONE);
if (this->m_timer.m_thread.Valid()) { if (this->m_timer.m_thread.Valid()) {
this->m_interval = 100; this->m_interval = 100;
@ -42,9 +42,9 @@ void Grunt::ClientLink::Call() {
this->m_critSect.Enter(); this->m_critSect.Enter();
if (this->m_state == 2) { if (this->m_state == STATE_CONNECTED) {
this->m_clientResponse->GetLogonMethod(); this->m_clientResponse->GetLogonMethod();
} else if (this->m_state == 6 && !this->m_clientResponse->OnlineIdle()) { } else if (this->m_state == STATE_AUTHENTICATED && !this->m_clientResponse->OnlineIdle()) {
this->Disconnect(); this->Disconnect();
} }
@ -73,7 +73,7 @@ int32_t Grunt::ClientLink::CmdAuthLogonChallenge(CDataStore& msg) {
return 1; return 1;
} }
this->SetState(2); this->SetState(STATE_CONNECTED);
if (result >= GRUNT_RESULT_LAST) { if (result >= GRUNT_RESULT_LAST) {
// TODO WLog error // TODO WLog error
@ -190,11 +190,11 @@ int32_t Grunt::ClientLink::CmdAuthLogonChallenge(CDataStore& msg) {
SRP6_Random srpRandom(randomSeed, sizeof(randomSeed)); SRP6_Random srpRandom(randomSeed, sizeof(randomSeed));
if (this->m_srpClient.CalculateProof(largeSafePrime, largeSafePrimeLen, generator, generatorLen, salt, 32, serverPublicKey, 32, srpRandom)) { if (this->m_srpClient.CalculateProof(largeSafePrime, largeSafePrimeLen, generator, generatorLen, salt, 32, serverPublicKey, 32, srpRandom)) {
this->SetState(2); this->SetState(STATE_CONNECTED);
this->m_clientResponse->LogonResult(GRUNT_RESULT_5, nullptr, 0, 0); this->m_clientResponse->LogonResult(GRUNT_RESULT_5, nullptr, 0, 0);
} else { } else {
this->SetState(4); this->SetState(STATE_CONNECT_VERSION);
this->m_clientResponse->SetPinInfo(pinEnabled, pinGridSeed, pinSalt); this->m_clientResponse->SetPinInfo(pinEnabled, pinGridSeed, pinSalt);
@ -238,7 +238,7 @@ int32_t Grunt::ClientLink::CmdAuthLogonProof(CDataStore& msg) {
} }
if (result != 10) { if (result != 10) {
this->SetState(2); this->SetState(STATE_CONNECTED);
// TODO range check on result // TODO range check on result
@ -265,7 +265,7 @@ int32_t Grunt::ClientLink::CmdAuthLogonProof(CDataStore& msg) {
if (msg.Tell() <= msg.Size()) { if (msg.Tell() <= msg.Size()) {
if (this->m_srpClient.VerifyServerProof(static_cast<uint8_t*>(serverProof), 20)) { if (this->m_srpClient.VerifyServerProof(static_cast<uint8_t*>(serverProof), 20)) {
this->SetState(2); this->SetState(STATE_CONNECTED);
this->m_clientResponse->LogonResult(Grunt::GRUNT_RESULT_11, nullptr, 0, 0); this->m_clientResponse->LogonResult(Grunt::GRUNT_RESULT_11, nullptr, 0, 0);
} else { } else {
this->m_accountFlags = accountFlags; this->m_accountFlags = accountFlags;
@ -273,7 +273,7 @@ int32_t Grunt::ClientLink::CmdAuthLogonProof(CDataStore& msg) {
// this->uint94 = 0; // this->uint94 = 0;
this->m_surveyID = surveyID; this->m_surveyID = surveyID;
this->SetState(6); this->SetState(STATE_AUTHENTICATED);
this->m_clientResponse->LogonResult(Grunt::GRUNT_RESULT_0, this->m_srpClient.sessionKey, 40, logonFlags); this->m_clientResponse->LogonResult(Grunt::GRUNT_RESULT_0, this->m_srpClient.sessionKey, 40, logonFlags);
} }
@ -395,7 +395,7 @@ void Grunt::ClientLink::Connect(const char* a2) {
return; return;
} }
this->SetState(1); this->SetState(STATE_CONNECTING);
auto connectionMem = SMemAlloc(sizeof(WowConnection), __FILE__, __LINE__, 0x0); auto connectionMem = SMemAlloc(sizeof(WowConnection), __FILE__, __LINE__, 0x0);
auto connection = new (connectionMem) WowConnection(this, nullptr); auto connection = new (connectionMem) WowConnection(this, nullptr);
@ -422,7 +422,7 @@ void Grunt::ClientLink::Disconnect() {
} }
void Grunt::ClientLink::GetRealmList() { void Grunt::ClientLink::GetRealmList() {
if (this->m_state != 6) { if (this->m_state != STATE_AUTHENTICATED) {
return; return;
} }
@ -440,7 +440,7 @@ void Grunt::ClientLink::GetRealmList() {
} }
void Grunt::ClientLink::LogonNewSession(const Grunt::ClientLink::Logon& logon) { void Grunt::ClientLink::LogonNewSession(const Grunt::ClientLink::Logon& logon) {
this->SetState(3); this->SetState(STATE_AUTH_CHALLENGE);
SStrCopy(this->m_accountName, logon.accountName, sizeof(this->m_accountName)); SStrCopy(this->m_accountName, logon.accountName, sizeof(this->m_accountName));
SStrUpper(this->m_accountName); SStrUpper(this->m_accountName);
@ -505,7 +505,7 @@ void Grunt::ClientLink::ProveVersion(const uint8_t* versionChecksum) {
// cdKeys.int0 = 0; // cdKeys.int0 = 0;
// } // }
if (this->m_state == 4) { if (this->m_state == STATE_CONNECT_VERSION) {
command.Put(static_cast<uint8_t>(CMD_AUTH_LOGON_PROOF)); command.Put(static_cast<uint8_t>(CMD_AUTH_LOGON_PROOF));
command.PutData(this->m_srpClient.clientPublicKey, sizeof(this->m_srpClient.clientPublicKey)); command.PutData(this->m_srpClient.clientPublicKey, sizeof(this->m_srpClient.clientPublicKey));
command.PutData(this->m_srpClient.clientProof, sizeof(this->m_srpClient.clientProof)); command.PutData(this->m_srpClient.clientProof, sizeof(this->m_srpClient.clientProof));
@ -546,7 +546,7 @@ void Grunt::ClientLink::Send(CDataStore& msg) {
this->m_critSect.Leave(); this->m_critSect.Leave();
} }
void Grunt::ClientLink::SetState(int32_t state) { void Grunt::ClientLink::SetState(STATE state) {
this->m_critSect.Enter(); this->m_critSect.Enter();
this->m_state = state; this->m_state = state;
@ -561,7 +561,7 @@ void Grunt::ClientLink::WCCantConnect(WowConnection* conn, uint32_t timeStamp, N
void Grunt::ClientLink::WCConnected(WowConnection* conn, WowConnection* inbound, uint32_t timeStamp, const NETCONNADDR* addr) { void Grunt::ClientLink::WCConnected(WowConnection* conn, WowConnection* inbound, uint32_t timeStamp, const NETCONNADDR* addr) {
this->m_critSect.Enter(); this->m_critSect.Enter();
this->SetState(2); this->SetState(STATE_CONNECTED);
int32_t connected = this->m_clientResponse->Connected(addr->peerAddr); int32_t connected = this->m_clientResponse->Connected(addr->peerAddr);

View File

@ -25,6 +25,16 @@ class Grunt::ClientLink : public WowConnectionResponse, Grunt::Pending, Grunt::T
CMD_XFER_DATA = 49, CMD_XFER_DATA = 49,
}; };
enum STATE {
STATE_NONE = 0,
STATE_CONNECTING = 1,
STATE_CONNECTED = 2,
STATE_AUTH_CHALLENGE = 3,
STATE_CONNECT_VERSION = 4,
STATE_RECONNECT_VERSION = 5,
STATE_AUTHENTICATED = 6
};
struct Logon { struct Logon {
const char* accountName; const char* accountName;
const char* password; const char* password;
@ -43,7 +53,7 @@ class Grunt::ClientLink : public WowConnectionResponse, Grunt::Pending, Grunt::T
uint32_t m_accountFlags = 0x0; uint32_t m_accountFlags = 0x0;
uint32_t m_surveyID = 0; uint32_t m_surveyID = 0;
uint32_t m_clientIP = 0; uint32_t m_clientIP = 0;
int32_t m_state; STATE m_state;
SRP6_Client m_srpClient; SRP6_Client m_srpClient;
SCritSect m_critSect; SCritSect m_critSect;
CDataStore m_datastore1B0; CDataStore m_datastore1B0;
@ -75,7 +85,7 @@ class Grunt::ClientLink : public WowConnectionResponse, Grunt::Pending, Grunt::T
void PackLogon(CDataStore& msg, const Logon& logon); void PackLogon(CDataStore& msg, const Logon& logon);
void ProveVersion(const uint8_t* versionChecksum); void ProveVersion(const uint8_t* versionChecksum);
void Send(CDataStore& msg); void Send(CDataStore& msg);
void SetState(int32_t state); void SetState(STATE state);
}; };
#endif #endif