From dbb28ef3422bf2442e15d75fd52180cfb9b40102 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 8 Nov 2008 12:58:05 +0000 Subject: adds rcon, rconpassword and sv_password --- src/client/client.cc | 28 ++++++++++++++++++++-------- src/client/input.cc | 2 +- src/core/application.cc | 31 ++++++++++++++++++++++++++----- src/core/application.h | 3 +++ src/core/cvar.cc | 4 ++-- src/core/cvar.h | 4 ++-- src/core/gameconnection.cc | 8 ++++++++ src/core/gameconnection.h | 3 +++ src/core/netclient.h | 4 ++++ src/core/netconnection.cc | 9 +++++++++ src/core/netconnection.h | 3 +++ src/core/netserver.cc | 27 +++++++++++++++++++++++++++ src/core/player.cc | 24 +++++++++++++++++++++--- src/core/player.h | 6 +++--- 14 files changed, 132 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/client/client.cc b/src/client/client.cc index 823a384..6fccbe8 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -101,8 +101,13 @@ void Client::init(int count, char **arguments) core::Cvar::sv_private = core::Cvar::set("sv_private", "0"); core::Application::init(count, arguments); - // client variables + // engine variables + cl_framerate = core::Cvar::get("cl_framerate", "125", core::Cvar::Archive); + cl_framerate->set_info("[int] client framerate in frames/sec"); + + // player info variables core::Cvar *cvar = 0; + cvar = core::Cvar::get("cl_name", "Player", core::Cvar::Archive | core::Cvar::Info); cvar->set_info("[str] player name"); @@ -111,9 +116,9 @@ void Client::init(int count, char **arguments) cvar = core::Cvar::get("cl_colorsecond", "1.0 1.0 1.0", core::Cvar::Archive | core::Cvar::Info); cvar->set_info("[r g b] player secondary color"); - - cl_framerate = core::Cvar::get("cl_framerate", "125", core::Cvar::Archive); - cl_framerate->set_info("[int] client framerate in frames/sec"); + + cvar = core::Cvar::get("rconpassword", "", core::Cvar::Archive | core::Cvar::Info); + cvar->set_info("[string] password for remote console access"); // initialize SDL, but do not initialize any subsystems SDL_Init(0); @@ -207,15 +212,22 @@ void Client::frame(unsigned long timestamp) if (!core::application()->connected() && !ui::console()->visible()) { ui::console()->toggle(); } - } else { + } else if (!ui::root()->active()) { + // show the main menu on non-interactive modules - if (!core::game()->interactive() && !ui::root()->active()) { + if (!core::game()->interactive()) { ui::root()->show_menu("main"); - } - if (core::game()->interactive() && !ui::root()->active() && !core::localcontrol()) { + // show the join menu when player does not control an entity + } else if (core::game()->time() && !core::localcontrol()) { ui::root()->show_menu("join"); } + } else { + if (core::localcontrol()) { + if (ui::root()->active()->label().compare("join") == 0) { + ui::root()->hide_menu(); + } + } } video::frame((float)(timestamp - previous_timestamp) / 1000.0f); diff --git a/src/client/input.cc b/src/client/input.cc index d4ccb17..1df64df 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -686,7 +686,7 @@ void frame() switch (event.type) { case SDL_VIDEORESIZE: - video::resize((float) event.resize.w, (float) event.resize.h); + video::resize(event.resize.w, event.resize.h); break; case SDL_MOUSEMOTION: diff --git a/src/core/application.cc b/src/core/application.cc index 300aaa6..7326383 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -127,6 +127,12 @@ void Application::init(int count, char **arguments) Cvar::sv_name = Cvar::get("sv_name", "osirion server", Cvar::Archive); Cvar::sv_name->set_info("[string] server name"); + Cvar::sv_description = Cvar::get("sv_description", "default server", Cvar::Archive); + Cvar::sv_description->set_info("[string] server description"); + + Cvar::sv_password = Cvar::get("sv_password", "", Cvar::Archive); + Cvar::sv_password->set_info("[string] server rcon password"); + // network settings Cvar::net_host = Cvar::get("net_host", "0.0.0.0", Cvar::Archive); Cvar::net_host->set_info("[ip] IP address the network server binds to"); @@ -143,10 +149,6 @@ void Application::init(int count, char **arguments) Cvar::net_framerate = Cvar::get("net_framerate", "25"); Cvar::net_framerate->set_info("[int] network framerate in frames/sec"); - // passwords - Cvar::rconpassword = Cvar::get("rconpassword", "", Cvar::Archive); - Cvar::rconpassword->set_info("[string] password for remote console access"); - #ifdef _WIN32 Cvar::con_ansi = Cvar::get("con_ansi", "0", Cvar::Archive); #else @@ -174,7 +176,7 @@ void Application::init(int count, char **arguments) func->set_info("exit the application"); func = Func::add("load", Application::func_load); - func->set_info("[str] load a game module"); + func->set_info("[string] load a game module"); func = Func::add("connect", Application::func_connect); func->set_info("[ip] without ip, create a game"); @@ -188,6 +190,9 @@ void Application::init(int count, char **arguments) func = Func::add("msg", Application::func_msg); func->set_info("msg [player] [text] send a private message to another player"); + func = Func::add("rcon", Application::func_rcon); + func->set_info("[string] send a console command to the server"); + func = 0; } @@ -546,6 +551,22 @@ void Application::func_msg(std::string const &args) } } +void Application::func_rcon(std::string const &args) +{ + if (connection()) { + core::Cvar *rconpassword = core::Cvar::find("rconpassword"); + if (rconpassword && rconpassword->str().size()) { + connection()->rcon(args); + } else { + con_warn << "rconpassword not set!" << std::endl; + } + } else if (server()) { + cmd() << args << "\n"; + } else { + con_print << "Not connected." << std::endl; + } +} + void Application::func_load(std::string const &args) { std::string name(args); diff --git a/src/core/application.h b/src/core/application.h index bb76cfe..bcd4042 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -121,6 +121,7 @@ private: static void func_say(std::string const &args); static void func_msg(std::string const &args); static void func_load(std::string const &args); + static void func_rcon(std::string const &args); }; /// pointer to the application @@ -131,6 +132,8 @@ inline sys::ConsoleInterface *console() { return sys::ConsoleInterface::instance /// pointer to the game interface inline GameInterface *game() { return Application::instance()->game(); } + } + #endif // __INCLUDED_CORE_APPLICATION_H__ diff --git a/src/core/cvar.cc b/src/core/cvar.cc index 7db202d..2e5de5a 100644 --- a/src/core/cvar.cc +++ b/src/core/cvar.cc @@ -22,6 +22,8 @@ Cvar *Cvar::sv_dedicated = 0; Cvar *Cvar::sv_private = 0; Cvar *Cvar::sv_framerate = 0; Cvar *Cvar::sv_name = 0; +Cvar *Cvar::sv_description = 0; +Cvar *Cvar::sv_password = 0; Cvar *Cvar::cl_prediction = 0; @@ -31,8 +33,6 @@ Cvar *Cvar::net_maxclients = 0; Cvar *Cvar::net_timeout = 0; Cvar *Cvar::net_framerate = 0; -Cvar *Cvar::rconpassword = 0; - Cvar::Registry Cvar::cvar_registry; Cvar::Cvar(const char *name, const unsigned int flags) : cvar_name(), cvar_info(), cvar_str() diff --git a/src/core/cvar.h b/src/core/cvar.h index acb6f89..5683d94 100644 --- a/src/core/cvar.h +++ b/src/core/cvar.h @@ -113,6 +113,8 @@ public: static Cvar *sv_private; // client with private server static Cvar *sv_framerate; // server framerate static Cvar *sv_name; // server name + static Cvar *sv_description; // server description + static Cvar *sv_password; // server rcon password static Cvar *con_ansi; // console ANSI colors @@ -124,8 +126,6 @@ public: static Cvar *net_timeout; // network timeout in seconds static Cvar *net_framerate; // client network send framerate - static Cvar *rconpassword; // rcon password - private: std::string cvar_name; std::string cvar_info; diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc index eaafe91..7942f9e 100644 --- a/src/core/gameconnection.cc +++ b/src/core/gameconnection.cc @@ -87,6 +87,14 @@ void GameConnection::forward(std::string const &cmdline) connection_network->send_command(cmdline); } +void GameConnection::rcon(std::string const &cmdline) +{ + if (!connection_network->connected()) + return; + + connection_network->send_rcon(cmdline); +} + void GameConnection::say(std::string const &args) { if (!connection_network->connected()) diff --git a/src/core/gameconnection.h b/src/core/gameconnection.h index 70e3015..e1a7008 100644 --- a/src/core/gameconnection.h +++ b/src/core/gameconnection.h @@ -42,6 +42,9 @@ public: /// forward a command line to the remote server void forward(std::string const &cmdline); + /// forward a remote console command + void rcon(std::string const &cmdline); + /// localplayer sends a chat message to the public channel void say(std::string const &args); diff --git a/src/core/netclient.h b/src/core/netclient.h index 3671b4e..879a801 100644 --- a/src/core/netclient.h +++ b/src/core/netclient.h @@ -11,14 +11,18 @@ #include #ifndef _WIN32 + #include #include #include #include #include + #else + #include + #endif #include diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc index 704551b..ba23df3 100644 --- a/src/core/netconnection.cc +++ b/src/core/netconnection.cc @@ -373,6 +373,15 @@ void NetConnection::send_command(std::string const &cmdline) this->send_raw(msg); } +// send a "rcon" command line message to the server +void NetConnection::send_rcon(std::string const &cmdline) +{ + std::string msg("rcon "); + msg.append(cmdline); + msg += '\n'; + this->send_raw(msg); +} + // send a "say" chat message message to the server void NetConnection::send_say(std::string const &text) { diff --git a/src/core/netconnection.h b/src/core/netconnection.h index 66f7369..e6e31f7 100644 --- a/src/core/netconnection.h +++ b/src/core/netconnection.h @@ -68,6 +68,9 @@ public: /// send a command line to the remote server void send_command(std::string const &cmdline); + /// send a console command to the remote server + void send_rcon(std::string const &cmdline); + /// transmit messages in the send queue to the remote server void transmit(); diff --git a/src/core/netserver.cc b/src/core/netserver.cc index cdcdad7..c6214c9 100644 --- a/src/core/netserver.cc +++ b/src/core/netserver.cc @@ -613,6 +613,33 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me return; } + if (command == "rcon") { + if ((message.size() > command.size()+1) && Cvar::sv_password->str().size()) { + if ((Cvar::sv_password->str().compare(client->player()->rconpassword()) == 0)) { + con_print << "^B" << client->player()->name() << "^F rcon: " << message.substr(command.size()+1) << std::endl; + + core::CommandBuffer::exec(); + core::console()->set_rcon(true); + + core::cmd() << message.substr(command.size()+1) << "\n"; + core::CommandBuffer::exec(); + + while(console()->rconbuf().size()) { + server()->send(client->player(), (*console()->rconbuf().begin())); + core::console()->rconbuf().pop_front(); + } + + // disable rcon buffering + console()->set_rcon(false); + + } else { + server()->send(client->player(), "rcon access denied"); + con_print << "^B" << client->player()->name() << "^W rcon access denied" << std::endl; + } + } + return; + + } // cup - client update entity if (command == "cup") { //con_debug << message << "\n"; diff --git a/src/core/player.cc b/src/core/player.cc index f5f28bd..865c859 100644 --- a/src/core/player.cc +++ b/src/core/player.cc @@ -32,7 +32,6 @@ void Player::clear() player_name.clear(); player_dirty = false; player_zonechange = false; - player_rcon = false; player_mute = false; player_mission_target = 0; player_view = 0; @@ -103,11 +102,22 @@ void Player::update_info() if (is >> color_second) player_color_second.assign(color_second); } + + Cvar *passwd = Cvar::find("rconpassword"); + if (passwd) { + player_rconpassword.assign(passwd->str()); + } else { + player_rconpassword.clear(); + } } void Player::serialize_client_update(std::ostream & os) { - os << " " << player_color << " " << player_color_second << " \"" << player_name << "\""; + os << player_color << " " + << player_color_second << " " + << "\"" << player_name << "\" " + << "\"" << player_rconpassword << "\""; + } void Player::receive_client_update(std::istream &is) @@ -122,7 +132,15 @@ void Player::receive_client_update(std::istream &is) n += c; if (n.size()) - player_name = n; + player_name.assign(n); + + n.clear(); + while ( (is.get(c)) && (c != '"')); + while ( (is.get(c)) && (c != '"')) + n += c; + + if (n.size()) + player_rconpassword.assign(n); } void Player::serialize_server_update(std::ostream & os) const diff --git a/src/core/player.h b/src/core/player.h index 44ee923..04f9615 100644 --- a/src/core/player.h +++ b/src/core/player.h @@ -67,6 +67,8 @@ public: /// player has been muted by admin or console inline bool mute() const { return player_mute; } + inline const std::string &rconpassword() const { return player_rconpassword; } + /// mission target inline Entity *mission_target() { return player_mission_target; } @@ -119,9 +121,6 @@ public: /// player has changed zone bool player_zonechange; - /// indicates rcon access - bool player_rcon; - /// id of the player int player_id; @@ -152,6 +151,7 @@ private: Zone *player_zone; float player_credits; + std::string player_rconpassword; }; } -- cgit v1.2.3