14 #include "../stdafx.h" 
   16 #include "../saveload/saveload.h" 
   17 #include "../saveload/saveload_filter.h" 
   18 #include "../command_func.h" 
   19 #include "../console_func.h" 
   20 #include "../strings_func.h" 
   21 #include "../window_func.h" 
   22 #include "../company_func.h" 
   23 #include "../company_base.h" 
   24 #include "../company_gui.h" 
   25 #include "../core/random_func.hpp" 
   26 #include "../date_func.h" 
   27 #include "../gfx_func.h" 
   33 #include "../core/backup_type.hpp" 
   35 #include "table/strings.h" 
   37 #include "../safeguards.h" 
   44   static const size_t CHUNK = 32 * 1024;  
 
   66     size_t in_packet = p->
size - p->
pos;
 
   67     size_t to_write  = 
min((
size_t)(this->
bufe - this->
buf), in_packet);
 
   72       memcpy(this->
buf, pbuf, to_write);
 
   73       this->
buf += to_write;
 
   77     if (to_write == in_packet) 
return;
 
   81     to_write   = in_packet - to_write;
 
   85     memcpy(this->
buf, pbuf, to_write);
 
   86     this->
buf += to_write;
 
   89    size_t Read(byte *rbuf, 
size_t size)
 
   94     const byte *rbufe = rbuf + ret_size;
 
   96     while (rbuf != rbufe) {
 
  102       size_t to_write = 
min(this->
bufe - this->
buf, rbufe - rbuf);
 
  103       memcpy(rbuf, this->
buf, to_write);
 
  105       this->
buf += to_write;
 
  151   if (this->
sock == INVALID_SOCKET) 
return status;
 
  193     default:                                  errorno = NETWORK_ERROR_GENERAL; 
break;
 
  250 #ifdef NETWORK_SEND_DOUBLE_SEED 
  255         NetworkError(STR_NETWORK_ERROR_DESYNC);
 
  257         DEBUG(net, 0, 
"Sync error detected!");
 
  412   my_client->NetworkGameSocketHandler::SendCommand(p, cp);
 
  566     for (uint i = 0; i < NETWORK_VEH_END; i++) {
 
  569     for (uint i = 0; i < NETWORK_VEH_END; i++) {
 
  642   static const StringID network_error_strings[] = {
 
  643     STR_NETWORK_ERROR_LOSTCONNECTION,    
 
  644     STR_NETWORK_ERROR_LOSTCONNECTION,    
 
  645     STR_NETWORK_ERROR_LOSTCONNECTION,    
 
  646     STR_NETWORK_ERROR_LOSTCONNECTION,    
 
  647     STR_NETWORK_ERROR_LOSTCONNECTION,    
 
  648     STR_NETWORK_ERROR_LOSTCONNECTION,    
 
  649     STR_NETWORK_ERROR_SERVER_ERROR,      
 
  650     STR_NETWORK_ERROR_SERVER_ERROR,      
 
  651     STR_NETWORK_ERROR_WRONG_REVISION,    
 
  652     STR_NETWORK_ERROR_LOSTCONNECTION,    
 
  653     STR_NETWORK_ERROR_WRONG_PASSWORD,    
 
  654     STR_NETWORK_ERROR_SERVER_ERROR,      
 
  655     STR_NETWORK_ERROR_KICKED,            
 
  656     STR_NETWORK_ERROR_CHEATER,           
 
  657     STR_NETWORK_ERROR_SERVER_FULL,       
 
  658     STR_NETWORK_ERROR_TOO_MANY_COMMANDS, 
 
  659     STR_NETWORK_ERROR_TIMEOUT_PASSWORD,  
 
  660     STR_NETWORK_ERROR_TIMEOUT_COMPUTER,  
 
  661     STR_NETWORK_ERROR_TIMEOUT_MAP,       
 
  662     STR_NETWORK_ERROR_TIMEOUT_JOIN,      
 
  664   assert_compile(
lengthof(network_error_strings) == NETWORK_ERROR_END);
 
  668   StringID err = STR_NETWORK_ERROR_LOSTCONNECTION;
 
  669   if (error < (ptrdiff_t)
lengthof(network_error_strings)) err = network_error_strings[
error];
 
  686   for (; grf_count > 0; grf_count--) {
 
  694       char buf[
sizeof(c.
md5sum) * 2 + 1];
 
  732   p->
Recv_string(_password_server_id, 
sizeof(_password_server_id));
 
  754   p->
Recv_string(_password_server_id, 
sizeof(_password_server_id));
 
  864       ShowJoinStatusWindow();
 
  881 #ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME 
  887 #ifdef NETWORK_SEND_DOUBLE_SEED 
  914 #ifdef NETWORK_SEND_DOUBLE_SEED 
  959       case NETWORK_ACTION_CHAT_CLIENT:
 
  966       case NETWORK_ACTION_GIVE_MONEY:
 
  969       case NETWORK_ACTION_CHAT_COMPANY: {
 
  973         GetString(name, str, 
lastof(name));
 
 1017     NetworkTextMessage(NETWORK_ACTION_LEAVE, 
CC_DEFAULT, 
false, ci->
client_name, NULL, STR_NETWORK_MESSAGE_CLIENT_LEAVING);
 
 1020     DEBUG(net, 0, 
"Unknown client (%d) is leaving the game", client_id);
 
 1094   if (client_id == 0) {
 
 1096     DEBUG(net, 0, 
"[move] received invalid client index = 0");
 
 1118   _network_server_max_companies = p->
Recv_uint8();
 
 1119   _network_server_max_spectators = p->
Recv_uint8();
 
 1148   if (lag < 5) 
return;
 
 1159   static uint last_lag = 0;
 
 1160   if (last_lag == lag) 
return;
 
 1164   ShowErrorMessage(STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION_CAPTION, STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION, 
WL_INFO);
 
 1227   if (ci == NULL) 
return;