diff options
author | Stijn Buys <ingar@osirion.org> | 2008-05-24 12:49:33 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-05-24 12:49:33 +0000 |
commit | 1af2280ebabbd41c8b77747b6834fefbde0f0e80 (patch) | |
tree | b7501865a383b6789ed755261eb9e1467dd73cd7 /src/core | |
parent | 1b8c92e759adf6605803d86931d349a06f963554 (diff) |
Hail
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/gameserver.cc | 23 | ||||
-rw-r--r-- | src/core/gameserver.h | 3 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index c18b1fa..687623e 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -113,6 +113,29 @@ void GameServer::abort() server_running = false; } +Player *GameServer::find_player(std::string const search) +{ + std::istringstream searchstr(search); + int id = 0; + if (searchstr >> id) { + for (std::list<Player *>:: iterator it = players.begin(); it != players.end(); it++) { + if ((*it)->id() == id) { + return (*it); + } + } + } + + if (search.size() <3) + return 0; + + for (std::list<Player *>:: iterator it = players.begin(); it != players.end(); it++) { + if ((*it)->name().find(search) != std::string::npos) + return (*it); + } + + return 0; +} + void GameServer::list_players(Player *player) { using namespace std; diff --git a/src/core/gameserver.h b/src/core/gameserver.h index d7d6eb8..025ea4d 100644 --- a/src/core/gameserver.h +++ b/src/core/gameserver.h @@ -64,6 +64,9 @@ public: /// a player sends a command to the game server void exec(Player *player, std::string const &cmdline); + /// find the first player who's id or name matches the search string + Player *find_player(std::string const search); + std::list<Player *> players; /*----- static ---------------------------------------------------- */ |