Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/gameserver.cc105
-rw-r--r--src/core/gameserver.h15
-rw-r--r--src/core/netconnection.cc5
3 files changed, 83 insertions, 42 deletions
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) {