Network - Added reconnect with the last address you connected on.

This commit is contained in:
Pontus Fransson 2014-02-19 14:49:20 +01:00
parent f1cd73425c
commit 717e95bdfe
5 changed files with 13 additions and 17 deletions

View File

@ -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;
}

View File

@ -157,8 +157,6 @@ std::vector<SmartPointer<ObjectTypeHeader>> 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;

View File

@ -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)
{

View File

@ -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)

View File

@ -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);