1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-27 13:39:42 +00:00

[Server] Simplify getPlayer methods, add isPlayerExists method

This commit is contained in:
Koncord 2018-07-17 00:29:45 +08:00
parent 193034f09c
commit 1a9bf253f6
2 changed files with 12 additions and 4 deletions

View file

@ -54,9 +54,10 @@ void Players::newPlayer(RakNet::RakNetGUID guid)
Player *Players::getPlayer(RakNet::RakNetGUID guid) Player *Players::getPlayer(RakNet::RakNetGUID guid)
{ {
if (players.count(guid) == 0) auto it = players.find(guid);
if (it == players.end())
return nullptr; return nullptr;
return players[guid]; return it->second;
} }
TPlayers *Players::getPlayers() TPlayers *Players::getPlayers()
@ -123,9 +124,10 @@ int Player::getLoadState()
Player *Players::getPlayer(unsigned short id) Player *Players::getPlayer(unsigned short id)
{ {
if (slots.find(id) == slots.end()) auto it = slots.find(id);
if (it == slots.end())
return nullptr; return nullptr;
return slots[id]; return it->second;
} }
CellController::TContainer *Player::getCells() CellController::TContainer *Player::getCells()
@ -174,3 +176,8 @@ void Player::forEachLoaded(std::function<void(Player *pl, Player *other)> func)
func(this, pl); func(this, pl);
} }
} }
bool Players::isPlayerExists(RakNet::RakNetGUID guid)
{
return players.find(guid) != players.end();
}

View file

@ -34,6 +34,7 @@ public:
static Player *getPlayer(unsigned short id); static Player *getPlayer(unsigned short id);
static TPlayers *getPlayers(); static TPlayers *getPlayers();
static unsigned short getLastPlayerId(); static unsigned short getLastPlayerId();
static bool isPlayerExists(RakNet::RakNetGUID guid);
private: private:
static TPlayers players; static TPlayers players;