author | celestar |
Mon, 15 Jan 2007 20:14:06 +0000 | |
branch | custombridgeheads |
changeset 5650 | aefc131bf5ce |
parent 5648 | 1608018c5ff2 |
permissions | -rw-r--r-- |
5642 | 1 |
/* $Id$ */ |
2 |
||
3 |
#ifndef NETWORK_H |
|
4 |
#define NETWORK_H |
|
5 |
||
6 |
#define NOREV_STRING "norev000" |
|
7 |
||
8 |
#ifdef ENABLE_NETWORK |
|
9 |
||
10 |
#include "../player.h" |
|
11 |
#include "core/config.h" |
|
12 |
#include "core/game.h" |
|
13 |
||
14 |
// If this line is enable, every frame will have a sync test |
|
15 |
// this is not needed in normal games. Normal is like 1 sync in 100 |
|
16 |
// frames. You can enable this if you have a lot of desyncs on a certain |
|
17 |
// game. |
|
18 |
// Remember: both client and server have to be compiled with this |
|
19 |
// option enabled to make it to work. If one of the two has it disabled |
|
20 |
// nothing will happen. |
|
21 |
//#define ENABLE_NETWORK_SYNC_EVERY_FRAME |
|
22 |
||
23 |
// In theory sending 1 of the 2 seeds is enough to check for desyncs |
|
24 |
// so in theory, this next define can be left off. |
|
25 |
//#define NETWORK_SEND_DOUBLE_SEED |
|
26 |
||
27 |
// How many clients can we have? Like.. MAX_PLAYERS - 1 is the amount of |
|
28 |
// players that can really play.. so.. a max of 4 spectators.. gives us.. |
|
29 |
// MAX_PLAYERS + 3 |
|
30 |
#define MAX_CLIENTS (MAX_PLAYERS + 3) |
|
31 |
||
32 |
||
33 |
// Do not change this next line. It should _ALWAYS_ be MAX_CLIENTS + 1 |
|
34 |
#define MAX_CLIENT_INFO (MAX_CLIENTS + 1) |
|
35 |
||
36 |
#define MAX_INTERFACES 9 |
|
37 |
||
38 |
||
39 |
// How many vehicle/station types we put over the network |
|
40 |
#define NETWORK_VEHICLE_TYPES 5 |
|
41 |
#define NETWORK_STATION_TYPES 5 |
|
42 |
||
43 |
typedef struct NetworkPlayerInfo { |
|
44 |
char company_name[NETWORK_NAME_LENGTH]; // Company name |
|
45 |
char password[NETWORK_PASSWORD_LENGTH]; // The password for the player |
|
46 |
Year inaugurated_year; // What year the company started in |
|
47 |
int64 company_value; // The company value |
|
48 |
int64 money; // The amount of money the company has |
|
49 |
int64 income; // How much did the company earned last year |
|
50 |
uint16 performance; // What was his performance last month? |
|
51 |
byte use_password; // 0: No password 1: There is a password |
|
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? |
|
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 |
|
56 |
} NetworkPlayerInfo; |
|
57 |
||
58 |
typedef struct NetworkClientInfo { |
|
59 |
uint16 client_index; // Index of the client (same as ClientState->index) |
|
60 |
char client_name[NETWORK_CLIENT_NAME_LENGTH]; // Name of the client |
|
61 |
byte client_lang; // The language of the client |
|
5650
aefc131bf5ce
(svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
celestar
parents:
5648
diff
changeset
|
62 |
PlayerID client_playas; // As which player is this client playing (PlayerID) |
5642 | 63 |
uint32 client_ip; // IP-address of the client (so he can be banned) |
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 |
|
66 |
} NetworkClientInfo; |
|
67 |
||
68 |
typedef struct NetworkGameList { |
|
69 |
NetworkGameInfo info; |
|
70 |
uint32 ip; |
|
71 |
uint16 port; |
|
72 |
bool online; // False if the server did not respond (default status) |
|
73 |
bool manually; // True if the server was added manually |
|
74 |
struct NetworkGameList *next; |
|
75 |
} NetworkGameList; |
|
76 |
||
77 |
typedef enum { |
|
78 |
NETWORK_JOIN_STATUS_CONNECTING, |
|
79 |
NETWORK_JOIN_STATUS_AUTHORIZING, |
|
80 |
NETWORK_JOIN_STATUS_WAITING, |
|
81 |
NETWORK_JOIN_STATUS_DOWNLOADING, |
|
82 |
NETWORK_JOIN_STATUS_PROCESSING, |
|
83 |
NETWORK_JOIN_STATUS_REGISTERING, |
|
84 |
||
85 |
NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO, |
|
86 |
} NetworkJoinStatus; |
|
87 |
||
88 |
// language ids for server_lang and client_lang |
|
89 |
typedef enum { |
|
90 |
NETLANG_ANY = 0, |
|
91 |
NETLANG_ENGLISH = 1, |
|
92 |
NETLANG_GERMAN = 2, |
|
93 |
NETLANG_FRENCH = 3, |
|
94 |
} NetworkLanguage; |
|
95 |
||
96 |
VARDEF NetworkGameList *_network_game_list; |
|
97 |
||
98 |
VARDEF NetworkGameInfo _network_game_info; |
|
99 |
VARDEF NetworkPlayerInfo _network_player_info[MAX_PLAYERS]; |
|
100 |
VARDEF NetworkClientInfo _network_client_info[MAX_CLIENT_INFO]; |
|
101 |
||
102 |
VARDEF char _network_player_name[NETWORK_CLIENT_NAME_LENGTH]; |
|
103 |
VARDEF char _network_default_ip[NETWORK_HOSTNAME_LENGTH]; |
|
104 |
||
105 |
VARDEF uint16 _network_own_client_index; |
|
106 |
VARDEF char _network_unique_id[NETWORK_NAME_LENGTH]; // Our own unique ID |
|
107 |
||
108 |
VARDEF uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode |
|
109 |
VARDEF uint32 _frame_counter_max; // To where we may go with our clients |
|
110 |
||
111 |
VARDEF uint32 _last_sync_frame; // Used in the server to store the last time a sync packet was sent to clients. |
|
112 |
||
113 |
// networking settings |
|
114 |
VARDEF uint32 _broadcast_list[MAX_INTERFACES + 1]; |
|
115 |
||
116 |
VARDEF uint16 _network_server_port; |
|
117 |
/* We use bind_ip and bind_ip_host, where bind_ip_host is the readable form of |
|
118 |
bind_ip_host, and bind_ip the numeric value, because we want a nice number |
|
119 |
in the openttd.cfg, but we wants to use the uint32 internally.. */ |
|
120 |
VARDEF uint32 _network_server_bind_ip; |
|
121 |
VARDEF char _network_server_bind_ip_host[NETWORK_HOSTNAME_LENGTH]; |
|
122 |
VARDEF bool _is_network_server; // Does this client wants to be a network-server? |
|
123 |
VARDEF char _network_server_name[NETWORK_NAME_LENGTH]; |
|
124 |
VARDEF char _network_server_password[NETWORK_PASSWORD_LENGTH]; |
|
125 |
VARDEF char _network_rcon_password[NETWORK_PASSWORD_LENGTH]; |
|
126 |
||
127 |
VARDEF uint16 _network_max_join_time; ///< Time a client can max take to join |
|
128 |
VARDEF bool _network_pause_on_join; ///< Pause the game when a client tries to join (more chance of succeeding join) |
|
129 |
||
130 |
VARDEF uint16 _redirect_console_to_client; |
|
131 |
||
132 |
VARDEF uint16 _network_sync_freq; |
|
133 |
VARDEF uint8 _network_frame_freq; |
|
134 |
||
135 |
VARDEF uint32 _sync_seed_1, _sync_seed_2; |
|
136 |
VARDEF uint32 _sync_frame; |
|
137 |
VARDEF bool _network_first_time; |
|
138 |
// Vars needed for the join-GUI |
|
139 |
VARDEF NetworkJoinStatus _network_join_status; |
|
140 |
VARDEF uint8 _network_join_waiting; |
|
141 |
VARDEF uint16 _network_join_kbytes; |
|
142 |
VARDEF uint16 _network_join_kbytes_total; |
|
143 |
||
144 |
VARDEF char _network_last_host[NETWORK_HOSTNAME_LENGTH]; |
|
145 |
VARDEF short _network_last_port; |
|
146 |
VARDEF uint32 _network_last_host_ip; |
|
147 |
VARDEF uint8 _network_reconnect; |
|
148 |
||
149 |
VARDEF bool _network_udp_server; |
|
150 |
VARDEF uint16 _network_udp_broadcast; |
|
151 |
||
152 |
VARDEF byte _network_lan_internet; |
|
153 |
||
154 |
VARDEF bool _network_need_advertise; |
|
155 |
VARDEF uint32 _network_last_advertise_frame; |
|
156 |
VARDEF uint8 _network_advertise_retries; |
|
157 |
||
158 |
VARDEF bool _network_autoclean_companies; |
|
159 |
VARDEF uint8 _network_autoclean_unprotected; // Remove a company after X months |
|
160 |
VARDEF uint8 _network_autoclean_protected; // Unprotect a company after X months |
|
161 |
||
162 |
VARDEF Year _network_restart_game_year; // If this year is reached, the server automaticly restarts |
|
163 |
VARDEF uint8 _network_min_players; // Minimum number of players for game to unpause |
|
164 |
||
165 |
NetworkGameList *NetworkQueryServer(const char* host, unsigned short port, bool game_info); |
|
166 |
||
167 |
byte NetworkSpectatorCount(void); |
|
168 |
||
169 |
VARDEF char *_network_host_list[10]; |
|
170 |
VARDEF char *_network_ban_list[25]; |
|
171 |
||
172 |
void ParseConnectionString(const char **player, const char **port, char *connection_string); |
|
173 |
void NetworkUpdateClientInfo(uint16 client_index); |
|
174 |
void NetworkAddServer(const char *b); |
|
175 |
void NetworkRebuildHostList(void); |
|
176 |
bool NetworkChangeCompanyPassword(byte argc, char *argv[]); |
|
177 |
void NetworkPopulateCompanyInfo(void); |
|
178 |
void UpdateNetworkGameWindow(bool unselect); |
|
179 |
void CheckMinPlayers(void); |
|
180 |
||
181 |
void NetworkStartUp(void); |
|
5648
1608018c5ff2
(svn r8059) [cbh] - Sync with r7788:8032 from trunk
celestar
parents:
5643
diff
changeset
|
182 |
void NetworkUDPStop(void); |
5642 | 183 |
void NetworkShutDown(void); |
184 |
void NetworkGameLoop(void); |
|
185 |
void NetworkUDPGameLoop(void); |
|
186 |
bool NetworkServerStart(void); |
|
187 |
bool NetworkClientConnectGame(const char *host, uint16 port); |
|
188 |
void NetworkReboot(void); |
|
189 |
void NetworkDisconnect(void); |
|
190 |
||
191 |
VARDEF bool _network_server; ///< network-server is active |
|
192 |
VARDEF bool _network_available; ///< is network mode available? |
|
193 |
||
194 |
#else /* ENABLE_NETWORK */ |
|
195 |
/* Network function stubs when networking is disabled */ |
|
196 |
||
197 |
static inline void NetworkStartUp(void) {} |
|
198 |
static inline void NetworkShutDown(void) {} |
|
199 |
||
200 |
#define _networking 0 |
|
201 |
#define _network_server 0 |
|
202 |
#define _network_available 0 |
|
203 |
||
204 |
#endif /* ENABLE_NETWORK */ |
|
205 |
||
206 |
/* These variables must always be registered! */ |
|
207 |
VARDEF bool _network_dedicated; ///< are we a dedicated server? |
|
208 |
VARDEF bool _network_advertise; ///< is the server advertising to the master server? |
|
209 |
VARDEF PlayerID _network_playas; ///< an id to play as.. (see players.h:Players) |
|
210 |
||
211 |
#endif /* NETWORK_H */ |