darkvater@211: #ifndef NETWORK_H darkvater@211: #define NETWORK_H darkvater@211: truelight@543: #include "network_core.h" truelight@543: truelight@543: #ifdef ENABLE_NETWORK truelight@543: 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 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@543: #define NETWORK_NAME_LENGTH 80 truelight@543: #define NETWORK_HOSTNAME_LENGTH 80 truelight@624: #define NETWORK_REVISION_LENGTH 10 truelight@543: #define NETWORK_PASSWORD_LENGTH 20 truelight@543: #define NETWORK_PLAYERS_LENGTH 200 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 { truelight@543: char server_name[NETWORK_NAME_LENGTH]; // Server name truelight@543: char hostname[NETWORK_HOSTNAME_LENGTH]; // Hostname of the server (if any) truelight@543: char server_revision[NETWORK_REVISION_LENGTH]; // The SVN version number the server is using (e.g.: 'r304') truelight@543: // It even shows a SVN version in release-version, so truelight@543: // it is easy to compare if a server is of the correct version truelight@543: byte server_lang; // Language of the server (we should make a nice table for this) truelight@543: byte use_password; // Is set to != 0 if it uses a password truelight@543: char server_password[NETWORK_PASSWORD_LENGTH]; // On the server: the game password, on the client: != "" if server has password truelight@543: byte clients_max; // Max clients allowed on server truelight@543: byte clients_on; // Current count of clients on server truelight@543: byte spectators_on; // How many spectators do we have? truelight@543: uint16 game_date; // Current date truelight@543: uint16 start_date; // When the game started truelight@543: char map_name[NETWORK_NAME_LENGTH]; // Map which is played ["random" for a randomized map] truelight@543: uint16 map_width; // Map width truelight@543: uint16 map_height; // Map height truelight@543: byte map_set; // Graphical set truelight@543: bool dedicated; // Is this a dedicated server? darkvater@211: } NetworkGameInfo; darkvater@211: truelight@543: typedef struct NetworkPlayerInfo { truelight@543: char company_name[NETWORK_NAME_LENGTH]; // Company name truelight@543: char password[NETWORK_PASSWORD_LENGTH]; // The password for the player truelight@543: byte inaugurated_year; // What year the company started in truelight@543: int64 company_value; // The company value truelight@543: int64 money; // The amount of money the company has truelight@543: int64 income; // How much did the company earned last year truelight@543: uint16 performance; // What was his performance last month? truelight@543: uint16 num_vehicle[NETWORK_VEHICLE_TYPES]; // How many vehicles are there of this type? truelight@543: uint16 num_station[NETWORK_STATION_TYPES]; // How many stations are there of this type? truelight@543: char players[NETWORK_PLAYERS_LENGTH]; // The players that control this company (Name1, name2, ..) truelight@543: } NetworkPlayerInfo; truelight@543: truelight@543: typedef struct NetworkClientInfo { truelight@543: uint16 client_index; // Index of the client (same as ClientState->index) truelight@543: char client_name[NETWORK_NAME_LENGTH]; // Name of the client truelight@543: byte client_lang; // The language of the client truelight@543: byte client_playas; // As which player is this client playing truelight@543: uint32 client_ip; // IP-address of the client (so he can be banned) truelight@543: uint16 join_date; // Gamedate the player has joined truelight@602: 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; truelight@543: bool online; // False if the server did not respond (default status) 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, 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 { truelight@543: NETLANG_ANY = 0, truelight@543: NETLANG_ENGLISH = 1, truelight@543: NETLANG_GERMAN = 2, truelight@543: 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: truelight@543: VARDEF char _network_player_name[NETWORK_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: truelight@543: // networking settings truelight@543: VARDEF uint32 _network_ip_list[MAX_INTERFACES + 1]; // Network IPs truelight@543: VARDEF uint16 _network_game_count; truelight@543: truelight@543: VARDEF uint16 _network_lobby_company_count; truelight@543: truelight@543: VARDEF uint _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@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@543: #endif /* ENABLE_NETWORK */ truelight@543: truelight@543: // Those variables must always be registered! truelight@543: VARDEF bool _networking; truelight@543: VARDEF bool _network_available; // is network mode available? truelight@543: VARDEF bool _network_server; // network-server is active truelight@543: VARDEF bool _network_dedicated; // are we a dedicated server? truelight@543: VARDEF byte _network_playas; // an id to play as.. darkvater@211: darkvater@228: void ParseConnectionString(const byte **player, const byte **port, byte *connection_string); truelight@543: void NetworkUpdateClientInfo(uint16 client_index); darkvater@228: darkvater@211: #endif /* NETWORK_H */