From ad12a91cdae152aff87404dce7718706b91d5cb4 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 17 Oct 2010 17:41:52 +0000 Subject: (svn r20974) -Add: remote console (rcon) for remote admins (dihedral) --- src/network/network_admin.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/network/network_admin.cpp') 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 ************/ @@ -671,6 +702,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 */ -- cgit v1.2.3-54-g00ecf