Skip to content

Commit

Permalink
Server: Don't rename existing player if its session is disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLynix committed Jul 19, 2024
1 parent 013e578 commit 7b614c9
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/ServerLib/ServerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,21 @@ namespace tsom
// TODO: Override the player session with this one
if (ServerPlayer* player = FindPlayerByUuid(uuid))
player->GetSession()->Disconnect(DisconnectionType::Kick);

// Check if a player already has this nickname and rename it if it's the case
if (ServerPlayer* player = FindPlayerByNickname(nickname))
else
{
std::string newNickname;
unsigned int counter = 2;
do
// Check if a player already has this nickname and rename it if it's the case
if (ServerPlayer* player = FindPlayerByNickname(nickname))
{
newNickname = fmt::format("{}_{}", nickname, counter++);
} while (FindPlayerByNickname(newNickname) != nullptr);
std::string newNickname;
unsigned int counter = 2;
do
{
newNickname = fmt::format("{}_{}", nickname, counter++);
} while (FindPlayerByNickname(newNickname) != nullptr);

player->UpdateNickname(newNickname);
m_pendingPlayerRename.push_back({ player->GetPlayerIndex(), std::move(newNickname) });
player->UpdateNickname(newNickname);
m_pendingPlayerRename.push_back({ player->GetPlayerIndex(), std::move(newNickname) });
}
}

std::size_t playerIndex;
Expand Down

0 comments on commit 7b614c9

Please sign in to comment.