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: tron@2153: #include "player.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@668: /* Stuff for the master-server */ truelight@668: #define NETWORK_MASTER_SERVER_PORT 3978 truelight@668: #define NETWORK_MASTER_SERVER_HOST "master.openttd.org" truelight@668: #define NETWORK_MASTER_SERVER_WELCOME_MESSAGE "OpenTTDRegister" truelight@668: truelight@543: #define NETWORK_DEFAULT_PORT 3979 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: truelight@1026: enum { rubidium@4344: NETWORK_NAME_LENGTH = 80, rubidium@4344: NETWORK_HOSTNAME_LENGTH = 80, rubidium@4344: NETWORK_REVISION_LENGTH = 15, rubidium@4344: NETWORK_PASSWORD_LENGTH = 20, truelight@1026: NETWORK_PLAYERS_LENGTH = 200, rubidium@4344: NETWORK_CLIENT_NAME_LENGTH = 25, truelight@1026: NETWORK_RCONCOMMAND_LENGTH = 500, ludde@2071: rubidium@5339: NETWORK_GRF_NAME_LENGTH = 80, ///< Maximum length of the name of a GRF rubidium@5339: /* Maximum number of GRFs that can be sent. rubidium@5339: * This value is related to number of handles (files) OpenTTD can open. rubidium@5339: * This is currently 64 and about 10 are currently used when OpenTTD loads rubidium@5339: * without any NewGRFs. Therefore one can only load about 55 NewGRFs, so rubidium@5339: * this is not a limit, but rather a way to easily check whether the limit rubidium@5339: * imposed by the handle count is reached. Secondly it isn't possible to rubidium@5339: * send much more GRF IDs + MD5sums in the PACKET_UDP_SERVER_RESPONSE, due rubidium@5339: * to the limited size of UDP packets. */ rubidium@5339: NETWORK_MAX_GRF_COUNT = 55, rubidium@5339: rubidium@4344: NETWORK_NUM_LANGUAGES = 4, truelight@1026: }; truelight@543: truelight@543: // This is the struct used by both client and server truelight@543: // some fields will be empty on the client (like game_password) by default truelight@543: // and only filled with data a player enters. darkvater@211: typedef struct NetworkGameInfo { Darkvater@2879: char server_name[NETWORK_NAME_LENGTH]; // Server name Darkvater@2879: char hostname[NETWORK_HOSTNAME_LENGTH]; // Hostname of the server (if any) Darkvater@2879: char server_revision[NETWORK_REVISION_LENGTH]; // The SVN version number the server is using (e.g.: 'r304') Darkvater@2879: // It even shows a SVN version in release-version, so Darkvater@2879: // it is easy to compare if a server is of the correct version rubidium@5339: bool version_compatible; // Can we connect to this server or not? (based on server_revision) rubidium@5339: bool compatible; // Can we connect to this server or not? (based on server_revision _and_ grf_match Darkvater@2879: byte server_lang; // Language of the server (we should make a nice table for this) Darkvater@2879: byte use_password; // Is set to != 0 if it uses a password Darkvater@2879: char server_password[NETWORK_PASSWORD_LENGTH]; // On the server: the game password, on the client: != "" if server has password Darkvater@2879: byte clients_max; // Max clients allowed on server Darkvater@2879: byte clients_on; // Current count of clients on server Darkvater@2879: byte companies_max; // Max companies allowed on server Darkvater@2944: byte companies_on; // How many started companies do we have (XXX - disabled for server atm, use ActivePlayerCount()) Darkvater@2879: byte spectators_max; // Max spectators allowed on server Darkvater@2944: byte spectators_on; // How many spectators do we have? (XXX - disabled for server atm, use NetworkSpectatorCount()) rubidium@4289: Date game_date; // Current date rubidium@4289: Date start_date; // When the game started Darkvater@2879: char map_name[NETWORK_NAME_LENGTH]; // Map which is played ["random" for a randomized map] Darkvater@2879: uint16 map_width; // Map width Darkvater@2879: uint16 map_height; // Map height Darkvater@2879: byte map_set; // Graphical set Darkvater@2879: bool dedicated; // Is this a dedicated server? Darkvater@2879: char rcon_password[NETWORK_PASSWORD_LENGTH]; // RCon password for the server. "" if rcon is disabled rubidium@5339: struct GRFConfig *grfconfig; // List of NewGRF files required darkvater@211: } NetworkGameInfo; darkvater@211: truelight@543: typedef 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@4344: byte use_password; // 0: No password 1: There is 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 truelight@543: } NetworkPlayerInfo; truelight@543: truelight@543: typedef 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@4344: byte 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 truelight@543: } NetworkClientInfo; darkvater@211: darkvater@211: typedef struct NetworkGameList { truelight@543: NetworkGameInfo info; darkvater@211: uint32 ip; darkvater@211: uint16 port; rubidium@4344: bool online; // False if the server did not respond (default status) rubidium@4344: bool manually; // True if the server was added manually truelight@543: struct NetworkGameList *next; darkvater@211: } NetworkGameList; darkvater@211: truelight@543: typedef enum { 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, truelight@543: } NetworkJoinStatus; truelight@543: truelight@543: // language ids for server_lang and client_lang truelight@543: typedef enum { rubidium@4344: NETLANG_ANY = 0, truelight@543: NETLANG_ENGLISH = 1, rubidium@4344: NETLANG_GERMAN = 2, rubidium@4344: NETLANG_FRENCH = 3, truelight@543: } NetworkLanguage; truelight@543: truelight@543: VARDEF NetworkGameList *_network_game_list; 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: tron@1329: NetworkGameList *NetworkQueryServer(const char* host, unsigned short port, bool game_info); darkvater@774: Darkvater@2944: byte NetworkSpectatorCount(void); 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); tron@4038: void NetworkRebuildHostList(void); tron@4038: bool NetworkChangeCompanyPassword(byte argc, char *argv[]); tron@4038: void NetworkPopulateCompanyInfo(void); Darkvater@5034: void UpdateNetworkGameWindow(bool unselect); peter1138@4716: void CheckMinPlayers(void); tron@4038: Darkvater@4829: void NetworkStartUp(void); Darkvater@4829: void NetworkUDPClose(void); Darkvater@4829: void NetworkShutDown(void); Darkvater@4829: void NetworkGameLoop(void); Darkvater@4829: void NetworkUDPGameLoop(void); Darkvater@4829: bool NetworkServerStart(void); Darkvater@4880: bool NetworkClientConnectGame(const char *host, uint16 port); Darkvater@4829: void NetworkReboot(void); Darkvater@4829: void NetworkDisconnect(void); Darkvater@4830: Darkvater@4830: VARDEF bool _networking; ///< are we in networking mode? Darkvater@4830: VARDEF bool _network_server; ///< network-server is active Darkvater@4830: VARDEF bool _network_available; ///< is network mode available? Darkvater@4830: Darkvater@4830: #else /* ENABLE_NETWORK */ Darkvater@4830: /* Network function stubs when networking is disabled */ Darkvater@4830: Darkvater@4830: static inline void NetworkStartUp(void) {} Darkvater@4830: static inline void NetworkShutDown(void) {} Darkvater@4830: Darkvater@4830: #define _networking 0 Darkvater@4830: #define _network_server 0 Darkvater@4830: #define _network_available 0 Darkvater@4830: truelight@543: #endif /* ENABLE_NETWORK */ truelight@543: Darkvater@4830: /* These variables must always be registered! */ Darkvater@4830: VARDEF bool _network_dedicated; ///< are we a dedicated server? Darkvater@4830: VARDEF bool _network_advertise; ///< is the server advertising to the master server? Darkvater@4880: VARDEF PlayerID _network_playas; ///< an id to play as.. (see players.h:Players) darkvater@211: darkvater@211: #endif /* NETWORK_H */