diff options
author | Stijn Buys <ingar@osirion.org> | 2009-01-11 12:15:22 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2009-01-11 12:15:22 +0000 |
commit | 20e8e4c0fb1262a25c2491679da4587d264208a2 (patch) | |
tree | c836dc74bfb82088c70bdd636dfb1f236043f58d /src/core/gameinterface.cc | |
parent | 7082a5a1b7258580c698a09cf9fb8bec0bc97472 (diff) |
core::Player interface updates
Diffstat (limited to 'src/core/gameinterface.cc')
-rw-r--r-- | src/core/gameinterface.cc | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc index c566e41..1695fb0 100644 --- a/src/core/gameinterface.cc +++ b/src/core/gameinterface.cc @@ -23,7 +23,18 @@ namespace core void func_list_players(std::string const &args) { - game()->list_players(); + + if (args.size()) { + Player *player = game()->find_player(args); + if (!player) { + con_print << "^BPlayer '" + args + "^B' not found"; + return; + } else { + player->print(); + } + } else { + game()->list_players(); + } } const float MIN_DELTA = 10e-10; @@ -120,15 +131,45 @@ void GameInterface::clear() game_players.clear(); } + +Player *GameInterface::find_player(const std::string &search) +{ + using aux::lowercase; + + std::istringstream searchstr(search); + int id = 0; + if (searchstr >> id) { + for (std::list<Player *>:: iterator it = game_players.begin(); it != game_players.end(); it++) { + if ((*it)->id() == id) { + return (*it); + } + } + } + + if (search.size() <3) + return 0; + + for (std::list<Player *>:: iterator it = game_players.begin(); it != game_players.end(); it++) { + if (aux::text_strip_lowercase((*it)->name()).find(lowercase(search)) != std::string::npos) + return (*it); + } + + return 0; +} + void GameInterface::list_players() { using namespace std; - stringstream msgstr; int count = 0; for (Players::iterator it = game_players.begin(); it != game_players.end(); it++) { - msgstr.str(""); - con_print << setw(3) << (*it)->id() << setw(5) << (*it)->ping() << aux::pad_left((*it)->name(), 24) << std::endl; + const Player *player = (*it); + con_print << " " + << "id^B" << setw(5) << player->id() << " " + << aux::pad_left(player->name(), 24) << "^N " + << "ping^B" << setw(5) << player->ping() << "^N " + << "level^B" << setw(3) << player->level() << "^N" + << std::endl; count++; } |