From f532ab241d6e589822669d761247397941ab3cbd Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 10 Oct 2017 05:48:56 +0300 Subject: [PATCH] [Server] Avoid duplicates of the same player in a cell's loaders --- apps/openmw-mp/Cell.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/openmw-mp/Cell.cpp b/apps/openmw-mp/Cell.cpp index 05ce084ac..207b684a6 100644 --- a/apps/openmw-mp/Cell.cpp +++ b/apps/openmw-mp/Cell.cpp @@ -29,8 +29,17 @@ Cell::Iterator Cell::end() const void Cell::addPlayer(Player *player) { - auto it = find(player->cells.begin(), player->cells.end(), this); - if (it == player->cells.end()) + // Ensure the player hasn't already been added + auto it = find(begin(), end(), player); + + if (it != end()) + { + LOG_APPEND(Log::LOG_INFO, "- Attempt to add %s to Cell %s again was ignored", player->npc.mName.c_str(), getDescription().c_str()); + return; + } + + auto it2 = find(player->cells.begin(), player->cells.end(), this); + if (it2 == player->cells.end()) { LOG_APPEND(Log::LOG_INFO, "- Adding %s to Player %s", getDescription().c_str(), player->npc.mName.c_str());