19 #include "../stdafx.h" 
   20 #include "../date_func.h" 
   21 #include "../map_func.h" 
   27 #include "../core/endian_func.hpp" 
   28 #include "../company_base.h" 
   29 #include "../thread/thread.h" 
   31 #include "../newgrf_text.h" 
   32 #include "../strings_func.h" 
   33 #include "table/strings.h" 
   37 #include "../safeguards.h" 
   88   if (_udp_client_socket != NULL) _udp_client_socket->
SendPacket(&p, address);
 
  221   static const uint MIN_CI_SIZE = 54;
 
  234       FOR_ALL_COMPANIES(company) {
 
  237         GetString(company_name, STR_COMPANY_NAME, company_name + max_cname_length - 1);
 
  239         free -= (int)strlen(company_name);
 
  241       if (free >= 0) 
break;
 
  244       assert(max_cname_length > 0);
 
  251   FOR_ALL_COMPANIES(company) {
 
  278   uint8 in_reply_count = 0;
 
  279   size_t packet_len = 0;
 
  286   for (i = 0; i < num_grfs; i++) {
 
  294     if (f == NULL) 
continue; 
 
  304     in_reply[in_reply_count] = f;
 
  308   if (in_reply_count == 0) 
return;
 
  312   for (i = 0; i < in_reply_count; i++) {
 
  352   item->info.compatible = 
true;
 
  363     uint in_request_count = 0;
 
  365     for (c = item->
info.grfconfig; c != NULL; c = c->
next) {
 
  368       in_request[in_request_count] = c;
 
  372     if (in_request_count > 0) {
 
  378       for (i = 0; i < in_request_count; i++) {
 
  386   if (item->info.hostname[0] == 
'\0') {
 
  390   if (client_addr->
GetAddress()->ss_family == AF_INET6) {
 
  391     strecat(item->info.server_name, 
" (IPv6)", 
lastof(item->info.server_name));
 
  396   item->info.compatible &= item->info.version_compatible; 
 
  415       sockaddr_storage addr_storage;
 
  416       memset(&addr_storage, 0, 
sizeof(addr_storage));
 
  419         addr_storage.ss_family = AF_INET;
 
  420         ((sockaddr_in*)&addr_storage)->sin_addr.s_addr = TO_LE32(p->
Recv_uint32());
 
  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();
 
  449   for (i = 0; i < num_grfs; i++) {
 
  478     config->
name->Release();
 
  480     config->
name->AddRef();
 
  484     config->
name->Release();
 
  486     config->
name->AddRef();
 
  487     config->
info->Release();
 
  489     config->
info->AddRef();
 
  490     config->
url->Release();
 
  492     config->
url->AddRef();
 
  503     DEBUG(net, 4, 
"[udp] broadcasting to %s", addr->GetHostname());
 
  520   _udp_client_socket->
SendPacket(&p, &out_addr, 
true);
 
  531   DEBUG(net, 0, 
"[udp] searching server");
 
  543   DEBUG(net, 1, 
"[udp] removing advertise from master server");
 
  555   if (_udp_master_socket != NULL) _udp_master_socket->
SendPacket(&p, &out_addr, 
true);
 
  582   DEBUG(net, 1, 
"[udp] advertising to master server");
 
  585   static byte session_key_retries = 0;
 
  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));
 
  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");
 
  609   if (_udp_master_socket != NULL) _udp_master_socket->
SendPacket(&p, &out_addr, 
true);
 
  619   static uint32 _last_advertisement = 0; 
 
  620   static uint32 _next_advertisement = 0; 
 
  621   static uint32 _next_retry         = 0; 
 
  648   if (_next_advertisement < _last_advertisement) _next_advertisement = UINT32_MAX;
 
  649   if (_next_retry         < _last_advertisement) _next_retry         = UINT32_MAX;
 
  662   DEBUG(net, 1, 
"[udp] initializing listeners");
 
  663   assert(_udp_client_socket == NULL && _udp_server_socket == NULL && _udp_master_socket == NULL);
 
  686   _udp_server_socket->
Close();
 
  687   _udp_master_socket->
Close();
 
  688   _udp_client_socket->
Close();
 
  692   _udp_client_socket = NULL;
 
  693   _udp_server_socket = NULL;
 
  694   _udp_master_socket = NULL;
 
  699   DEBUG(net, 1, 
"[udp] closed listeners");