228 cs->status = STATUS_AUTHORIZING; |
228 cs->status = STATUS_AUTHORIZING; |
229 |
229 |
230 Packet *p = NetworkSend_Init(PACKET_SERVER_NEED_PASSWORD); |
230 Packet *p = NetworkSend_Init(PACKET_SERVER_NEED_PASSWORD); |
231 p->Send_uint8(type); |
231 p->Send_uint8(type); |
232 p->Send_uint32(_settings_game.game_creation.generation_seed); |
232 p->Send_uint32(_settings_game.game_creation.generation_seed); |
233 p->Send_string(_network_unique_id); |
233 p->Send_string(_settings_client.network.network_id); |
234 cs->Send_Packet(p); |
234 cs->Send_Packet(p); |
235 } |
235 } |
236 |
236 |
237 DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WELCOME) |
237 DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WELCOME) |
238 { |
238 { |
253 _network_game_info.clients_on++; |
253 _network_game_info.clients_on++; |
254 |
254 |
255 p = NetworkSend_Init(PACKET_SERVER_WELCOME); |
255 p = NetworkSend_Init(PACKET_SERVER_WELCOME); |
256 p->Send_uint16(cs->index); |
256 p->Send_uint16(cs->index); |
257 p->Send_uint32(_settings_game.game_creation.generation_seed); |
257 p->Send_uint32(_settings_game.game_creation.generation_seed); |
258 p->Send_string(_network_unique_id); |
258 p->Send_string(_settings_client.network.network_id); |
259 cs->Send_Packet(p); |
259 cs->Send_Packet(p); |
260 |
260 |
261 // Transmit info about all the active clients |
261 // Transmit info about all the active clients |
262 FOR_ALL_CLIENTS(new_cs) { |
262 FOR_ALL_CLIENTS(new_cs) { |
263 if (new_cs != cs && new_cs->status > STATUS_AUTH) |
263 if (new_cs != cs && new_cs->status > STATUS_AUTH) |
798 SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(new_cs, DEREF_CLIENT_INFO(cs)); |
798 SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(new_cs, DEREF_CLIENT_INFO(cs)); |
799 SEND_COMMAND(PACKET_SERVER_JOIN)(new_cs, cs->index); |
799 SEND_COMMAND(PACKET_SERVER_JOIN)(new_cs, cs->index); |
800 } |
800 } |
801 } |
801 } |
802 |
802 |
803 if (_network_pause_on_join) { |
803 if (_settings_client.network.pause_on_join) { |
804 /* Now pause the game till the client is in sync */ |
804 /* Now pause the game till the client is in sync */ |
805 DoCommandP(0, 1, 0, NULL, CMD_PAUSE); |
805 DoCommandP(0, 1, 0, NULL, CMD_PAUSE); |
806 |
806 |
807 NetworkServer_HandleChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game paused (incoming client)", NETWORK_SERVER_INDEX); |
807 NetworkServer_HandleChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game paused (incoming client)", NETWORK_SERVER_INDEX); |
808 } |
808 } |
1019 if (frame + DAY_TICKS < _frame_counter) return; |
1019 if (frame + DAY_TICKS < _frame_counter) return; |
1020 |
1020 |
1021 /* Now he is! Unpause the game */ |
1021 /* Now he is! Unpause the game */ |
1022 cs->status = STATUS_ACTIVE; |
1022 cs->status = STATUS_ACTIVE; |
1023 |
1023 |
1024 if (_network_pause_on_join) { |
1024 if (_settings_client.network.pause_on_join) { |
1025 DoCommandP(0, 0, 0, NULL, CMD_PAUSE); |
1025 DoCommandP(0, 0, 0, NULL, CMD_PAUSE); |
1026 NetworkServer_HandleChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused (client connected)", NETWORK_SERVER_INDEX); |
1026 NetworkServer_HandleChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused (client connected)", NETWORK_SERVER_INDEX); |
1027 } |
1027 } |
1028 |
1028 |
1029 CheckMinPlayers(); |
1029 CheckMinPlayers(); |
1363 } |
1363 } |
1364 |
1364 |
1365 /* Check if we want to restart the map */ |
1365 /* Check if we want to restart the map */ |
1366 static void NetworkCheckRestartMap() |
1366 static void NetworkCheckRestartMap() |
1367 { |
1367 { |
1368 if (_network_restart_game_year != 0 && _cur_year >= _network_restart_game_year) { |
1368 if (_settings_client.network.restart_game_year != 0 && _cur_year >= _settings_client.network.restart_game_year) { |
1369 DEBUG(net, 0, "Auto-restarting map. Year %d reached", _cur_year); |
1369 DEBUG(net, 0, "Auto-restarting map. Year %d reached", _cur_year); |
1370 |
1370 |
1371 StartNewGameWithoutGUI(GENERATE_NEW_SEED); |
1371 StartNewGameWithoutGUI(GENERATE_NEW_SEED); |
1372 } |
1372 } |
1373 } |
1373 } |
1382 NetworkTCPSocketHandler *cs; |
1382 NetworkTCPSocketHandler *cs; |
1383 const NetworkClientInfo *ci; |
1383 const NetworkClientInfo *ci; |
1384 const Player *p; |
1384 const Player *p; |
1385 bool clients_in_company[MAX_PLAYERS]; |
1385 bool clients_in_company[MAX_PLAYERS]; |
1386 |
1386 |
1387 if (!_network_autoclean_companies) return; |
1387 if (!_settings_client.network.autoclean_companies) return; |
1388 |
1388 |
1389 memset(clients_in_company, 0, sizeof(clients_in_company)); |
1389 memset(clients_in_company, 0, sizeof(clients_in_company)); |
1390 |
1390 |
1391 /* Detect the active companies */ |
1391 /* Detect the active companies */ |
1392 FOR_ALL_CLIENTS(cs) { |
1392 FOR_ALL_CLIENTS(cs) { |
1407 if (!clients_in_company[p->index]) { |
1407 if (!clients_in_company[p->index]) { |
1408 /* The company is empty for one month more */ |
1408 /* The company is empty for one month more */ |
1409 _network_player_info[p->index].months_empty++; |
1409 _network_player_info[p->index].months_empty++; |
1410 |
1410 |
1411 /* Is the company empty for autoclean_unprotected-months, and is there no protection? */ |
1411 /* Is the company empty for autoclean_unprotected-months, and is there no protection? */ |
1412 if (_network_player_info[p->index].months_empty > _network_autoclean_unprotected && _network_player_info[p->index].password[0] == '\0') { |
1412 if (_network_player_info[p->index].months_empty > _settings_client.network.autoclean_unprotected && _network_player_info[p->index].password[0] == '\0') { |
1413 /* Shut the company down */ |
1413 /* Shut the company down */ |
1414 DoCommandP(0, 2, p->index, NULL, CMD_PLAYER_CTRL); |
1414 DoCommandP(0, 2, p->index, NULL, CMD_PLAYER_CTRL); |
1415 IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d", p->index + 1); |
1415 IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d", p->index + 1); |
1416 } |
1416 } |
1417 /* Is the compnay empty for autoclean_protected-months, and there is a protection? */ |
1417 /* Is the compnay empty for autoclean_protected-months, and there is a protection? */ |
1418 if (_network_player_info[p->index].months_empty > _network_autoclean_protected && _network_player_info[p->index].password[0] != '\0') { |
1418 if (_network_player_info[p->index].months_empty > _settings_client.network.autoclean_protected && _network_player_info[p->index].password[0] != '\0') { |
1419 /* Unprotect the company */ |
1419 /* Unprotect the company */ |
1420 _network_player_info[p->index].password[0] = '\0'; |
1420 _network_player_info[p->index].password[0] = '\0'; |
1421 IConsolePrintF(CC_DEFAULT, "Auto-removed protection from company #%d", p->index+1); |
1421 IConsolePrintF(CC_DEFAULT, "Auto-removed protection from company #%d", p->index+1); |
1422 _network_player_info[p->index].months_empty = 0; |
1422 _network_player_info[p->index].months_empty = 0; |
1423 } |
1423 } |
1508 #ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME |
1508 #ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME |
1509 bool send_sync = false; |
1509 bool send_sync = false; |
1510 #endif |
1510 #endif |
1511 |
1511 |
1512 #ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME |
1512 #ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME |
1513 if (_frame_counter >= _last_sync_frame + _network_sync_freq) { |
1513 if (_frame_counter >= _last_sync_frame + _settings_client.network.sync_freq) { |
1514 _last_sync_frame = _frame_counter; |
1514 _last_sync_frame = _frame_counter; |
1515 send_sync = true; |
1515 send_sync = true; |
1516 } |
1516 } |
1517 #endif |
1517 #endif |
1518 |
1518 |
1540 } else { |
1540 } else { |
1541 cs->lag_test = 0; |
1541 cs->lag_test = 0; |
1542 } |
1542 } |
1543 } else if (cs->status == STATUS_PRE_ACTIVE) { |
1543 } else if (cs->status == STATUS_PRE_ACTIVE) { |
1544 int lag = NetworkCalculateLag(cs); |
1544 int lag = NetworkCalculateLag(cs); |
1545 if (lag > _network_max_join_time) { |
1545 if (lag > _settings_client.network.max_join_time) { |
1546 IConsolePrintF(CC_ERROR,"Client #%d is dropped because it took longer than %d ticks for him to join", cs->index, _network_max_join_time); |
1546 IConsolePrintF(CC_ERROR,"Client #%d is dropped because it took longer than %d ticks for him to join", cs->index, _settings_client.network.max_join_time); |
1547 NetworkCloseClient(cs); |
1547 NetworkCloseClient(cs); |
1548 } |
1548 } |
1549 } else if (cs->status == STATUS_INACTIVE) { |
1549 } else if (cs->status == STATUS_INACTIVE) { |
1550 int lag = NetworkCalculateLag(cs); |
1550 int lag = NetworkCalculateLag(cs); |
1551 if (lag > 4 * DAY_TICKS) { |
1551 if (lag > 4 * DAY_TICKS) { |