src/network/network_internal.h
branchNewGRF_ports
changeset 6872 1c4a4a609f85
child 9826 9707ad4c9b60
child 10184 fcf5fb2548eb
equal deleted inserted replaced
6871:5a9dc001e1ad 6872:1c4a4a609f85
       
     1 /* $Id$ */
       
     2 
       
     3 #ifndef NETWORK_INTERNAL_H
       
     4 #define NETWORK_INTERNAL_H
       
     5 
       
     6 #ifdef ENABLE_NETWORK
       
     7 
       
     8 #include "../player_type.h"
       
     9 #include "../economy_type.h"
       
    10 #include "core/config.h"
       
    11 #include "core/game.h"
       
    12 
       
    13 // If this line is enable, every frame will have a sync test
       
    14 //  this is not needed in normal games. Normal is like 1 sync in 100
       
    15 //  frames. You can enable this if you have a lot of desyncs on a certain
       
    16 //  game.
       
    17 // Remember: both client and server have to be compiled with this
       
    18 //  option enabled to make it to work. If one of the two has it disabled
       
    19 //  nothing will happen.
       
    20 //#define ENABLE_NETWORK_SYNC_EVERY_FRAME
       
    21 
       
    22 // In theory sending 1 of the 2 seeds is enough to check for desyncs
       
    23 //   so in theory, this next define can be left off.
       
    24 //#define NETWORK_SEND_DOUBLE_SEED
       
    25 
       
    26 // How many clients can we have? Like.. MAX_PLAYERS - 1 is the amount of
       
    27 //  players that can really play.. so.. a max of 4 spectators.. gives us..
       
    28 //  MAX_PLAYERS + 3
       
    29 #define MAX_CLIENTS (MAX_PLAYERS + 3)
       
    30 
       
    31 
       
    32 // Do not change this next line. It should _ALWAYS_ be MAX_CLIENTS + 1
       
    33 #define MAX_CLIENT_INFO (MAX_CLIENTS + 1)
       
    34 
       
    35 #define MAX_INTERFACES 9
       
    36 
       
    37 
       
    38 // How many vehicle/station types we put over the network
       
    39 #define NETWORK_VEHICLE_TYPES 5
       
    40 #define NETWORK_STATION_TYPES 5
       
    41 
       
    42 struct NetworkPlayerInfo {
       
    43 	char company_name[NETWORK_NAME_LENGTH];         // Company name
       
    44 	char password[NETWORK_PASSWORD_LENGTH];         // The password for the player
       
    45 	Year inaugurated_year;                          // What year the company started in
       
    46 	Money company_value;                            // The company value
       
    47 	Money money;                                    // The amount of money the company has
       
    48 	Money income;                                   // How much did the company earned last year
       
    49 	uint16 performance;                             // What was his performance last month?
       
    50 	bool use_password;                              // Is there a password
       
    51 	uint16 num_vehicle[NETWORK_VEHICLE_TYPES];      // How many vehicles are there of this type?
       
    52 	uint16 num_station[NETWORK_STATION_TYPES];      // How many stations are there of this type?
       
    53 	char players[NETWORK_PLAYERS_LENGTH];           // The players that control this company (Name1, name2, ..)
       
    54 	uint16 months_empty;                            // How many months the company is empty
       
    55 };
       
    56 
       
    57 struct NetworkClientInfo {
       
    58 	uint16 client_index;                            // Index of the client (same as ClientState->index)
       
    59 	char client_name[NETWORK_CLIENT_NAME_LENGTH];   // Name of the client
       
    60 	byte client_lang;                               // The language of the client
       
    61 	PlayerID client_playas;                         // As which player is this client playing (PlayerID)
       
    62 	uint32 client_ip;                               // IP-address of the client (so he can be banned)
       
    63 	Date join_date;                                 // Gamedate the player has joined
       
    64 	char unique_id[NETWORK_UNIQUE_ID_LENGTH];       // Every play sends an unique id so we can indentify him
       
    65 };
       
    66 
       
    67 enum NetworkJoinStatus {
       
    68 	NETWORK_JOIN_STATUS_CONNECTING,
       
    69 	NETWORK_JOIN_STATUS_AUTHORIZING,
       
    70 	NETWORK_JOIN_STATUS_WAITING,
       
    71 	NETWORK_JOIN_STATUS_DOWNLOADING,
       
    72 	NETWORK_JOIN_STATUS_PROCESSING,
       
    73 	NETWORK_JOIN_STATUS_REGISTERING,
       
    74 
       
    75 	NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO,
       
    76 };
       
    77 
       
    78 /* Language ids for server_lang and client_lang. Do NOT modify the order. */
       
    79 enum NetworkLanguage {
       
    80 	NETLANG_ANY = 0,
       
    81 	NETLANG_ENGLISH,
       
    82 	NETLANG_GERMAN,
       
    83 	NETLANG_FRENCH,
       
    84 	NETLANG_BRAZILIAN,
       
    85 	NETLANG_BULGARIAN,
       
    86 	NETLANG_CHINESE,
       
    87 	NETLANG_CZECH,
       
    88 	NETLANG_DANISH,
       
    89 	NETLANG_DUTCH,
       
    90 	NETLANG_ESPERANTO,
       
    91 	NETLANG_FINNISH,
       
    92 	NETLANG_HUNGARIAN,
       
    93 	NETLANG_ICELANDIC,
       
    94 	NETLANG_ITALIAN,
       
    95 	NETLANG_JAPANESE,
       
    96 	NETLANG_KOREAN,
       
    97 	NETLANG_LITHUANIAN,
       
    98 	NETLANG_NORWEGIAN,
       
    99 	NETLANG_POLISH,
       
   100 	NETLANG_PORTUGUESE,
       
   101 	NETLANG_ROMANIAN,
       
   102 	NETLANG_RUSSIAN,
       
   103 	NETLANG_SLOVAK,
       
   104 	NETLANG_SLOVENIAN,
       
   105 	NETLANG_SPANISH,
       
   106 	NETLANG_SWEDISH,
       
   107 	NETLANG_TURKISH,
       
   108 	NETLANG_UKRAINIAN,
       
   109 	NETLANG_COUNT
       
   110 };
       
   111 
       
   112 VARDEF NetworkGameInfo _network_game_info;
       
   113 VARDEF NetworkPlayerInfo _network_player_info[MAX_PLAYERS];
       
   114 VARDEF NetworkClientInfo _network_client_info[MAX_CLIENT_INFO];
       
   115 
       
   116 VARDEF char _network_player_name[NETWORK_CLIENT_NAME_LENGTH];
       
   117 VARDEF char _network_default_ip[NETWORK_HOSTNAME_LENGTH];
       
   118 
       
   119 VARDEF uint16 _network_own_client_index;
       
   120 VARDEF char _network_unique_id[NETWORK_UNIQUE_ID_LENGTH]; // Our own unique ID
       
   121 
       
   122 VARDEF uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode
       
   123 VARDEF uint32 _frame_counter_max; // To where we may go with our clients
       
   124 
       
   125 VARDEF uint32 _last_sync_frame; // Used in the server to store the last time a sync packet was sent to clients.
       
   126 
       
   127 // networking settings
       
   128 VARDEF uint32 _broadcast_list[MAX_INTERFACES + 1];
       
   129 
       
   130 VARDEF uint16 _network_server_port;
       
   131 /* We use bind_ip and bind_ip_host, where bind_ip_host is the readable form of
       
   132     bind_ip_host, and bind_ip the numeric value, because we want a nice number
       
   133     in the openttd.cfg, but we wants to use the uint32 internally.. */
       
   134 VARDEF uint32 _network_server_bind_ip;
       
   135 VARDEF char _network_server_bind_ip_host[NETWORK_HOSTNAME_LENGTH];
       
   136 VARDEF bool _is_network_server; // Does this client wants to be a network-server?
       
   137 VARDEF char _network_server_name[NETWORK_NAME_LENGTH];
       
   138 VARDEF char _network_server_password[NETWORK_PASSWORD_LENGTH];
       
   139 VARDEF char _network_rcon_password[NETWORK_PASSWORD_LENGTH];
       
   140 VARDEF char _network_default_company_pass[NETWORK_PASSWORD_LENGTH];
       
   141 
       
   142 VARDEF uint16 _network_max_join_time;             ///< Time a client can max take to join
       
   143 VARDEF bool _network_pause_on_join;               ///< Pause the game when a client tries to join (more chance of succeeding join)
       
   144 
       
   145 VARDEF uint16 _redirect_console_to_client;
       
   146 
       
   147 VARDEF uint16 _network_sync_freq;
       
   148 VARDEF uint8 _network_frame_freq;
       
   149 
       
   150 VARDEF uint32 _sync_seed_1, _sync_seed_2;
       
   151 VARDEF uint32 _sync_frame;
       
   152 VARDEF bool _network_first_time;
       
   153 // Vars needed for the join-GUI
       
   154 VARDEF NetworkJoinStatus _network_join_status;
       
   155 VARDEF uint8 _network_join_waiting;
       
   156 VARDEF uint16 _network_join_kbytes;
       
   157 VARDEF uint16 _network_join_kbytes_total;
       
   158 
       
   159 VARDEF char _network_last_host[NETWORK_HOSTNAME_LENGTH];
       
   160 VARDEF short _network_last_port;
       
   161 VARDEF uint32 _network_last_host_ip;
       
   162 VARDEF uint8 _network_reconnect;
       
   163 
       
   164 VARDEF bool _network_udp_server;
       
   165 VARDEF uint16 _network_udp_broadcast;
       
   166 
       
   167 VARDEF byte _network_lan_internet;
       
   168 
       
   169 VARDEF bool _network_need_advertise;
       
   170 VARDEF uint32 _network_last_advertise_frame;
       
   171 VARDEF uint8 _network_advertise_retries;
       
   172 
       
   173 VARDEF bool _network_autoclean_companies;
       
   174 VARDEF uint8 _network_autoclean_unprotected; // Remove a company after X months
       
   175 VARDEF uint8 _network_autoclean_protected;   // Unprotect a company after X months
       
   176 
       
   177 VARDEF Year _network_restart_game_year;      // If this year is reached, the server automaticly restarts
       
   178 VARDEF uint8 _network_min_players;           // Minimum number of players for game to unpause
       
   179 
       
   180 void NetworkTCPQueryServer(const char* host, unsigned short port);
       
   181 
       
   182 byte NetworkSpectatorCount();
       
   183 
       
   184 VARDEF char *_network_host_list[10];
       
   185 VARDEF char *_network_ban_list[25];
       
   186 
       
   187 void ParseConnectionString(const char **player, const char **port, char *connection_string);
       
   188 void NetworkUpdateClientInfo(uint16 client_index);
       
   189 void NetworkAddServer(const char *b);
       
   190 void NetworkRebuildHostList();
       
   191 bool NetworkChangeCompanyPassword(byte argc, char *argv[]);
       
   192 void NetworkPopulateCompanyInfo();
       
   193 void UpdateNetworkGameWindow(bool unselect);
       
   194 void CheckMinPlayers();
       
   195 void NetworkStartDebugLog(const char *hostname, uint16 port);
       
   196 
       
   197 void NetworkUDPCloseAll();
       
   198 void NetworkGameLoop();
       
   199 void NetworkUDPGameLoop();
       
   200 bool NetworkServerStart();
       
   201 bool NetworkClientConnectGame(const char *host, uint16 port);
       
   202 void NetworkReboot();
       
   203 void NetworkDisconnect();
       
   204 
       
   205 bool IsNetworkCompatibleVersion(const char *version);
       
   206 
       
   207 #endif /* ENABLE_NETWORK */
       
   208 #endif /* NETWORK_INTERNAL_H */