OpenTTD Source 20260421-master-gc2fbc6fdeb
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef NETWORK_CORE_TCP_COORDINATOR_H
11#define NETWORK_CORE_TCP_COORDINATOR_H
12
13#include "os_abstraction.h"
14#include "tcp.h"
15#include "packet.h"
16#include "network_game_info.h"
17
47
49 static constexpr bool value = true;
50};
51
62
72
75protected:
77
89 virtual bool ReceiveGameCoordinatorError(Packet &p);
90
104 virtual bool ReceiveServerRegister(Packet &p);
105
116 virtual bool ReceiveGameCoordinatorRegisterAck(Packet &p);
117
127 virtual bool ReceiveServerUpdate(Packet &p);
128
140 virtual bool ReceiveClientListing(Packet &p);
141
155 virtual bool ReceiveGameCoordinatorListing(Packet &p);
156
166 virtual bool ReceiveClientConnect(Packet &p);
167
178 virtual bool ReceiveGameCoordinatorConnecting(Packet &p);
179
190 virtual bool ReceiveServerOrClientConnectFailed(Packet &p);
191
202 virtual bool ReceiveGameCoordinatorConnectFailed(Packet &p);
203
214 virtual bool ReceiveClientConnected(Packet &p);
215
228 virtual bool ReceiveGameCoordinatorDirectConnect(Packet &p);
229
243 virtual bool ReceiveGameCoordinatorStunRequest(Packet &p);
244
256 virtual bool ReceiveServerOrClientStunResult(Packet &p);
257
272 virtual bool ReceiveGameCoordinatorStunConnect(Packet &p);
273
295 virtual bool ReceiveGameCoordinatorNewGRFLookup(Packet &p);
296
309 virtual bool ReceiveGameCoordinatorTurnConnect(Packet &p);
310
311 bool HandlePacket(Packet &p);
312public:
318
319 bool ReceivePackets();
320};
321
322#endif /* NETWORK_CORE_TCP_COORDINATOR_H */
virtual bool ReceiveGameCoordinatorError(Packet &p)
Game Coordinator indicates there was an error.
bool ReceiveInvalidPacket(PacketCoordinatorType type)
Helper for logging receiving invalid packets.
virtual bool ReceiveGameCoordinatorListing(Packet &p)
Game Coordinator replies with a list of all public servers.
virtual bool ReceiveGameCoordinatorStunConnect(Packet &p)
Game Coordinator informs the client/server of its STUN peer (the host:ip of the other side).
virtual bool ReceiveClientListing(Packet &p)
Client requests a list of all public servers.
virtual bool ReceiveServerOrClientStunResult(Packet &p)
Client/server informs the Game Coordinator the result of a STUN request.
virtual bool ReceiveGameCoordinatorDirectConnect(Packet &p)
Game Coordinator requests that the Client makes a direct connection to the indicated peer,...
virtual bool ReceiveServerUpdate(Packet &p)
Send an update of the current state of the server to the Game Coordinator.
virtual bool ReceiveClientConnected(Packet &p)
Client informs the Game Coordinator the connection with the Server is established.
virtual bool ReceiveServerOrClientConnectFailed(Packet &p)
Client or Server failed to connect to the remote side.
virtual bool ReceiveGameCoordinatorConnecting(Packet &p)
Game Coordinator informs the Client under what token it will start the attempt to connect the Server ...
virtual bool ReceiveGameCoordinatorTurnConnect(Packet &p)
Game Coordinator requests that we make a connection to the indicated peer, which is a TURN server.
bool HandlePacket(Packet &p)
Handle the given packet, i.e.
virtual bool ReceiveGameCoordinatorConnectFailed(Packet &p)
Game Coordinator informs the Client that it failed to find a way to connect the Client to the Server.
virtual bool ReceiveGameCoordinatorRegisterAck(Packet &p)
Game Coordinator acknowledges the registration.
NetworkCoordinatorSocketHandler(SOCKET s=INVALID_SOCKET)
Create a new cs socket handler for a given cs.
virtual bool ReceiveGameCoordinatorStunRequest(Packet &p)
Game Coordinator requests the client/server to do a STUN request to the STUN server.
virtual bool ReceiveServerRegister(Packet &p)
Server is starting a multiplayer game and wants to let the Game Coordinator know.
bool ReceivePackets()
Receive a packet at TCP level.
virtual bool ReceiveGameCoordinatorNewGRFLookup(Packet &p)
Game Coordinator informs the client of updates for the NewGRFs lookup table as used by the NewGRF des...
virtual bool ReceiveClientConnect(Packet &p)
Client wants to connect to a Server.
NetworkTCPSocketHandler(SOCKET s=INVALID_SOCKET)
Construct a socket handler for a TCP connection.
Definition tcp.h:64
Convert NetworkGameInfo to Packet and back.
Includes and/or implementations for the network stuff.
Basic functions to create, fill and read packets.
static constexpr bool value
This is an enumeration of a PacketType.
Trait to mark an enumeration as a PacketType.
Definition packet.h:33
Basic functions to receive and send TCP packets.
PacketCoordinatorType
Enum with all types of TCP Game Coordinator packets.
@ ServerOrClientConnectFailed
Client/server tells the Game Coordinator the current connection attempt failed.
@ GameCoordinatorConnecting
Game Coordinator informs the client of the token assigned to the connection attempt.
@ GameCoordinatorStunConnect
Game Coordinator tells client/server to connect() reusing the STUN local address.
@ GameCoordinatorError
Game Coordinator indicates there was an error.
@ ClientListing
Client is requesting a listing of all public servers.
@ ServerOrClientStunResult
Client/server informs the Game Coordinator of the result of the STUN request.
@ GameCoordinatorConnectFailed
Game Coordinator informs client/server it has given up on the connection attempt.
@ ServerRegister
Server registration.
@ GameCoordinatorStunRequest
Game Coordinator tells client/server to initiate a STUN request.
@ GameCoordinatorDirectConnect
Game Coordinator tells client to directly connect to the hostname:port of the server.
@ ClientConnected
Client informs the Game Coordinator the connection with the server is established.
@ GameCoordinatorTurnConnect
Game Coordinator tells client/server to connect to a specific TURN server.
@ ServerUpdate
Server sends an set intervals an update of the server.
@ GameCoordinatorListing
Game Coordinator returns a listing of all public servers.
@ ClientConnect
Client wants to connect to a server based on an invite code.
@ GameCoordinatorRegisterAck
Game Coordinator accepts the registration.
@ GameCoordinatorNewGRFLookup
Game Coordinator informs client about NewGRF lookup table updates needed for GC_LISTING.
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.