23#include "../safeguards.h"
31 std::unique_ptr<NetworkUDPSocketHandler>
socket =
nullptr;
37 this->socket->CloseSocket();
38 this->socket =
nullptr;
43 this->socket->ReceivePackets();
94 Debug(net, 5,
"Broadcasting to {}", addr.GetHostname());
107 Debug(net, 3,
"Searching server");
119 Debug(net, 3,
"Initializing UDP listeners");
146 Debug(net, 5,
"Closed UDP listeners");
std::vector< NetworkAddress > NetworkAddressList
Type for a list of addresses.
Helper class for handling all client side communication.
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 SendPacket(Packet &p, NetworkAddress &recv, bool all=false, bool broadcast=false)
Send a packet over UDP.
Helper class for handling all server side communication.
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,...)
Output a line of debugging information.
NetworkAddressList _broadcast_list
List of broadcast addresses.
NetworkGame * NetworkAddServer(std::string_view 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.
Variables and function used internally.
static void NetworkUDPBroadCast(NetworkUDPSocketHandler &socket)
Broadcast to all ips.
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 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...
std::unique_ptr< 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.