diff options
author | rubidium <rubidium@openttd.org> | 2010-12-30 18:14:37 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-12-30 18:14:37 +0000 |
commit | 6546561360597708e61609de4290fb3b1cbe7068 (patch) | |
tree | 2472c0c34def0d4a7ab64fe04e13bd4aff20497e /src/network/network_admin.cpp | |
parent | 661e13a86af45f88bc0fd7d8c045f66ceddd041e (diff) | |
download | openttd-6546561360597708e61609de4290fb3b1cbe7068.tar.xz |
(svn r21668) -Feature: command logging using the admin interface (dihedral)
Diffstat (limited to 'src/network/network_admin.cpp')
-rw-r--r-- | src/network/network_admin.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp index 47b05542d..fe76f164d 100644 --- a/src/network/network_admin.cpp +++ b/src/network/network_admin.cpp @@ -18,6 +18,8 @@ #include "network_admin.h" #include "network.h" #include "network_base.h" +#include "network_server.h" +#include "../command_func.h" #include "../company_base.h" #include "../console_func.h" #include "../core/pool_func.hpp" @@ -25,6 +27,7 @@ #include "../rev.h" #include "table/strings.h" +#include "network_client.h" /* This file handles all the admin network commands. */ @@ -50,6 +53,8 @@ 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_STATS ADMIN_FREQUENCY_AUTOMATIC, ///< ADMIN_UPDATE_CHAT ADMIN_FREQUENCY_AUTOMATIC, ///< ADMIN_UPDATE_CONSOLE + ADMIN_FREQUENCY_POLL, ///< ADMIN_UPDATE_CMD_NAMES + ADMIN_FREQUENCY_AUTOMATIC, ///< ADMIN_UPDATE_CMD_LOGGING }; assert_compile(lengthof(_admin_update_type_frequencies) == ADMIN_UPDATE_END); @@ -448,6 +453,53 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendConsole(const char *origi return NETWORK_RECV_STATUS_OKAY; } +NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdNames() +{ + Packet *p = new Packet(ADMIN_PACKET_SERVER_CMD_NAMES); + + for (uint i = 0; i < CMD_END; i++) { + const char *cmdname = GetCommandName(i); + + /* Should SEND_MTU be exceeded, start a new packet + * (magic 5: 1 bool "more data" and one uint16 "command id", one + * byte for string '\0' termination and 1 bool "no more data" */ + if (p->size + strlen(cmdname) + 5 >= SEND_MTU) { + p->Send_bool(false); + this->SendPacket(p); + + p = new Packet(ADMIN_PACKET_SERVER_CMD_NAMES); + } + + p->Send_bool(true); + p->Send_uint16(i); + p->Send_string(cmdname); + } + + /* Marker to notify the end of the packet has been reached. */ + p->Send_bool(false); + this->SendPacket(p); + + return NETWORK_RECV_STATUS_OKAY; +} + +NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdLogging(ClientID client_id, const CommandPacket *cp) +{ + Packet *p = new Packet(ADMIN_PACKET_SERVER_CMD_LOGGING); + + p->Send_uint32(client_id); + p->Send_uint8 (cp->company); + p->Send_uint16(cp->cmd & CMD_ID_MASK); + p->Send_uint32(cp->p1); + p->Send_uint32(cp->p2); + p->Send_uint32(cp->tile); + p->Send_string(cp->text); + p->Send_uint32(cp->frame); + + this->SendPacket(p); + + return NETWORK_RECV_STATUS_OKAY; +} + /*********** * Receiving functions ************/ @@ -551,6 +603,11 @@ DEF_ADMIN_RECEIVE_COMMAND(Server, ADMIN_PACKET_ADMIN_POLL) this->SendCompanyStats(); break; + case ADMIN_UPDATE_CMD_NAMES: + /* The admin is requesting the names of DoCommands. */ + this->SendCmdNames(); + break; + default: /* An unsupported "poll" update type. */ DEBUG(net, 3, "[admin] Not supported poll %d (%d) from '%s' (%s).", type, d1, this->admin_name, this->admin_version); @@ -747,6 +804,23 @@ void NetworkAdminConsole(const char *origin, const char *string) } /** + * Distribute CommandPacket details over the admin network for logging purposes. + * @param owner The owner of the CommandPacket (who sent us the CommandPacket). + * @param cp The CommandPacket to be distributed. + */ +void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacket *cp) +{ + ClientID client_id = owner == NULL ? _network_own_client_id : owner->client_id; + + ServerNetworkAdminSocketHandler *as; + FOR_ALL_ADMIN_SOCKETS(as) { + if (as->update_frequency[ADMIN_UPDATE_CMD_LOGGING] & ADMIN_FREQUENCY_AUTOMATIC) { + as->SendCmdLogging(client_id, cp); + } + } +} + +/** * Send a Welcome packet to all connected admins */ void ServerNetworkAdminSocketHandler::WelcomeAll() |