network_internal.h

00001 /* $Id: network_internal.h 11840 2008-01-13 21:51:53Z rubidium $ */
00002 
00003 #ifndef NETWORK_INTERNAL_H
00004 #define NETWORK_INTERNAL_H
00005 
00006 #ifdef ENABLE_NETWORK
00007 
00008 #include "../player_type.h"
00009 #include "../economy_type.h"
00010 #include "core/config.h"
00011 #include "core/game.h"
00012 
00013 // If this line is enable, every frame will have a sync test
00014 //  this is not needed in normal games. Normal is like 1 sync in 100
00015 //  frames. You can enable this if you have a lot of desyncs on a certain
00016 //  game.
00017 // Remember: both client and server have to be compiled with this
00018 //  option enabled to make it to work. If one of the two has it disabled
00019 //  nothing will happen.
00020 //#define ENABLE_NETWORK_SYNC_EVERY_FRAME
00021 
00022 // In theory sending 1 of the 2 seeds is enough to check for desyncs
00023 //   so in theory, this next define can be left off.
00024 //#define NETWORK_SEND_DOUBLE_SEED
00025 
00026 // How many clients can we have? Like.. MAX_PLAYERS - 1 is the amount of
00027 //  players that can really play.. so.. a max of 4 spectators.. gives us..
00028 //  MAX_PLAYERS + 3
00029 #define MAX_CLIENTS (MAX_PLAYERS + 3)
00030 
00031 
00032 // Do not change this next line. It should _ALWAYS_ be MAX_CLIENTS + 1
00033 #define MAX_CLIENT_INFO (MAX_CLIENTS + 1)
00034 
00035 #define MAX_INTERFACES 9
00036 
00037 
00038 // How many vehicle/station types we put over the network
00039 #define NETWORK_VEHICLE_TYPES 5
00040 #define NETWORK_STATION_TYPES 5
00041 
00042 struct NetworkPlayerInfo {
00043   char company_name[NETWORK_NAME_LENGTH];         // Company name
00044   char password[NETWORK_PASSWORD_LENGTH];         // The password for the player
00045   Year inaugurated_year;                          // What year the company started in
00046   Money company_value;                            // The company value
00047   Money money;                                    // The amount of money the company has
00048   Money income;                                   // How much did the company earned last year
00049   uint16 performance;                             // What was his performance last month?
00050   bool use_password;                              // Is there a password
00051   uint16 num_vehicle[NETWORK_VEHICLE_TYPES];      // How many vehicles are there of this type?
00052   uint16 num_station[NETWORK_STATION_TYPES];      // How many stations are there of this type?
00053   char players[NETWORK_PLAYERS_LENGTH];           // The players that control this company (Name1, name2, ..)
00054   uint16 months_empty;                            // How many months the company is empty
00055 };
00056 
00057 struct NetworkClientInfo {
00058   uint16 client_index;                            // Index of the client (same as ClientState->index)
00059   char client_name[NETWORK_CLIENT_NAME_LENGTH];   // Name of the client
00060   byte client_lang;                               // The language of the client
00061   PlayerID client_playas;                         // As which player is this client playing (PlayerID)
00062   uint32 client_ip;                               // IP-address of the client (so he can be banned)
00063   Date join_date;                                 // Gamedate the player has joined
00064   char unique_id[NETWORK_UNIQUE_ID_LENGTH];       // Every play sends an unique id so we can indentify him
00065 };
00066 
00067 enum NetworkJoinStatus {
00068   NETWORK_JOIN_STATUS_CONNECTING,
00069   NETWORK_JOIN_STATUS_AUTHORIZING,
00070   NETWORK_JOIN_STATUS_WAITING,
00071   NETWORK_JOIN_STATUS_DOWNLOADING,
00072   NETWORK_JOIN_STATUS_PROCESSING,
00073   NETWORK_JOIN_STATUS_REGISTERING,
00074 
00075   NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO,
00076 };
00077 
00078 /* Language ids for server_lang and client_lang. Do NOT modify the order. */
00079 enum NetworkLanguage {
00080   NETLANG_ANY = 0,
00081   NETLANG_ENGLISH,
00082   NETLANG_GERMAN,
00083   NETLANG_FRENCH,
00084   NETLANG_BRAZILIAN,
00085   NETLANG_BULGARIAN,
00086   NETLANG_CHINESE,
00087   NETLANG_CZECH,
00088   NETLANG_DANISH,
00089   NETLANG_DUTCH,
00090   NETLANG_ESPERANTO,
00091   NETLANG_FINNISH,
00092   NETLANG_HUNGARIAN,
00093   NETLANG_ICELANDIC,
00094   NETLANG_ITALIAN,
00095   NETLANG_JAPANESE,
00096   NETLANG_KOREAN,
00097   NETLANG_LITHUANIAN,
00098   NETLANG_NORWEGIAN,
00099   NETLANG_POLISH,
00100   NETLANG_PORTUGUESE,
00101   NETLANG_ROMANIAN,
00102   NETLANG_RUSSIAN,
00103   NETLANG_SLOVAK,
00104   NETLANG_SLOVENIAN,
00105   NETLANG_SPANISH,
00106   NETLANG_SWEDISH,
00107   NETLANG_TURKISH,
00108   NETLANG_UKRAINIAN,
00109   NETLANG_COUNT
00110 };
00111 
00112 VARDEF NetworkGameInfo _network_game_info;
00113 VARDEF NetworkPlayerInfo _network_player_info[MAX_PLAYERS];
00114 VARDEF NetworkClientInfo _network_client_info[MAX_CLIENT_INFO];
00115 
00116 VARDEF char _network_player_name[NETWORK_CLIENT_NAME_LENGTH];
00117 VARDEF char _network_default_ip[NETWORK_HOSTNAME_LENGTH];
00118 
00119 VARDEF uint16 _network_own_client_index;
00120 VARDEF char _network_unique_id[NETWORK_UNIQUE_ID_LENGTH]; // Our own unique ID
00121 
00122 VARDEF uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode
00123 VARDEF uint32 _frame_counter_max; // To where we may go with our clients
00124 
00125 VARDEF uint32 _last_sync_frame; // Used in the server to store the last time a sync packet was sent to clients.
00126 
00127 // networking settings
00128 VARDEF uint32 _broadcast_list[MAX_INTERFACES + 1];
00129 
00130 VARDEF uint16 _network_server_port;
00131 /* We use bind_ip and bind_ip_host, where bind_ip_host is the readable form of
00132     bind_ip_host, and bind_ip the numeric value, because we want a nice number
00133     in the openttd.cfg, but we wants to use the uint32 internally.. */
00134 VARDEF uint32 _network_server_bind_ip;
00135 VARDEF char _network_server_bind_ip_host[NETWORK_HOSTNAME_LENGTH];
00136 VARDEF bool _is_network_server; // Does this client wants to be a network-server?
00137 VARDEF char _network_server_name[NETWORK_NAME_LENGTH];
00138 VARDEF char _network_server_password[NETWORK_PASSWORD_LENGTH];
00139 VARDEF char _network_rcon_password[NETWORK_PASSWORD_LENGTH];
00140 VARDEF char _network_default_company_pass[NETWORK_PASSWORD_LENGTH];
00141 
00142 VARDEF uint16 _network_max_join_time;             
00143 VARDEF bool _network_pause_on_join;               
00144 
00145 VARDEF uint16 _redirect_console_to_client;
00146 
00147 VARDEF uint16 _network_sync_freq;
00148 VARDEF uint8 _network_frame_freq;
00149 
00150 VARDEF uint32 _sync_seed_1, _sync_seed_2;
00151 VARDEF uint32 _sync_frame;
00152 VARDEF bool _network_first_time;
00153 // Vars needed for the join-GUI
00154 VARDEF NetworkJoinStatus _network_join_status;
00155 VARDEF uint8 _network_join_waiting;
00156 VARDEF uint16 _network_join_kbytes;
00157 VARDEF uint16 _network_join_kbytes_total;
00158 
00159 VARDEF char _network_last_host[NETWORK_HOSTNAME_LENGTH];
00160 VARDEF short _network_last_port;
00161 VARDEF uint32 _network_last_host_ip;
00162 VARDEF uint8 _network_reconnect;
00163 
00164 VARDEF bool _network_udp_server;
00165 VARDEF uint16 _network_udp_broadcast;
00166 
00167 VARDEF byte _network_lan_internet;
00168 
00169 VARDEF bool _network_need_advertise;
00170 VARDEF uint32 _network_last_advertise_frame;
00171 VARDEF uint8 _network_advertise_retries;
00172 
00173 VARDEF bool _network_autoclean_companies;
00174 VARDEF uint8 _network_autoclean_unprotected; // Remove a company after X months
00175 VARDEF uint8 _network_autoclean_protected;   // Unprotect a company after X months
00176 
00177 VARDEF Year _network_restart_game_year;      // If this year is reached, the server automaticly restarts
00178 VARDEF uint8 _network_min_players;           // Minimum number of players for game to unpause
00179 
00180 void NetworkTCPQueryServer(const char* host, unsigned short port);
00181 
00182 byte NetworkSpectatorCount();
00183 
00184 VARDEF char *_network_host_list[10];
00185 VARDEF char *_network_ban_list[25];
00186 
00187 void ParseConnectionString(const char **player, const char **port, char *connection_string);
00188 void NetworkUpdateClientInfo(uint16 client_index);
00189 void NetworkAddServer(const char *b);
00190 void NetworkRebuildHostList();
00191 bool NetworkChangeCompanyPassword(byte argc, char *argv[]);
00192 void NetworkPopulateCompanyInfo();
00193 void UpdateNetworkGameWindow(bool unselect);
00194 void CheckMinPlayers();
00195 void NetworkStartDebugLog(const char *hostname, uint16 port);
00196 
00197 void NetworkUDPCloseAll();
00198 void NetworkGameLoop();
00199 void NetworkUDPGameLoop();
00200 bool NetworkServerStart();
00201 bool NetworkClientConnectGame(const char *host, uint16 port);
00202 void NetworkReboot();
00203 void NetworkDisconnect();
00204 
00205 bool IsNetworkCompatibleVersion(const char *version);
00206 
00207 #endif /* ENABLE_NETWORK */
00208 #endif /* NETWORK_INTERNAL_H */

Generated on Wed Oct 1 17:03:21 2008 for openttd by  doxygen 1.5.6