summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/network/core/tcp_admin.cpp4
-rw-r--r--src/network/core/tcp_admin.h9
-rw-r--r--src/network/network_admin.cpp20
-rw-r--r--src/network/network_admin.h1
4 files changed, 34 insertions, 0 deletions
diff --git a/src/network/core/tcp_admin.cpp b/src/network/core/tcp_admin.cpp
index 60ccfd064..29cd251ed 100644
--- a/src/network/core/tcp_admin.cpp
+++ b/src/network/core/tcp_admin.cpp
@@ -63,6 +63,8 @@ NetworkRecvStatus NetworkAdminSocketHandler::HandlePacket(Packet *p)
ADMIN_COMMAND(ADMIN_PACKET_SERVER_NEWGAME)
ADMIN_COMMAND(ADMIN_PACKET_SERVER_SHUTDOWN)
+ ADMIN_COMMAND(ADMIN_PACKET_SERVER_DATE)
+
default:
if (this->HasClientQuit()) {
DEBUG(net, 0, "[tcp/admin] received invalid packet type %d from '%s' (%s)", type, this->admin_name, this->admin_version);
@@ -120,4 +122,6 @@ DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_WELCOME)
DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_NEWGAME)
DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_SHUTDOWN)
+DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_DATE)
+
#endif /* ENABLE_NETWORK */
diff --git a/src/network/core/tcp_admin.h b/src/network/core/tcp_admin.h
index 3ed444257..f93b5c388 100644
--- a/src/network/core/tcp_admin.h
+++ b/src/network/core/tcp_admin.h
@@ -39,6 +39,8 @@ enum PacketAdminType {
ADMIN_PACKET_SERVER_NEWGAME, ///< The server tells the admin its going to start a new game.
ADMIN_PACKET_SERVER_SHUTDOWN, ///< The server tells the admin its shutting down.
+ ADMIN_PACKET_SERVER_DATE, ///< The server tells the admin what the current game date is.
+
INVALID_ADMIN_PACKET = 0xFF, ///< An invalid marker for admin packets.
};
@@ -51,6 +53,7 @@ enum AdminStatus {
/** Update types an admin can register a frequency for */
enum AdminUpdateType {
+ ADMIN_UPDATE_DATE, ///< Updates about the date of the game.
ADMIN_UPDATE_END ///< Must ALWAYS be on the end of this list!! (period)
};
@@ -152,6 +155,12 @@ protected:
*/
DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_SHUTDOWN);
+ /**
+ * Send the current date of the game:
+ * uint32 Current game date.
+ */
+ DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_DATE);
+
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 11b8d8ade..18c4870b4 100644
--- a/src/network/network_admin.cpp
+++ b/src/network/network_admin.cpp
@@ -40,6 +40,7 @@ static const int ADMIN_AUTHORISATION_TIMEOUT = 10000;
/** Frequencies, which may be registered for a certain update type. */
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
};
assert_compile(lengthof(_admin_update_type_frequencies) == ADMIN_UPDATE_END);
@@ -169,6 +170,16 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendShutdown()
return NETWORK_RECV_STATUS_OKAY;
}
+NetworkRecvStatus ServerNetworkAdminSocketHandler::SendDate()
+{
+ Packet *p = new Packet(ADMIN_PACKET_SERVER_DATE);
+
+ p->Send_uint32(_date);
+ this->Send_Packet(p);
+
+ return NETWORK_RECV_STATUS_OKAY;
+}
+
/***********
* Receiving functions
************/
@@ -231,6 +242,11 @@ DEF_ADMIN_RECEIVE_COMMAND(Server, ADMIN_PACKET_ADMIN_POLL)
uint32 d1 = p->Recv_uint32();
switch (type) {
+ case ADMIN_UPDATE_DATE:
+ /* The admin is requesting the current date. */
+ this->SendDate();
+ 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);
@@ -267,6 +283,10 @@ void NetworkAdminUpdate(AdminUpdateFrequency freq)
if (as->update_frequency[i] & freq) {
/* Update the admin for the required details */
switch (i) {
+ case ADMIN_UPDATE_DATE:
+ as->SendDate();
+ break;
+
default: NOT_REACHED();
}
}
diff --git a/src/network/network_admin.h b/src/network/network_admin.h
index c958f876f..bbddf2183 100644
--- a/src/network/network_admin.h
+++ b/src/network/network_admin.h
@@ -43,6 +43,7 @@ public:
NetworkRecvStatus SendWelcome();
NetworkRecvStatus SendNewGame();
NetworkRecvStatus SendShutdown();
+ NetworkRecvStatus SendDate();
static void Send();
static void AcceptConnection(SOCKET s, const NetworkAddress &address);