~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/network/network_internal.h

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: network_internal.h 11840 2008-01-13 21:51:53Z rubidium $ */
 
1
/* $Id: network_internal.h 15718 2009-03-15 00:32:18Z rubidium $ */
 
2
 
 
3
/** @file network_internal.h Variables and function used internally. */
2
4
 
3
5
#ifndef NETWORK_INTERNAL_H
4
6
#define NETWORK_INTERNAL_H
5
7
 
6
8
#ifdef ENABLE_NETWORK
7
9
 
8
 
#include "../player_type.h"
9
 
#include "../economy_type.h"
 
10
#include "network.h"
 
11
#include "network_func.h"
 
12
#include "network_base.h"
 
13
#include "core/os_abstraction.h"
 
14
#include "core/core.h"
10
15
#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.
 
16
#include "core/packet.h"
 
17
#include "core/tcp_game.h"
 
18
 
 
19
#include "../command_type.h"
 
20
 
 
21
/**
 
22
 * If this line is enable, every frame will have a sync test
 
23
 *  this is not needed in normal games. Normal is like 1 sync in 100
 
24
 *  frames. You can enable this if you have a lot of desyncs on a certain
 
25
 *  game.
 
26
 * Remember: both client and server have to be compiled with this
 
27
 *  option enabled to make it to work. If one of the two has it disabled
 
28
 *  nothing will happen.
 
29
 */
20
30
//#define ENABLE_NETWORK_SYNC_EVERY_FRAME
21
31
 
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.
 
32
/**
 
33
 * In theory sending 1 of the 2 seeds is enough to check for desyncs
 
34
 *   so in theory, this next define can be left off.
 
35
 */
24
36
//#define NETWORK_SEND_DOUBLE_SEED
25
37
 
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
 
};
 
38
enum MapPacket {
 
39
        MAP_PACKET_START,
 
40
        MAP_PACKET_NORMAL,
 
41
        MAP_PACKET_END,
 
42
};
 
43
 
66
44
 
67
45
enum NetworkJoinStatus {
68
46
        NETWORK_JOIN_STATUS_CONNECTING,
75
53
        NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO,
76
54
};
77
55
 
78
 
/* Language ids for server_lang and client_lang. Do NOT modify the order. */
 
56
/** Language ids for server_lang and client_lang. Do NOT modify the order. */
79
57
enum NetworkLanguage {
80
58
        NETLANG_ANY = 0,
81
59
        NETLANG_ENGLISH,
106
84
        NETLANG_SWEDISH,
107
85
        NETLANG_TURKISH,
108
86
        NETLANG_UKRAINIAN,
 
87
        NETLANG_AFRIKAANS,
 
88
        NETLANG_CROATIAN,
 
89
        NETLANG_CATALAN,
 
90
        NETLANG_ESTONIAN,
 
91
        NETLANG_GALICIAN,
 
92
        NETLANG_GREEK,
 
93
        NETLANG_LATVIAN,
109
94
        NETLANG_COUNT
110
95
};
111
96
 
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);
 
97
extern uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode
 
98
extern uint32 _frame_counter_max; // To where we may go with our clients
 
99
extern uint32 _frame_counter;
 
100
 
 
101
extern uint32 _last_sync_frame; // Used in the server to store the last time a sync packet was sent to clients.
 
102
 
 
103
/* networking settings */
 
104
extern uint32 _broadcast_list[MAX_INTERFACES + 1];
 
105
 
 
106
extern uint32 _network_server_bind_ip;
 
107
 
 
108
extern uint32 _sync_seed_1, _sync_seed_2;
 
109
extern uint32 _sync_frame;
 
110
extern bool _network_first_time;
 
111
/* Vars needed for the join-GUI */
 
112
extern NetworkJoinStatus _network_join_status;
 
113
extern uint8 _network_join_waiting;
 
114
extern uint32 _network_join_bytes;
 
115
extern uint32 _network_join_bytes_total;
 
116
 
 
117
extern uint8 _network_reconnect;
 
118
 
 
119
extern bool _network_udp_server;
 
120
extern uint16 _network_udp_broadcast;
 
121
 
 
122
extern uint8 _network_advertise_retries;
 
123
 
 
124
extern CompanyMask _network_company_passworded;
 
125
 
 
126
void NetworkTCPQueryServer(NetworkAddress address);
 
127
 
189
128
void NetworkAddServer(const char *b);
190
129
void NetworkRebuildHostList();
191
 
bool NetworkChangeCompanyPassword(byte argc, char *argv[]);
192
 
void NetworkPopulateCompanyInfo();
193
130
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
131
 
205
132
bool IsNetworkCompatibleVersion(const char *version);
206
133
 
 
134
/* From network_command.cpp */
 
135
/**
 
136
 * Everything we need to know about a command to be able to execute it.
 
137
 */
 
138
struct CommandPacket : CommandContainer {
 
139
        CommandPacket *next; ///< the next command packet (if in queue)
 
140
        CompanyByte company; ///< company that is executing the command
 
141
        uint32 frame;        ///< the frame in which this packet is executed
 
142
        bool my_cmd;         ///< did the command originate from "me"
 
143
};
 
144
 
 
145
void NetworkAddCommandQueue(CommandPacket cp, NetworkClientSocket *cs = NULL);
 
146
void NetworkExecuteLocalCommandQueue();
 
147
void NetworkFreeLocalCommandQueue();
 
148
 
 
149
/* from network.c */
 
150
void NetworkCloseClient(NetworkClientSocket *cs);
 
151
void NetworkTextMessage(NetworkAction action, ConsoleColour colour, bool self_send, const char *name, const char *str = "", int64 data = 0);
 
152
void NetworkGetClientName(char *clientname, size_t size, const NetworkClientSocket *cs);
 
153
uint NetworkCalculateLag(const NetworkClientSocket *cs);
 
154
byte NetworkGetCurrentLanguageIndex();
 
155
NetworkClientSocket *NetworkFindClientStateFromClientID(ClientID client_id);
 
156
StringID GetNetworkErrorMsg(NetworkErrorCode err);
 
157
bool NetworkFindName(char new_name[NETWORK_CLIENT_NAME_LENGTH]);
 
158
 
 
159
/* Macros to make life a bit more easier */
 
160
#define DEF_CLIENT_RECEIVE_COMMAND(type) NetworkRecvStatus NetworkPacketReceive_ ## type ## _command(Packet *p)
 
161
#define DEF_CLIENT_SEND_COMMAND(type) void NetworkPacketSend_ ## type ## _command()
 
162
#define DEF_CLIENT_SEND_COMMAND_PARAM(type) void NetworkPacketSend_ ## type ## _command
 
163
#define DEF_SERVER_RECEIVE_COMMAND(type) void NetworkPacketReceive_ ## type ## _command(NetworkClientSocket *cs, Packet *p)
 
164
#define DEF_SERVER_SEND_COMMAND(type) void NetworkPacketSend_ ## type ## _command(NetworkClientSocket *cs)
 
165
#define DEF_SERVER_SEND_COMMAND_PARAM(type) void NetworkPacketSend_ ## type ## _command
 
166
 
 
167
#define SEND_COMMAND(type) NetworkPacketSend_ ## type ## _command
 
168
#define RECEIVE_COMMAND(type) NetworkPacketReceive_ ## type ## _command
 
169
 
207
170
#endif /* ENABLE_NETWORK */
208
171
#endif /* NETWORK_INTERNAL_H */