src/network/network.h
branchgamebalance
changeset 9895 7bd07f43b0e3
parent 6504 5578f2fa1a73
child 9912 1ac8aac92385
equal deleted inserted replaced
9894:70d78ac95d6c 9895:7bd07f43b0e3
    38 
    38 
    39 // How many vehicle/station types we put over the network
    39 // How many vehicle/station types we put over the network
    40 #define NETWORK_VEHICLE_TYPES 5
    40 #define NETWORK_VEHICLE_TYPES 5
    41 #define NETWORK_STATION_TYPES 5
    41 #define NETWORK_STATION_TYPES 5
    42 
    42 
    43 typedef struct NetworkPlayerInfo {
    43 struct NetworkPlayerInfo {
    44 	char company_name[NETWORK_NAME_LENGTH];         // Company name
    44 	char company_name[NETWORK_NAME_LENGTH];         // Company name
    45 	char password[NETWORK_PASSWORD_LENGTH];         // The password for the player
    45 	char password[NETWORK_PASSWORD_LENGTH];         // The password for the player
    46 	Year inaugurated_year;                          // What year the company started in
    46 	Year inaugurated_year;                          // What year the company started in
    47 	int64 company_value;                            // The company value
    47 	int64 company_value;                            // The company value
    48 	int64 money;                                    // The amount of money the company has
    48 	int64 money;                                    // The amount of money the company has
    51 	bool use_password;                              // Is there a password
    51 	bool use_password;                              // Is there a password
    52 	uint16 num_vehicle[NETWORK_VEHICLE_TYPES];      // How many vehicles are there of this type?
    52 	uint16 num_vehicle[NETWORK_VEHICLE_TYPES];      // How many vehicles are there of this type?
    53 	uint16 num_station[NETWORK_STATION_TYPES];      // How many stations are there of this type?
    53 	uint16 num_station[NETWORK_STATION_TYPES];      // How many stations are there of this type?
    54 	char players[NETWORK_PLAYERS_LENGTH];           // The players that control this company (Name1, name2, ..)
    54 	char players[NETWORK_PLAYERS_LENGTH];           // The players that control this company (Name1, name2, ..)
    55 	uint16 months_empty;                            // How many months the company is empty
    55 	uint16 months_empty;                            // How many months the company is empty
    56 } NetworkPlayerInfo;
    56 };
    57 
    57 
    58 typedef struct NetworkClientInfo {
    58 struct NetworkClientInfo {
    59 	uint16 client_index;                            // Index of the client (same as ClientState->index)
    59 	uint16 client_index;                            // Index of the client (same as ClientState->index)
    60 	char client_name[NETWORK_CLIENT_NAME_LENGTH];   // Name of the client
    60 	char client_name[NETWORK_CLIENT_NAME_LENGTH];   // Name of the client
    61 	byte client_lang;                               // The language of the client
    61 	byte client_lang;                               // The language of the client
    62 	PlayerID client_playas;                         // As which player is this client playing (PlayerID)
    62 	PlayerID client_playas;                         // As which player is this client playing (PlayerID)
    63 	uint32 client_ip;                               // IP-address of the client (so he can be banned)
    63 	uint32 client_ip;                               // IP-address of the client (so he can be banned)
    64 	Date join_date;                                 // Gamedate the player has joined
    64 	Date join_date;                                 // Gamedate the player has joined
    65 	char unique_id[NETWORK_NAME_LENGTH];            // Every play sends an unique id so we can indentify him
    65 	char unique_id[NETWORK_NAME_LENGTH];            // Every play sends an unique id so we can indentify him
    66 } NetworkClientInfo;
    66 };
    67 
    67 
    68 typedef enum {
    68 enum NetworkJoinStatus {
    69 	NETWORK_JOIN_STATUS_CONNECTING,
    69 	NETWORK_JOIN_STATUS_CONNECTING,
    70 	NETWORK_JOIN_STATUS_AUTHORIZING,
    70 	NETWORK_JOIN_STATUS_AUTHORIZING,
    71 	NETWORK_JOIN_STATUS_WAITING,
    71 	NETWORK_JOIN_STATUS_WAITING,
    72 	NETWORK_JOIN_STATUS_DOWNLOADING,
    72 	NETWORK_JOIN_STATUS_DOWNLOADING,
    73 	NETWORK_JOIN_STATUS_PROCESSING,
    73 	NETWORK_JOIN_STATUS_PROCESSING,
    74 	NETWORK_JOIN_STATUS_REGISTERING,
    74 	NETWORK_JOIN_STATUS_REGISTERING,
    75 
    75 
    76 	NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO,
    76 	NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO,
    77 } NetworkJoinStatus;
    77 };
    78 
    78 
    79 // language ids for server_lang and client_lang
    79 // language ids for server_lang and client_lang
    80 typedef enum {
    80 enum NetworkLanguage {
    81 	NETLANG_ANY     = 0,
    81 	NETLANG_ANY     = 0,
    82 	NETLANG_ENGLISH = 1,
    82 	NETLANG_ENGLISH = 1,
    83 	NETLANG_GERMAN  = 2,
    83 	NETLANG_GERMAN  = 2,
    84 	NETLANG_FRENCH  = 3,
    84 	NETLANG_FRENCH  = 3,
    85 } NetworkLanguage;
    85 };
    86 
    86 
    87 VARDEF NetworkGameInfo _network_game_info;
    87 VARDEF NetworkGameInfo _network_game_info;
    88 VARDEF NetworkPlayerInfo _network_player_info[MAX_PLAYERS];
    88 VARDEF NetworkPlayerInfo _network_player_info[MAX_PLAYERS];
    89 VARDEF NetworkClientInfo _network_client_info[MAX_CLIENT_INFO];
    89 VARDEF NetworkClientInfo _network_client_info[MAX_CLIENT_INFO];
    90 
    90 
   151 VARDEF Year _network_restart_game_year;      // If this year is reached, the server automaticly restarts
   151 VARDEF Year _network_restart_game_year;      // If this year is reached, the server automaticly restarts
   152 VARDEF uint8 _network_min_players;           // Minimum number of players for game to unpause
   152 VARDEF uint8 _network_min_players;           // Minimum number of players for game to unpause
   153 
   153 
   154 void NetworkTCPQueryServer(const char* host, unsigned short port);
   154 void NetworkTCPQueryServer(const char* host, unsigned short port);
   155 
   155 
   156 byte NetworkSpectatorCount(void);
   156 byte NetworkSpectatorCount();
   157 
   157 
   158 VARDEF char *_network_host_list[10];
   158 VARDEF char *_network_host_list[10];
   159 VARDEF char *_network_ban_list[25];
   159 VARDEF char *_network_ban_list[25];
   160 
   160 
   161 void ParseConnectionString(const char **player, const char **port, char *connection_string);
   161 void ParseConnectionString(const char **player, const char **port, char *connection_string);
   162 void NetworkUpdateClientInfo(uint16 client_index);
   162 void NetworkUpdateClientInfo(uint16 client_index);
   163 void NetworkAddServer(const char *b);
   163 void NetworkAddServer(const char *b);
   164 void NetworkRebuildHostList(void);
   164 void NetworkRebuildHostList();
   165 bool NetworkChangeCompanyPassword(byte argc, char *argv[]);
   165 bool NetworkChangeCompanyPassword(byte argc, char *argv[]);
   166 void NetworkPopulateCompanyInfo(void);
   166 void NetworkPopulateCompanyInfo();
   167 void UpdateNetworkGameWindow(bool unselect);
   167 void UpdateNetworkGameWindow(bool unselect);
   168 void CheckMinPlayers(void);
   168 void CheckMinPlayers();
   169 void NetworkStartDebugLog(const char *hostname, uint16 port);
   169 void NetworkStartDebugLog(const char *hostname, uint16 port);
   170 
   170 
   171 void NetworkStartUp(void);
   171 void NetworkStartUp();
   172 void NetworkUDPCloseAll();
   172 void NetworkUDPCloseAll();
   173 void NetworkShutDown(void);
   173 void NetworkShutDown();
   174 void NetworkGameLoop(void);
   174 void NetworkGameLoop();
   175 void NetworkUDPGameLoop(void);
   175 void NetworkUDPGameLoop();
   176 bool NetworkServerStart(void);
   176 bool NetworkServerStart();
   177 bool NetworkClientConnectGame(const char *host, uint16 port);
   177 bool NetworkClientConnectGame(const char *host, uint16 port);
   178 void NetworkReboot(void);
   178 void NetworkReboot();
   179 void NetworkDisconnect(void);
   179 void NetworkDisconnect();
   180 
   180 
   181 bool IsNetworkCompatibleVersion(const char *version);
   181 bool IsNetworkCompatibleVersion(const char *version);
   182 
   182 
   183 VARDEF bool _network_server;     ///< network-server is active
   183 VARDEF bool _network_server;     ///< network-server is active
   184 VARDEF bool _network_available;  ///< is network mode available?
   184 VARDEF bool _network_available;  ///< is network mode available?
   186 VARDEF bool _network_advertise;  ///< is the server advertising to the master server?
   186 VARDEF bool _network_advertise;  ///< is the server advertising to the master server?
   187 
   187 
   188 #else /* ENABLE_NETWORK */
   188 #else /* ENABLE_NETWORK */
   189 /* Network function stubs when networking is disabled */
   189 /* Network function stubs when networking is disabled */
   190 
   190 
   191 static inline void NetworkStartUp(void) {}
   191 static inline void NetworkStartUp() {}
   192 static inline void NetworkShutDown(void) {}
   192 static inline void NetworkShutDown() {}
   193 
   193 
   194 #define _networking 0
   194 #define _networking 0
   195 #define _network_server 0
   195 #define _network_server 0
   196 #define _network_available 0
   196 #define _network_available 0
   197 #define _network_dedicated 0
   197 #define _network_dedicated 0