OpenTTD Source  1.11.2
network_udp.cpp File Reference
#include "../stdafx.h"
#include "../date_func.h"
#include "../map_func.h"
#include "../debug.h"
#include "core/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 "../thread.h"
#include "../rev.h"
#include "../newgrf_text.h"
#include "../strings_func.h"
#include "table/strings.h"
#include <mutex>
#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  MasterNetworkUDPSocketHandler
 ‍*** Communication with the masterserver ***‍/ More...
 
class  ServerNetworkUDPSocketHandler
 ‍*** Communication with clients (we are server) ***‍/ More...
 
class  ClientNetworkUDPSocketHandler
 ‍*** Communication with servers (we are client) ***‍/ More...
 

Functions

static const std::chrono::minutes ADVERTISE_NORMAL_INTERVAL (15)
 interval between advertising.
 
static const std::chrono::seconds ADVERTISE_RETRY_INTERVAL (10)
 re-advertise when no response after this amount of time.
 
static void DoNetworkUDPQueryServer (NetworkAddress &address, bool needs_mutex, bool manually)
 Helper function doing the actual work for querying the server. More...
 
void NetworkUDPQueryServer (NetworkAddress address, bool manually)
 Query a specific server. More...
 
static void NetworkUDPBroadCast (NetworkUDPSocketHandler *socket)
 Broadcast to all ips.
 
void NetworkUDPQueryMasterServer ()
 Request the the server-list from the master server.
 
void NetworkUDPSearchGame ()
 Find all servers.
 
static void NetworkUDPRemoveAdvertiseThread ()
 Thread entry point for de-advertising.
 
void NetworkUDPRemoveAdvertise (bool blocking)
 Remove our advertise from the master-server. More...
 
static void NetworkUDPAdvertiseThread ()
 Thread entry point for advertising.
 
void NetworkUDPAdvertise ()
 Register us to the master server This function checks if it needs to send an advertise. More...
 
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 uint64 _session_key = 0
 Session key to register ourselves to the master server.
 
static const uint32 ADVERTISE_RETRY_TIMES = 3
 give up re-advertising after this much failed retries
 
static bool _network_udp_server
 Is the UDP server started?
 
static uint16 _network_udp_broadcast
 Timeout for the UDP broadcasts.
 
static uint8 _network_advertise_retries
 The number of advertisement retries we did.
 
static UDPSocket _udp_client ("Client")
 udp client socket
 
static UDPSocket _udp_server ("Server")
 udp server socket
 
static UDPSocket _udp_master ("Master")
 udp master socket
 

Detailed Description

This file handles the UDP related communication.

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

Definition in file network_udp.cpp.

Function Documentation

◆ DoNetworkUDPQueryServer()

static void DoNetworkUDPQueryServer ( NetworkAddress address,
bool  needs_mutex,
bool  manually 
)
static

Helper function doing the actual work for querying the server.

Parameters
addressThe address of the server.
needs_mutexWhether we need to acquire locks when sending the packet or not.
manuallyWhether the address was entered manually.

Definition at line 90 of file network_udp.cpp.

References _udp_client, NetworkGameList::address, NetworkAddress::GetAddressAsString(), NetworkAddress::GetHostname(), NetworkGameInfo::hostname, NetworkGameList::info, lastof, lock, NetworkGameList::manually, UDPSocket::mutex, NetworkGameListAddItemDelayed(), PACKET_UDP_CLIENT_FIND_SERVER, NetworkUDPSocketHandler::SendPacket(), NetworkGameInfo::server_name, UDPSocket::socket, and strecpy().

Referenced by NetworkUDPQueryServer().

◆ NetworkUDPAdvertise()

void NetworkUDPAdvertise ( )

Register us to the master server This function checks if it needs to send an advertise.

< The last time we performed an advertisement.

Definition at line 565 of file network_udp.cpp.

References _network_advertise_retries, _network_need_advertise, _network_server, _network_udp_server, _networking, _settings_client, ADVERTISE_NORMAL_INTERVAL(), ADVERTISE_RETRY_INTERVAL(), ADVERTISE_RETRY_TIMES, ClientSettings::network, NetworkUDPAdvertiseThread(), NetworkSettings::server_advertise, and StartNewThread().

◆ NetworkUDPQueryServer()

void NetworkUDPQueryServer ( NetworkAddress  address,
bool  manually 
)

Query a specific server.

Parameters
addressThe address of the server.
manuallyWhether the address was entered manually.

Definition at line 112 of file network_udp.cpp.

References DoNetworkUDPQueryServer(), NetworkAddress::IsResolved(), and StartNewThread().

Referenced by NetworkGameListRequery(), and ShowNetworkLobbyWindow().

◆ NetworkUDPRemoveAdvertise()

void NetworkUDPRemoveAdvertise ( bool  blocking)

Remove our advertise from the master-server.

Parameters
blockingwhether to wait until the removal has finished.

Definition at line 513 of file network_udp.cpp.

References _network_server, _network_udp_server, _networking, NetworkUDPRemoveAdvertiseThread(), and StartNewThread().

Referenced by NetworkDisconnect(), and MasterNetworkUDPSocketHandler::Receive_MASTER_ACK_REGISTER().