summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-04-26 20:02:27 +0200
committerPatric Stout <github@truebrain.nl>2021-04-27 20:18:53 +0200
commitb3003dd163ab6b7902da33fa6cfaa29e45556db1 (patch)
tree545a4f7fbbacb9da797ed6948dd614424607851d /src/network
parent84c75a7b9a8aeb60506454260f9c98454ffb8ab5 (diff)
downloadopenttd-b3003dd163ab6b7902da33fa6cfaa29e45556db1.tar.xz
Add: ability to retrieve game info from server over TCP
Diffstat (limited to 'src/network')
-rw-r--r--src/network/core/tcp_game.cpp4
-rw-r--r--src/network/core/tcp_game.h19
-rw-r--r--src/network/network_server.cpp19
-rw-r--r--src/network/network_server.h2
4 files changed, 43 insertions, 1 deletions
diff --git a/src/network/core/tcp_game.cpp b/src/network/core/tcp_game.cpp
index 06e56e229..eb53db5ac 100644
--- a/src/network/core/tcp_game.cpp
+++ b/src/network/core/tcp_game.cpp
@@ -71,6 +71,8 @@ NetworkRecvStatus NetworkGameSocketHandler::HandlePacket(Packet *p)
case PACKET_SERVER_BANNED: return this->Receive_SERVER_BANNED(p);
case PACKET_CLIENT_JOIN: return this->Receive_CLIENT_JOIN(p);
case PACKET_SERVER_ERROR: return this->Receive_SERVER_ERROR(p);
+ case PACKET_CLIENT_GAME_INFO: return this->Receive_CLIENT_GAME_INFO(p);
+ case PACKET_SERVER_GAME_INFO: return this->Receive_SERVER_GAME_INFO(p);
case PACKET_CLIENT_COMPANY_INFO: return this->Receive_CLIENT_COMPANY_INFO(p);
case PACKET_SERVER_COMPANY_INFO: return this->Receive_SERVER_COMPANY_INFO(p);
case PACKET_SERVER_CLIENT_INFO: return this->Receive_SERVER_CLIENT_INFO(p);
@@ -157,6 +159,8 @@ NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_FULL(Packet *p) { ret
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_BANNED(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_BANNED); }
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_JOIN); }
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_ERROR); }
+NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_GAME_INFO(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_GAME_INFO); }
+NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_GAME_INFO(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_GAME_INFO); }
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_COMPANY_INFO(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_COMPANY_INFO); }
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMPANY_INFO(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_COMPANY_INFO); }
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_CLIENT_INFO); }
diff --git a/src/network/core/tcp_game.h b/src/network/core/tcp_game.h
index 95b5f8c6c..6dcc0bd01 100644
--- a/src/network/core/tcp_game.h
+++ b/src/network/core/tcp_game.h
@@ -24,7 +24,7 @@
*/
enum PacketGameType {
/*
- * These first three pair of packets (thus six in
+ * These first four pair of packets (thus eight in
* total) must remain in this order for backward
* and forward compatibility between clients that
* are trying to join directly.
@@ -42,6 +42,10 @@ enum PacketGameType {
PACKET_CLIENT_COMPANY_INFO, ///< Request information about all companies.
PACKET_SERVER_COMPANY_INFO, ///< Information about a single company.
+ /* Packets used to get the game info. */
+ PACKET_CLIENT_GAME_INFO, ///< Request information about the server.
+ PACKET_SERVER_GAME_INFO, ///< Information about the server.
+
/*
* Packets after here assume that the client
* and server are running the same version. As
@@ -184,6 +188,19 @@ protected:
virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet *p);
/**
+ * Request game information.
+ * @param p The packet that was just received.
+ */
+ virtual NetworkRecvStatus Receive_CLIENT_GAME_INFO(Packet *p);
+
+ /**
+ * Sends information about the game.
+ * Serialized NetworkGameInfo. See game_info.h for details.
+ * @param p The packet that was just received.
+ */
+ virtual NetworkRecvStatus Receive_SERVER_GAME_INFO(Packet *p);
+
+ /**
* Request company information (in detail).
* @param p The packet that was just received.
*/
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 6bc6f8291..fd69a8d37 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -353,6 +353,20 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendClientInfo(NetworkClientIn
return NETWORK_RECV_STATUS_OKAY;
}
+/** Send the client information about the server. */
+NetworkRecvStatus ServerNetworkGameSocketHandler::SendGameInfo()
+{
+ NetworkGameInfo ngi;
+ FillNetworkGameInfo(ngi);
+
+ Packet *p = new Packet(PACKET_SERVER_GAME_INFO);
+ SerializeNetworkGameInfo(p, &ngi);
+
+ this->SendPacket(p);
+
+ return NETWORK_RECV_STATUS_OKAY;
+}
+
/** Send the client information about the companies. */
NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyInfo()
{
@@ -828,6 +842,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendConfigUpdate()
* DEF_SERVER_RECEIVE_COMMAND has parameter: NetworkClientSocket *cs, Packet *p
************/
+NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GAME_INFO(Packet *p)
+{
+ return this->SendGameInfo();
+}
+
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMPANY_INFO(Packet *p)
{
return this->SendCompanyInfo();
diff --git a/src/network/network_server.h b/src/network/network_server.h
index 4f6033fab..e72377e82 100644
--- a/src/network/network_server.h
+++ b/src/network/network_server.h
@@ -24,6 +24,7 @@ extern NetworkClientSocketPool _networkclientsocket_pool;
class ServerNetworkGameSocketHandler : public NetworkClientSocketPool::PoolItem<&_networkclientsocket_pool>, public NetworkGameSocketHandler, public TCPListenHandler<ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED> {
protected:
NetworkRecvStatus Receive_CLIENT_JOIN(Packet *p) override;
+ NetworkRecvStatus Receive_CLIENT_GAME_INFO(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_COMPANY_INFO(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD(Packet *p) override;
@@ -40,6 +41,7 @@ protected:
NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_MOVE(Packet *p) override;
+ NetworkRecvStatus SendGameInfo();
NetworkRecvStatus SendCompanyInfo();
NetworkRecvStatus SendNewGRFCheck();
NetworkRecvStatus SendWelcome();