Removed Tags file
Updated TODO file TcpClient: Added parameterless contructor, id is now -2 by default which is invalid, Added SendBytes method for C style arrays TcpServer: Added 2 CloseSocket function, one for TcpClient and another one for id, also added GetClientByID client is now declared on the stack in VoidNetClient Made Serializer code smaller, still need to integrate a compressor
This commit is contained in:
@ -164,6 +164,8 @@ void TcpServer::SendMessage(const NetworkMessage & message)
|
||||
}
|
||||
case Server: // this will only send the message to the server
|
||||
{
|
||||
if (message.tag == DISCONNECT)
|
||||
CloseSocket(message.sender);
|
||||
OnMessage(message);
|
||||
break;
|
||||
}
|
||||
@ -241,3 +243,31 @@ void TcpServer::AcceptConnection(TcpClient & client)
|
||||
Handshake handshake(client.GetID(), ConnectionCode::Accept);
|
||||
client.SendBytes(Handshake::EncodeHandshake(handshake));
|
||||
}
|
||||
|
||||
void TcpServer::CloseSocket(TcpClient & client)
|
||||
{
|
||||
NetworkMessage message;
|
||||
message.sender = -1;
|
||||
message.distribution_mode = ID;
|
||||
message.destination_id = client.GetID();
|
||||
message.tag = DISCONNECT;
|
||||
SendMessage(message);
|
||||
clients.erase(std::remove(clients.begin(), clients.end(), client), clients.end());
|
||||
}
|
||||
|
||||
void TcpServer::CloseSocket(uint16 id)
|
||||
{
|
||||
TcpClient client = GetClientByID(id);
|
||||
if (client.GetID() != -2)
|
||||
CloseSocket(client);
|
||||
}
|
||||
|
||||
const TcpClient & TcpServer::GetClientByID(uint16 id)
|
||||
{
|
||||
for (std::vector<TcpClient>::iterator it = clients.begin(); it != clients.end(); ++it)
|
||||
{
|
||||
if ((*it).GetID() == id)
|
||||
return *it;
|
||||
}
|
||||
return TcpClient();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user