diff options
author | Stijn Buys <ingar@osirion.org> | 2008-07-05 15:38:59 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-07-05 15:38:59 +0000 |
commit | cb1b7572369eebbd47efc9851afc8446dbe2f08a (patch) | |
tree | 8e3d7849bce4eba6d80df575e6b01653819efef3 | |
parent | e5aada2bf01e51753829215c0a3035aa8bd8135a (diff) |
enable Shared functions, rcon API
-rw-r--r-- | osirion.kdevelop.pcs | bin | 765753 -> 765753 bytes | |||
-rw-r--r-- | osirion.kdevses | 33 | ||||
-rw-r--r-- | src/core/gameserver.cc | 105 | ||||
-rw-r--r-- | src/core/gameserver.h | 15 | ||||
-rw-r--r-- | src/core/netconnection.cc | 5 | ||||
-rw-r--r-- | src/server/console.cc | 3 | ||||
-rw-r--r-- | src/sys/consoleinterface.cc | 14 | ||||
-rw-r--r-- | src/sys/consoleinterface.h | 9 |
8 files changed, 112 insertions, 72 deletions
diff --git a/osirion.kdevelop.pcs b/osirion.kdevelop.pcs Binary files differindex 2dbc80c..965f53d 100644 --- a/osirion.kdevelop.pcs +++ b/osirion.kdevelop.pcs diff --git a/osirion.kdevses b/osirion.kdevses index a84fe9f..640c7bb 100644 --- a/osirion.kdevses +++ b/osirion.kdevses @@ -1,37 +1,10 @@ <?xml version = '1.0' encoding = 'UTF-8'?> <!DOCTYPE KDevPrjSession> <KDevPrjSession> - <DocsAndViews NumberOfDocuments="10" > - <Doc0 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/server/server.cc" > - <View0 Encoding="" line="0" Type="Source" /> + <DocsAndViews NumberOfDocuments="1" > + <Doc0 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/server/console.cc" > + <View0 Encoding="" line="322" Type="Source" /> </Doc0> - <Doc1 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/server/console.cc" > - <View0 Encoding="" line="23" Type="Source" /> - </Doc1> - <Doc2 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/commandbuffer.cc" > - <View0 Encoding="" line="157" Type="Source" /> - </Doc2> - <Doc3 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/console.cc" > - <View0 Encoding="" line="17" Type="Source" /> - </Doc3> - <Doc4 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/console.h" > - <View0 Encoding="" line="14" Type="Source" /> - </Doc4> - <Doc5 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/sys/consoleinterface.cc" > - <View0 Encoding="" line="0" Type="Source" /> - </Doc5> - <Doc6 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/func.h" > - <View0 Encoding="" line="76" Type="Source" /> - </Doc6> - <Doc7 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/func.cc" > - <View0 Encoding="" line="92" Type="Source" /> - </Doc7> - <Doc8 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/gameserver.cc" > - <View0 Encoding="" line="72" Type="Source" /> - </Doc8> - <Doc9 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/chat.cc" > - <View0 Encoding="" line="130" Type="Source" /> - </Doc9> </DocsAndViews> <pluginList> <kdevdebugger> 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<Player *>:: 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<Player *>:: 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; } } diff --git a/src/core/gameserver.h b/src/core/gameserver.h index 3f8a2ec..7a2f4a6 100644 --- a/src/core/gameserver.h +++ b/src/core/gameserver.h @@ -32,6 +32,12 @@ public: /// returns true if the game server can not run a time frime inline bool error() { return !server_running; } + /// show a list of connected players + void list_players(); + + /// show the current time + void showtime(); + /*----- mutators -------------------------------------------------- */ /// is called when a player connects to the game server @@ -43,15 +49,9 @@ public: /// run a game server time frame void frame(float seconds); - /// a player requests a list of who is connected - void list_players(Player *player); - /// a player sends a chat message to the public channel void say(Player *player, std::string const &args); - /// a player requests the current time - void showtime(Player *player); - /// broadcast a message to all players void broadcast(std::string const & message, Player *ignore_player = 0); @@ -64,6 +64,9 @@ public: /// send a sound to a single player void send_sound(Player *player, std::string sound); + /// send a rcon message to a single player + void send_rcon(Player *player, std::string message); + /// a player sends a command to the game server void exec(Player *player, std::string const &cmdline); diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc index b89887c..4c916a1 100644 --- a/src/core/netconnection.cc +++ b/src/core/netconnection.cc @@ -323,6 +323,7 @@ void NetConnection::transmit() * disconnect * msg info <text> * msg public <name> <text> + * msg rcon <text> * msg snd <soundname> * die * ent @@ -344,6 +345,10 @@ void NetConnection::parse_incoming_message(const std::string & message) if (message.size() > 9) { application()->notify_message(message.substr(9)); } + } else if (level =="rcon") { + if (message.size() > 9) { + con_print << message.substr(9) << std::endl; + } } else if (level == "public") { // FIXME - separate sender nickname if (message.size() > 11) { diff --git a/src/server/console.cc b/src/server/console.cc index cdaa1f9..1fb7f38 100644 --- a/src/server/console.cc +++ b/src/server/console.cc @@ -99,6 +99,9 @@ void Console::resize() void Console::flush() { + if (rcon()) + return; + char line[MAXCMDSIZE]; while(consoleinterface_buffer.getline(line, MAXCMDSIZE-1)) { diff --git a/src/sys/consoleinterface.cc b/src/sys/consoleinterface.cc index 8b734ff..45508ee 100644 --- a/src/sys/consoleinterface.cc +++ b/src/sys/consoleinterface.cc @@ -23,6 +23,8 @@ ConsoleInterface::ConsoleInterface() sys::quit(2); } + consoleinterface_rcon = false; + consoleinterface_instance = this; consoleinterface_text.clear(); consoleinterface_buffer.clear(); @@ -64,6 +66,9 @@ std::ostream & ConsoleInterface::debugstream() void ConsoleInterface::flush() { + if (rcon()) + return; + char line[MAXCMDSIZE]; while(consoleinterface_buffer.getline(line, MAXCMDSIZE-1)) { @@ -170,4 +175,13 @@ void ConsoleInterface::print_ansi(const char *line) std::cout << "\033[0;39m"; } +void ConsoleInterface::buffer_rcon(bool enable) +{ + if (enable) { + flush(); + } + + consoleinterface_rcon = enable; +} + } // namespace sys diff --git a/src/sys/consoleinterface.h b/src/sys/consoleinterface.h index 6475676..33052cf 100644 --- a/src/sys/consoleinterface.h +++ b/src/sys/consoleinterface.h @@ -66,6 +66,14 @@ public: /// a pointer to the current console instance static ConsoleInterface *instance(); + /// enable or disable rcon + void buffer_rcon(bool enable = true); + + /// return the console inputbuffer + inline std::stringstream & buffer() { return consoleinterface_buffer; } + + inline bool rcon() { return consoleinterface_rcon; } + protected: std::deque<std::string> consoleinterface_text; std::stringstream consoleinterface_buffer; @@ -77,6 +85,7 @@ private: /// console singleton static ConsoleInterface *consoleinterface_instance; bool consoleinterface_ansi; + bool consoleinterface_rcon; }; } // namespace sys |