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");
122 _udp_client.socket = std::make_unique<ClientNetworkUDPSocketHandler>();
126 _udp_server.socket = std::make_unique<ServerNetworkUDPSocketHandler>(&server);
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.
NetworkUDPSocketHandler(NetworkAddressList *bind=nullptr)
Create an UDP socket but don't listen yet.
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.
Functions related to debugging.
#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.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Definition of base types and functions in a cross-platform compatible way.
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.