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 | |
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... | |
struct | NetworkUDPQueryServerInfo |
Simpler wrapper struct for NetworkUDPQueryServerThread. More... | |
Functions | |
DEF_UDP_RECEIVE_COMMAND (Master, PACKET_UDP_MASTER_ACK_REGISTER) | |
DEF_UDP_RECEIVE_COMMAND (Master, PACKET_UDP_MASTER_SESSION_KEY) | |
DEF_UDP_RECEIVE_COMMAND (Server, PACKET_UDP_CLIENT_FIND_SERVER) | |
DEF_UDP_RECEIVE_COMMAND (Server, PACKET_UDP_CLIENT_DETAIL_INFO) | |
DEF_UDP_RECEIVE_COMMAND (Server, PACKET_UDP_CLIENT_GET_NEWGRFS) | |
A client has requested the names of some NewGRFs. | |
DEF_UDP_RECEIVE_COMMAND (Client, PACKET_UDP_SERVER_RESPONSE) | |
DEF_UDP_RECEIVE_COMMAND (Client, PACKET_UDP_MASTER_RESPONSE_LIST) | |
DEF_UDP_RECEIVE_COMMAND (Client, PACKET_UDP_SERVER_NEWGRFS) | |
The return of the client's request of the names of some NewGRFs. | |
static void | NetworkUDPBroadCast (NetworkUDPSocketHandler *socket) |
void | NetworkUDPQueryMasterServer () |
void | NetworkUDPSearchGame () |
static void | NetworkUDPQueryServerThread (void *pntr) |
Threaded part for resolving the IP of a server and querying it. | |
void | NetworkUDPQueryServer (NetworkAddress address, bool manually) |
static void | NetworkUDPRemoveAdvertiseThread (void *pntr) |
void | NetworkUDPRemoveAdvertise (bool blocking) |
Remove our advertise from the master-server. | |
static void | NetworkUDPAdvertiseThread (void *pntr) |
void | NetworkUDPAdvertise () |
void | NetworkUDPInitialize () |
void | NetworkUDPClose () |
Variables | |
static ThreadMutex * | _network_udp_mutex = ThreadMutex::New() |
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.
DEF_UDP_RECEIVE_COMMAND | ( | Server | , | |
PACKET_UDP_CLIENT_GET_NEWGRFS | ||||
) |
A client has requested the names of some NewGRFs.
Replying this can be tricky as we have a limit of SEND_MTU bytes in the reply packet and we can send up to 100 bytes per NewGRF (GRF ID, MD5sum and NETWORK_GRF_NAME_LENGTH bytes for the name). As SEND_MTU is _much_ less than 100 * NETWORK_MAX_GRF_COUNT, it could be that a packet overflows. To stop this we only reply with the first N NewGRFs so that if the first N + 1 NewGRFs would be sent, the packet overflows. in_reply and in_reply_count are used to keep a list of GRFs to send in the reply.
Definition at line 195 of file network_udp.cpp.
References DEBUG, FGCM_EXACT, FindGRFConfig(), GRFConfig::GetName(), GRFIdentifier::grfid, lastof, GRFIdentifier::md5sum, min(), NETWORK_GRF_NAME_LENGTH, NETWORK_MAX_GRF_COUNT, PACKET_UDP_SERVER_NEWGRFS, SEND_MTU, Packet::Send_string(), and strecpy().
static void NetworkUDPQueryServerThread | ( | void * | pntr | ) | [static] |
Threaded part for resolving the IP of a server and querying it.
pntr | the NetworkUDPQueryServerInfo. |
Definition at line 470 of file network_udp.cpp.
References NetworkGameList::address, ThreadMutex::BeginCritical(), ThreadMutex::EndCritical(), NetworkAddress::GetAddressAsString(), NetworkAddress::GetHostname(), NetworkGameInfo::hostname, NetworkGameList::info, lastof, NetworkUDPQueryServerInfo::manually, NetworkGameList::manually, NetworkGameListAddItemDelayed(), PACKET_UDP_CLIENT_FIND_SERVER, NetworkUDPSocketHandler::SendPacket(), NetworkGameInfo::server_name, and strecpy().
void NetworkUDPRemoveAdvertise | ( | bool | blocking | ) |
Remove our advertise from the master-server.
blocking | whether to wait until the removal has finished. |
Definition at line 521 of file network_udp.cpp.
References _network_server, _networking, and ThreadObject::New().
Referenced by NetworkDisconnect().