OpenTTD Source
20240919-master-gdf0233f4c2
|
Go to the documentation of this file.
15 #include "../stdafx.h"
16 #include "../timer/timer_game_calendar.h"
17 #include "../map_func.h"
19 #include "core/network_game_info.h"
24 #include "../core/endian_func.hpp"
25 #include "../company_base.h"
27 #include "../newgrf_text.h"
28 #include "../strings_func.h"
29 #include "table/strings.h"
33 #include "../safeguards.h"
49 this->socket =
nullptr;
105 Debug(net, 5,
"Broadcasting to {}", addr.GetHostname());
118 Debug(net, 3,
"Searching server");
130 Debug(net, 3,
"Initializing UDP listeners");
157 Debug(net, 5,
"Closed UDP listeners");
Base socket handler for all UDP sockets.
void SendPacket(Packet &p, NetworkAddress &recv, bool all=false, bool broadcast=false)
Send a packet over UDP.
NetworkGameList * NetworkAddServer(const std::string &connection_string, bool manually, bool never_expire)
Validates an address entered as a string and adds the server to the list.
const std::string name
The name of the socket.
void NetworkUDPServerListen()
Start the listening of the UDP server component.
void GetBindAddresses(NetworkAddressList *addresses, uint16_t port)
Get the addresses to bind to.
static UDPSocket _udp_client("Client")
udp client socket
static UDPSocket _udp_server("Server")
udp server socket
static void NetworkUDPBroadCast(NetworkUDPSocketHandler *socket)
Broadcast to all ips.
ClientSettings _settings_client
The current settings for this game.
void CloseSocket()
Close the actual UDP socket.
void NetworkUDPSearchGame()
Find all servers.
Some information about a socket, which exists before the actual socket has been created to provide lo...
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
@ PACKET_UDP_SERVER_RESPONSE
Reply of the game server with game information.
std::vector< NetworkAddress > NetworkAddressList
Type for a list of addresses.
NetworkUDPSocketHandler * socket
The actual socket, which may be nullptr when not initialized yet.
void Receive_CLIENT_FIND_SERVER(Packet &p, NetworkAddress &client_addr) override
Queries to the server for information about the game.
std::string GetAddressAsString(bool with_family=true)
Get the address as a string, e.g.
Internal entity of a packet.
*** Communication with servers (we are client) ***/
@ PACKET_UDP_CLIENT_FIND_SERVER
Queries a game server for game information.
uint16_t server_port
port the server listens on
void NetworkBackgroundUDPLoop()
Receive the UDP packets.
*** Communication with clients (we are server) ***/
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
static bool _network_udp_server
Is the UDP server started?
void NetworkUDPInitialize()
Initialize the whole UDP bit.
const std::string & GetHostname()
Get the hostname; in case it wasn't given the IPv4 dotted representation is given.
bool Listen()
Start listening on the given host and port.
void NetworkUDPClose()
Close all UDP related stuff.
NetworkSettings network
settings related to the network
void ReceivePackets()
Receive a packet at UDP level.
void Receive_SERVER_RESPONSE(Packet &p, NetworkAddress &client_addr) override
Response to a query letting the client know we are here.
ServerNetworkUDPSocketHandler(NetworkAddressList *addresses)
Create the socket.
static uint16_t _network_udp_broadcast
Timeout for the UDP broadcasts.
NetworkAddressList _broadcast_list
List of broadcast addresses.