summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-10-17 17:38:16 +0000
committerrubidium <rubidium@openttd.org>2010-10-17 17:38:16 +0000
commitca5d9f70024a513b4d5a6cfcddb3b250f591d630 (patch)
treed8b7f60f2b9315b0ee8fbfb8e2da267b172c58a0 /src
parentae20cb4f3dff0f3a9478e918b90ef61279c8b33c (diff)
downloadopenttd-ca5d9f70024a513b4d5a6cfcddb3b250f591d630.tar.xz
(svn r20971) -Add: company economy updates at intervals to remote admins (dihedral)
Diffstat (limited to 'src')
-rw-r--r--src/network/core/tcp_admin.cpp2
-rw-r--r--src/network/core/tcp_admin.h17
-rw-r--r--src/network/network_admin.cpp44
-rw-r--r--src/network/network_admin.h1
4 files changed, 64 insertions, 0 deletions
diff --git a/src/network/core/tcp_admin.cpp b/src/network/core/tcp_admin.cpp
index 41855feeb..7d5b37c2d 100644
--- a/src/network/core/tcp_admin.cpp
+++ b/src/network/core/tcp_admin.cpp
@@ -73,6 +73,7 @@ NetworkRecvStatus NetworkAdminSocketHandler::HandlePacket(Packet *p)
ADMIN_COMMAND(ADMIN_PACKET_SERVER_COMPANY_INFO)
ADMIN_COMMAND(ADMIN_PACKET_SERVER_COMPANY_UPDATE)
ADMIN_COMMAND(ADMIN_PACKET_SERVER_COMPANY_REMOVE)
+ ADMIN_COMMAND(ADMIN_PACKET_SERVER_COMPANY_ECONOMY)
default:
if (this->HasClientQuit()) {
@@ -141,5 +142,6 @@ DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_NEW)
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)
#endif /* ENABLE_NETWORK */
diff --git a/src/network/core/tcp_admin.h b/src/network/core/tcp_admin.h
index fdd9cf81c..c13d37a1b 100644
--- a/src/network/core/tcp_admin.h
+++ b/src/network/core/tcp_admin.h
@@ -49,6 +49,7 @@ enum PacketAdminType {
ADMIN_PACKET_SERVER_COMPANY_INFO, ///< The server gives the admin information about a company.
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.
INVALID_ADMIN_PACKET = 0xFF, ///< An invalid marker for admin packets.
};
@@ -65,6 +66,7 @@ enum AdminUpdateType {
ADMIN_UPDATE_DATE, ///< Updates about the date of the game.
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_END ///< Must ALWAYS be on the end of this list!! (period)
};
@@ -259,6 +261,21 @@ protected:
*/
DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_REMOVE);
+ /**
+ * Economy update of a specific company:
+ * uint8 ID of the company.
+ * uint64 Money.
+ * uint64 Loan.
+ * uint64 Income.
+ * uint64 Company value (last quarter).
+ * uint16 Performance (last quarter).
+ * uint16 Delivered cargo (last quarter).
+ * uint64 Company value (previous quarter).
+ * uint16 Performance (previous quarter).
+ * uint16 Delivered cargo (previous quarter).
+ */
+ DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_ECONOMY);
+
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 b6341ed20..ac33be65a 100644
--- a/src/network/network_admin.cpp
+++ b/src/network/network_admin.cpp
@@ -43,6 +43,7 @@ static const AdminUpdateFrequency _admin_update_type_frequencies[] = {
ADMIN_FREQUENCY_POLL | ADMIN_FREQUENCY_DAILY | ADMIN_FREQUENCY_WEEKLY | ADMIN_FREQUENCY_MONTHLY | ADMIN_FREQUENCY_QUARTERLY | ADMIN_FREQUENCY_ANUALLY, ///< ADMIN_UPDATE_DATE
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
};
assert_compile(lengthof(_admin_update_type_frequencies) == ADMIN_UPDATE_END);
@@ -319,6 +320,40 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyRemove(CompanyID c
return NETWORK_RECV_STATUS_OKAY;
}
+NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyEconomy()
+{
+ const Company *company;
+ FOR_ALL_COMPANIES(company) {
+ /* Get the income. */
+ Money income = 0;
+ for (uint i = 0; i < lengthof(company->yearly_expenses[0]); i++) {
+ income -= company->yearly_expenses[0][i];
+ }
+
+ Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_ECONOMY);
+
+ p->Send_uint8(company->index);
+
+ /* Current information. */
+ p->Send_uint64(company->money);
+ p->Send_uint64(company->current_loan);
+ p->Send_uint64(income);
+ p->Send_uint16(company->cur_economy.delivered_cargo);
+
+ /* Send stats for the last 2 quarters. */
+ for (uint i = 0; i < 2; i++) {
+ p->Send_uint64(company->old_economy[i].company_value);
+ p->Send_uint16(company->old_economy[i].performance_history);
+ p->Send_uint16(company->old_economy[i].delivered_cargo);
+ }
+
+ this->Send_Packet(p);
+ }
+
+
+ return NETWORK_RECV_STATUS_OKAY;
+}
+
/***********
* Receiving functions
************/
@@ -412,6 +447,11 @@ DEF_ADMIN_RECEIVE_COMMAND(Server, ADMIN_PACKET_ADMIN_POLL)
}
break;
+ case ADMIN_UPDATE_COMPANY_ECONOMY:
+ /* The admin is requesting economy info. */
+ this->SendCompanyEconomy();
+ 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);
@@ -565,6 +605,10 @@ void NetworkAdminUpdate(AdminUpdateFrequency freq)
as->SendDate();
break;
+ case ADMIN_UPDATE_COMPANY_ECONOMY:
+ as->SendCompanyEconomy();
+ break;
+
default: NOT_REACHED();
}
}
diff --git a/src/network/network_admin.h b/src/network/network_admin.h
index 96b9f74e2..4a3bd91d5 100644
--- a/src/network/network_admin.h
+++ b/src/network/network_admin.h
@@ -53,6 +53,7 @@ public:
NetworkRecvStatus SendCompanyInfo(const Company *c);
NetworkRecvStatus SendCompanyUpdate(const Company *c);
NetworkRecvStatus SendCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr);
+ NetworkRecvStatus SendCompanyEconomy();
static void Send();
static void AcceptConnection(SOCKET s, const NetworkAddress &address);