OpenTTD Source 20241224-master-gf74b0cf984
network_udp.cpp File Reference

This file handles the UDP related communication. More...

#include "../stdafx.h"
#include "../timer/timer_game_calendar.h"
#include "../map_func.h"
#include "../debug.h"
#include "core/network_game_info.h"
#include "network_gamelist.h"
#include "network_internal.h"
#include "network_udp.h"
#include "network.h"
#include "../core/endian_func.hpp"
#include "../company_base.h"
#include "../rev.h"
#include "../newgrf_text.h"
#include "../strings_func.h"
#include "table/strings.h"
#include "core/udp.h"
#include "../safeguards.h"

Go to the source code of this file.

Data Structures

struct  UDPSocket
 Some information about a socket, which exists before the actual socket has been created to provide locking and the likes. More...
 
class  ServerNetworkUDPSocketHandler
 ‍*** Communication with clients (we are server) ***‍/ More...
 
class  ClientNetworkUDPSocketHandler
 ‍*** Communication with servers (we are client) ***‍/ More...
 

Functions

static void NetworkUDPBroadCast (NetworkUDPSocketHandler *socket)
 Broadcast to all ips.
 
void NetworkUDPSearchGame ()
 Find all servers.
 
void NetworkUDPInitialize ()
 Initialize the whole UDP bit.
 
void NetworkUDPServerListen ()
 Start the listening of the UDP server component.
 
void NetworkUDPClose ()
 Close all UDP related stuff.
 
void NetworkBackgroundUDPLoop ()
 Receive the UDP packets.
 

Variables

static bool _network_udp_server
 Is the UDP server started?
 
static uint16_t _network_udp_broadcast
 Timeout for the UDP broadcasts.
 
static UDPSocket _udp_client ("Client")
 udp client socket
 
static UDPSocket _udp_server ("Server")
 udp server socket
 

Detailed Description

This file handles the UDP related communication.

This is the GameServer <-> GameClient communication before the game is being joined.

Definition in file network_udp.cpp.

Function Documentation

◆ NetworkBackgroundUDPLoop()

void NetworkBackgroundUDPLoop ( )

Receive the UDP packets.

Definition at line 161 of file network_udp.cpp.

References _network_udp_broadcast, _network_udp_server, _udp_client, and _udp_server.

Referenced by NetworkBackgroundLoop().

◆ NetworkUDPBroadCast()

static void NetworkUDPBroadCast ( NetworkUDPSocketHandler socket)
static

Broadcast to all ips.

Definition at line 102 of file network_udp.cpp.

References _broadcast_list, Debug, PACKET_UDP_CLIENT_FIND_SERVER, and NetworkUDPSocketHandler::SendPacket().

Referenced by NetworkUDPSearchGame().

◆ NetworkUDPClose()

void NetworkUDPClose ( )

Close all UDP related stuff.

Definition at line 150 of file network_udp.cpp.

References _network_udp_broadcast, _network_udp_server, _udp_client, _udp_server, and Debug.

Referenced by NetworkShutDown(), and NetworkUDPInitialize().

◆ NetworkUDPInitialize()

◆ NetworkUDPSearchGame()

void NetworkUDPSearchGame ( )

Find all servers.

Definition at line 113 of file network_udp.cpp.

References _network_udp_broadcast, _udp_client, Debug, NetworkUDPBroadCast(), and UDPSocket::socket.

Referenced by NetworkGameWindow::OnClick().

◆ NetworkUDPServerListen()

void NetworkUDPServerListen ( )

Start the listening of the UDP server component.

Definition at line 144 of file network_udp.cpp.

References _network_udp_server, _udp_server, NetworkUDPSocketHandler::Listen(), and UDPSocket::socket.

Variable Documentation

◆ _network_udp_broadcast

uint16_t _network_udp_broadcast
static

Timeout for the UDP broadcasts.

Definition at line 36 of file network_udp.cpp.

Referenced by NetworkBackgroundUDPLoop(), NetworkUDPClose(), NetworkUDPInitialize(), and NetworkUDPSearchGame().

◆ _network_udp_server

bool _network_udp_server
static

Is the UDP server started?

Definition at line 35 of file network_udp.cpp.

Referenced by NetworkBackgroundUDPLoop(), NetworkUDPClose(), NetworkUDPInitialize(), and NetworkUDPServerListen().