[ServerCommandHandler] Now deletes ServerPlayer instance on disconnection.

This commit is contained in:
Quentin Bazin 2020-02-24 17:20:49 +09:00
parent 879dc28eb2
commit 47d57f7fc3
2 changed files with 20 additions and 14 deletions

View File

@ -128,22 +128,24 @@ void Server::handleClientMessages() {
// DEBUG("TCP message received:", Network::commandToString(command)); // DEBUG("TCP message received:", Network::commandToString(command));
if (command == Network::Command::ClientDisconnect) { if (m_isRunning) {
m_selector.remove(*client.tcpSocket); for (auto &it : m_commands) {
m_info.removeClient(client.id);
// if (m_info.clients().size() == 0) {
// // m_tcpListener.close();
// m_isRunning = false;
// }
--i;
}
if (m_isRunning)
for (auto &it : m_commands)
if (command == it.first) if (command == it.first)
it.second(client, packet); it.second(client, packet);
if (command == Network::Command::ClientDisconnect) {
m_selector.remove(*client.tcpSocket);
m_info.removeClient(client.id);
// if (m_info.clients().size() == 0) {
// // m_tcpListener.close();
// m_isRunning = false;
// }
--i;
}
}
}
} }
} }
} }

View File

@ -113,6 +113,10 @@ void ServerCommandHandler::setupCallbacks() {
// m_world.sendSpawnData(client, player); // m_world.sendSpawnData(client, player);
}); });
m_server.setCommandCallback(Network::Command::ClientDisconnect, [this](Client &client, sf::Packet &) {
m_players.erase(client.id);
});
m_server.setCommandCallback(Network::Command::ChunkRequest, [this](Client &client, sf::Packet &packet) { m_server.setCommandCallback(Network::Command::ChunkRequest, [this](Client &client, sf::Packet &packet) {
s32 cx, cy, cz; s32 cx, cy, cz;
packet >> cx >> cy >> cz; packet >> cx >> cy >> cz;