tron@2186: /* $Id$ */ tron@2186: rubidium@10429: /** @file network_internal.h Variables and function used internally. */ rubidium@10429: rubidium@8772: #ifndef NETWORK_INTERNAL_H rubidium@8772: #define NETWORK_INTERNAL_H darkvater@211: truelight@543: #ifdef ENABLE_NETWORK truelight@543: rubidium@8750: #include "../player_type.h" rubidium@8750: #include "../economy_type.h" rubidium@5720: #include "core/config.h" rubidium@5720: #include "core/game.h" tron@2153: rubidium@9285: /** rubidium@9285: * If this line is enable, every frame will have a sync test rubidium@9285: * this is not needed in normal games. Normal is like 1 sync in 100 rubidium@9285: * frames. You can enable this if you have a lot of desyncs on a certain rubidium@9285: * game. rubidium@9285: * Remember: both client and server have to be compiled with this rubidium@9285: * option enabled to make it to work. If one of the two has it disabled rubidium@9285: * nothing will happen. rubidium@9285: */ truelight@543: //#define ENABLE_NETWORK_SYNC_EVERY_FRAME truelight@543: rubidium@9285: /** rubidium@9285: * In theory sending 1 of the 2 seeds is enough to check for desyncs rubidium@9285: * so in theory, this next define can be left off. rubidium@9285: */ truelight@543: //#define NETWORK_SEND_DOUBLE_SEED truelight@543: truelight@543: rubidium@9285: enum { rubidium@9285: /** rubidium@9285: * How many clients can we have? Like.. MAX_PLAYERS - 1 is the amount of rubidium@9285: * players that can really play.. so.. a max of 4 spectators.. gives us.. rubidium@9285: * MAX_PLAYERS + 3 rubidium@9285: */ rubidium@9285: MAX_CLIENTS = MAX_PLAYERS + 3, truelight@543: rubidium@9285: /** Do not change this next line. It should _ALWAYS_ be MAX_CLIENTS + 1 */ rubidium@9285: MAX_CLIENT_INFO = MAX_CLIENTS + 1, truelight@543: rubidium@9285: /** Maximum number of internet interfaces supported. */ rubidium@9285: MAX_INTERFACES = 9, rubidium@9285: rubidium@9285: /** How many vehicle/station types we put over the network */ rubidium@9285: NETWORK_VEHICLE_TYPES = 5, rubidium@9285: NETWORK_STATION_TYPES = 5, rubidium@9286: }; truelight@543: rubidium@6574: struct NetworkPlayerInfo { rubidium@9285: char company_name[NETWORK_NAME_LENGTH]; ///< Company name rubidium@9285: char password[NETWORK_PASSWORD_LENGTH]; ///< The password for the player rubidium@9285: Year inaugurated_year; ///< What year the company started in rubidium@9285: Money company_value; ///< The company value rubidium@9285: Money money; ///< The amount of money the company has rubidium@9285: Money income; ///< How much did the company earned last year rubidium@9285: uint16 performance; ///< What was his performance last month? rubidium@9285: bool use_password; ///< Is there a password rubidium@9285: uint16 num_vehicle[NETWORK_VEHICLE_TYPES]; ///< How many vehicles are there of this type? rubidium@9285: uint16 num_station[NETWORK_STATION_TYPES]; ///< How many stations are there of this type? rubidium@9285: char players[NETWORK_PLAYERS_LENGTH]; ///< The players that control this company (Name1, name2, ..) rubidium@9285: uint16 months_empty; ///< How many months the company is empty rubidium@6574: }; truelight@543: rubidium@6574: struct NetworkClientInfo { rubidium@9285: uint16 client_index; ///< Index of the client (same as ClientState->index) rubidium@9285: char client_name[NETWORK_CLIENT_NAME_LENGTH]; ///< Name of the client rubidium@9285: byte client_lang; ///< The language of the client rubidium@9285: PlayerID client_playas; ///< As which player is this client playing (PlayerID) rubidium@9285: uint32 client_ip; ///< IP-address of the client (so he can be banned) rubidium@9285: Date join_date; ///< Gamedate the player has joined rubidium@9285: char unique_id[NETWORK_UNIQUE_ID_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: rubidium@9285: /** Language ids for server_lang and client_lang. Do NOT modify the order. */ rubidium@6574: enum NetworkLanguage { glx@7289: NETLANG_ANY = 0, glx@7289: NETLANG_ENGLISH, glx@7289: NETLANG_GERMAN, glx@7289: NETLANG_FRENCH, glx@7289: NETLANG_BRAZILIAN, glx@7289: NETLANG_BULGARIAN, glx@7289: NETLANG_CHINESE, glx@7289: NETLANG_CZECH, glx@7289: NETLANG_DANISH, glx@7289: NETLANG_DUTCH, glx@7289: NETLANG_ESPERANTO, glx@7289: NETLANG_FINNISH, glx@7289: NETLANG_HUNGARIAN, glx@7289: NETLANG_ICELANDIC, glx@7289: NETLANG_ITALIAN, glx@7289: NETLANG_JAPANESE, glx@7289: NETLANG_KOREAN, glx@7289: NETLANG_LITHUANIAN, glx@7289: NETLANG_NORWEGIAN, glx@7289: NETLANG_POLISH, glx@7289: NETLANG_PORTUGUESE, glx@7289: NETLANG_ROMANIAN, glx@7289: NETLANG_RUSSIAN, glx@7289: NETLANG_SLOVAK, glx@7289: NETLANG_SLOVENIAN, glx@7289: NETLANG_SPANISH, glx@7289: NETLANG_SWEDISH, glx@7289: NETLANG_TURKISH, glx@7289: NETLANG_UKRAINIAN, glx@9226: NETLANG_AFRIKAANS, glx@9226: NETLANG_CROATIAN, glx@9226: NETLANG_CATALAN, glx@9226: NETLANG_ESTONIAN, glx@9226: NETLANG_GALICIAN, glx@9226: NETLANG_GREEK, glx@9226: NETLANG_LATVIAN, glx@7292: NETLANG_COUNT 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@8303: VARDEF char _network_unique_id[NETWORK_UNIQUE_ID_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]; rubidium@8494: VARDEF char _network_default_company_pass[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@5870: void NetworkUDPCloseAll(); 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: truelight@543: #endif /* ENABLE_NETWORK */ rubidium@8772: #endif /* NETWORK_INTERNAL_H */