[Server] Remove player from Cells when disconnected

This commit is contained in:
Koncord 2017-02-19 22:27:00 +08:00
parent f2ce46ffed
commit 67099e437a
3 changed files with 17 additions and 0 deletions

View file

@ -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) void CellController::update(Player *player)
{ {
for(auto cell : player->cellStateChanges.cellStates) for(auto cell : player->cellStateChanges.cellStates)

View file

@ -32,6 +32,7 @@ public:
void removeCell(Cell *); void removeCell(Cell *);
void removePlayer(Cell *cell, Player *player); void removePlayer(Cell *cell, Player *player);
void deletePlayer(Player *player);
Cell *getCellByXY(int x, int y); Cell *getCellByXY(int x, int y);
Cell *getCellByID(std::string cellid); Cell *getCellByID(std::string cellid);

View file

@ -15,6 +15,8 @@ void Players::deletePlayer(RakNet::RakNetGUID guid)
if (players[guid] != 0) if (players[guid] != 0)
{ {
CellController::get()->deletePlayer(players[guid]);
LOG_APPEND(Log::LOG_INFO, "- Emptying slot %i", LOG_APPEND(Log::LOG_INFO, "- Emptying slot %i",
players[guid]->getId()); players[guid]->getId());