Reconnect is now possible.
This commit is contained in:
@@ -15,6 +15,7 @@ public:
|
||||
void Receive(Packet & packet, PlayerDefinition & playerDefinition);
|
||||
void Send(Packet & packet, PlayerDefinition & playerDefinition);
|
||||
void Send(Packet & packet);
|
||||
void Disconnect();
|
||||
private:
|
||||
// TCP logic
|
||||
boost::asio::io_service m_IOService;
|
||||
|
||||
@@ -58,13 +58,14 @@ void Client::Update()
|
||||
}
|
||||
|
||||
if (m_IsConnected) {
|
||||
hasServerTimedOut();
|
||||
// Don't send 1 input in 1 packet, bunch em up.
|
||||
if (m_SendInputIntervalMs < (1000 * (std::clock() - m_TimeSinceSentInputs) / (double)CLOCKS_PER_SEC)) {
|
||||
sendInputCommands();
|
||||
m_TimeSinceSentInputs = std::clock();
|
||||
}
|
||||
sendLocalPlayerTransform();
|
||||
|
||||
m_IsConnected = !hasServerTimedOut();
|
||||
}
|
||||
//Network::Update();
|
||||
}
|
||||
@@ -380,7 +381,7 @@ bool Client::hasServerTimedOut()
|
||||
if (timeSincePing > m_TimeoutMs) {
|
||||
// Clear everything and go to menu.
|
||||
LOG_INFO("Server has timed out, returning to menu, Beep Boop.");
|
||||
m_IsConnected = false;
|
||||
m_Reliable.Disconnect();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -302,6 +302,8 @@ void Server::disconnect(PlayerID playerID)
|
||||
e.PlayerID = playerID;
|
||||
m_EventBroker->Publish(e);
|
||||
|
||||
m_ConnectedPlayers[playerID].TCPSocket->shutdown(boost::asio::ip::tcp::socket::shutdown_both);
|
||||
m_ConnectedPlayers[playerID].TCPSocket->close();
|
||||
m_ConnectedPlayers.erase(playerID);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,10 @@ void TCPClient::Connect(std::string playerName, std::string address, int port)
|
||||
|
||||
void TCPClient::Disconnect()
|
||||
{
|
||||
|
||||
m_Socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both);
|
||||
m_Socket->close();
|
||||
m_Socket = nullptr;
|
||||
m_IsConnected = false;
|
||||
}
|
||||
|
||||
void TCPClient::Receive(Packet& packet)
|
||||
@@ -87,6 +90,10 @@ int TCPClient::readBuffer(char* data)
|
||||
|
||||
void TCPClient::Send(Packet & packet)
|
||||
{
|
||||
if (!m_Socket) {
|
||||
LOG_WARNING("TCPClient::Send: Socket is null");
|
||||
return;
|
||||
}
|
||||
packet.UpdateSize();
|
||||
boost::system::error_code error;
|
||||
m_Socket->send(boost::asio::buffer(
|
||||
|
||||
@@ -72,6 +72,11 @@ void TCPServer::Send(Packet & packet)
|
||||
0);
|
||||
}
|
||||
|
||||
void TCPServer::Disconnect()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TCPServer::Receive(Packet & packet, PlayerDefinition & playerDefinition)
|
||||
{
|
||||
int bytesRead = readBuffer(m_ReadBuffer, playerDefinition);
|
||||
|
||||
Reference in New Issue
Block a user