This file handles the UDP related communication. More...
#include "../stdafx.h"#include "../date_func.h"#include "../map_func.h"#include "../debug.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/thread.h"#include "../rev.h"#include "../newgrf_text.h"#include "../strings_func.h"#include "table/strings.h"#include "core/udp.h"Go to the source code of this file.
Data Structures | |
| struct | NetworkUDPQueryServerInfo |
| Simpler wrapper struct for NetworkUDPQueryServerThread. 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 void | NetworkUDPQueryServer (NetworkAddress *address, bool needs_mutex, bool manually) |
| Helper function doing the actual work for querying the server. | |
| static void | NetworkUDPQueryServerThread (void *pntr) |
| Threaded part for resolving the IP of a server and querying it. | |
| void | NetworkUDPQueryServer (NetworkAddress address, bool manually) |
| Query a specific server. | |
| 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 (void *pntr) |
| Thread entry point for de-advertising. | |
| void | NetworkUDPRemoveAdvertise (bool blocking) |
| Remove our advertise from the master-server. | |
| static void | NetworkUDPAdvertiseThread (void *pntr) |
| Thread entry point for advertising. | |
| void | NetworkUDPAdvertise () |
| Register us to the master server This function checks if it needs to send an advertise. | |
| void | NetworkUDPInitialize () |
| Initialize the whole UDP bit. | |
| void | NetworkUDPClose () |
| Close all UDP related stuff. | |
| void | NetworkBackgroundUDPLoop () |
| Receive the UDP packets. | |
Variables | |
| static ThreadMutex * | _network_udp_mutex = ThreadMutex::New() |
| Mutex for all out threaded udp resoltion and such. | |
| static uint64 | _session_key = 0 |
| Session key to register ourselves to the master server. | |
| static const uint | ADVERTISE_NORMAL_INTERVAL = 30000 |
| interval between advertising in ticks (15 minutes) | |
| static const uint | ADVERTISE_RETRY_INTERVAL = 300 |
| readvertise when no response after this many ticks (9 seconds) | |
| static const uint | ADVERTISE_RETRY_TIMES = 3 |
| give up readvertising after this much failed retries | |
| NetworkUDPSocketHandler * | _udp_client_socket = NULL |
| udp client socket | |
| NetworkUDPSocketHandler * | _udp_server_socket = NULL |
| udp server socket | |
| NetworkUDPSocketHandler * | _udp_master_socket = NULL |
| udp master socket | |
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.
| void NetworkBackgroundUDPLoop | ( | ) |
Receive the UDP packets.
Definition at line 689 of file network_udp.cpp.
References _network_udp_broadcast, _network_udp_server, ThreadMutex::BeginCritical(), ThreadMutex::EndCritical(), and NetworkUDPSocketHandler::ReceivePackets().
Referenced by NetworkBackgroundLoop().
| static void NetworkUDPAdvertiseThread | ( | void * | pntr | ) | [static] |
Thread entry point for advertising.
| pntr | unused. |
Definition at line 575 of file network_udp.cpp.
References _network_advertise_retries, _session_key, _settings_client, ThreadMutex::BeginCritical(), DEBUG, ThreadMutex::EndCritical(), NetworkAddress::GetAddressAsString(), ClientSettings::network, NETWORK_MASTER_SERVER_HOST, NETWORK_MASTER_SERVER_PORT, NETWORK_MASTER_SERVER_VERSION, NETWORK_MASTER_SERVER_WELCOME_MESSAGE, PACKET_UDP_SERVER_REGISTER, Packet::Send_string(), Packet::Send_uint16(), Packet::Send_uint64(), Packet::Send_uint8(), NetworkUDPSocketHandler::SendPacket(), and NetworkSettings::server_port.
Referenced by NetworkUDPAdvertise().
| void NetworkUDPClose | ( | ) |
Close all UDP related stuff.
Definition at line 669 of file network_udp.cpp.
References _network_udp_broadcast, _network_udp_server, ThreadMutex::BeginCritical(), NetworkUDPSocketHandler::Close(), DEBUG, and ThreadMutex::EndCritical().
Referenced by NetworkShutDown(), and NetworkUDPInitialize().
| void NetworkUDPInitialize | ( | ) |
Initialize the whole UDP bit.
Definition at line 643 of file network_udp.cpp.
References _network_udp_broadcast, _network_udp_server, _settings_client, ThreadMutex::BeginCritical(), SmallVector< T, S >::Clear(), DEBUG, ThreadMutex::EndCritical(), GetBindAddresses(), ClientSettings::network, NetworkUDPClose(), and NetworkSettings::server_port.
Referenced by NetworkDisconnect().
| static void NetworkUDPQueryServer | ( | NetworkAddress * | address, | |
| bool | needs_mutex, | |||
| bool | manually | |||
| ) | [static] |
Helper function doing the actual work for querying the server.
| address | The address of the server. | |
| needs_mutex | Whether we need to acquire locks when sending the packet or not. | |
| manually | Whether the address was entered manually. |
Definition at line 73 of file network_udp.cpp.
References NetworkGameList::address, ThreadMutex::BeginCritical(), ThreadMutex::EndCritical(), NetworkAddress::GetAddressAsString(), NetworkAddress::GetHostname(), NetworkGameInfo::hostname, NetworkGameList::info, lastof, NetworkGameList::manually, NetworkGameListAddItemDelayed(), PACKET_UDP_CLIENT_FIND_SERVER, NetworkUDPSocketHandler::SendPacket(), NetworkGameInfo::server_name, and strecpy().
Referenced by NetworkGameListRequery(), NetworkUDPQueryServerThread(), NetworkLobbyWindow::OnClick(), ClientNetworkUDPSocketHandler::Receive_MASTER_RESPONSE_LIST(), and ShowNetworkLobbyWindow().
| void NetworkUDPQueryServer | ( | NetworkAddress | address, | |
| bool | manually | |||
| ) |
Query a specific server.
| address | The address of the server. | |
| manually | Whether the address was entered manually. |
Definition at line 107 of file network_udp.cpp.
References NetworkAddress::IsResolved(), NetworkUDPQueryServerThread(), and ThreadObject::New().
| static void NetworkUDPQueryServerThread | ( | void * | pntr | ) | [static] |
Threaded part for resolving the IP of a server and querying it.
| pntr | the NetworkUDPQueryServerInfo. |
Definition at line 94 of file network_udp.cpp.
References NetworkUDPQueryServerInfo::manually, and NetworkUDPQueryServer().
Referenced by NetworkUDPQueryServer().
| void NetworkUDPRemoveAdvertise | ( | bool | blocking | ) |
Remove our advertise from the master-server.
| blocking | whether to wait until the removal has finished. |
Definition at line 561 of file network_udp.cpp.
References _network_server, _network_udp_server, _networking, NetworkUDPRemoveAdvertiseThread(), and ThreadObject::New().
Referenced by NetworkDisconnect(), and MasterNetworkUDPSocketHandler::Receive_MASTER_ACK_REGISTER().
| static void NetworkUDPRemoveAdvertiseThread | ( | void * | pntr | ) | [static] |
Thread entry point for de-advertising.
| pntr | unused. |
Definition at line 539 of file network_udp.cpp.
References _settings_client, ThreadMutex::BeginCritical(), DEBUG, ThreadMutex::EndCritical(), ClientSettings::network, NETWORK_MASTER_SERVER_HOST, NETWORK_MASTER_SERVER_PORT, NETWORK_MASTER_SERVER_VERSION, PACKET_UDP_SERVER_UNREGISTER, Packet::Send_uint16(), Packet::Send_uint8(), NetworkUDPSocketHandler::SendPacket(), and NetworkSettings::server_port.
Referenced by NetworkUDPRemoveAdvertise().
ThreadMutex* _network_udp_mutex = ThreadMutex::New() [static] |
Mutex for all out threaded udp resoltion and such.
Definition at line 38 of file network_udp.cpp.
1.7.1