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.h18
-rw-r--r--src/network/network_admin.cpp22
-rw-r--r--src/network/network_admin.h2
4 files changed, 46 insertions, 0 deletions
diff --git a/src/network/core/tcp_admin.cpp b/src/network/core/tcp_admin.cpp
index e87dd5924..0a3153319 100644
--- a/src/network/core/tcp_admin.cpp
+++ b/src/network/core/tcp_admin.cpp
@@ -61,6 +61,7 @@ NetworkRecvStatus NetworkAdminSocketHandler::HandlePacket(Packet *p)
case ADMIN_PACKET_ADMIN_CHAT: return this->Receive_ADMIN_CHAT(p);
case ADMIN_PACKET_ADMIN_RCON: return this->Receive_ADMIN_RCON(p);
case ADMIN_PACKET_ADMIN_GAMESCRIPT: return this->Receive_ADMIN_GAMESCRIPT(p);
+ case ADMIN_PACKET_ADMIN_PING: return this->Receive_ADMIN_PING(p);
case ADMIN_PACKET_SERVER_FULL: return this->Receive_SERVER_FULL(p);
case ADMIN_PACKET_SERVER_BANNED: return this->Receive_SERVER_BANNED(p);
@@ -88,6 +89,7 @@ NetworkRecvStatus NetworkAdminSocketHandler::HandlePacket(Packet *p)
case ADMIN_PACKET_SERVER_CMD_NAMES: return this->Receive_SERVER_CMD_NAMES(p);
case ADMIN_PACKET_SERVER_CMD_LOGGING: return this->Receive_SERVER_CMD_LOGGING(p);
case ADMIN_PACKET_SERVER_RCON_END: return this->Receive_SERVER_RCON_END(p);
+ case ADMIN_PACKET_SERVER_PONG: return this->Receive_SERVER_PONG(p);
default:
if (this->HasClientQuit()) {
@@ -137,6 +139,7 @@ NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_POLL(Packet *p) { ret
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_CHAT(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_CHAT); }
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_RCON(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_RCON); }
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_GAMESCRIPT(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_GAMESCRIPT); }
+NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_PING(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_PING); }
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_FULL(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_FULL); }
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_BANNED(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_BANNED); }
@@ -164,5 +167,6 @@ NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CONSOLE(Packet *p) {
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CMD_NAMES(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CMD_NAMES); }
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CMD_LOGGING(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CMD_LOGGING); }
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_RCON_END(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_RCON_END); }
+NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_PONG(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_PONG); }
#endif /* ENABLE_NETWORK */
diff --git a/src/network/core/tcp_admin.h b/src/network/core/tcp_admin.h
index d642deb4c..72c2e1160 100644
--- a/src/network/core/tcp_admin.h
+++ b/src/network/core/tcp_admin.h
@@ -33,6 +33,7 @@ enum PacketAdminType {
ADMIN_PACKET_ADMIN_CHAT, ///< The admin sends a chat message to be distributed.
ADMIN_PACKET_ADMIN_RCON, ///< The admin sends a remote console command.
ADMIN_PACKET_ADMIN_GAMESCRIPT, ///< The admin sends a JSON string for the GameScript.
+ ADMIN_PACKET_ADMIN_PING, ///< The admin sends a ping to the server, expecting a ping-reply (PONG) packet.
ADMIN_PACKET_SERVER_FULL = 100, ///< The server tells the admin it cannot accept the admin.
ADMIN_PACKET_SERVER_BANNED, ///< The server tells the admin it is banned.
@@ -61,6 +62,7 @@ enum PacketAdminType {
ADMIN_PACKET_SERVER_CMD_LOGGING, ///< The server gives the admin copies of incoming command packets.
ADMIN_PACKET_SERVER_GAMESCRIPT, ///< The server gives the admin information from the GameScript in JSON.
ADMIN_PACKET_SERVER_RCON_END, ///< The server indicates that the remote console command has completed.
+ ADMIN_PACKET_SERVER_PONG, ///< The server replies to a ping request from the admin.
INVALID_ADMIN_PACKET = 0xFF, ///< An invalid marker for admin packets.
};
@@ -182,6 +184,14 @@ protected:
virtual NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet *p);
/**
+ * Ping the server, requiring the server to reply with a pong packet.
+ * uint32 Integer value to pass to the server, which is quoted in the reply.
+ * @param p The packet that was just received.
+ * @return The state the network should have.
+ */
+ virtual NetworkRecvStatus Receive_ADMIN_PING(Packet *p);
+
+ /**
* The server is full (connection gets closed).
* @param p The packet that was just received.
* @return The state the network should have.
@@ -456,6 +466,14 @@ protected:
virtual NetworkRecvStatus Receive_SERVER_CMD_LOGGING(Packet *p);
/**
+ * Send a ping-reply (pong) to the admin that sent us the ping packet.
+ * uint32 Integer identifier - should be the same as read from the admins ping packet.
+ * @param p The packet that was just received.
+ * @return The state the network should have.
+ */
+ virtual NetworkRecvStatus Receive_SERVER_PONG(Packet *p);
+
+ /**
* Notify the admin connection that the rcon command has finished.
* string The command as requested by the admin connection.
* @param p The packet that was just received.
diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp
index 93cfe2807..326559e0b 100644
--- a/src/network/network_admin.cpp
+++ b/src/network/network_admin.cpp
@@ -540,6 +540,17 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_GAMESCRIPT(Pack
return NETWORK_RECV_STATUS_OKAY;
}
+NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_PING(Packet *p)
+{
+ if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
+
+ uint32 d1 = p->Recv_uint32();
+
+ DEBUG(net, 2, "[admin] Ping from '%s' (%s): '%d'", this->admin_name, this->admin_version, d1);
+
+ return this->SendPong(d1);
+}
+
/**
* Send console output of other clients.
* @param origin The origin of the string.
@@ -581,6 +592,17 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendGameScript(const char *js
return NETWORK_RECV_STATUS_OKAY;
}
+/** Send ping-reply (pong) to admin **/
+NetworkRecvStatus ServerNetworkAdminSocketHandler::SendPong(uint32 d1)
+{
+ Packet *p = new Packet(ADMIN_PACKET_SERVER_PONG);
+
+ p->Send_uint32(d1);
+ this->SendPacket(p);
+
+ return NETWORK_RECV_STATUS_OKAY;
+}
+
/** Send the names of the commands. */
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdNames()
{
diff --git a/src/network/network_admin.h b/src/network/network_admin.h
index 8348e741b..cb478fc7e 100644
--- a/src/network/network_admin.h
+++ b/src/network/network_admin.h
@@ -35,8 +35,10 @@ protected:
virtual NetworkRecvStatus Receive_ADMIN_CHAT(Packet *p);
virtual NetworkRecvStatus Receive_ADMIN_RCON(Packet *p);
virtual NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet *p);
+ virtual NetworkRecvStatus Receive_ADMIN_PING(Packet *p);
NetworkRecvStatus SendProtocol();
+ NetworkRecvStatus SendPong(uint32 d1);
public:
AdminUpdateFrequency update_frequency[ADMIN_UPDATE_END]; ///< Admin requested update intervals.
uint32 realtime_connect; ///< Time of connection.