mirror of
				https://github.com/thunderbrewhq/thunderbrew
				synced 2025-10-30 07:46:03 +03:00 
			
		
		
		
	feat(net): implement NetClient::Disconnect
This commit is contained in:
		
							parent
							
								
									032e9f93d8
								
							
						
					
					
						commit
						41dc426db3
					
				| @ -1174,6 +1174,7 @@ enum NETSTATE { | ||||
|     NS_STATE_3          = 3, | ||||
|     NS_CONNECTING       = 4, | ||||
|     NS_CONNECTED        = 5, | ||||
|     NS_DISCONNECTING    = 6 | ||||
| }; | ||||
| 
 | ||||
| enum WOW_CONN_STATE { | ||||
|  | ||||
| @ -100,7 +100,9 @@ void ClientConnection::Connect() { | ||||
| } | ||||
| 
 | ||||
| int32_t ClientConnection::Disconnect() { | ||||
|     // TODO
 | ||||
|     this->NetClient::Disconnect(); | ||||
|     this->m_connected = 0; | ||||
|     // TODO: WardenClient_Destroy();
 | ||||
|     return 0; | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -98,6 +98,12 @@ void NETEVENTQUEUE::Poll() { | ||||
|     this->m_critSect.Leave(); | ||||
| } | ||||
| 
 | ||||
| void NETEVENTQUEUE::Clear() { | ||||
|     this->m_critSect.Enter(); | ||||
|     this->m_eventQueue.Clear(); | ||||
|     this->m_critSect.Leave(); | ||||
| } | ||||
| 
 | ||||
| void NetClient::AddRef() { | ||||
|     SInterlockedIncrement(&this->m_refCount); | ||||
| } | ||||
| @ -144,6 +150,34 @@ void NetClient::Connect(const char* addrStr) { | ||||
|     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) { | ||||
|     if (this->m_netState != NS_INITIALIZED) { | ||||
|         SErrDisplayAppFatal("Expected (m_netState == NS_INITIALIZED), got %d", this->m_netState); | ||||
|  | ||||
| @ -43,6 +43,7 @@ class NETEVENTQUEUE { | ||||
|             {}; | ||||
|         void AddEvent(EVENTID eventId, void* conn, NetClient* client, const void* data, uint32_t bytes); | ||||
|         void Poll(); | ||||
|         void Clear(); | ||||
| }; | ||||
| 
 | ||||
| class NetClient : public WowConnectionResponse { | ||||
| @ -62,6 +63,7 @@ class NetClient : public WowConnectionResponse { | ||||
|         void AddRef(); | ||||
|         void AuthChallengeHandler(WowConnection* conn, CDataStore* msg); | ||||
|         void Connect(const char* addrStr); | ||||
|         void Disconnect(); | ||||
|         int32_t ConnectInternal(const char* host, uint16_t port); | ||||
|         void DelRef(); | ||||
|         void EnableEncryption(WowConnection* conn, uint8_t* seed, uint8_t seedLen); | ||||
|  | ||||
| @ -55,7 +55,7 @@ int32_t Script_GetCharacterInfo(lua_State* L) { | ||||
|     } | ||||
| 
 | ||||
|     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); // race
 | ||||
|         lua_pushnil(L); // class
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 VDm
						VDm