summaryrefslogtreecommitdiff
path: root/src/network/network_admin.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-10-17 17:41:52 +0000
committerrubidium <rubidium@openttd.org>2010-10-17 17:41:52 +0000
commitad12a91cdae152aff87404dce7718706b91d5cb4 (patch)
tree8a6658076b75e1dbe9d0dbe207e9fdc7c65363e2 /src/network/network_admin.cpp
parentd9602f4ef936b79c1d1ee785477323618e46f9cf (diff)
downloadopenttd-ad12a91cdae152aff87404dce7718706b91d5cb4.tar.xz
(svn r20974) -Add: remote console (rcon) for remote admins (dihedral)
Diffstat (limited to 'src/network/network_admin.cpp')
-rw-r--r--src/network/network_admin.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp
index 565976c70..081d59e12 100644
--- a/src/network/network_admin.cpp
+++ b/src/network/network_admin.cpp
@@ -28,6 +28,9 @@
/* This file handles all the admin network commands. */
+/** Redirection of the (remote) console to the admin. */
+AdminIndex _redirect_console_to_admin = INVALID_ADMIN_ID;
+
/** The amount of admins connected. */
byte _network_admins_connected = 0;
@@ -67,6 +70,7 @@ ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler()
{
_network_admins_connected--;
DEBUG(net, 1, "[admin] '%s' (%s) has disconnected", this->admin_name, this->admin_version);
+ if (_redirect_console_to_admin == this->index) _redirect_console_to_admin = INVALID_ADMIN_ID;
}
/**
@@ -399,6 +403,33 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendChat(NetworkAction action
return NETWORK_RECV_STATUS_OKAY;
}
+NetworkRecvStatus ServerNetworkAdminSocketHandler::SendRcon(uint16 colour, const char *result)
+{
+ Packet *p = new Packet(ADMIN_PACKET_SERVER_RCON);
+
+ p->Send_uint16(colour);
+ p->Send_string(result);
+ this->Send_Packet(p);
+
+ return NETWORK_RECV_STATUS_OKAY;
+}
+
+DEF_ADMIN_RECEIVE_COMMAND(Server, ADMIN_PACKET_ADMIN_RCON)
+{
+ if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
+
+ char command[NETWORK_RCONCOMMAND_LENGTH];
+
+ p->Recv_string(command, sizeof(command));
+
+ DEBUG(net, 2, "[admin] Rcon command from '%s' (%s): '%s'", this->admin_name, this->admin_version, command);
+
+ _redirect_console_to_admin = this->index;
+ IConsoleCmdExec(command);
+ _redirect_console_to_admin = INVALID_ADMIN_ID;
+ return NETWORK_RECV_STATUS_OKAY;
+}
+
/***********
* Receiving functions
************/
@@ -672,6 +703,17 @@ void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_i
}
/**
+ * Pass the rcon reply to the admin.
+ * @param admin_index The admin to give the reply.
+ * @param colour_code The colour of the string.
+ * @param string The string to show.
+ */
+void NetworkServerSendAdminRcon(AdminIndex admin_index, ConsoleColour colour_code, const char *string)
+{
+ ServerNetworkAdminSocketHandler::Get(admin_index)->SendRcon(colour_code, string);
+}
+
+/**
* Send a Welcome packet to all connected admins
*/
void ServerNetworkAdminSocketHandler::WelcomeAll()