From 717e95bdfe6b87cecf83ac68ab2a9c26f27a19cf Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 19 Feb 2014 14:49:20 +0100 Subject: [PATCH] Network - Added reconnect with the last address you connected on. --- .../GameClientState/LanMenuState.cpp | 3 --- Code/Game/LevelLoader/LevelParser.cpp | 2 -- Code/Game/LevelLoader/ParseFunctions.cpp | 3 +-- Code/Network/NetworkAPI/NetworkClient.cpp | 18 ++++++++++-------- .../Network/NetworkDependencies/Connection.cpp | 4 ++-- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 7bd709cc..8c096617 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -126,9 +126,6 @@ void LanMenuState::ChangeState( ClientState next ) // attempt to connect to lobby if( !this->privData->nwClient->Connect(this->privData->connectPort, (*this->privData->connectIP)[0]) ) return; - //this->privData->nwClient->Disconnect(); - //if( !this->privData->nwClient->Reconnect() ) - //return; break; default: break; } diff --git a/Code/Game/LevelLoader/LevelParser.cpp b/Code/Game/LevelLoader/LevelParser.cpp index 0c450f71..5f5a5341 100644 --- a/Code/Game/LevelLoader/LevelParser.cpp +++ b/Code/Game/LevelLoader/LevelParser.cpp @@ -157,8 +157,6 @@ std::vector> LevelParser::Parse(std::string filen break; } //this is a hotfix, fix so you only load the relevant data when the file is updated - - default: //Couldn't find specialType break; diff --git a/Code/Game/LevelLoader/ParseFunctions.cpp b/Code/Game/LevelLoader/ParseFunctions.cpp index b6b57d83..09adb298 100644 --- a/Code/Game/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/LevelLoader/ParseFunctions.cpp @@ -152,10 +152,9 @@ namespace GameLogic start = 0; LevelLoaderInternal::FormatVersion version; memcpy(&version, &buf[0], sizeof(version)); - start += 4; + start += 8; memcpy(&volume.geoType, &buf[start], sizeof(volume.geoType)); - start += sizeof(volume.geoType); switch(volume.geoType) { diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index 5bd10165..fc561845 100644 --- a/Code/Network/NetworkAPI/NetworkClient.cpp +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -290,9 +290,12 @@ bool NetworkClient::Connect(ConnectionInfo& socket) bool NetworkClient::Connect(unsigned short port, const char serverIP[]) { - if(this->IsConnected()) return false; - if(this->privateData) return false; - if(!this->privateData) this->privateData = new PrivateData(); + //Return true if you are already connected. + if(this->IsConnected()) + return true; + + if(!this->privateData) + this->privateData = new PrivateData(); int result = this->privateData->connection.Connect(port, serverIP, false); @@ -319,10 +322,10 @@ bool NetworkClient::Connect(unsigned short port, std::wstring serverIP) bool NetworkClient::Reconnect() { + //Return true if you are already connected. if(this->IsConnected()) - return false; - //if(this->privateData) - //return false; + return true; + if(!this->privateData) this->privateData = new PrivateData(); int result = this->privateData->connection.Reconnect(); @@ -342,11 +345,10 @@ void NetworkClient::Disconnect() { if(!privateData) return; - privateData->thread.Terminate(); + privateData->thread.Stop(); privateData->connection.Disconnect(); this->privateData->sendQueue.Clear(); this->privateData->recieveQueue.Clear(); - } void NetworkClient::Send(CustomProtocolObject& protocol) diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index a9abf75c..2cd992a2 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -91,14 +91,14 @@ int Connection::Reconnect() if(this->socket == -1 || this->socket == 0) InitiateSocket(); struct hostent *hostEnt; - if((hostEnt = gethostbyname(lastConnectAddr.c_str())) == NULL) + if((hostEnt = gethostbyname(this->lastConnectAddr.c_str())) == NULL) { return WSAGetLastError(); } struct sockaddr_in server; server.sin_family = AF_INET; - server.sin_port = htons(lastConnectPort); + server.sin_port = htons(this->lastConnectPort); server.sin_addr.s_addr = *(unsigned long*) hostEnt->h_addr; SetBlockingMode(true);