OpenTTD

network_udp.cpp
Go to the documentation of this file.
1 /* $Id: network_udp.cpp 27670 2016-10-30 17:29:33Z frosch $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
9
17 #ifdef ENABLE_NETWORK
18
19 #include "../stdafx.h"
20 #include "../date_func.h"
21 #include "../map_func.h"
22 #include "../debug.h"
23 #include "network_gamelist.h"
24 #include "network_internal.h"
25 #include "network_udp.h"
26 #include "network.h"
27 #include "../core/endian_func.hpp"
28 #include "../company_base.h"
29 #include "../thread/thread.h"
30 #include "../rev.h"
31 #include "../newgrf_text.h"
32 #include "../strings_func.h"
33 #include "table/strings.h"
34
35 #include "core/udp.h"
36
37 #include "../safeguards.h"
38
40 static ThreadMutex *_network_udp_mutex = ThreadMutex::New();
41
43 static uint64 _session_key = 0;
44
45 static const uint32 ADVERTISE_NORMAL_INTERVAL = 15 * 60 * 1000;
46 static const uint32 ADVERTISE_RETRY_INTERVAL = 10 * 1000;
47 static const uint32 ADVERTISE_RETRY_TIMES = 3;
48
49 NetworkUDPSocketHandler *_udp_client_socket = NULL;
50 NetworkUDPSocketHandler *_udp_server_socket = NULL;
51 NetworkUDPSocketHandler *_udp_master_socket = NULL;
52
54 struct NetworkUDPQueryServerInfo : NetworkAddress {
55 bool manually;
56
62 NetworkUDPQueryServerInfo(const NetworkAddress &address, bool manually) :
63 NetworkAddress(address),
64 manually(manually)
65 {
66 }
67 };
68
75 static void NetworkUDPQueryServer(NetworkAddress *address, bool needs_mutex, bool manually)
76 {
77 /* Clear item in gamelist */
78 NetworkGameList *item = CallocT<NetworkGameList>(1);
79 address->GetAddressAsString(item->info.server_name, lastof(item->info.server_name));
80 strecpy(item->info.hostname, address->GetHostname(), lastof(item->info.hostname));
81 item->address = *address;
82 item->manually = manually;
83 NetworkGameListAddItemDelayed(item);
84
85 if (needs_mutex) _network_udp_mutex->BeginCritical();
86 /* Init the packet */
87 Packet p(PACKET_UDP_CLIENT_FIND_SERVER);
88 if (_udp_client_socket != NULL) _udp_client_socket->SendPacket(&p, address);
89 if (needs_mutex) _network_udp_mutex->EndCritical();
90 }
91
96 static void NetworkUDPQueryServerThread(void *pntr)
97 {
98 NetworkUDPQueryServerInfo *info = (NetworkUDPQueryServerInfo*)pntr;
99 NetworkUDPQueryServer(info, true, info->manually);
100
101 delete info;
102 }
103
109 void NetworkUDPQueryServer(NetworkAddress address, bool manually)
110 {
111 NetworkUDPQueryServerInfo *info = new NetworkUDPQueryServerInfo(address, manually);
112 if (address.IsResolved() || !ThreadObject::New(NetworkUDPQueryServerThread, info, NULL, "ottd:udp-query")) {
113 NetworkUDPQueryServerThread(info);
114 }
115 }
116
118
120 class MasterNetworkUDPSocketHandler : public NetworkUDPSocketHandler {
121 protected:
122 virtual void Receive_MASTER_ACK_REGISTER(Packet *p, NetworkAddress *client_addr);
123 virtual void Receive_MASTER_SESSION_KEY(Packet *p, NetworkAddress *client_addr);
124 public:
129 MasterNetworkUDPSocketHandler(NetworkAddressList *addresses) : NetworkUDPSocketHandler(addresses) {}
130 virtual ~MasterNetworkUDPSocketHandler() {}
131 };
132
133 void MasterNetworkUDPSocketHandler::Receive_MASTER_ACK_REGISTER(Packet *p, NetworkAddress *client_addr)
134 {
135 _network_advertise_retries = 0;
136 DEBUG(net, 2, "[udp] advertising on master server successful (%s)", NetworkAddress::AddressFamilyAsString(client_addr->GetAddress()->ss_family));
137
138 /* We are advertised, but we don't want to! */
139 if (!_settings_client.network.server_advertise) NetworkUDPRemoveAdvertise(false);
140 }
141
142 void MasterNetworkUDPSocketHandler::Receive_MASTER_SESSION_KEY(Packet *p, NetworkAddress *client_addr)
143 {
144 _session_key = p->Recv_uint64();
145 DEBUG(net, 2, "[udp] received new session key from master server (%s)", NetworkAddress::AddressFamilyAsString(client_addr->GetAddress()->ss_family));
146 }
147
149
151 class ServerNetworkUDPSocketHandler : public NetworkUDPSocketHandler {
152 protected:
153 virtual void Receive_CLIENT_FIND_SERVER(Packet *p, NetworkAddress *client_addr);
154 virtual void Receive_CLIENT_DETAIL_INFO(Packet *p, NetworkAddress *client_addr);
155 virtual void Receive_CLIENT_GET_NEWGRFS(Packet *p, NetworkAddress *client_addr);
156 public:
161 ServerNetworkUDPSocketHandler(NetworkAddressList *addresses) : NetworkUDPSocketHandler(addresses) {}
162 virtual ~ServerNetworkUDPSocketHandler() {}
163 };
164
165 void ServerNetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER(Packet *p, NetworkAddress *client_addr)
166 {
167 /* Just a fail-safe.. should never happen */
168 if (!_network_udp_server) {
169 return;
170 }
171
172 NetworkGameInfo ngi;
173
174 /* Update some game_info */
175 ngi.clients_on = _network_game_info.clients_on;
176 ngi.start_date = ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1);
177
178 ngi.server_lang = _settings_client.network.server_lang;
179 ngi.use_password = !StrEmpty(_settings_client.network.server_password);
180 ngi.clients_max = _settings_client.network.max_clients;
181 ngi.companies_on = (byte)Company::GetNumItems();
182 ngi.companies_max = _settings_client.network.max_companies;
183 ngi.spectators_on = NetworkSpectatorCount();
184 ngi.spectators_max = _settings_client.network.max_spectators;
185 ngi.game_date = _date;
186 ngi.map_width = MapSizeX();
187 ngi.map_height = MapSizeY();
188 ngi.map_set = _settings_game.game_creation.landscape;
189 ngi.dedicated = _network_dedicated;
190 ngi.grfconfig = _grfconfig;
191
192 strecpy(ngi.map_name, _network_game_info.map_name, lastof(ngi.map_name));
193 strecpy(ngi.server_name, _settings_client.network.server_name, lastof(ngi.server_name));
194 strecpy(ngi.server_revision, _openttd_revision, lastof(ngi.server_revision));
195
196 Packet packet(PACKET_UDP_SERVER_RESPONSE);
197 this->SendNetworkGameInfo(&packet, &ngi);
198
199 /* Let the client know that we are here */
200 this->SendPacket(&packet, client_addr);
201
202 DEBUG(net, 2, "[udp] queried from %s", client_addr->GetHostname());
203 }
204
205 void ServerNetworkUDPSocketHandler::Receive_CLIENT_DETAIL_INFO(Packet *p, NetworkAddress *client_addr)
206 {
207 /* Just a fail-safe.. should never happen */
208 if (!_network_udp_server) return;
209
210 Packet packet(PACKET_UDP_SERVER_DETAIL_INFO);
211
212 /* Send the amount of active companies */
213 packet.Send_uint8 (NETWORK_COMPANY_INFO_VERSION);
214 packet.Send_uint8 ((uint8)Company::GetNumItems());
215
216 /* Fetch the latest version of the stats */
217 NetworkCompanyStats company_stats[MAX_COMPANIES];
218 NetworkPopulateCompanyStats(company_stats);
219
220 /* The minimum company information "blob" size. */
221 static const uint MIN_CI_SIZE = 54;
222 uint max_cname_length = NETWORK_COMPANY_NAME_LENGTH;
223
224 if (Company::GetNumItems() * (MIN_CI_SIZE + NETWORK_COMPANY_NAME_LENGTH) >= (uint)SEND_MTU - packet.size) {
225 /* Assume we can at least put the company information in the packets. */
226 assert(Company::GetNumItems() * MIN_CI_SIZE < (uint)SEND_MTU - packet.size);
227
228 /* At this moment the company names might not fit in the
229 * packet. Check whether that is really the case. */
230
231 for (;;) {
232 int free = SEND_MTU - packet.size;
233 Company *company;
234 FOR_ALL_COMPANIES(company) {
235 char company_name[NETWORK_COMPANY_NAME_LENGTH];
236 SetDParam(0, company->index);
237 GetString(company_name, STR_COMPANY_NAME, company_name + max_cname_length - 1);
238 free -= MIN_CI_SIZE;
239 free -= (int)strlen(company_name);
240 }
241 if (free >= 0) break;
242
243 /* Try again, with slightly shorter strings. */
244 assert(max_cname_length > 0);
245 max_cname_length--;
246 }
247 }
248
249 Company *company;
250 /* Go through all the companies */
251 FOR_ALL_COMPANIES(company) {
252 /* Send the information */
253 this->SendCompanyInformation(&packet, company, &company_stats[company->index], max_cname_length);
254 }
255
256 this->SendPacket(&packet, client_addr);
257 }
258
272 void ServerNetworkUDPSocketHandler::Receive_CLIENT_GET_NEWGRFS(Packet *p, NetworkAddress *client_addr)
273 {
274 uint8 num_grfs;
275 uint i;
276
277 const GRFConfig *in_reply[NETWORK_MAX_GRF_COUNT];
278 uint8 in_reply_count = 0;
279 size_t packet_len = 0;
280
281 DEBUG(net, 6, "[udp] newgrf data request from %s", client_addr->GetAddressAsString());
282
283 num_grfs = p->Recv_uint8 ();
284 if (num_grfs > NETWORK_MAX_GRF_COUNT) return;
285
286 for (i = 0; i < num_grfs; i++) {
287 GRFIdentifier c;
288 const GRFConfig *f;
289
290 this->ReceiveGRFIdentifier(p, &c);
291
292 /* Find the matching GRF file */
293 f = FindGRFConfig(c.grfid, FGCM_EXACT, c.md5sum);
294 if (f == NULL) continue; // The GRF is unknown to this server
295
296 /* If the reply might exceed the size of the packet, only reply
297 * the current list and do not send the other data.
298 * The name could be an empty string, if so take the filename. */
299 packet_len += sizeof(c.grfid) + sizeof(c.md5sum) +
300 min(strlen(f->GetName()) + 1, (size_t)NETWORK_GRF_NAME_LENGTH);
301 if (packet_len > SEND_MTU - 4) { // 4 is 3 byte header + grf count in reply
302 break;
303 }
304 in_reply[in_reply_count] = f;
305 in_reply_count++;
306 }
307
308 if (in_reply_count == 0) return;
309
310 Packet packet(PACKET_UDP_SERVER_NEWGRFS);
311 packet.Send_uint8(in_reply_count);
312 for (i = 0; i < in_reply_count; i++) {
313 char name[NETWORK_GRF_NAME_LENGTH];
314
315 /* The name could be an empty string, if so take the filename */
316 strecpy(name, in_reply[i]->GetName(), lastof(name));
317 this->SendGRFIdentifier(&packet, &in_reply[i]->ident);
318 packet.Send_string(name);
319 }
320
321 this->SendPacket(&packet, client_addr);
322 }
323
325
327 class ClientNetworkUDPSocketHandler : public NetworkUDPSocketHandler {
328 protected:
329 virtual void Receive_SERVER_RESPONSE(Packet *p, NetworkAddress *client_addr);
330 virtual void Receive_MASTER_RESPONSE_LIST(Packet *p, NetworkAddress *client_addr);
331 virtual void Receive_SERVER_NEWGRFS(Packet *p, NetworkAddress *client_addr);
332 virtual void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config);
333 public:
334 virtual ~ClientNetworkUDPSocketHandler() {}
335 };
336
337 void ClientNetworkUDPSocketHandler::Receive_SERVER_RESPONSE(Packet *p, NetworkAddress *client_addr)
338 {
339 NetworkGameList *item;
340
341 /* Just a fail-safe.. should never happen */
342 if (_network_udp_server) return;
343
344 DEBUG(net, 4, "[udp] server response from %s", client_addr->GetAddressAsString());
345
346 /* Find next item */
347 item = NetworkGameListAddItem(*client_addr);
348
349 ClearGRFConfigList(&item->info.grfconfig);
350 this->ReceiveNetworkGameInfo(p, &item->info);
351
352 item->info.compatible = true;
353 {
354 /* Checks whether there needs to be a request for names of GRFs and makes
355 * the request if necessary. GRFs that need to be requested are the GRFs
356 * that do not exist on the clients system and we do not have the name
357 * resolved of, i.e. the name is still UNKNOWN_GRF_NAME_PLACEHOLDER.
358 * The in_request array and in_request_count are used so there is no need
359 * to do a second loop over the GRF list, which can be relatively expensive
360 * due to the string comparisons. */
361 const GRFConfig *in_request[NETWORK_MAX_GRF_COUNT];
362 const GRFConfig *c;
363 uint in_request_count = 0;
364
365 for (c = item->info.grfconfig; c != NULL; c = c->next) {
366 if (c->status == GCS_NOT_FOUND) item->info.compatible = false;
367 if (c->status != GCS_NOT_FOUND || strcmp(c->GetName(), UNKNOWN_GRF_NAME_PLACEHOLDER) != 0) continue;
368 in_request[in_request_count] = c;
369 in_request_count++;
370 }
371
372 if (in_request_count > 0) {
373 /* There are 'unknown' GRFs, now send a request for them */
374 uint i;
375 Packet packet(PACKET_UDP_CLIENT_GET_NEWGRFS);
376
377 packet.Send_uint8(in_request_count);
378 for (i = 0; i < in_request_count; i++) {
379 this->SendGRFIdentifier(&packet, &in_request[i]->ident);
380 }
381
382 this->SendPacket(&packet, &item->address);
383 }
384 }
385
386 if (item->info.hostname[0] == '\0') {
387 seprintf(item->info.hostname, lastof(item->info.hostname), "%s", client_addr->GetHostname());
388 }
389
390 if (client_addr->GetAddress()->ss_family == AF_INET6) {
391 strecat(item->info.server_name, " (IPv6)", lastof(item->info.server_name));
392 }
393
394 /* Check if we are allowed on this server based on the revision-match */
395 item->info.version_compatible = IsNetworkCompatibleVersion(item->info.server_revision);
396 item->info.compatible &= item->info.version_compatible; // Already contains match for GRFs
397
398 item->online = true;
399
400 UpdateNetworkGameWindow();
401 }
402
403 void ClientNetworkUDPSocketHandler::Receive_MASTER_RESPONSE_LIST(Packet *p, NetworkAddress *client_addr)
404 {
405 /* packet begins with the protocol version (uint8)
406 * then an uint16 which indicates how many
407 * ip:port pairs are in this packet, after that
408 * an uint32 (ip) and an uint16 (port) for each pair.
409 */
410
411 ServerListType type = (ServerListType)(p->Recv_uint8() - 1);
412
413 if (type < SLT_END) {
414 for (int i = p->Recv_uint16(); i != 0 ; i--) {
415 sockaddr_storage addr_storage;
416 memset(&addr_storage, 0, sizeof(addr_storage));
417
418 if (type == SLT_IPv4) {
419 addr_storage.ss_family = AF_INET;
420 ((sockaddr_in*)&addr_storage)->sin_addr.s_addr = TO_LE32(p->Recv_uint32());
421 } else {
422 assert(type == SLT_IPv6);
423 addr_storage.ss_family = AF_INET6;
424 byte *addr = (byte*)&((sockaddr_in6*)&addr_storage)->sin6_addr;
425 for (uint i = 0; i < sizeof(in6_addr); i++) *addr++ = p->Recv_uint8();
426 }
427 NetworkAddress addr(addr_storage, type == SLT_IPv4 ? sizeof(sockaddr_in) : sizeof(sockaddr_in6));
428 addr.SetPort(p->Recv_uint16());
429
430 /* Somehow we reached the end of the packet */
431 if (this->HasClientQuit()) return;
432
433 NetworkUDPQueryServer(&addr, false, false);
434 }
435 }
436 }
437
439 void ClientNetworkUDPSocketHandler::Receive_SERVER_NEWGRFS(Packet *p, NetworkAddress *client_addr)
440 {
441 uint8 num_grfs;
442 uint i;
443
444 DEBUG(net, 6, "[udp] newgrf data reply from %s", client_addr->GetAddressAsString());
445
446 num_grfs = p->Recv_uint8 ();
447 if (num_grfs > NETWORK_MAX_GRF_COUNT) return;
448
449 for (i = 0; i < num_grfs; i++) {
450 char name[NETWORK_GRF_NAME_LENGTH];
451 GRFIdentifier c;
452
453 this->ReceiveGRFIdentifier(p, &c);
454 p->Recv_string(name, sizeof(name));
455
456 /* An empty name is not possible under normal circumstances
457 * and causes problems when showing the NewGRF list. */
458 if (StrEmpty(name)) continue;
459
460 /* Try to find the GRFTextWrapper for the name of this GRF ID and MD5sum tuple.
461 * If it exists and not resolved yet, then name of the fake GRF is
462 * overwritten with the name from the reply. */
463 GRFTextWrapper *unknown_name = FindUnknownGRFName(c.grfid, c.md5sum, false);
464 if (unknown_name != NULL && strcmp(GetGRFStringFromGRFText(unknown_name->text), UNKNOWN_GRF_NAME_PLACEHOLDER) == 0) {
465 AddGRFTextToList(&unknown_name->text, name);
466 }
467 }
468 }
469
470 void ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config)
471 {
472 /* Find the matching GRF file */
473 const GRFConfig *f = FindGRFConfig(config->ident.grfid, FGCM_EXACT, config->ident.md5sum);
474 if (f == NULL) {
475 /* Don't know the GRF, so mark game incompatible and the (possibly)
476 * already resolved name for this GRF (another server has sent the
477 * name of the GRF already */
478 config->name->Release();
479 config->name = FindUnknownGRFName(config->ident.grfid, config->ident.md5sum, true);
480 config->name->AddRef();
481 config->status = GCS_NOT_FOUND;
482 } else {
483 config->filename = f->filename;
484 config->name->Release();
485 config->name = f->name;
486 config->name->AddRef();
487 config->info->Release();
488 config->info = f->info;
489 config->info->AddRef();
490 config->url->Release();
491 config->url = f->url;
492 config->url->AddRef();
493 }
494 SetBit(config->flags, GCF_COPY);
495 }
496
498 static void NetworkUDPBroadCast(NetworkUDPSocketHandler *socket)
499 {
500 for (NetworkAddress *addr = _broadcast_list.Begin(); addr != _broadcast_list.End(); addr++) {
501 Packet p(PACKET_UDP_CLIENT_FIND_SERVER);
502
503 DEBUG(net, 4, "[udp] broadcasting to %s", addr->GetHostname());
504
505 socket->SendPacket(&p, addr, true, true);
506 }
507 }
508
509
511 void NetworkUDPQueryMasterServer()
512 {
513 Packet p(PACKET_UDP_CLIENT_GET_LIST);
514 NetworkAddress out_addr(NETWORK_MASTER_SERVER_HOST, NETWORK_MASTER_SERVER_PORT);
515
516 /* packet only contains protocol version */
517 p.Send_uint8(NETWORK_MASTER_SERVER_VERSION);
518 p.Send_uint8(SLT_AUTODETECT);
519
520 _udp_client_socket->SendPacket(&p, &out_addr, true);
521
522 DEBUG(net, 2, "[udp] master server queried at %s", out_addr.GetAddressAsString());
523 }
524
526 void NetworkUDPSearchGame()
527 {
528 /* We are still searching.. */
529 if (_network_udp_broadcast > 0) return;
530
531 DEBUG(net, 0, "[udp] searching server");
532
533 NetworkUDPBroadCast(_udp_client_socket);
534 _network_udp_broadcast = 300; // Stay searching for 300 ticks
535 }
536
541 static void NetworkUDPRemoveAdvertiseThread(void *pntr)
542 {
543 DEBUG(net, 1, "[udp] removing advertise from master server");
544
545 /* Find somewhere to send */
546 NetworkAddress out_addr(NETWORK_MASTER_SERVER_HOST, NETWORK_MASTER_SERVER_PORT);
547
548 /* Send the packet */
549 Packet p(PACKET_UDP_SERVER_UNREGISTER);
550 /* Packet is: Version, server_port */
551 p.Send_uint8 (NETWORK_MASTER_SERVER_VERSION);
552 p.Send_uint16(_settings_client.network.server_port);
553
554 _network_udp_mutex->BeginCritical();
555 if (_udp_master_socket != NULL) _udp_master_socket->SendPacket(&p, &out_addr, true);
556 _network_udp_mutex->EndCritical();
557 }
558
563 void NetworkUDPRemoveAdvertise(bool blocking)
564 {
565 /* Check if we are advertising */
566 if (!_networking || !_network_server || !_network_udp_server) return;
567
568 if (blocking || !ThreadObject::New(NetworkUDPRemoveAdvertiseThread, NULL, NULL, "ottd:udp-advert")) {
569 NetworkUDPRemoveAdvertiseThread(NULL);
570 }
571 }
572
577 static void NetworkUDPAdvertiseThread(void *pntr)
578 {
579 /* Find somewhere to send */
580 NetworkAddress out_addr(NETWORK_MASTER_SERVER_HOST, NETWORK_MASTER_SERVER_PORT);
581
582 DEBUG(net, 1, "[udp] advertising to master server");
583
584 /* Add a bit more messaging when we cannot get a session key */
585 static byte session_key_retries = 0;
586 if (_session_key == 0 && session_key_retries++ == 2) {
587 DEBUG(net, 0, "[udp] advertising to the master server is failing");
588 DEBUG(net, 0, "[udp] we are not receiving the session key from the server");
589 DEBUG(net, 0, "[udp] please allow udp packets from %s to you to be delivered", out_addr.GetAddressAsString(false));
590 DEBUG(net, 0, "[udp] please allow udp packets from you to %s to be delivered", out_addr.GetAddressAsString(false));
591 }
592 if (_session_key != 0 && _network_advertise_retries == 0) {
593 DEBUG(net, 0, "[udp] advertising to the master server is failing");
594 DEBUG(net, 0, "[udp] we are not receiving the acknowledgement from the server");
595 DEBUG(net, 0, "[udp] this usually means that the master server cannot reach us");
596 DEBUG(net, 0, "[udp] please allow udp and tcp packets to port %u to be delivered", _settings_client.network.server_port);
597 DEBUG(net, 0, "[udp] please allow udp and tcp packets from port %u to be delivered", _settings_client.network.server_port);
598 }
599
600 /* Send the packet */
601 Packet p(PACKET_UDP_SERVER_REGISTER);
602 /* Packet is: WELCOME_MESSAGE, Version, server_port */
603 p.Send_string(NETWORK_MASTER_SERVER_WELCOME_MESSAGE);
604 p.Send_uint8 (NETWORK_MASTER_SERVER_VERSION);
605 p.Send_uint16(_settings_client.network.server_port);
606 p.Send_uint64(_session_key);
607
608 _network_udp_mutex->BeginCritical();
609 if (_udp_master_socket != NULL) _udp_master_socket->SendPacket(&p, &out_addr, true);
610 _network_udp_mutex->EndCritical();
611 }
612
617 void NetworkUDPAdvertise()
618 {
619 static uint32 _last_advertisement = 0;
620 static uint32 _next_advertisement = 0;
621 static uint32 _next_retry = 0;
622
623 /* Check if we should send an advertise */
624 if (!_networking || !_network_server || !_network_udp_server || !_settings_client.network.server_advertise) return;
625
626 if (_network_need_advertise || _realtime_tick < _last_advertisement) {
627 /* Forced advertisement, or a wrapping of time in which case we determine the advertisement/retry times again. */
628 _network_need_advertise = false;
629 _network_advertise_retries = ADVERTISE_RETRY_TIMES;
630 } else {
631 /* Only send once every ADVERTISE_NORMAL_INTERVAL ticks */
632 if (_network_advertise_retries == 0) {
633 if (_realtime_tick <= _next_advertisement) return;
634
635 _network_advertise_retries = ADVERTISE_RETRY_TIMES;
636 } else {
637 /* An actual retry. */
638 if (_realtime_tick <= _next_retry) return;
639 }
640 }
641
642 _network_advertise_retries--;
643 _last_advertisement = _realtime_tick;
644 _next_advertisement = _realtime_tick + ADVERTISE_NORMAL_INTERVAL;
645 _next_retry = _realtime_tick + ADVERTISE_RETRY_INTERVAL;
646
647 /* Make sure we do not have an overflow when checking these; when time wraps, we simply force an advertisement. */
648 if (_next_advertisement < _last_advertisement) _next_advertisement = UINT32_MAX;
649 if (_next_retry < _last_advertisement) _next_retry = UINT32_MAX;
650
651 if (!ThreadObject::New(NetworkUDPAdvertiseThread, NULL, NULL, "ottd:udp-advert")) {
652 NetworkUDPAdvertiseThread(NULL);
653 }
654 }
655
657 void NetworkUDPInitialize()
658 {
659 /* If not closed, then do it. */
660 if (_udp_server_socket != NULL) NetworkUDPClose();
661
662 DEBUG(net, 1, "[udp] initializing listeners");
663 assert(_udp_client_socket == NULL && _udp_server_socket == NULL && _udp_master_socket == NULL);
664
665 _network_udp_mutex->BeginCritical();
666
667 _udp_client_socket = new ClientNetworkUDPSocketHandler();
668
669 NetworkAddressList server;
670 GetBindAddresses(&server, _settings_client.network.server_port);
671 _udp_server_socket = new ServerNetworkUDPSocketHandler(&server);
672
673 server.Clear();
674 GetBindAddresses(&server, 0);
675 _udp_master_socket = new MasterNetworkUDPSocketHandler(&server);
676
677 _network_udp_server = false;
678 _network_udp_broadcast = 0;
679 _network_udp_mutex->EndCritical();
680 }
681
683 void NetworkUDPClose()
684 {
685 _network_udp_mutex->BeginCritical();
686 _udp_server_socket->Close();
687 _udp_master_socket->Close();
688 _udp_client_socket->Close();
689 delete _udp_client_socket;
690 delete _udp_server_socket;
691 delete _udp_master_socket;
692 _udp_client_socket = NULL;
693 _udp_server_socket = NULL;
694 _udp_master_socket = NULL;
695 _network_udp_mutex->EndCritical();
696
697 _network_udp_server = false;
698 _network_udp_broadcast = 0;
699 DEBUG(net, 1, "[udp] closed listeners");
700 }
701
703 void NetworkBackgroundUDPLoop()
704 {
705 _network_udp_mutex->BeginCritical();
706
707 if (_network_udp_server) {
708 _udp_server_socket->ReceivePackets();
709 _udp_master_socket->ReceivePackets();
710 } else {
711 _udp_client_socket->ReceivePackets();
712 if (_network_udp_broadcast > 0) _network_udp_broadcast--;
713 }
714
715 _network_udp_mutex->EndCritical();
716 }
717
718 #endif /* ENABLE_NETWORK */
NetworkGameInfo::start_date
Date start_date
When the game started.
Definition: game.h:38
NetworkGameInfo::spectators_max
byte spectators_max
Max spectators allowed on server.
Definition: game.h:55
NetworkGameInfo::map_height
uint16 map_height
Map height.
Definition: game.h:41
SLT_AUTODETECT
Autodetect the type based on the connection.
Definition: udp.h:44
MapSizeX
static uint MapSizeX()
Get the size of the map along the X.
Definition: map_func.h:74
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:77
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:56
NetworkUDPQueryServerInfo
Simpler wrapper struct for NetworkUDPQueryServerThread.
Definition: network_udp.cpp:54
IsNetworkCompatibleVersion
bool IsNetworkCompatibleVersion(const char *other)
Checks whether the given version string is compatible with our version.
Definition: network.cpp:1107
MapSizeY
static uint MapSizeY()
Get the size of the map along the Y.
Definition: map_func.h:84
_realtime_tick
uint32 _realtime_tick
The real time in the game.
Definition: debug.cpp:48
Packet
Internal entity of a packet.
Definition: packet.h:44
NetworkSettings::server_advertise
bool server_advertise
advertise the server to the masterserver
Definition: settings_type.h:250
_grfconfig
GRFConfig * _grfconfig
First item in list of current GRF set up.
Definition: newgrf_config.cpp:192
GameCreationSettings::landscape
byte landscape
the landscape we&#39;re currently in
Definition: settings_type.h:288
strecat
static char * strecat(char *dst, const char *src, const char *last)
Appends characters from one string to another.
Definition: depend.cpp:99
GetBindAddresses
void GetBindAddresses(NetworkAddressList *addresses, uint16 port)
Get the addresses to bind to.
Definition: network.cpp:635
Packet::Recv_uint32
uint32 Recv_uint32()
Read a 32 bits integer from the packet.
Definition: packet.cpp:250
PACKET_UDP_CLIENT_FIND_SERVER
Queries a game server for game information.
Definition: udp.h:25
ClientNetworkUDPSocketHandler
*** Communication with servers (we are client) ***/
Definition: network_udp.cpp:327
ClientNetworkUDPSocketHandler::Receive_MASTER_RESPONSE_LIST
virtual void Receive_MASTER_RESPONSE_LIST(Packet *p, NetworkAddress *client_addr)
The server sends a list of servers.
Definition: network_udp.cpp:403
NetworkSettings::server_name
char server_name[NETWORK_NAME_LENGTH]
name of the server
Definition: settings_type.h:246
NetworkAddress::address
sockaddr_storage address
The resolved address.
Definition: address.h:35
PACKET_UDP_CLIENT_GET_NEWGRFS
Requests the name for a list of GRFs (GRF_ID and MD5)
Definition: udp.h:34
NetworkUDPSocketHandler::ReceivePackets
void ReceivePackets()
Receive a packet at UDP level.
Definition: udp.cpp:121
ClearGRFConfigList
void ClearGRFConfigList(GRFConfig **config)
Clear a GRF Config list, freeing all nodes.
Definition: newgrf_config.cpp:444
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:398
NetworkGameInfo::server_lang
byte server_lang
Language of the server (we should make a nice table for this)
Definition: game.h:50
Packet::Send_string
void Send_string(const char *data)
Sends a string over the network.
Definition: packet.cpp:152
ClientNetworkUDPSocketHandler::Receive_SERVER_RESPONSE
virtual void Receive_SERVER_RESPONSE(Packet *p, NetworkAddress *client_addr)
Return of server information to the client.
Definition: network_udp.cpp:337
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:123
NetworkUDPQueryServerThread
static void NetworkUDPQueryServerThread(void *pntr)
Threaded part for resolving the IP of a server and querying it.
Definition: network_udp.cpp:96
_udp_master_socket
NetworkUDPSocketHandler * _udp_master_socket
udp master socket
Definition: network_udp.cpp:51
NetworkPopulateCompanyStats
void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
Populate the company stats.
Definition: network_server.cpp:1564
PACKET_UDP_CLIENT_GET_LIST
Request for serverlist from master server.
Definition: udp.h:31
SLT_IPv4
Get the IPv4 addresses.
Definition: udp.h:42
Packet::Send_uint8
void Send_uint8(uint8 data)
Package a 8 bits integer in the packet.
Definition: packet.cpp:100
_network_udp_broadcast
uint16 _network_udp_broadcast
Timeout for the UDP broadcasts.
Definition: network.cpp:82
SLT_IPv6
Get the IPv6 addresses.
Definition: udp.h:43
GRFConfig::status
GRFStatus status
NOSAVE: GRFStatus, enum.
Definition: newgrf_config.h:169
GRFTextWrapper::text
struct GRFText * text
The actual text.
Definition: newgrf_config.h:146
ThreadMutex
Cross-platform Mutex.
Definition: thread.h:56
ServerNetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER
virtual void Receive_CLIENT_FIND_SERVER(Packet *p, NetworkAddress *client_addr)
Queries to the server for information about the game.
Definition: network_udp.cpp:165
_session_key
static uint64 _session_key
Session key to register ourselves to the master server.
Definition: network_udp.cpp:43
network_udp.h
Sending and receiving UDP messages.
ADVERTISE_RETRY_TIMES
static const uint32 ADVERTISE_RETRY_TIMES
give up re-advertising after this much failed retries
Definition: network_udp.cpp:47
SmallVector::Clear
void Clear()
Remove all items from the list.
Definition: smallvec_type.hpp:98
NetworkAddress
Wrapper for (un)resolved network addresses; there&#39;s no reason to transform a numeric IP to a string a...
Definition: address.h:31
SmallVector::Begin
const T * Begin() const
Get the pointer to the first item (const)
Definition: smallvec_type.hpp:272
NetworkUDPQueryServerInfo::manually
bool manually
Did we connect manually or not?
Definition: network_udp.cpp:55
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
NetworkGameInfo::map_width
uint16 map_width
Map width.
Definition: game.h:40
_network_udp_mutex
static ThreadMutex * _network_udp_mutex
Mutex for all out threaded udp resolution and such.
Definition: network_udp.cpp:40
NetworkUDPSocketHandler
Base socket handler for all UDP sockets.
Definition: udp.h:50
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:50
ServerNetworkUDPSocketHandler
*** Communication with clients (we are server) ***/
Definition: network_udp.cpp:151
SmallVector< NetworkAddress, 4 >
GCS_NOT_FOUND
GRF file was not found in the local cache.
Definition: newgrf_config.h:38
NetworkGameList
Structure with information shown in the game list (GUI)
Definition: network_gamelist.h:19
FindGRFConfig
const GRFConfig * FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum, uint32 desired_version)
Find a NewGRF in the scanned list.
Definition: newgrf_config.cpp:809
PACKET_UDP_SERVER_UNREGISTER
Request to be removed from the server-list.
Definition: udp.h:33
GRFConfig::ident
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
Definition: newgrf_config.h:158
_udp_server_socket
NetworkUDPSocketHandler * _udp_server_socket
udp server socket
Definition: network_udp.cpp:50
ThreadMutex::EndCritical
virtual void EndCritical(bool allow_recursive=false)=0
End of the critical section.
ClientNetworkUDPSocketHandler::Receive_SERVER_NEWGRFS
virtual void Receive_SERVER_NEWGRFS(Packet *p, NetworkAddress *client_addr)
The return of the client&#39;s request of the names of some NewGRFs.
Definition: network_udp.cpp:439
GRFIdentifier
Basic data to distinguish a GRF.
Definition: newgrf_config.h:84
SmallVector::End
const T * End() const
Get the pointer behind the last valid item (const)
Definition: smallvec_type.hpp:292
_network_udp_server
bool _network_udp_server
Is the UDP server started?
Definition: network.cpp:81
GRFConfig::next
struct GRFConfig * next
NOSAVE: Next item in the linked list.
Definition: newgrf_config.h:178
NetworkGameInfo::server_name
char server_name[NETWORK_NAME_LENGTH]
Server name.
Definition: game.h:42
NetworkUDPAdvertise
void NetworkUDPAdvertise()
Register us to the master server This function checks if it needs to send an advertise.
Definition: network_udp.cpp:617
UpdateNetworkGameWindow
void UpdateNetworkGameWindow()
Update the network new window because a new server is found on the network.
Definition: network_gui.cpp:84
_network_dedicated
bool _network_dedicated
are we a dedicated server?
Definition: network.cpp:59
NetworkGameInfo
The game information that is sent from the server to the clients.
Definition: game.h:36
NetworkGameInfo::companies_max
byte companies_max
Max companies allowed on server.
Definition: game.h:53
NETWORK_GRF_NAME_LENGTH
static const uint NETWORK_GRF_NAME_LENGTH
Maximum length of the name of a GRF.
Definition: config.h:54
NetworkUDPAdvertiseThread
static void NetworkUDPAdvertiseThread(void *pntr)
Thread entry point for advertising.
Definition: network_udp.cpp:577
_broadcast_list
NetworkAddressList _broadcast_list
List of broadcast addresses.
Definition: network.cpp:74
NETWORK_MASTER_SERVER_VERSION
static const byte NETWORK_MASTER_SERVER_VERSION
What version of master-server-protocol do we use?
Definition: config.h:40
ClientSettings::network
NetworkSettings network
settings related to the network
Definition: settings_type.h:562
NetworkGameListAddItem
NetworkGameList * NetworkGameListAddItem(NetworkAddress address)
Add a new item to the linked gamelist.
Definition: network_gamelist.cpp:80
FindUnknownGRFName
GRFTextWrapper * FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create)
Finds the name of a NewGRF in the list of names for unknown GRFs.
Definition: newgrf_config.cpp:854
ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig
virtual void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config)
Function that is called for every GRFConfig that is read when receiving a NetworkGameInfo.
Definition: network_udp.cpp:470
NetworkGameInfo::companies_on
byte companies_on
How many started companies do we have.
Definition: game.h:52
NetworkUDPSearchGame
void NetworkUDPSearchGame()
Find all servers.
Definition: network_udp.cpp:526
Packet::Send_uint64
void Send_uint64(uint64 data)
Package a 64 bits integer in the packet.
Definition: packet.cpp:134
MasterNetworkUDPSocketHandler
*** Communication with the masterserver ***/
Definition: network_udp.cpp:120
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:153
AddGRFTextToList
void AddGRFTextToList(GRFText **list, GRFText *text_to_add)
Add a GRFText to a GRFText list.
Definition: newgrf_text.cpp:578
NetworkSettings::max_spectators
uint8 max_spectators
maximum amount of spectators
Definition: settings_type.h:262
Packet::Send_uint16
void Send_uint16(uint16 data)
Package a 16 bits integer in the packet.
Definition: packet.cpp:110
_network_need_advertise
bool _network_need_advertise
Whether we need to advertise.
Definition: network.cpp:65
NetworkGameInfo::clients_max
byte clients_max
Max clients allowed on server.
Definition: game.h:51
NetworkUDPRemoveAdvertiseThread
static void NetworkUDPRemoveAdvertiseThread(void *pntr)
Thread entry point for de-advertising.
Definition: network_udp.cpp:541
NETWORK_MASTER_SERVER_HOST
static const char *const NETWORK_MASTER_SERVER_HOST
DNS hostname of the masterserver.
Definition: config.h:18
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:76
PACKET_UDP_SERVER_REGISTER
Packet to register itself to the master server.
Definition: udp.h:29
NetworkUDPQueryMasterServer
void NetworkUDPQueryMasterServer()
Request the the server-list from the master server.
Definition: network_udp.cpp:511
GCF_COPY
The data is copied from a grf in _all_grfs.
Definition: newgrf_config.h:28
NetworkUDPBroadCast
static void NetworkUDPBroadCast(NetworkUDPSocketHandler *socket)
Broadcast to all ips.
Definition: network_udp.cpp:498
NetworkGameInfo::use_password
bool use_password
Is this server passworded?
Definition: game.h:48
NetworkUDPQueryServerInfo::NetworkUDPQueryServerInfo
NetworkUDPQueryServerInfo(const NetworkAddress &address, bool manually)
Create the structure.
Definition: network_udp.cpp:62
ServerNetworkUDPSocketHandler::Receive_CLIENT_GET_NEWGRFS
virtual void Receive_CLIENT_GET_NEWGRFS(Packet *p, NetworkAddress *client_addr)
A client has requested the names of some NewGRFs.
Definition: network_udp.cpp:272
ThreadMutex::New
static ThreadMutex * New()
Create a new mutex.
Definition: thread_none.cpp:32
PACKET_UDP_SERVER_DETAIL_INFO
Reply of the game server about details of the game, such as companies.
Definition: udp.h:28
GRFConfig::flags
uint8 flags
NOSAVE: GCF_Flags, bitset.
Definition: newgrf_config.h:168
ServerListType
ServerListType
The types of server lists we can get.
Definition: udp.h:41
NetworkGameList::address
NetworkAddress address
The connection info of the game server.
Definition: network_gamelist.h:21
NetworkAddress::GetHostname
const char * GetHostname()
Get the hostname; in case it wasn&#39;t given the IPv4 dotted representation is given.
Definition: address.cpp:26
NetworkServerGameInfo::clients_on
byte clients_on
Current count of clients on server.
Definition: game.h:30
NetworkGameList::info
NetworkGameInfo info
The game information of this server.
Definition: network_gamelist.h:20
NetworkGameInfo::server_revision
char server_revision[NETWORK_REVISION_LENGTH]
The version number the server is using (e.g.: &#39;r304&#39; or 0.5.0)
Definition: game.h:44
network.h
Basic functions/variables used all over the place.
Packet::size
PacketSize size
The size of the whole packet for received packets.
Definition: packet.h:52
NETWORK_MASTER_SERVER_WELCOME_MESSAGE
static const char *const NETWORK_MASTER_SERVER_WELCOME_MESSAGE
Message sent to the masterserver to &#39;identify&#39; this client as OpenTTD.
Definition: config.h:26
_network_game_info
NetworkServerGameInfo _network_game_info
Information about our game.
Definition: network.cpp:61
min
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
NetworkSettings::server_lang
uint8 server_lang
language of the server
Definition: settings_type.h:265
GRFTextWrapper
Reference counted wrapper around a GRFText pointer.
Definition: newgrf_config.h:145
NetworkGameInfo::dedicated
bool dedicated
Is this a dedicated server?
Definition: game.h:45
MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:25
NetworkUDPSocketHandler::SendPacket
void SendPacket(Packet *p, NetworkAddress *recv, bool all=false, bool broadcast=false)
Send a packet over UDP.
Definition: udp.cpp:83
ServerNetworkUDPSocketHandler::ServerNetworkUDPSocketHandler
ServerNetworkUDPSocketHandler(NetworkAddressList *addresses)
Create the socket.
Definition: network_udp.cpp:161
NetworkSettings::max_companies
uint8 max_companies
maximum amount of companies
Definition: settings_type.h:260
DEBUG
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:39
NetworkAddress::SetPort
void SetPort(uint16 port)
Set the port.
Definition: address.cpp:58
PACKET_UDP_SERVER_NEWGRFS
Sends the list of NewGRF&#39;s requested.
Definition: udp.h:35
NetworkUDPInitialize
void NetworkUDPInitialize()
Initialize the whole UDP bit.
Definition: network_udp.cpp:657
GRFConfig::url
GRFTextWrapper * url
NOSAVE: URL belonging to this GRF.
Definition: newgrf_config.h:163
NetworkServerGameInfo::map_name
char map_name[NETWORK_NAME_LENGTH]
Map which is played ["random" for a randomized map].
Definition: game.h:29
Company
Definition: company_base.h:110
NetworkSettings::server_port
uint16 server_port
port the server listens on
Definition: settings_type.h:243
NetworkGameInfo::map_set
byte map_set
Graphical set.
Definition: game.h:56
_udp_client_socket
NetworkUDPSocketHandler * _udp_client_socket
udp client socket
Definition: network_udp.cpp:49
NetworkGameInfo::game_date
Date game_date
Current date.
Definition: game.h:39
NetworkUDPSocketHandler::Close
void Close()
Close the given UDP socket.
Definition: udp.cpp:62
GetGRFStringFromGRFText
const char * GetGRFStringFromGRFText(const GRFText *text)
Get a C-string from a GRFText-list.
Definition: newgrf_text.cpp:721
MasterNetworkUDPSocketHandler::Receive_MASTER_ACK_REGISTER
virtual void Receive_MASTER_ACK_REGISTER(Packet *p, NetworkAddress *client_addr)
The master server acknowledges the registration.
Definition: network_udp.cpp:133
Packet::Recv_uint8
uint8 Recv_uint8()
Read a 8 bits integer from the packet.
Definition: packet.cpp:221
MasterNetworkUDPSocketHandler::Receive_MASTER_SESSION_KEY
virtual void Receive_MASTER_SESSION_KEY(Packet *p, NetworkAddress *client_addr)
The master server sends us a session key.
Definition: network_udp.cpp:142
Packet::Recv_uint64
uint64 Recv_uint64()
Read a 64 bits integer from the packet.
Definition: packet.cpp:267
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:59
ServerNetworkUDPSocketHandler::Receive_CLIENT_DETAIL_INFO
virtual void Receive_CLIENT_DETAIL_INFO(Packet *p, NetworkAddress *client_addr)
Query for detailed information about companies.
Definition: network_udp.cpp:205
network_internal.h
Variables and function used internally.
Pool::PoolItem<&_company_pool >::GetNumItems
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:276
UNKNOWN_GRF_NAME_PLACEHOLDER
#define UNKNOWN_GRF_NAME_PLACEHOLDER
For communication about GRFs over the network.
Definition: newgrf_config.h:234
network_gamelist.h
Handling of the list of games.
ADVERTISE_NORMAL_INTERVAL
static const uint32 ADVERTISE_NORMAL_INTERVAL
interval between advertising in ms (15 minutes)
Definition: network_udp.cpp:45
NetworkBackgroundUDPLoop
void NetworkBackgroundUDPLoop()
Receive the UDP packets.
Definition: network_udp.cpp:703
NetworkGameListAddItemDelayed
void NetworkGameListAddItemDelayed(NetworkGameList *item)
Add a new item to the linked gamelist, but do it delayed in the next tick or so to prevent race condi...
Definition: network_gamelist.cpp:39
NetworkSettings::max_clients
uint8 max_clients
maximum amount of clients
Definition: settings_type.h:261
NETWORK_COMPANY_NAME_LENGTH
static const uint NETWORK_COMPANY_NAME_LENGTH
The maximum length of the company name, in bytes including &#39;\0&#39;.
Definition: config.h:43
ADVERTISE_RETRY_INTERVAL
static const uint32 ADVERTISE_RETRY_INTERVAL
re-advertise when no response after this many ms (10 seconds)
Definition: network_udp.cpp:46
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: depend.cpp:68
GRFConfig::filename
char * filename
Filename - either with or without full path.
Definition: newgrf_config.h:160
NetworkAddress::AddressFamilyAsString
static const char * AddressFamilyAsString(int family)
Convert the address family into a string.
Definition: address.cpp:427
SEND_MTU
static const uint16 SEND_MTU
Number of bytes we can pack in a single packet.
Definition: config.h:35
GRFConfig::name
GRFTextWrapper * name
NOSAVE: GRF name (Action 0x08)
Definition: newgrf_config.h:161
MasterNetworkUDPSocketHandler::MasterNetworkUDPSocketHandler
MasterNetworkUDPSocketHandler(NetworkAddressList *addresses)
Create the socket.
Definition: network_udp.cpp:129
NetworkUDPQueryServer
static void NetworkUDPQueryServer(NetworkAddress *address, bool needs_mutex, bool manually)
Helper function doing the actual work for querying the server.
Definition: network_udp.cpp:75
_network_server
bool _network_server
network-server is active
Definition: network.cpp:57
NetworkGameList::manually
bool manually
True if the server was added manually.
Definition: network_gamelist.h:23
NetworkUDPRemoveAdvertise
void NetworkUDPRemoveAdvertise(bool blocking)
Remove our advertise from the master-server.
Definition: network_udp.cpp:563
GRFConfig::GetName
const char * GetName() const
Get the name of this grf.
Definition: newgrf_config.cpp:126
GRFIdentifier::grfid
uint32 grfid
GRF ID (defined by Action 0x08)
Definition: newgrf_config.h:85
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:114
PACKET_UDP_SERVER_RESPONSE
Reply of the game server with game information.
Definition: udp.h:26
NetworkCompanyStats
Simple calculated statistics of a company.
Definition: network_type.h:61
_network_advertise_retries
uint8 _network_advertise_retries
The number of advertisement retries we did.
Definition: network.cpp:83
NetworkGameInfo::hostname
char hostname[NETWORK_HOSTNAME_LENGTH]
Hostname of the server (if any)
Definition: game.h:43
SLT_END
End of &#39;arrays&#39; marker.
Definition: udp.h:46
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:544
ConvertYMDToDate
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition: date.cpp:149
Packet::Recv_uint16
uint16 Recv_uint16()
Read a 16 bits integer from the packet.
Definition: packet.cpp:235
ThreadMutex::BeginCritical
virtual void BeginCritical(bool allow_recursive=false)=0
Begin the critical section.
GRFIdentifier::md5sum
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF) ...
Definition: newgrf_config.h:86
FGCM_EXACT
Only find Grfs matching md5sum.
Definition: newgrf_config.h:194
NETWORK_COMPANY_INFO_VERSION
static const byte NETWORK_COMPANY_INFO_VERSION
What version of company info is this?
Definition: config.h:39
NetworkSettings::server_password
char server_password[NETWORK_PASSWORD_LENGTH]
password for joining this server
Definition: settings_type.h:247
NetworkUDPClose
void NetworkUDPClose()
Close all UDP related stuff.
Definition: network_udp.cpp:683
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
NetworkGameInfo::grfconfig
GRFConfig * grfconfig
List of NewGRF files used.
Definition: game.h:37
ThreadObject::New
static bool New(OTTDThreadFunc proc, void *param, ThreadObject **thread=NULL, const char *name=NULL)
Create a thread; proc will be called as first function inside the thread, with optional params...
Definition: thread_morphos.cpp:196
GameCreationSettings::starting_year
Year starting_year
starting date
Definition: settings_type.h:277
udp.h
Basic functions to receive and send UDP packets.
NETWORK_MASTER_SERVER_PORT
static const uint16 NETWORK_MASTER_SERVER_PORT
The default port of the master server (UDP)
Definition: config.h:28
NetworkAddress::GetAddress
const sockaddr_storage * GetAddress()
Get the address in its internal representation.
Definition: address.cpp:128
NetworkAddress::GetAddressAsString
void GetAddressAsString(char *buffer, const char *last, bool with_family=true)
Get the address as a string, e.g.
Definition: address.cpp:81
NetworkGameInfo::spectators_on
byte spectators_on
How many spectators do we have?
Definition: game.h:54
NETWORK_MAX_GRF_COUNT
static const uint NETWORK_MAX_GRF_COUNT
Maximum number of GRFs that can be sent.
Definition: config.h:60
Packet::Recv_string
void Recv_string(char *buffer, size_t size, StringValidationSettings settings=SVS_REPLACE_WITH_QUESTION_MARK)
Reads a string till it finds a &#39;\0&#39; in the stream.
Definition: packet.cpp:290
NetworkAddress::IsResolved
bool IsResolved() const
Check whether the IP address has been resolved already.
Definition: address.h:128
GRFConfig::info
GRFTextWrapper * info
NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
Definition: newgrf_config.h:162
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:201