Skip to content

Commit

Permalink
fix: block re-login with different protocols (#1877)
Browse files Browse the repository at this point in the history
Resolves #1668
  • Loading branch information
dudantas authored Nov 22, 2023
1 parent 8e2f213 commit ac056e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Player> foundPlayer = g_game().getPlayerUniqueLogin(name);
if (!foundPlayer) {
Expand Down Expand Up @@ -734,6 +736,11 @@ void ProtocolGame::onRecvFirstMessage(NetworkMessage &msg) {

std::shared_ptr<Player> 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!");
}

Expand Down

0 comments on commit ac056e7

Please sign in to comment.