feat(net): implement NetClient::Disconnect

This commit is contained in:
VDm 2025-04-10 01:05:04 +04:00
parent 032e9f93d8
commit 41dc426db3
5 changed files with 41 additions and 2 deletions

View File

@ -1174,6 +1174,7 @@ enum NETSTATE {
NS_STATE_3 = 3, NS_STATE_3 = 3,
NS_CONNECTING = 4, NS_CONNECTING = 4,
NS_CONNECTED = 5, NS_CONNECTED = 5,
NS_DISCONNECTING = 6
}; };
enum WOW_CONN_STATE { enum WOW_CONN_STATE {

View File

@ -100,7 +100,9 @@ void ClientConnection::Connect() {
} }
int32_t ClientConnection::Disconnect() { int32_t ClientConnection::Disconnect() {
// TODO this->NetClient::Disconnect();
this->m_connected = 0;
// TODO: WardenClient_Destroy();
return 0; return 0;
} }

View File

@ -98,6 +98,12 @@ void NETEVENTQUEUE::Poll() {
this->m_critSect.Leave(); this->m_critSect.Leave();
} }
void NETEVENTQUEUE::Clear() {
this->m_critSect.Enter();
this->m_eventQueue.Clear();
this->m_critSect.Leave();
}
void NetClient::AddRef() { void NetClient::AddRef() {
SInterlockedIncrement(&this->m_refCount); SInterlockedIncrement(&this->m_refCount);
} }
@ -144,6 +150,34 @@ void NetClient::Connect(const char* addrStr) {
this->ConnectInternal(host, port); this->ConnectInternal(host, port);
} }
void NetClient::Disconnect() {
if (this->m_redirectConnection) {
// TODO: this->m_redirectConnection->SetResponse(0, 0);
this->m_redirectConnection->Disconnect();
this->m_redirectConnection->Release();
}
if (this->m_netState == NS_CONNECTED) {
this->m_netState = NS_DISCONNECTING;
this->m_serverConnection->Disconnect();
} else {
// TODO: this->m_serverConnection->SetResponse(0, 0);
this->m_serverConnection->Disconnect();
this->m_netEventQueue->Clear();
this->m_serverConnection->Release();
auto connectionMem = SMemAlloc(sizeof(WowConnection), __FILE__, __LINE__, 0x0);
if (connectionMem) {
auto connection = new (connectionMem) WowConnection(this, nullptr);
this->m_serverConnection = connection;
} else {
this->m_serverConnection = nullptr;
}
this->m_netState = NS_INITIALIZED;
}
}
int32_t NetClient::ConnectInternal(const char* host, uint16_t port) { int32_t NetClient::ConnectInternal(const char* host, uint16_t port) {
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);

View File

@ -43,6 +43,7 @@ class NETEVENTQUEUE {
{}; {};
void AddEvent(EVENTID eventId, void* conn, NetClient* client, const void* data, uint32_t bytes); void AddEvent(EVENTID eventId, void* conn, NetClient* client, const void* data, uint32_t bytes);
void Poll(); void Poll();
void Clear();
}; };
class NetClient : public WowConnectionResponse { class NetClient : public WowConnectionResponse {
@ -62,6 +63,7 @@ class NetClient : public WowConnectionResponse {
void AddRef(); void AddRef();
void AuthChallengeHandler(WowConnection* conn, CDataStore* msg); void AuthChallengeHandler(WowConnection* conn, CDataStore* msg);
void Connect(const char* addrStr); void Connect(const char* addrStr);
void Disconnect();
int32_t ConnectInternal(const char* host, uint16_t port); int32_t ConnectInternal(const char* host, uint16_t port);
void DelRef(); void DelRef();
void EnableEncryption(WowConnection* conn, uint8_t* seed, uint8_t seedLen); void EnableEncryption(WowConnection* conn, uint8_t* seed, uint8_t seedLen);

View File

@ -55,7 +55,7 @@ int32_t Script_GetCharacterInfo(lua_State* L) {
} }
int32_t index = static_cast<int32_t>(lua_tonumber(L, 1)) - 1; int32_t index = static_cast<int32_t>(lua_tonumber(L, 1)) - 1;
if (index < 0 || index > CCharacterSelection::GetNumCharacters()) { if (index < 0 || index >= CCharacterSelection::GetNumCharacters()) {
lua_pushnil(L); // name lua_pushnil(L); // name
lua_pushnil(L); // race lua_pushnil(L); // race
lua_pushnil(L); // class lua_pushnil(L); // class