Merge branch 'GameClient' of https://github.com/dean11/Danbias into GameServer
This commit is contained in:
commit
efe29b7a18
|
@ -33,6 +33,8 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
|
|||
Loader loader;
|
||||
char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize);
|
||||
|
||||
if(buffer)
|
||||
{
|
||||
//Read format version
|
||||
LevelLoaderInternal::FormatVersion levelFormatVersion;
|
||||
ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion));
|
||||
|
@ -213,6 +215,7 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return objects;
|
||||
}
|
||||
|
|
|
@ -317,6 +317,11 @@ bool NetworkClient::Connect(unsigned short port, std::wstring serverIP)
|
|||
return this->Connect(port, ip.c_str());
|
||||
}
|
||||
|
||||
bool NetworkClient::Reconnect()
|
||||
{
|
||||
return this->privateData->connection.Reconnect();
|
||||
}
|
||||
|
||||
void NetworkClient::Disconnect()
|
||||
{
|
||||
if(!privateData) return;
|
||||
|
|
|
@ -93,6 +93,11 @@ namespace Oyster
|
|||
*/
|
||||
bool Connect(unsigned short port, std::wstring serverIP);
|
||||
|
||||
/**Tries to connect with the same port and ip it earlier used for Connect.
|
||||
*
|
||||
*/
|
||||
bool Reconnect();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -58,6 +58,9 @@ int Connection::Connect(unsigned short port , const char serverName[], bool bloc
|
|||
{
|
||||
if(this->socket == -1 || this->socket == 0) InitiateSocket();
|
||||
|
||||
lastConnectPort = port;
|
||||
lastConnectAddr = serverName;
|
||||
|
||||
struct hostent *hostEnt;
|
||||
if((hostEnt = gethostbyname(serverName)) == NULL)
|
||||
{
|
||||
|
@ -83,6 +86,37 @@ int Connection::Connect(unsigned short port , const char serverName[], bool bloc
|
|||
return 0;
|
||||
}
|
||||
|
||||
int Connection::Reconnect()
|
||||
{
|
||||
if(this->socket == -1 || this->socket == 0) InitiateSocket();
|
||||
|
||||
struct hostent *hostEnt;
|
||||
if((hostEnt = gethostbyname(lastConnectAddr.c_str())) == NULL)
|
||||
{
|
||||
return WSAGetLastError();
|
||||
}
|
||||
|
||||
struct sockaddr_in server;
|
||||
server.sin_family = AF_INET;
|
||||
server.sin_port = htons(lastConnectPort);
|
||||
server.sin_addr.s_addr = *(unsigned long*) hostEnt->h_addr;
|
||||
|
||||
SetBlockingMode(true);
|
||||
|
||||
if(connect(this->socket, (sockaddr*)&server, sizeof(server)) == SOCKET_ERROR)
|
||||
{
|
||||
return WSAGetLastError();
|
||||
}
|
||||
|
||||
closed = false;
|
||||
stillSending = true;
|
||||
|
||||
SetBlockingMode(blocking);
|
||||
|
||||
//connection succesfull!
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Connection::InitiateServer(unsigned short port)
|
||||
{
|
||||
int errorCode = 0;
|
||||
|
|
|
@ -28,6 +28,7 @@ namespace Oyster
|
|||
virtual int Disconnect();
|
||||
virtual int Connect(ConnectionInfo info, bool blocking = false);
|
||||
virtual int Connect(unsigned short port , const char serverName[], bool blocking = false);
|
||||
virtual int Reconnect();
|
||||
|
||||
virtual ConnectionInfo Listen();
|
||||
|
||||
|
@ -47,6 +48,11 @@ namespace Oyster
|
|||
bool stillSending;
|
||||
bool closed;
|
||||
std::string addr;
|
||||
|
||||
std::string lastConnectAddr;
|
||||
unsigned short lastConnectPort;
|
||||
|
||||
bool blocking;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,9 @@ namespace Oyster
|
|||
//(servers uses Listen instead of connect)
|
||||
virtual int Connect( unsigned short port, const char serverName[] ) { return false; };
|
||||
|
||||
//Tries to connect with the same port and ip used for Connect.
|
||||
virtual int Reconnect() = 0;
|
||||
|
||||
//Disconnects the client or server TODO: optimize!
|
||||
virtual int Disconnect() = 0;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue