From a3a341fee64843985be9c7a10c105ab65d2ac416 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 10 Mar 2018 22:18:33 +0200 Subject: [PATCH] [Server] Reimplement 4ebfcc4a21051702425c9f0ad9a710814e7cca90 for 0.6 --- apps/openmw-mp/Networking.cpp | 3 ++- apps/openmw-mp/Player.cpp | 16 ++++++++++++---- apps/openmw-mp/Player.hpp | 3 ++- .../processors/player/ProcessorHandshake.hpp | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 7a0339c81..9c7eb949f 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -117,7 +117,8 @@ void Networking::processPlayerPacket(RakNet::Packet *packet) if (!player->isHandshaked()) { LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Have not completed handshake with player %d", player->getId()); - //KickPlayer(player->guid); + if (player->handshakeAttempts() > 5) + kickPlayer(player->guid); return; } diff --git a/apps/openmw-mp/Player.cpp b/apps/openmw-mp/Player.cpp index 4dea0b4a6..18e51a89a 100644 --- a/apps/openmw-mp/Player.cpp +++ b/apps/openmw-mp/Player.cpp @@ -8,6 +8,8 @@ TPlayers Players::players; TSlots Players::slots; +using namespace std; + void Players::deletePlayer(RakNet::RakNetGUID guid) { LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Deleting player with guid %lu", guid.g); @@ -69,7 +71,7 @@ unsigned short Players::getLastPlayerId() Player::Player(RakNet::RakNetGUID guid) : BasePlayer(guid) { - handshakeState = false; + handshakeCounter = 0; loadState = NOTLOADED; } @@ -88,16 +90,22 @@ void Player::setId(unsigned short id) this->id = id; } +bool Player::isHandshaked() +{ + return handshakeCounter == numeric_limits::max(); +} + void Player::setHandshake() { - handshakeState = true; + handshakeCounter = numeric_limits::max(); } -bool Player::isHandshaked() +int Player::handshakeAttempts() { - return handshakeState; + return handshakeCounter++; } + void Player::setLoadState(int state) { loadState = state; diff --git a/apps/openmw-mp/Player.hpp b/apps/openmw-mp/Player.hpp index 8dfd23c0f..aa52d7574 100644 --- a/apps/openmw-mp/Player.hpp +++ b/apps/openmw-mp/Player.hpp @@ -58,6 +58,7 @@ public: void setId(unsigned short id); bool isHandshaked(); + int handshakeAttempts(); void setHandshake(); void setLoadState(int state); @@ -72,7 +73,7 @@ public: private: CellController::TContainer cells; - bool handshakeState; + int handshakeCounter; int loadState; }; diff --git a/apps/openmw/mwmp/processors/player/ProcessorHandshake.hpp b/apps/openmw/mwmp/processors/player/ProcessorHandshake.hpp index 78652b225..abbf9431c 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorHandshake.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorHandshake.hpp @@ -19,7 +19,7 @@ namespace mwmp virtual void Do(PlayerPacket &packet, BasePlayer *player) { - packet.setPlayer(getLocalPlayer()); // player is 0 because myGuid will be setted after ProcessUserMyID + packet.setPlayer(getLocalPlayer()); // player is 0 because myGuid will be set after ProcessUserMyID packet.Send(serverAddr); } };