From e5aada2bf01e51753829215c0a3035aa8bd8135a Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 5 Jul 2008 10:17:39 +0000 Subject: ncurses updates, refactored say --- src/core/application.cc | 15 +++++++++++++++ src/core/commandbuffer.cc | 4 +++- src/core/func.cc | 6 +++++- src/core/func.h | 2 +- src/core/gameconnection.cc | 12 +++++++++++- src/core/gameconnection.h | 3 +++ src/core/gameserver.cc | 11 ++--------- src/core/gameserver.h | 2 +- 8 files changed, 41 insertions(+), 14 deletions(-) (limited to 'src/core') diff --git a/src/core/application.cc b/src/core/application.cc index cd6d278..f8c563c 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -59,6 +59,17 @@ void func_disconnect(std::string const &args) application()->disconnect(); } +void func_say(std::string const &args) +{ + if (connection()) { + connection()->say(args); + } else if (server()) { + server()->say(localplayer(), args); + } else { + con_print << "Not connected." << std::endl; + } +} + // --------------- signal_handler ----------------------------------- #ifndef _WIN32 @@ -207,6 +218,9 @@ void Application::init(int count, char **arguments) func = Func::add("disconnect", func_disconnect); func->set_info("leave the current game"); + + func = Func::add("say",func_say); + func->set_info("say [text] say something on the public chat"); } void Application::shutdown() @@ -224,6 +238,7 @@ void Application::shutdown() save_config(); // remove our engine functions + Func::remove("say"); Func::remove("help"); Func::remove("quit"); diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc index b34b04b..80e7e36 100644 --- a/src/core/commandbuffer.cc +++ b/src/core/commandbuffer.cc @@ -153,7 +153,9 @@ void CommandBuffer::exec(std::string const &cmdline) while (cmdstream.get(c)) args += c; } - if ((f->flags() & Func::Game)) { + + // console can not execute game functions, and neither should rcon + if ((f->flags() & Func::Game) && (Cvar::sv_dedicated->value() == 0)) { if (application()->connected()) { f->exec(game()->localplayer(), args); } diff --git a/src/core/func.cc b/src/core/func.cc index 27c46a0..ad25426 100644 --- a/src/core/func.cc +++ b/src/core/func.cc @@ -81,7 +81,7 @@ Func *Func::find(const std::string &name) void Func::list() { std::map::iterator it; - con_print << "Flags: G=Game" << std::endl; + con_print << "Flags: G=Game S=Shared" << std::endl; for (it = registry.begin(); it != registry.end(); it++) { std::string typeindicator; @@ -89,6 +89,10 @@ void Func::list() typeindicator += 'G'; else typeindicator += ' '; + if (((*it).second->flags() & Shared) == Shared) + typeindicator += 'S'; + else + typeindicator += ' '; con_print << " " << typeindicator << " " << (*it).second->name() << " " << (*it).second->info() << std::endl; } diff --git a/src/core/func.h b/src/core/func.h index 2c02599..d72e583 100644 --- a/src/core/func.h +++ b/src/core/func.h @@ -27,7 +27,7 @@ class Func { public: /// function flags - enum Flags {Game=1}; + enum Flags {Game=1, Shared=2}; /// create a new function Func(char const * name, void *ptr, unsigned int flags = 0); diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc index 6090a52..4d2a745 100644 --- a/src/core/gameconnection.cc +++ b/src/core/gameconnection.cc @@ -68,7 +68,6 @@ void GameConnection::abort() void GameConnection::forward(std::string const &cmdline) { - if (!connection_network->connected()) return; @@ -78,6 +77,17 @@ void GameConnection::forward(std::string const &cmdline) connection_network->send(netmessage); } +void GameConnection::say(std::string const &args) +{ + if (!connection_network->connected()) + return; + + std::string netmessage("say "); + netmessage.append(args); + netmessage += '\n'; + connection_network->send(netmessage); +} + void GameConnection::frame(float seconds) { if (!running()) diff --git a/src/core/gameconnection.h b/src/core/gameconnection.h index 65fd495..d0da18e 100644 --- a/src/core/gameconnection.h +++ b/src/core/gameconnection.h @@ -36,6 +36,9 @@ public: /// forward a command line to the remote server void forward(std::string const &cmdline); + /// localplayer sends a chat message to the public channel + void say(std::string const &args); + /*----- static ---------------------------------------------------- */ /// return the current game connection diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index cddddff..c7a71ff 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -17,11 +17,6 @@ namespace core { -void func_say(Player *player, std::string const &args) -{ - server()->say(player, args); -} - void func_who(Player *player, std::string const &args) { server()->list_players(player); @@ -74,9 +69,8 @@ GameServer::GameServer() : GameInterface() server_network = 0; } - Func::add("say",func_say); - Func::add("time", func_time); - Func::add("who", func_who); + Func::add("time", func_time, Func::Shared); + Func::add("who", func_who, Func::Shared); if (!Cvar::sv_dedicated->value()) { player_connect(localplayer()); @@ -106,7 +100,6 @@ GameServer::~GameServer() delete server_module; } - Func::remove("say"); Func::remove("time"); Func::remove("who"); diff --git a/src/core/gameserver.h b/src/core/gameserver.h index a7ee159..3f8a2ec 100644 --- a/src/core/gameserver.h +++ b/src/core/gameserver.h @@ -46,7 +46,7 @@ public: /// a player requests a list of who is connected void list_players(Player *player); - /// a player sends a chat message on the public channel + /// a player sends a chat message to the public channel void say(Player *player, std::string const &args); /// a player requests the current time -- cgit v1.2.3