diff --git a/src/network/protocols/game_protocol.cpp b/src/network/protocols/game_protocol.cpp index e81da7f0e..dd379a06c 100644 --- a/src/network/protocols/game_protocol.cpp +++ b/src/network/protocols/game_protocol.cpp @@ -184,7 +184,13 @@ void GameProtocol::handleControllerAction(Event *event) //rewind_delta = not_rewound - cur_ticks; } uint8_t kart_id = data.getUInt8(); - assert(kart_id < World::getWorld()->getNumKarts()); + if (NetworkConfig::get()->isServer() && + !event->getPeer()->availableKartID(kart_id)) + { + Log::warn("GameProtocol", "Wrong kart id %d from %s.", + kart_id, event->getPeer()->getAddress().toString().c_str()); + return; + } PlayerAction action = (PlayerAction)(data.getUInt8()); int value = data.getUInt32(); diff --git a/src/network/protocols/server_lobby.cpp b/src/network/protocols/server_lobby.cpp index 40e3c0a3e..7444d4e5b 100644 --- a/src/network/protocols/server_lobby.cpp +++ b/src/network/protocols/server_lobby.cpp @@ -496,13 +496,17 @@ void ServerLobby::asynchronousUpdate() m_game_setup->sortPlayersForGrandPrix(); m_game_setup->sortPlayersForTeamGame(); auto players = m_game_setup->getConnectedPlayers(); + for (auto& player : players) + player->getPeer()->clearAvailableKartIDs(); NetworkString* load_world = getNetworkString(); load_world->setSynchronous(true); load_world->addUInt8(LE_LOAD_WORLD).encodeString(std::get<0>(result)) .addUInt8(std::get<1>(result)).addUInt8(std::get<2>(result)) .addUInt8((uint8_t)players.size()); - for (auto player : players) + for (unsigned i = 0; i < players.size(); i++) { + std::shared_ptr& player = players[i]; + player->getPeer()->addAvailableKartID(i); load_world->encodeString(player->getName()) .addUInt32(player->getHostId()) .addFloat(player->getDefaultKartColor()) diff --git a/src/network/stk_peer.hpp b/src/network/stk_peer.hpp index fbf6c45f4..a6b931ef3 100644 --- a/src/network/stk_peer.hpp +++ b/src/network/stk_peer.hpp @@ -89,6 +89,8 @@ protected: std::atomic m_average_ping; + std::set m_available_kart_ids; + public: STKPeer(ENetPeer *enet_peer, STKHost* host, uint32_t host_id); // ------------------------------------------------------------------------ @@ -181,6 +183,13 @@ public: bool isWaitingForGame() const { return m_waiting_for_game.load(); } // ------------------------------------------------------------------------ bool isDisconnected() const { return m_disconnected.load(); } + // ------------------------------------------------------------------------ + void clearAvailableKartIDs() { m_available_kart_ids.clear(); } + // ------------------------------------------------------------------------ + void addAvailableKartID(unsigned id) { m_available_kart_ids.insert(id); } + // ------------------------------------------------------------------------ + bool availableKartID(unsigned id) + { return m_available_kart_ids.find(id) != m_available_kart_ids.end(); } }; // STKPeer #endif // STK_PEER_HPP