tron@2186: /* $Id$ */ tron@2186: darkvater@211: #ifndef NETWORK_H darkvater@211: #define NETWORK_H darkvater@211: darkvater@663: #define NOREV_STRING "norev000" truelight@543: truelight@543: #ifdef ENABLE_NETWORK truelight@543: rubidium@5720: #include "../player.h" rubidium@5720: #include "core/config.h" rubidium@5720: #include "core/game.h" tron@2153: truelight@543: // If this line is enable, every frame will have a sync test truelight@543: // this is not needed in normal games. Normal is like 1 sync in 100 truelight@543: // frames. You can enable this if you have a lot of desyncs on a certain truelight@543: // game. truelight@543: // Remember: both client and server have to be compiled with this truelight@543: // option enabled to make it to work. If one of the two has it disabled truelight@543: // nothing will happen. truelight@543: //#define ENABLE_NETWORK_SYNC_EVERY_FRAME truelight@543: truelight@543: // In theory sending 1 of the 2 seeds is enough to check for desyncs truelight@543: // so in theory, this next define can be left off. truelight@543: //#define NETWORK_SEND_DOUBLE_SEED truelight@543: truelight@543: // How many clients can we have? Like.. MAX_PLAYERS - 1 is the amount of truelight@543: // players that can really play.. so.. a max of 4 spectators.. gives us.. truelight@543: // MAX_PLAYERS + 3 truelight@543: #define MAX_CLIENTS (MAX_PLAYERS + 3) truelight@543: truelight@543: truelight@543: // Do not change this next line. It should _ALWAYS_ be MAX_CLIENTS + 1 truelight@543: #define MAX_CLIENT_INFO (MAX_CLIENTS + 1) truelight@543: truelight@543: #define MAX_INTERFACES 9 truelight@543: truelight@543: truelight@543: // How many vehicle/station types we put over the network truelight@543: #define NETWORK_VEHICLE_TYPES 5 truelight@543: #define NETWORK_STATION_TYPES 5 truelight@543: rubidium@6574: struct NetworkPlayerInfo { rubidium@4344: char company_name[NETWORK_NAME_LENGTH]; // Company name rubidium@4344: char password[NETWORK_PASSWORD_LENGTH]; // The password for the player rubidium@4344: Year inaugurated_year; // What year the company started in rubidium@4344: int64 company_value; // The company value rubidium@4344: int64 money; // The amount of money the company has rubidium@4344: int64 income; // How much did the company earned last year rubidium@4344: uint16 performance; // What was his performance last month? rubidium@6169: bool use_password; // Is there a password rubidium@4344: uint16 num_vehicle[NETWORK_VEHICLE_TYPES]; // How many vehicles are there of this type? rubidium@4344: uint16 num_station[NETWORK_STATION_TYPES]; // How many stations are there of this type? rubidium@4344: char players[NETWORK_PLAYERS_LENGTH]; // The players that control this company (Name1, name2, ..) rubidium@4344: uint16 months_empty; // How many months the company is empty rubidium@6574: }; truelight@543: rubidium@6574: struct NetworkClientInfo { rubidium@4344: uint16 client_index; // Index of the client (same as ClientState->index) rubidium@4344: char client_name[NETWORK_CLIENT_NAME_LENGTH]; // Name of the client rubidium@4344: byte client_lang; // The language of the client rubidium@5838: PlayerID client_playas; // As which player is this client playing (PlayerID) rubidium@4344: uint32 client_ip; // IP-address of the client (so he can be banned) rubidium@4344: Date join_date; // Gamedate the player has joined rubidium@4344: char unique_id[NETWORK_NAME_LENGTH]; // Every play sends an unique id so we can indentify him rubidium@6574: }; darkvater@211: rubidium@6574: enum NetworkJoinStatus { truelight@543: NETWORK_JOIN_STATUS_CONNECTING, truelight@543: NETWORK_JOIN_STATUS_AUTHORIZING, truelight@543: NETWORK_JOIN_STATUS_WAITING, truelight@543: NETWORK_JOIN_STATUS_DOWNLOADING, truelight@543: NETWORK_JOIN_STATUS_PROCESSING, truelight@670: NETWORK_JOIN_STATUS_REGISTERING, signde@239: truelight@543: NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO, rubidium@6574: }; truelight@543: truelight@543: // language ids for server_lang and client_lang rubidium@6574: enum NetworkLanguage { rubidium@4344: NETLANG_ANY = 0, truelight@543: NETLANG_ENGLISH = 1, rubidium@4344: NETLANG_GERMAN = 2, rubidium@4344: NETLANG_FRENCH = 3, rubidium@6574: }; truelight@543: truelight@543: VARDEF NetworkGameInfo _network_game_info; truelight@543: VARDEF NetworkPlayerInfo _network_player_info[MAX_PLAYERS]; truelight@543: VARDEF NetworkClientInfo _network_client_info[MAX_CLIENT_INFO]; truelight@543: Darkvater@3623: VARDEF char _network_player_name[NETWORK_CLIENT_NAME_LENGTH]; truelight@543: VARDEF char _network_default_ip[NETWORK_HOSTNAME_LENGTH]; truelight@543: truelight@543: VARDEF uint16 _network_own_client_index; truelight@602: VARDEF char _network_unique_id[NETWORK_NAME_LENGTH]; // Our own unique ID truelight@543: truelight@543: VARDEF uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode truelight@543: VARDEF uint32 _frame_counter_max; // To where we may go with our clients truelight@543: ludde@2079: VARDEF uint32 _last_sync_frame; // Used in the server to store the last time a sync packet was sent to clients. ludde@2079: truelight@543: // networking settings tron@4034: VARDEF uint32 _broadcast_list[MAX_INTERFACES + 1]; truelight@543: peter1138@3152: VARDEF uint16 _network_server_port; truelight@629: /* We use bind_ip and bind_ip_host, where bind_ip_host is the readable form of truelight@629: bind_ip_host, and bind_ip the numeric value, because we want a nice number truelight@629: in the openttd.cfg, but we wants to use the uint32 internally.. */ truelight@629: VARDEF uint32 _network_server_bind_ip; truelight@629: VARDEF char _network_server_bind_ip_host[NETWORK_HOSTNAME_LENGTH]; truelight@543: VARDEF bool _is_network_server; // Does this client wants to be a network-server? truelight@543: VARDEF char _network_server_name[NETWORK_NAME_LENGTH]; truelight@1026: VARDEF char _network_server_password[NETWORK_PASSWORD_LENGTH]; truelight@1026: VARDEF char _network_rcon_password[NETWORK_PASSWORD_LENGTH]; truelight@1026: peter1138@3173: VARDEF uint16 _network_max_join_time; ///< Time a client can max take to join peter1138@3173: VARDEF bool _network_pause_on_join; ///< Pause the game when a client tries to join (more chance of succeeding join) truelight@1602: truelight@1026: VARDEF uint16 _redirect_console_to_client; truelight@543: truelight@543: VARDEF uint16 _network_sync_freq; truelight@543: VARDEF uint8 _network_frame_freq; truelight@543: truelight@543: VARDEF uint32 _sync_seed_1, _sync_seed_2; truelight@543: VARDEF uint32 _sync_frame; truelight@543: VARDEF bool _network_first_time; truelight@543: // Vars needed for the join-GUI truelight@543: VARDEF NetworkJoinStatus _network_join_status; truelight@543: VARDEF uint8 _network_join_waiting; truelight@543: VARDEF uint16 _network_join_kbytes; truelight@543: VARDEF uint16 _network_join_kbytes_total; truelight@543: truelight@543: VARDEF char _network_last_host[NETWORK_HOSTNAME_LENGTH]; truelight@543: VARDEF short _network_last_port; truelight@543: VARDEF uint32 _network_last_host_ip; truelight@543: VARDEF uint8 _network_reconnect; truelight@543: truelight@543: VARDEF bool _network_udp_server; truelight@543: VARDEF uint16 _network_udp_broadcast; truelight@543: truelight@764: VARDEF byte _network_lan_internet; truelight@764: peter1138@2861: VARDEF bool _network_need_advertise; peter1138@2861: VARDEF uint32 _network_last_advertise_frame; truelight@764: VARDEF uint8 _network_advertise_retries; truelight@668: truelight@690: VARDEF bool _network_autoclean_companies; truelight@690: VARDEF uint8 _network_autoclean_unprotected; // Remove a company after X months truelight@690: VARDEF uint8 _network_autoclean_protected; // Unprotect a company after X months truelight@690: rubidium@4293: VARDEF Year _network_restart_game_year; // If this year is reached, the server automaticly restarts peter1138@4716: VARDEF uint8 _network_min_players; // Minimum number of players for game to unpause truelight@785: rubidium@6167: void NetworkTCPQueryServer(const char* host, unsigned short port); darkvater@774: rubidium@6573: byte NetworkSpectatorCount(); Darkvater@2944: Darkvater@3041: VARDEF char *_network_host_list[10]; Darkvater@3041: VARDEF char *_network_ban_list[25]; Darkvater@3041: tron@4038: void ParseConnectionString(const char **player, const char **port, char *connection_string); tron@4038: void NetworkUpdateClientInfo(uint16 client_index); tron@4038: void NetworkAddServer(const char *b); rubidium@6573: void NetworkRebuildHostList(); tron@4038: bool NetworkChangeCompanyPassword(byte argc, char *argv[]); rubidium@6573: void NetworkPopulateCompanyInfo(); Darkvater@5034: void UpdateNetworkGameWindow(bool unselect); rubidium@6573: void CheckMinPlayers(); truelight@6210: void NetworkStartDebugLog(const char *hostname, uint16 port); tron@4038: rubidium@6573: void NetworkStartUp(); rubidium@5870: void NetworkUDPCloseAll(); rubidium@6573: void NetworkShutDown(); rubidium@6573: void NetworkGameLoop(); rubidium@6573: void NetworkUDPGameLoop(); rubidium@6573: bool NetworkServerStart(); Darkvater@4880: bool NetworkClientConnectGame(const char *host, uint16 port); rubidium@6573: void NetworkReboot(); rubidium@6573: void NetworkDisconnect(); Darkvater@4830: rubidium@6504: bool IsNetworkCompatibleVersion(const char *version); rubidium@6504: Darkvater@4830: VARDEF bool _network_server; ///< network-server is active Darkvater@4830: VARDEF bool _network_available; ///< is network mode available? rubidium@5962: VARDEF bool _network_dedicated; ///< are we a dedicated server? rubidium@5962: VARDEF bool _network_advertise; ///< is the server advertising to the master server? Darkvater@4830: Darkvater@4830: #else /* ENABLE_NETWORK */ Darkvater@4830: /* Network function stubs when networking is disabled */ Darkvater@4830: rubidium@6573: static inline void NetworkStartUp() {} rubidium@6573: static inline void NetworkShutDown() {} Darkvater@4830: Darkvater@4830: #define _networking 0 Darkvater@4830: #define _network_server 0 Darkvater@4830: #define _network_available 0 rubidium@5962: #define _network_dedicated 0 rubidium@5962: #define _network_advertise 0 Darkvater@4830: truelight@543: #endif /* ENABLE_NETWORK */ truelight@543: rubidium@5962: /* Thss variable must always be registered! */ Darkvater@4880: VARDEF PlayerID _network_playas; ///< an id to play as.. (see players.h:Players) darkvater@211: darkvater@211: #endif /* NETWORK_H */