From cb1b7572369eebbd47efc9851afc8446dbe2f08a Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 5 Jul 2008 15:38:59 +0000 Subject: enable Shared functions, rcon API --- src/core/gameserver.cc | 105 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 36 deletions(-) (limited to 'src/core/gameserver.cc') diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index c7a71ff..cd656ed 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -17,14 +17,14 @@ namespace core { -void func_who(Player *player, std::string const &args) +void func_who(std::string const &args) { - server()->list_players(player); + server()->list_players(); } -void func_time(Player *player, std::string const &args) +void func_time(std::string const &args) { - server()->showtime(player); + server()->showtime(); } GameServer *GameServer::server_instance = 0; @@ -113,6 +113,37 @@ void GameServer::abort() server_running = false; } +void GameServer::list_players() +{ + using namespace std; + stringstream msgstr; + int count = 0; + + for (std::list:: iterator it = players.begin(); it != players.end(); it++) { + msgstr.str(""); + con_print << setw(3) << (*it)->id() << aux::spaces((*it)->name(), 24) << std::endl; + count++; + } + + con_print << count << " connected " << aux::plural("player", count) << std::endl; +} + +void GameServer::showtime() +{ + using namespace std; + + int minutes = (int) floorf(server_time / 60.0f); + int seconds = (int) floorf(server_time - (float) minutes* 60.0f); + + int syshours = sys::time() / 3600; + int sysminutes = (sys::time() - syshours * 3600) / 60; + int sysseconds = sys::time() % 60; + + con_print << + "Uptime " << minutes << ":" << setfill('0') << setw(2) << seconds << + " Server localtime " << setfill(' ') << setw(2) << syshours << ":" << setfill('0') << setw(2) << sysminutes << ":" << setw(2) << sysseconds << std::endl; +} + Player *GameServer::find_player(std::string const search) { using aux::lowercase; @@ -138,24 +169,6 @@ Player *GameServer::find_player(std::string const search) return 0; } -void GameServer::list_players(Player *player) -{ - using namespace std; - stringstream msgstr; - int count = 0; - - for (std::list:: iterator it = players.begin(); it != players.end(); it++) { - msgstr.str(""); - msgstr << setw(3) << (*it)->id() << aux::spaces((*it)->name(), 24); - send(player, msgstr.str()); - count++; - } - - msgstr.str(""); - msgstr << count << " connected " << aux::plural("player", count); - send(player, msgstr.str()); -} - void GameServer::say(Player *player, std::string const &message) { if (!message.size()) @@ -179,20 +192,6 @@ void GameServer::say(Player *player, std::string const &message) } } -void GameServer::showtime(Player *player) -{ - int minutes = (int) floorf(server_time / 60.0f); - int seconds = (int) floorf(server_time - (float) minutes* 60.0f); - - int syshours = sys::time() / 3600; - int sysminutes = (sys::time() - syshours * 3600) / 60; - int sysseconds = sys::time() % 60; - - std::stringstream str; - str << "Uptime " << minutes << ":" << seconds << " Local time " << syshours << ":" << sysminutes << ":" << sysseconds; - send(player, str.str()); -} - void GameServer::broadcast(std::string const & message, Player *ignore_player) { // send to application @@ -242,6 +241,25 @@ void GameServer::send(Player *player, std::string message) } } +void GameServer::send_rcon(Player *player, std::string message) +{ + // send to application + if (player->id() == localplayer()->id()) { + con_print << message << std::endl; + } + + // send to remote clients + if (server_network) { + NetClient *client = server_network->find_client(player); + if (client) { + std::string netmessage("msg rcon "); + netmessage.append(message); + netmessage += '\n'; + server_network->send(client, netmessage); + } + } +} + void GameServer::send_sound(Player *player, std::string sound) { if (player->id() == localplayer()->id()) { @@ -280,6 +298,21 @@ void GameServer::exec(Player *player, std::string const & cmdline) //con_debug << "About to execute " << function->name() << " " << args << "'\n"; function->exec(player, args); return; + } else if ((function->flags() & Func::Shared) == Func::Shared) { + + // enable rcon buffering + sys::ConsoleInterface::instance()->buffer_rcon(true); + function->exec(args); + + char line[MAXCMDSIZE]; + + while(sys::ConsoleInterface::instance()->buffer().getline(line, MAXCMDSIZE-1)) { + send_rcon(player, std::string(line)); + } + + // disable rcon buffering + sys::ConsoleInterface::instance()->buffer_rcon(false); + return; } } -- cgit v1.2.3