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");
std::vector< NetworkAddress > NetworkAddressList
Type for a list of addresses.
*** Communication with servers (we are client) ***/
void Receive_SERVER_RESPONSE(Packet &p, NetworkAddress &client_addr) override
Response to a query letting the client know we are here.
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
const std::string & GetHostname()
Get the hostname; in case it wasn't given the IPv4 dotted representation is given.
std::string GetAddressAsString(bool with_family=true)
Get the address as a string, e.g.
Base socket handler for all UDP sockets.
void CloseSocket()
Close the actual UDP socket.
bool Listen()
Start listening on the given host and port.
void SendPacket(Packet &p, NetworkAddress &recv, bool all=false, bool broadcast=false)
Send a packet over UDP.
void ReceivePackets()
Receive a packet at UDP level.
*** Communication with clients (we are server) ***/
void Receive_CLIENT_FIND_SERVER(Packet &p, NetworkAddress &client_addr) override
Queries to the server for information about the game.
ServerNetworkUDPSocketHandler(NetworkAddressList *addresses)
Create the socket.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
NetworkAddressList _broadcast_list
List of broadcast addresses.
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.
void GetBindAddresses(NetworkAddressList *addresses, uint16_t port)
Get the addresses to bind to.
Basic functions/variables used all over the place.
Handling of the list of games.
Variables and function used internally.
void NetworkUDPClose()
Close all UDP related stuff.
static UDPSocket _udp_server("Server")
udp server socket
void NetworkUDPInitialize()
Initialize the whole UDP bit.
void NetworkUDPSearchGame()
Find all servers.
void NetworkUDPServerListen()
Start the listening of the UDP server component.
static UDPSocket _udp_client("Client")
udp client socket
void NetworkBackgroundUDPLoop()
Receive the UDP packets.
static uint16_t _network_udp_broadcast
Timeout for the UDP broadcasts.
static void NetworkUDPBroadCast(NetworkUDPSocketHandler *socket)
Broadcast to all ips.
static bool _network_udp_server
Is the UDP server started?
Sending and receiving UDP messages.
ClientSettings _settings_client
The current settings for this game.
NetworkSettings network
settings related to the network
uint16_t server_port
port the server listens on
Internal entity of a packet.
Some information about a socket, which exists before the actual socket has been created to provide lo...
NetworkUDPSocketHandler * socket
The actual socket, which may be nullptr when not initialized yet.
const std::string name
The name of the socket.
Basic functions to receive and send UDP packets.
@ PACKET_UDP_CLIENT_FIND_SERVER
Queries a game server for game information.
@ PACKET_UDP_SERVER_RESPONSE
Reply of the game server with game information.