OpenTTD Source  20241120-master-g6d3adc6169
tcp_coordinator.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
12 #ifndef NETWORK_CORE_TCP_COORDINATOR_H
13 #define NETWORK_CORE_TCP_COORDINATOR_H
14 
15 #include "os_abstraction.h"
16 #include "tcp.h"
17 #include "packet.h"
18 #include "network_game_info.h"
19 
28 enum PacketCoordinatorType : uint8_t {
47 };
48 
58 };
59 
68 };
69 
72 protected:
74 
86  virtual bool Receive_GC_ERROR(Packet &p);
87 
101  virtual bool Receive_SERVER_REGISTER(Packet &p);
102 
113  virtual bool Receive_GC_REGISTER_ACK(Packet &p);
114 
124  virtual bool Receive_SERVER_UPDATE(Packet &p);
125 
137  virtual bool Receive_CLIENT_LISTING(Packet &p);
138 
152  virtual bool Receive_GC_LISTING(Packet &p);
153 
163  virtual bool Receive_CLIENT_CONNECT(Packet &p);
164 
175  virtual bool Receive_GC_CONNECTING(Packet &p);
176 
187  virtual bool Receive_SERCLI_CONNECT_FAILED(Packet &p);
188 
199  virtual bool Receive_GC_CONNECT_FAILED(Packet &p);
200 
211  virtual bool Receive_CLIENT_CONNECTED(Packet &p);
212 
225  virtual bool Receive_GC_DIRECT_CONNECT(Packet &p);
226 
240  virtual bool Receive_GC_STUN_REQUEST(Packet &p);
241 
253  virtual bool Receive_SERCLI_STUN_RESULT(Packet &p);
254 
269  virtual bool Receive_GC_STUN_CONNECT(Packet &p);
270 
292  virtual bool Receive_GC_NEWGRF_LOOKUP(Packet &p);
293 
306  virtual bool Receive_GC_TURN_CONNECT(Packet &p);
307 
308  bool HandlePacket(Packet &p);
309 public:
314  NetworkCoordinatorSocketHandler(SOCKET s = INVALID_SOCKET) : NetworkTCPSocketHandler(s) {}
315 
316  bool ReceivePackets();
317 };
318 
319 #endif /* NETWORK_CORE_TCP_COORDINATOR_H */
Base socket handler for all Game Coordinator TCP sockets.
virtual bool Receive_SERCLI_STUN_RESULT(Packet &p)
Client/server informs the Game Coordinator the result of a STUN request.
virtual bool Receive_CLIENT_LISTING(Packet &p)
Client requests a list of all public servers.
bool ReceiveInvalidPacket(PacketCoordinatorType type)
Helper for logging receiving invalid packets.
virtual bool Receive_GC_ERROR(Packet &p)
Game Coordinator indicates there was an error.
virtual bool Receive_CLIENT_CONNECTED(Packet &p)
Client informs the Game Coordinator the connection with the Server is established.
virtual bool Receive_GC_STUN_CONNECT(Packet &p)
Game Coordinator informs the client/server of its STUN peer (the host:ip of the other side).
virtual bool Receive_GC_NEWGRF_LOOKUP(Packet &p)
Game Coordinator informs the client of updates for the NewGRFs lookup table as used by the NewGRF des...
virtual bool Receive_GC_REGISTER_ACK(Packet &p)
Game Coordinator acknowledges the registration.
virtual bool Receive_GC_TURN_CONNECT(Packet &p)
Game Coordinator requests that we make a connection to the indicated peer, which is a TURN server.
virtual bool Receive_GC_LISTING(Packet &p)
Game Coordinator replies with a list of all public servers.
virtual bool Receive_GC_DIRECT_CONNECT(Packet &p)
Game Coordinator requests that the Client makes a direct connection to the indicated peer,...
virtual bool Receive_CLIENT_CONNECT(Packet &p)
Client wants to connect to a Server.
virtual bool Receive_SERCLI_CONNECT_FAILED(Packet &p)
Client or Server failed to connect to the remote side.
virtual bool Receive_GC_CONNECTING(Packet &p)
Game Coordinator informs the Client under what token it will start the attempt to connect the Server ...
virtual bool Receive_GC_STUN_REQUEST(Packet &p)
Game Coordinator requests the client/server to do a STUN request to the STUN server.
virtual bool Receive_SERVER_REGISTER(Packet &p)
Server is starting a multiplayer game and wants to let the Game Coordinator know.
virtual bool Receive_GC_CONNECT_FAILED(Packet &p)
Game Coordinator informs the Client that it failed to find a way to connect the Client to the Server.
bool HandlePacket(Packet &p)
Handle the given packet, i.e.
virtual bool Receive_SERVER_UPDATE(Packet &p)
Send an update of the current state of the server to the Game Coordinator.
NetworkCoordinatorSocketHandler(SOCKET s=INVALID_SOCKET)
Create a new cs socket handler for a given cs.
bool ReceivePackets()
Receive a packet at TCP level.
Base socket handler for all TCP sockets.
Definition: tcp.h:31
Network stuff has many things that needs to be included and/or implemented by default.
Basic functions to create, fill and read packets.
Internal entity of a packet.
Definition: packet.h:42
Basic functions to receive and send TCP packets.
PacketCoordinatorType
Enum with all types of TCP Game Coordinator packets.
@ PACKET_COORDINATOR_GC_STUN_CONNECT
Game Coordinator tells client/server to connect() reusing the STUN local address.
@ PACKET_COORDINATOR_GC_LISTING
Game Coordinator returns a listing of all public servers.
@ PACKET_COORDINATOR_SERCLI_CONNECT_FAILED
Client/server tells the Game Coordinator the current connection attempt failed.
@ PACKET_COORDINATOR_GC_TURN_CONNECT
Game Coordinator tells client/server to connect to a specific TURN server.
@ PACKET_COORDINATOR_SERCLI_STUN_RESULT
Client/server informs the Game Coordinator of the result of the STUN request.
@ PACKET_COORDINATOR_CLIENT_LISTING
Client is requesting a listing of all public servers.
@ PACKET_COORDINATOR_GC_STUN_REQUEST
Game Coordinator tells client/server to initiate a STUN request.
@ PACKET_COORDINATOR_GC_DIRECT_CONNECT
Game Coordinator tells client to directly connect to the hostname:port of the server.
@ PACKET_COORDINATOR_GC_NEWGRF_LOOKUP
Game Coordinator informs client about NewGRF lookup table updates needed for GC_LISTING.
@ PACKET_COORDINATOR_SERVER_REGISTER
Server registration.
@ PACKET_COORDINATOR_END
Must ALWAYS be on the end of this list!! (period)
@ PACKET_COORDINATOR_GC_REGISTER_ACK
Game Coordinator accepts the registration.
@ PACKET_COORDINATOR_CLIENT_CONNECT
Client wants to connect to a server based on an invite code.
@ PACKET_COORDINATOR_GC_CONNECTING
Game Coordinator informs the client of the token assigned to the connection attempt.
@ PACKET_COORDINATOR_GC_ERROR
Game Coordinator indicates there was an error.
@ PACKET_COORDINATOR_CLIENT_CONNECTED
Client informs the Game Coordinator the connection with the server is established.
@ PACKET_COORDINATOR_GC_CONNECT_FAILED
Game Coordinator informs client/server it has given up on the connection attempt.
@ PACKET_COORDINATOR_SERVER_UPDATE
Server sends an set intervals an update of the server.
NetworkCoordinatorErrorType
The type of error from the Game Coordinator.
@ NETWORK_COORDINATOR_ERROR_UNKNOWN
There was an unknown error.
@ NETWORK_COORDINATOR_ERROR_REGISTRATION_FAILED
Your request for registration failed.
@ NETWORK_COORDINATOR_ERROR_INVALID_INVITE_CODE
The invite code given is invalid.
@ NETWORK_COORDINATOR_ERROR_REUSE_OF_INVITE_CODE
The invite code is used by another (newer) server.
ConnectionType
The type of connection the Game Coordinator can detect we have.
@ CONNECTION_TYPE_ISOLATED
The Game Coordinator failed to find a way to connect to your server. Nobody will be able to join.
@ CONNECTION_TYPE_DIRECT
The Game Coordinator can directly connect to your server.
@ CONNECTION_TYPE_STUN
The Game Coordinator can connect to your server via a STUN request.
@ CONNECTION_TYPE_UNKNOWN
The Game Coordinator hasn't informed us yet what type of connection we have.
@ CONNECTION_TYPE_TURN
The Game Coordinator needs you to connect to a relay.