fixed some error handling in TCPClient.
This commit is contained in:
@@ -272,7 +272,7 @@ void Server::parseTCPConnect(Packet & packet)
|
|||||||
m_ConnectedPlayers.at(playerID).TCPPort = m_Port;
|
m_ConnectedPlayers.at(playerID).TCPPort = m_Port;
|
||||||
|
|
||||||
LOG_INFO("parseTCPConnect: Spectator \"%s\" connected on IP: %s", m_ConnectedPlayers.at(playerID).Name.c_str(),
|
LOG_INFO("parseTCPConnect: Spectator \"%s\" connected on IP: %s", m_ConnectedPlayers.at(playerID).Name.c_str(),
|
||||||
m_ConnectedPlayers.at(playerID).TCPAddress);
|
m_ConnectedPlayers.at(playerID).TCPAddress.to_string().c_str());
|
||||||
|
|
||||||
// Send a message to the player that connected
|
// Send a message to the player that connected
|
||||||
Packet connnectPacket(MessageType::Connect, m_ConnectedPlayers.at(playerID).PacketID);
|
Packet connnectPacket(MessageType::Connect, m_ConnectedPlayers.at(playerID).PacketID);
|
||||||
|
|||||||
@@ -19,17 +19,6 @@ void TCPClient::Connect(std::string playerName, std::string address, int port)
|
|||||||
Send(packet);
|
Send(packet);
|
||||||
LOG_INFO("Connect message sent again!");
|
LOG_INFO("Connect message sent again!");
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
boost::system::error_code error = boost::asio::error::host_not_found;
|
|
||||||
m_Socket->connect(m_Endpoint, error);
|
|
||||||
if (!error) {
|
|
||||||
m_IsConnected = true;
|
|
||||||
Packet packet(MessageType::Connect, m_SendPacketID);
|
|
||||||
packet.WriteString(playerName);
|
|
||||||
Send(packet);
|
|
||||||
LOG_INFO("Connect message sent!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (!m_IsConnected) {
|
else if (!m_IsConnected) {
|
||||||
boost::system::error_code error = boost::asio::error::host_not_found;
|
boost::system::error_code error = boost::asio::error::host_not_found;
|
||||||
@@ -46,6 +35,11 @@ void TCPClient::Connect(std::string playerName, std::string address, int port)
|
|||||||
Send(packet);
|
Send(packet);
|
||||||
LOG_INFO("Connect message sent!");
|
LOG_INFO("Connect message sent!");
|
||||||
}
|
}
|
||||||
|
// If error
|
||||||
|
else {
|
||||||
|
m_Socket->close();
|
||||||
|
m_Socket = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user