From 67099e437a951746d6cf0492d2a018ddecd312ed Mon Sep 17 00:00:00 2001 From: Koncord Date: Sun, 19 Feb 2017 22:27:00 +0800 Subject: [PATCH] [Server] Remove player from Cells when disconnected --- apps/openmw-mp/Cell.cpp | 14 ++++++++++++++ apps/openmw-mp/Cell.hpp | 1 + apps/openmw-mp/Player.cpp | 2 ++ 3 files changed, 17 insertions(+) diff --git a/apps/openmw-mp/Cell.cpp b/apps/openmw-mp/Cell.cpp index 6d27ab5f9..7341504e7 100644 --- a/apps/openmw-mp/Cell.cpp +++ b/apps/openmw-mp/Cell.cpp @@ -140,6 +140,20 @@ void CellController::removePlayer(Cell *cell, Player *player) } } +void CellController::deletePlayer(Player *player) +{ + for_each (cells.begin(), cells.end(), [&player](Cell *cell) { + for (auto it = cell->begin(); it != cell->end(); ++it) + { + if (*it == player) + { + cell->players.erase(it); + break; + } + } + }); +} + void CellController::update(Player *player) { for(auto cell : player->cellStateChanges.cellStates) diff --git a/apps/openmw-mp/Cell.hpp b/apps/openmw-mp/Cell.hpp index 54ff89e22..27d6ddba1 100644 --- a/apps/openmw-mp/Cell.hpp +++ b/apps/openmw-mp/Cell.hpp @@ -32,6 +32,7 @@ public: void removeCell(Cell *); void removePlayer(Cell *cell, Player *player); + void deletePlayer(Player *player); Cell *getCellByXY(int x, int y); Cell *getCellByID(std::string cellid); diff --git a/apps/openmw-mp/Player.cpp b/apps/openmw-mp/Player.cpp index 33edfd4f5..22a1cd994 100644 --- a/apps/openmw-mp/Player.cpp +++ b/apps/openmw-mp/Player.cpp @@ -15,6 +15,8 @@ void Players::deletePlayer(RakNet::RakNetGUID guid) if (players[guid] != 0) { + CellController::get()->deletePlayer(players[guid]); + LOG_APPEND(Log::LOG_INFO, "- Emptying slot %i", players[guid]->getId());