diff options
author | truelight <truelight@openttd.org> | 2005-01-15 20:09:16 +0000 |
---|---|---|
committer | truelight <truelight@openttd.org> | 2005-01-15 20:09:16 +0000 |
commit | 24c9e6ff66c6386a182b0fe5eef5f371793b468e (patch) | |
tree | be21df9ed89b0080e4d32a5e54c3f2dffd9f3437 /network_server.c | |
parent | e6d31cb89c43feebcd114d197166588e7ede72d3 (diff) | |
download | openttd-24c9e6ff66c6386a182b0fe5eef5f371793b468e.tar.xz |
(svn r1527) -Add: RCon (Remote Connection). A server can set:
'set rcon_pw <password>'
Which enables rcon. A client can now do:
'rcon <password> "<command>"'
The command will be executed on the server. (guru3)
-Fix: 'kick 1' did crash dedicated servers
-Fix: server password is now correctly saved
!!Warning!!: do not give your rcon password to people you do not thrust!
Diffstat (limited to 'network_server.c')
-rw-r--r-- | network_server.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/network_server.c b/network_server.c index c746de12b..0e37fc8ff 100644 --- a/network_server.c +++ b/network_server.c @@ -566,6 +566,15 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_NEWGAME) NetworkSend_Packet(p, cs); } +DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_RCON)(NetworkClientState *cs, uint16 color, const char *command) +{ + Packet *p = NetworkSend_Init(PACKET_SERVER_RCON); + + NetworkSend_uint16(p, color); + NetworkSend_string(p, command); + NetworkSend_Packet(p, cs); +} + // ********** // Receiving functions // DEF_SERVER_RECEIVE_COMMAND has parameter: NetworkClientState *cs, Packet *p @@ -1082,6 +1091,30 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_NAME) } } +DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_RCON) +{ + char pass[NETWORK_PASSWORD_LENGTH]; + char command[NETWORK_RCONCOMMAND_LENGTH]; + + if (_network_game_info.rcon_password[0] == '\0') + return; + + NetworkRecv_string(cs, p, pass, sizeof(pass)); + NetworkRecv_string(cs, p, command, sizeof(command)); + + if (strncmp(pass, _network_game_info.rcon_password, sizeof(pass)) != 0) { + DEBUG(net, 0)("[RCon] Wrong password from client-id %d", cs->index); + return; + } + + DEBUG(net, 0)("[RCon] Client-id %d executed: %s", cs->index, command); + + _redirect_console_to_client = cs->index; + IConsoleCmdExec(command); + _redirect_console_to_client = 0; + return; +} + // The layout for the receive-functions by the server typedef void NetworkServerPacket(NetworkClientState *cs, Packet *p); @@ -1121,6 +1154,8 @@ static NetworkServerPacket* const _network_server_packet[] = { NULL, /*PACKET_SERVER_ERROR_QUIT,*/ NULL, /*PACKET_SERVER_SHUTDOWN,*/ NULL, /*PACKET_SERVER_NEWGAME,*/ + NULL, /*PACKET_SERVER_RCON,*/ + RECEIVE_COMMAND(PACKET_CLIENT_RCON), }; // If this fails, check the array above with network_data.h |