13 #include "../map_func.h" |
13 #include "../map_func.h" |
14 #include "../command_func.h" |
14 #include "../command_func.h" |
15 #include "../variables.h" |
15 #include "../variables.h" |
16 #include "../date_func.h" |
16 #include "../date_func.h" |
17 #include "../newgrf_config.h" |
17 #include "../newgrf_config.h" |
|
18 #include "network_internal.h" |
18 #include "network_client.h" |
19 #include "network_client.h" |
19 #include "network_server.h" |
20 #include "network_server.h" |
20 #include "network_udp.h" |
21 #include "network_udp.h" |
21 #include "network_gamelist.h" |
22 #include "network_gamelist.h" |
22 #include "core/udp.h" |
23 #include "core/udp.h" |
36 #include "../landscape_type.h" |
37 #include "../landscape_type.h" |
37 #include "../rev.h" |
38 #include "../rev.h" |
38 #ifdef DEBUG_DUMP_COMMANDS |
39 #ifdef DEBUG_DUMP_COMMANDS |
39 #include "../core/alloc_func.hpp" |
40 #include "../core/alloc_func.hpp" |
40 #endif /* DEBUG_DUMP_COMMANDS */ |
41 #endif /* DEBUG_DUMP_COMMANDS */ |
41 |
|
42 #include "table/strings.h" |
42 #include "table/strings.h" |
43 |
43 |
44 bool _network_reload_cfg; |
44 bool _network_reload_cfg; |
45 bool _network_server; ///< network-server is active |
45 bool _network_server; ///< network-server is active |
46 bool _network_available; ///< is network mode available? |
46 bool _network_available; ///< is network mode available? |
47 bool _network_dedicated; ///< are we a dedicated server? |
47 bool _network_dedicated; ///< are we a dedicated server? |
48 bool _network_advertise; ///< is the server advertising to the master server? |
48 bool _network_advertise; ///< is the server advertising to the master server? |
|
49 bool _is_network_server; ///< Does this client wants to be a network-server? |
|
50 NetworkGameInfo _network_game_info; |
|
51 NetworkPlayerInfo _network_player_info[MAX_PLAYERS]; |
|
52 NetworkClientInfo _network_client_info[MAX_CLIENT_INFO]; |
|
53 uint16 _network_own_client_index; |
|
54 uint16 _redirect_console_to_client; |
|
55 bool _network_need_advertise; |
|
56 uint32 _network_last_advertise_frame; |
|
57 uint8 _network_reconnect; |
|
58 char *_network_host_list[10]; |
|
59 char *_network_ban_list[25]; |
|
60 uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode |
|
61 uint32 _frame_counter_max; // To where we may go with our clients |
|
62 uint32 _last_sync_frame; // Used in the server to store the last time a sync packet was sent to clients. |
|
63 uint32 _broadcast_list[MAX_INTERFACES + 1]; |
|
64 uint32 _network_server_bind_ip; |
|
65 uint32 _sync_seed_1, _sync_seed_2; |
|
66 uint32 _sync_frame; |
|
67 bool _network_first_time; |
|
68 uint32 _network_last_host_ip; |
|
69 bool _network_udp_server; |
|
70 uint16 _network_udp_broadcast; |
|
71 uint8 _network_advertise_retries; |
49 |
72 |
50 /* Check whether NETWORK_NUM_LANDSCAPES is still in sync with NUM_LANDSCAPE */ |
73 /* Check whether NETWORK_NUM_LANDSCAPES is still in sync with NUM_LANDSCAPE */ |
51 assert_compile((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE); |
74 assert_compile((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE); |
52 |
75 |
53 // global variables (declared in network_data.h) |
76 // global variables (declared in network_data.h) |
335 if (NetworkCountPlayers() < _settings_client.network.min_players) { |
358 if (NetworkCountPlayers() < _settings_client.network.min_players) { |
336 if (_min_players_paused) return; |
359 if (_min_players_paused) return; |
337 |
360 |
338 _min_players_paused = true; |
361 _min_players_paused = true; |
339 DoCommandP(0, 1, 0, NULL, CMD_PAUSE); |
362 DoCommandP(0, 1, 0, NULL, CMD_PAUSE); |
340 NetworkServer_HandleChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game paused (not enough players)", NETWORK_SERVER_INDEX); |
363 NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game paused (not enough players)", NETWORK_SERVER_INDEX); |
341 } else { |
364 } else { |
342 if (!_min_players_paused) return; |
365 if (!_min_players_paused) return; |
343 |
366 |
344 _min_players_paused = false; |
367 _min_players_paused = false; |
345 DoCommandP(0, 0, 0, NULL, CMD_PAUSE); |
368 DoCommandP(0, 0, 0, NULL, CMD_PAUSE); |
346 NetworkServer_HandleChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused (enough players)", NETWORK_SERVER_INDEX); |
369 NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused (enough players)", NETWORK_SERVER_INDEX); |
347 } |
370 } |
348 } |
371 } |
349 |
372 |
350 // Find all IP-aliases for this host |
373 // Find all IP-aliases for this host |
351 static void NetworkFindIPs() |
374 static void NetworkFindIPs() |
662 } |
685 } |
663 |
686 |
664 /* When the client was PRE_ACTIVE, the server was in pause mode, so unpause */ |
687 /* When the client was PRE_ACTIVE, the server was in pause mode, so unpause */ |
665 if (cs->status == STATUS_PRE_ACTIVE && _settings_client.network.pause_on_join) { |
688 if (cs->status == STATUS_PRE_ACTIVE && _settings_client.network.pause_on_join) { |
666 DoCommandP(0, 0, 0, NULL, CMD_PAUSE); |
689 DoCommandP(0, 0, 0, NULL, CMD_PAUSE); |
667 NetworkServer_HandleChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused", NETWORK_SERVER_INDEX); |
690 NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused", NETWORK_SERVER_INDEX); |
668 } |
691 } |
669 |
692 |
670 cs->Destroy(); |
693 cs->Destroy(); |
671 |
694 |
672 // Close the gap in the client-list |
695 // Close the gap in the client-list |