summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-10-17 17:38:41 +0000
committerrubidium <rubidium@openttd.org>2010-10-17 17:38:41 +0000
commit459514afe4f550a08d98958745d6cd8311c53fdd (patch)
treec66c0a60dff633ff91971112d417079527a44574 /src/network
parentca5d9f70024a513b4d5a6cfcddb3b250f591d630 (diff)
downloadopenttd-459514afe4f550a08d98958745d6cd8311c53fdd.tar.xz
(svn r20972) -Add: company statistics updates at intervals to remote admins (dihedral)
Diffstat (limited to 'src/network')
-rw-r--r--src/network/core/tcp_admin.cpp2
-rw-r--r--src/network/core/tcp_admin.h18
-rw-r--r--src/network/network_admin.cpp39
-rw-r--r--src/network/network_admin.h1
4 files changed, 60 insertions, 0 deletions
diff --git a/src/network/core/tcp_admin.cpp b/src/network/core/tcp_admin.cpp
index 7d5b37c2d..0d2d09fdd 100644
--- a/src/network/core/tcp_admin.cpp
+++ b/src/network/core/tcp_admin.cpp
@@ -74,6 +74,7 @@ NetworkRecvStatus NetworkAdminSocketHandler::HandlePacket(Packet *p)
ADMIN_COMMAND(ADMIN_PACKET_SERVER_COMPANY_UPDATE)
ADMIN_COMMAND(ADMIN_PACKET_SERVER_COMPANY_REMOVE)
ADMIN_COMMAND(ADMIN_PACKET_SERVER_COMPANY_ECONOMY)
+ ADMIN_COMMAND(ADMIN_PACKET_SERVER_COMPANY_STATS)
default:
if (this->HasClientQuit()) {
@@ -143,5 +144,6 @@ DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_INFO)
DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_UPDATE)
DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_REMOVE)
DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_ECONOMY)
+DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_STATS)
#endif /* ENABLE_NETWORK */
diff --git a/src/network/core/tcp_admin.h b/src/network/core/tcp_admin.h
index c13d37a1b..15f3ba0a7 100644
--- a/src/network/core/tcp_admin.h
+++ b/src/network/core/tcp_admin.h
@@ -50,6 +50,7 @@ enum PacketAdminType {
ADMIN_PACKET_SERVER_COMPANY_UPDATE, ///< The server gives the admin an information update on a company.
ADMIN_PACKET_SERVER_COMPANY_REMOVE, ///< The server tells the admin that a company was removed.
ADMIN_PACKET_SERVER_COMPANY_ECONOMY, ///< The server gives the admin some economy related company information.
+ ADMIN_PACKET_SERVER_COMPANY_STATS, ///< The server gives the admin some statistics about a company.
INVALID_ADMIN_PACKET = 0xFF, ///< An invalid marker for admin packets.
};
@@ -67,6 +68,7 @@ enum AdminUpdateType {
ADMIN_UPDATE_CLIENT_INFO, ///< Updates about the information of clients.
ADMIN_UPDATE_COMPANY_INFO, ///< Updates about the generic information of companies.
ADMIN_UPDATE_COMPANY_ECONOMY, ///< Updates about the economy of companies.
+ ADMIN_UPDATE_COMPANY_STATS, ///< Updates about the statistics of companies.
ADMIN_UPDATE_END ///< Must ALWAYS be on the end of this list!! (period)
};
@@ -276,6 +278,22 @@ protected:
*/
DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_ECONOMY);
+ /**
+ * Company statistics on stations and vehicles:
+ * uint8 ID of the company.
+ * uint16 Number of trains.
+ * uint16 Number of lorries.
+ * uint16 Number of busses.
+ * uint16 Number of planes.
+ * uint16 Number of ships.
+ * uint16 Number of train stations.
+ * uint16 Number of lorry stations.
+ * uint16 Number of bus stops.
+ * uint16 Number of airports and heliports.
+ * uint16 Number of harbours.
+ */
+ DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_STATS);
+
NetworkRecvStatus HandlePacket(Packet *p);
public:
NetworkRecvStatus CloseConnection(bool error = true);
diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp
index ac33be65a..7a86a4892 100644
--- a/src/network/network_admin.cpp
+++ b/src/network/network_admin.cpp
@@ -44,6 +44,7 @@ static const AdminUpdateFrequency _admin_update_type_frequencies[] = {
ADMIN_FREQUENCY_POLL | ADMIN_FREQUENCY_AUTOMATIC, ///< ADMIN_UPDATE_CLIENT_INFO
ADMIN_FREQUENCY_POLL | ADMIN_FREQUENCY_AUTOMATIC, ///< ADMIN_UPDATE_COMPANY_INFO
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
};
assert_compile(lengthof(_admin_update_type_frequencies) == ADMIN_UPDATE_END);
@@ -354,6 +355,35 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyEconomy()
return NETWORK_RECV_STATUS_OKAY;
}
+NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats()
+{
+ /* Fetch the latest version of the stats. */
+ NetworkCompanyStats company_stats[MAX_COMPANIES];
+ NetworkPopulateCompanyStats(company_stats);
+
+ const Company *company;
+
+ /* Go through all the companies. */
+ FOR_ALL_COMPANIES(company) {
+ Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_STATS);
+
+ /* Send the information. */
+ p->Send_uint8(company->index);
+
+ for (uint i = 0; i < NETWORK_VEH_END; i++) {
+ p->Send_uint16(company_stats->num_vehicle[i]);
+ }
+
+ for (uint i = 0; i < NETWORK_VEH_END; i++) {
+ p->Send_uint16(company_stats->num_station[i]);
+ }
+
+ this->Send_Packet(p);
+ }
+
+ return NETWORK_RECV_STATUS_OKAY;
+}
+
/***********
* Receiving functions
************/
@@ -452,6 +482,11 @@ DEF_ADMIN_RECEIVE_COMMAND(Server, ADMIN_PACKET_ADMIN_POLL)
this->SendCompanyEconomy();
break;
+ case ADMIN_UPDATE_COMPANY_STATS:
+ /* the admin is requesting company stats. */
+ this->SendCompanyStats();
+ 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);
@@ -609,6 +644,10 @@ void NetworkAdminUpdate(AdminUpdateFrequency freq)
as->SendCompanyEconomy();
break;
+ case ADMIN_UPDATE_COMPANY_STATS:
+ as->SendCompanyStats();
+ break;
+
default: NOT_REACHED();
}
}
diff --git a/src/network/network_admin.h b/src/network/network_admin.h
index 4a3bd91d5..7f4f67de1 100644
--- a/src/network/network_admin.h
+++ b/src/network/network_admin.h
@@ -54,6 +54,7 @@ public:
NetworkRecvStatus SendCompanyUpdate(const Company *c);
NetworkRecvStatus SendCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr);
NetworkRecvStatus SendCompanyEconomy();
+ NetworkRecvStatus SendCompanyStats();
static void Send();
static void AcceptConnection(SOCKET s, const NetworkAddress &address);