From 03ca8502bc9f54b85edfdf69a8b94a40613be892 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 18 Nov 2012 17:06:51 +0000 Subject: Added a method to find players by id. --- src/core/gameinterface.cc | 14 ++++++++++++++ src/core/gameinterface.h | 3 +++ 2 files changed, 17 insertions(+) (limited to 'src/core') 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:: 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(); -- cgit v1.2.3