diff options
author | rubidium <rubidium@openttd.org> | 2010-10-17 17:43:01 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-10-17 17:43:01 +0000 |
commit | a5d414a73490d290965f714ccc3ab556ffa4bc7e (patch) | |
tree | 76cd7149e81bbd4af5f1693458d7268e6fd66795 /src/network/network_admin.cpp | |
parent | ad12a91cdae152aff87404dce7718706b91d5cb4 (diff) | |
download | openttd-a5d414a73490d290965f714ccc3ab556ffa4bc7e.tar.xz |
(svn r20975) -Add: logging of console output for remote admins (dihedral)
Diffstat (limited to 'src/network/network_admin.cpp')
-rw-r--r-- | src/network/network_admin.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp index 081d59e12..faf663d7a 100644 --- a/src/network/network_admin.cpp +++ b/src/network/network_admin.cpp @@ -49,6 +49,7 @@ static const AdminUpdateFrequency _admin_update_type_frequencies[] = { ADMIN_FREQUENCY_POLL | ADMIN_FREQUENCY_WEEKLY | ADMIN_FREQUENCY_MONTHLY | ADMIN_FREQUENCY_QUARTERLY | ADMIN_FREQUENCY_ANUALLY, ///< ADMIN_UPDATE_COMPANY_ECONOMY ADMIN_FREQUENCY_POLL | ADMIN_FREQUENCY_WEEKLY | ADMIN_FREQUENCY_MONTHLY | ADMIN_FREQUENCY_QUARTERLY | ADMIN_FREQUENCY_ANUALLY, ///< ADMIN_UPDATE_COMPANY_STATS ADMIN_FREQUENCY_AUTOMATIC, ///< ADMIN_UPDATE_CHAT + ADMIN_FREQUENCY_AUTOMATIC, ///< ADMIN_UPDATE_CONSOLE }; assert_compile(lengthof(_admin_update_type_frequencies) == ADMIN_UPDATE_END); @@ -430,6 +431,23 @@ DEF_ADMIN_RECEIVE_COMMAND(Server, ADMIN_PACKET_ADMIN_RCON) return NETWORK_RECV_STATUS_OKAY; } +NetworkRecvStatus ServerNetworkAdminSocketHandler::SendConsole(const char *origin, const char *string) +{ + /* If the length of both strings, plus the 2 '\0' terminations and 3 bytes of the packet + * are bigger than the MTU, just ignore the message. Better safe than sorry. It should + * never occur though as the longest strings are chat messages, which are still 30% + * smaller than SEND_MTU. */ + if (strlen(origin) + strlen(string) + 2 + 3 >= SEND_MTU) return NETWORK_RECV_STATUS_OKAY; + + Packet *p = new Packet(ADMIN_PACKET_SERVER_CONSOLE); + + p->Send_string(origin); + p->Send_string(string); + this->Send_Packet(p); + + return NETWORK_RECV_STATUS_OKAY; +} + /*********** * Receiving functions ************/ @@ -714,6 +732,21 @@ void NetworkServerSendAdminRcon(AdminIndex admin_index, ConsoleColour colour_cod } /** + * Send console to the admin network (if they did opt in for the respective update). + * @param origin the origin of the message. + * @param string the message as printed on the console. + */ +void NetworkAdminConsole(const char *origin, const char *string) +{ + ServerNetworkAdminSocketHandler *as; + FOR_ALL_ADMIN_SOCKETS(as) { + if (as->update_frequency[ADMIN_UPDATE_CONSOLE] & ADMIN_FREQUENCY_AUTOMATIC) { + as->SendConsole(origin, string); + } + } +} + +/** * Send a Welcome packet to all connected admins */ void ServerNetworkAdminSocketHandler::WelcomeAll() |