From 1af2280ebabbd41c8b77747b6834fefbde0f0e80 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 24 May 2008 12:49:33 +0000 Subject: Hail --- src/core/gameserver.cc | 23 +++++++++++++++++++++++ src/core/gameserver.h | 3 +++ src/game/game.cc | 23 +++++++++++++++++++---- 3 files changed, 45 insertions(+), 4 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:: iterator it = players.begin(); it != players.end(); it++) { + if ((*it)->id() == id) { + return (*it); + } + } + } + + if (search.size() <3) + return 0; + + for (std::list:: 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 players; /*----- static ---------------------------------------------------- */ diff --git a/src/game/game.cc b/src/game/game.cc index ea72ce0..79c9040 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -99,16 +99,31 @@ void func_buy(core::Player *player, std::string const &args) core::server()->broadcast("^B" + player->name() + " ^Bpurchased " + aux::article(shipmodel->name())); player->player_dirty = true; } else { - core::server()->send(player, "Usage: buy <" + helpstr + "^N>"); + core::server()->send(player, "Usage: buy [" + helpstr + "^N]"); } } /// a player sends standard hails void func_hail(core::Player *player, std::string const &args) { - core::server()->send(player, "You broadcast a standard standard hail."); - core::server()->broadcast("^B" + player->name() + " ^Bbroadcasts a standard hail!", player); - core::server()->broadcast_sound("com/hail"); + std::string target; + std::istringstream is(args); + if (!(is >> target)) { + core::server()->send(player, "Usage: hail [player]"); + return; + } + + core::Player *targetplayer = core::server()->find_player(target); + if (!targetplayer) { + core::server()->send(player, "Player " + target + "^N not found."); + return; + } + + core::server()->send(player, "^BYou hail " + targetplayer->name() + "^B."); + core::server()->send_sound(player, "com/hail"); + + core::server()->send(targetplayer, "^B" + player->name() + "^B hails you!"); + core::server()->send_sound(targetplayer, "com/hail"); } /*----- Game ------------------------------------------------------ */ -- cgit v1.2.3