diff options
author | Stijn Buys <ingar@osirion.org> | 2012-11-18 17:06:51 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2012-11-18 17:06:51 +0000 |
commit | 03ca8502bc9f54b85edfdf69a8b94a40613be892 (patch) | |
tree | fda322d108389b93052c2d40d675b5f798315c63 /src/core | |
parent | 4271b3007fe88c812f7057716aa257cd499e940f (diff) |
Added a method to find players by id.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/gameinterface.cc | 14 | ||||
-rw-r--r-- | src/core/gameinterface.h | 3 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc index 898d97f..e7d7a31 100644 --- a/src/core/gameinterface.cc +++ b/src/core/gameinterface.cc @@ -178,6 +178,20 @@ void GameInterface::abort() { game_running = false; } +Player *GameInterface::find_player(const int playerid) +{ + if (playerid == 0) { + return 0; + } + + for (std::list<Player *>:: iterator it = game_players.begin(); it != game_players.end(); it++) { + if ((*it)->id() == playerid) { + return (*it); + } + } + return 0; +} + Player *GameInterface::find_player(const std::string &search) { using aux::lowercase; diff --git a/src/core/gameinterface.h b/src/core/gameinterface.h index d99903f..f118ad3 100644 --- a/src/core/gameinterface.h +++ b/src/core/gameinterface.h @@ -49,6 +49,9 @@ public: /// find the first player who's id or name matches the search string Player *find_player(const std::string &search); + + /// find a player id + Player *find_player(const int playerid); /// show a list of connected players void list_players(); |