From c12c8bf6057130ab0cfb873b819372c06c6bd3b1 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Wed, 22 Nov 2023 03:28:59 -0300 Subject: [PATCH] fix: relogin with different protocols --- src/creatures/players/player.hpp | 4 ++++ src/server/network/protocol/protocolgame.cpp | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 6e3ed43b90d..9757717e675 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -344,6 +344,10 @@ class Player final : public Creature, public Cylinder, public Bankable { operatingSystem = clientos; } + bool isOldProtocol() { + return client && client->oldProtocol; + } + uint32_t getProtocolVersion() const { if (!client) { return 0; diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index dc6cea87b90..c12797d1a29 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -469,6 +469,8 @@ void ProtocolGame::login(const std::string &name, uint32_t accountId, OperatingS writeToOutputBuffer(opcodeMessage); } + g_logger().debug("Player logging in in version '{}' and oldProtocol '{}'", getVersion(), oldProtocol); + // dispatcher thread std::shared_ptr foundPlayer = g_game().getPlayerUniqueLogin(name); if (!foundPlayer) { @@ -734,6 +736,11 @@ void ProtocolGame::onRecvFirstMessage(NetworkMessage &msg) { std::shared_ptr foundPlayer = g_game().getPlayerUniqueLogin(characterName); if (foundPlayer && foundPlayer->client) { + if (foundPlayer->getProtocolVersion() != getVersion() && foundPlayer->isOldProtocol() != oldProtocol) { + disconnectClient(fmt::format("You are already logged in using protocol '{}'. Please log out from the other session to connect here.", foundPlayer->getProtocolVersion())); + return; + } + foundPlayer->client->disconnectClient("You are already connected through another client. Please use only one client at a time!"); }