src/network/network.h
author rubidium
Thu, 27 Dec 2007 13:35:39 +0000
changeset 8640 1e93b81e96d2
parent 8617 931e0970d509
child 8743 62a558995c35
permissions -rw-r--r--
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2153
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2153
diff changeset
     2
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents:
diff changeset
     3
#ifndef NETWORK_H
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents:
diff changeset
     4
#define NETWORK_H
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents:
diff changeset
     5
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
     6
#ifdef ENABLE_NETWORK
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
     7
5720
cc0ceeafaa55 (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5339
diff changeset
     8
#include "../player.h"
cc0ceeafaa55 (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5339
diff changeset
     9
#include "core/config.h"
cc0ceeafaa55 (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5339
diff changeset
    10
#include "core/game.h"
2153
91e89aa8c299 (svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents: 2079
diff changeset
    11
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    12
// If this line is enable, every frame will have a sync test
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    13
//  this is not needed in normal games. Normal is like 1 sync in 100
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    14
//  frames. You can enable this if you have a lot of desyncs on a certain
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    15
//  game.
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    16
// Remember: both client and server have to be compiled with this
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    17
//  option enabled to make it to work. If one of the two has it disabled
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    18
//  nothing will happen.
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    19
//#define ENABLE_NETWORK_SYNC_EVERY_FRAME
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    20
7683
cd00f3932777 (svn r10462) -Add: a command dumper/loader that could be enabled compile-time and server side only to aid debugging some desyncs, i.e. dump the stream of commands so it could be replayed in exactly the same way later. This should primarily be used to make desyncs more easily reproducable, so it can be properly debugged.
rubidium
parents: 7486
diff changeset
    21
/*
cd00f3932777 (svn r10462) -Add: a command dumper/loader that could be enabled compile-time and server side only to aid debugging some desyncs, i.e. dump the stream of commands so it could be replayed in exactly the same way later. This should primarily be used to make desyncs more easily reproducable, so it can be properly debugged.
rubidium
parents: 7486
diff changeset
    22
 * Dumps all commands that are sent/received to stderr and saves every month.
cd00f3932777 (svn r10462) -Add: a command dumper/loader that could be enabled compile-time and server side only to aid debugging some desyncs, i.e. dump the stream of commands so it could be replayed in exactly the same way later. This should primarily be used to make desyncs more easily reproducable, so it can be properly debugged.
rubidium
parents: 7486
diff changeset
    23
 * This log can become quite large over time; say in the order of two to three
cd00f3932777 (svn r10462) -Add: a command dumper/loader that could be enabled compile-time and server side only to aid debugging some desyncs, i.e. dump the stream of commands so it could be replayed in exactly the same way later. This should primarily be used to make desyncs more easily reproducable, so it can be properly debugged.
rubidium
parents: 7486
diff changeset
    24
 * times the bandwidth used for network games.
cd00f3932777 (svn r10462) -Add: a command dumper/loader that could be enabled compile-time and server side only to aid debugging some desyncs, i.e. dump the stream of commands so it could be replayed in exactly the same way later. This should primarily be used to make desyncs more easily reproducable, so it can be properly debugged.
rubidium
parents: 7486
diff changeset
    25
 */
cd00f3932777 (svn r10462) -Add: a command dumper/loader that could be enabled compile-time and server side only to aid debugging some desyncs, i.e. dump the stream of commands so it could be replayed in exactly the same way later. This should primarily be used to make desyncs more easily reproducable, so it can be properly debugged.
rubidium
parents: 7486
diff changeset
    26
//#define DEBUG_DUMP_COMMANDS
cd00f3932777 (svn r10462) -Add: a command dumper/loader that could be enabled compile-time and server side only to aid debugging some desyncs, i.e. dump the stream of commands so it could be replayed in exactly the same way later. This should primarily be used to make desyncs more easily reproducable, so it can be properly debugged.
rubidium
parents: 7486
diff changeset
    27
cd00f3932777 (svn r10462) -Add: a command dumper/loader that could be enabled compile-time and server side only to aid debugging some desyncs, i.e. dump the stream of commands so it could be replayed in exactly the same way later. This should primarily be used to make desyncs more easily reproducable, so it can be properly debugged.
rubidium
parents: 7486
diff changeset
    28
#ifdef DEBUG_DUMP_COMMANDS
cd00f3932777 (svn r10462) -Add: a command dumper/loader that could be enabled compile-time and server side only to aid debugging some desyncs, i.e. dump the stream of commands so it could be replayed in exactly the same way later. This should primarily be used to make desyncs more easily reproducable, so it can be properly debugged.
rubidium
parents: 7486
diff changeset
    29
void CDECL debug_dump_commands(const char *s, ...);
cd00f3932777 (svn r10462) -Add: a command dumper/loader that could be enabled compile-time and server side only to aid debugging some desyncs, i.e. dump the stream of commands so it could be replayed in exactly the same way later. This should primarily be used to make desyncs more easily reproducable, so it can be properly debugged.
rubidium
parents: 7486
diff changeset
    30
#endif /* DEBUG_DUMP_COMMANDS */
cd00f3932777 (svn r10462) -Add: a command dumper/loader that could be enabled compile-time and server side only to aid debugging some desyncs, i.e. dump the stream of commands so it could be replayed in exactly the same way later. This should primarily be used to make desyncs more easily reproducable, so it can be properly debugged.
rubidium
parents: 7486
diff changeset
    31
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    32
// In theory sending 1 of the 2 seeds is enough to check for desyncs
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    33
//   so in theory, this next define can be left off.
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    34
//#define NETWORK_SEND_DOUBLE_SEED
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    35
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    36
// How many clients can we have? Like.. MAX_PLAYERS - 1 is the amount of
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    37
//  players that can really play.. so.. a max of 4 spectators.. gives us..
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    38
//  MAX_PLAYERS + 3
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    39
#define MAX_CLIENTS (MAX_PLAYERS + 3)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    40
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    41
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    42
// Do not change this next line. It should _ALWAYS_ be MAX_CLIENTS + 1
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    43
#define MAX_CLIENT_INFO (MAX_CLIENTS + 1)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    44
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    45
#define MAX_INTERFACES 9
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    46
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    47
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    48
// How many vehicle/station types we put over the network
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    49
#define NETWORK_VEHICLE_TYPES 5
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    50
#define NETWORK_STATION_TYPES 5
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    51
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    52
struct NetworkPlayerInfo {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    53
	char company_name[NETWORK_NAME_LENGTH];         // Company name
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    54
	char password[NETWORK_PASSWORD_LENGTH];         // The password for the player
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    55
	Year inaugurated_year;                          // What year the company started in
7486
d130c10f4dab (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 7292
diff changeset
    56
	Money company_value;                            // The company value
d130c10f4dab (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 7292
diff changeset
    57
	Money money;                                    // The amount of money the company has
d130c10f4dab (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 7292
diff changeset
    58
	Money income;                                   // How much did the company earned last year
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    59
	uint16 performance;                             // What was his performance last month?
6169
31cdbb4845f1 (svn r8546) -Codechange: add a seperate (wrapper) functions to send/receive booleans.
rubidium
parents: 6168
diff changeset
    60
	bool use_password;                              // Is there a password
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    61
	uint16 num_vehicle[NETWORK_VEHICLE_TYPES];      // How many vehicles are there of this type?
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    62
	uint16 num_station[NETWORK_STATION_TYPES];      // How many stations are there of this type?
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    63
	char players[NETWORK_PLAYERS_LENGTH];           // The players that control this company (Name1, name2, ..)
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    64
	uint16 months_empty;                            // How many months the company is empty
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    65
};
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    66
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    67
struct NetworkClientInfo {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    68
	uint16 client_index;                            // Index of the client (same as ClientState->index)
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    69
	char client_name[NETWORK_CLIENT_NAME_LENGTH];   // Name of the client
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    70
	byte client_lang;                               // The language of the client
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5772
diff changeset
    71
	PlayerID client_playas;                         // As which player is this client playing (PlayerID)
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    72
	uint32 client_ip;                               // IP-address of the client (so he can be banned)
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    73
	Date join_date;                                 // Gamedate the player has joined
8303
67babdcebe96 (svn r11357) -Fix: NetworkUniqueID could be 80 chars, while the max size we generate is 32. So reduce the size a bit. Pointed out by dihedral, so give him a big hug ;)
truelight
parents: 8060
diff changeset
    74
	char unique_id[NETWORK_UNIQUE_ID_LENGTH];       // Every play sends an unique id so we can indentify him
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    75
};
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents:
diff changeset
    76
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    77
enum NetworkJoinStatus {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    78
	NETWORK_JOIN_STATUS_CONNECTING,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    79
	NETWORK_JOIN_STATUS_AUTHORIZING,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    80
	NETWORK_JOIN_STATUS_WAITING,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    81
	NETWORK_JOIN_STATUS_DOWNLOADING,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    82
	NETWORK_JOIN_STATUS_PROCESSING,
670
7c58dc46609c (svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents: 668
diff changeset
    83
	NETWORK_JOIN_STATUS_REGISTERING,
239
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 228
diff changeset
    84
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    85
	NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO,
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    86
};
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
    87
7289
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
    88
/* Language ids for server_lang and client_lang. Do NOT modify the order. */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    89
enum NetworkLanguage {
7289
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
    90
	NETLANG_ANY = 0,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
    91
	NETLANG_ENGLISH,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
    92
	NETLANG_GERMAN,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
    93
	NETLANG_FRENCH,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
    94
	NETLANG_BRAZILIAN,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
    95
	NETLANG_BULGARIAN,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
    96
	NETLANG_CHINESE,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
    97
	NETLANG_CZECH,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
    98
	NETLANG_DANISH,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
    99
	NETLANG_DUTCH,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   100
	NETLANG_ESPERANTO,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   101
	NETLANG_FINNISH,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   102
	NETLANG_HUNGARIAN,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   103
	NETLANG_ICELANDIC,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   104
	NETLANG_ITALIAN,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   105
	NETLANG_JAPANESE,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   106
	NETLANG_KOREAN,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   107
	NETLANG_LITHUANIAN,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   108
	NETLANG_NORWEGIAN,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   109
	NETLANG_POLISH,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   110
	NETLANG_PORTUGUESE,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   111
	NETLANG_ROMANIAN,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   112
	NETLANG_RUSSIAN,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   113
	NETLANG_SLOVAK,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   114
	NETLANG_SLOVENIAN,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   115
	NETLANG_SPANISH,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   116
	NETLANG_SWEDISH,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   117
	NETLANG_TURKISH,
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6574
diff changeset
   118
	NETLANG_UKRAINIAN,
7292
d4cf2baf26ae (svn r10035) -Change: simplified network language string sorting
glx
parents: 7289
diff changeset
   119
	NETLANG_COUNT
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   120
};
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   121
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   122
VARDEF NetworkGameInfo _network_game_info;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   123
VARDEF NetworkPlayerInfo _network_player_info[MAX_PLAYERS];
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   124
VARDEF NetworkClientInfo _network_client_info[MAX_CLIENT_INFO];
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   125
3623
2dd90d28fe20 (svn r4521) - Fix: be consistent about the size of the player-name in MP. This hopefully fixes a crash on lesser OS's (eg Win98). Use ttd_strlcpy() to just copy over strings and properly terminate them because different implementations of snprintf() behave differently. Courtesy of TrueLight
Darkvater
parents: 3173
diff changeset
   126
VARDEF char _network_player_name[NETWORK_CLIENT_NAME_LENGTH];
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   127
VARDEF char _network_default_ip[NETWORK_HOSTNAME_LENGTH];
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   128
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   129
VARDEF uint16 _network_own_client_index;
8303
67babdcebe96 (svn r11357) -Fix: NetworkUniqueID could be 80 chars, while the max size we generate is 32. So reduce the size a bit. Pointed out by dihedral, so give him a big hug ;)
truelight
parents: 8060
diff changeset
   130
VARDEF char _network_unique_id[NETWORK_UNIQUE_ID_LENGTH]; // Our own unique ID
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   131
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   132
VARDEF uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   133
VARDEF uint32 _frame_counter_max; // To where we may go with our clients
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   134
2079
5afd2e7fc3bd (svn r2589) Fix: [network] Fixed static variable that wasn't initialized. Would stop the sync checking from working in some cases.
ludde
parents: 2071
diff changeset
   135
VARDEF uint32 _last_sync_frame; // Used in the server to store the last time a sync packet was sent to clients.
5afd2e7fc3bd (svn r2589) Fix: [network] Fixed static variable that wasn't initialized. Would stop the sync checking from working in some cases.
ludde
parents: 2071
diff changeset
   136
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   137
// networking settings
4034
091963647651 (svn r5293) -Fix: Not all network interfaces are capable of broadcasting. Don't record those which aren't
tron
parents: 3994
diff changeset
   138
VARDEF uint32 _broadcast_list[MAX_INTERFACES + 1];
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   139
3152
447059d1ecdd (svn r3775) Fix loading of server_port from config file, introduced in Darkvater's unified configuration changes (r3719+)
peter1138
parents: 3041
diff changeset
   140
VARDEF uint16 _network_server_port;
629
ce914eb4023d (svn r1059) -Fix: [Console] Renamed 'set port' to 'set server_port'
truelight
parents: 627
diff changeset
   141
/* We use bind_ip and bind_ip_host, where bind_ip_host is the readable form of
ce914eb4023d (svn r1059) -Fix: [Console] Renamed 'set port' to 'set server_port'
truelight
parents: 627
diff changeset
   142
    bind_ip_host, and bind_ip the numeric value, because we want a nice number
ce914eb4023d (svn r1059) -Fix: [Console] Renamed 'set port' to 'set server_port'
truelight
parents: 627
diff changeset
   143
    in the openttd.cfg, but we wants to use the uint32 internally.. */
ce914eb4023d (svn r1059) -Fix: [Console] Renamed 'set port' to 'set server_port'
truelight
parents: 627
diff changeset
   144
VARDEF uint32 _network_server_bind_ip;
ce914eb4023d (svn r1059) -Fix: [Console] Renamed 'set port' to 'set server_port'
truelight
parents: 627
diff changeset
   145
VARDEF char _network_server_bind_ip_host[NETWORK_HOSTNAME_LENGTH];
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   146
VARDEF bool _is_network_server; // Does this client wants to be a network-server?
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   147
VARDEF char _network_server_name[NETWORK_NAME_LENGTH];
1026
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1011
diff changeset
   148
VARDEF char _network_server_password[NETWORK_PASSWORD_LENGTH];
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1011
diff changeset
   149
VARDEF char _network_rcon_password[NETWORK_PASSWORD_LENGTH];
8494
88f26cafc858 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 8303
diff changeset
   150
VARDEF char _network_default_company_pass[NETWORK_PASSWORD_LENGTH];
1026
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1011
diff changeset
   151
3173
1b75b9a6ff71 (svn r3805) - [FS#62] Fix doxygen comments to refer to the correct parameter. (sulai)
peter1138
parents: 3152
diff changeset
   152
VARDEF uint16 _network_max_join_time;             ///< Time a client can max take to join
1b75b9a6ff71 (svn r3805) - [FS#62] Fix doxygen comments to refer to the correct parameter. (sulai)
peter1138
parents: 3152
diff changeset
   153
VARDEF bool _network_pause_on_join;               ///< Pause the game when a client tries to join (more chance of succeeding join)
1602
08783e4287dc (svn r2106) -Fix: improved the network-join algoritm, it is now a bit more stable
truelight
parents: 1441
diff changeset
   154
1026
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1011
diff changeset
   155
VARDEF uint16 _redirect_console_to_client;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   156
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   157
VARDEF uint16 _network_sync_freq;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   158
VARDEF uint8 _network_frame_freq;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   159
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   160
VARDEF uint32 _sync_seed_1, _sync_seed_2;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   161
VARDEF uint32 _sync_frame;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   162
VARDEF bool _network_first_time;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   163
// Vars needed for the join-GUI
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   164
VARDEF NetworkJoinStatus _network_join_status;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   165
VARDEF uint8 _network_join_waiting;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   166
VARDEF uint16 _network_join_kbytes;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   167
VARDEF uint16 _network_join_kbytes_total;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   168
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   169
VARDEF char _network_last_host[NETWORK_HOSTNAME_LENGTH];
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   170
VARDEF short _network_last_port;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   171
VARDEF uint32 _network_last_host_ip;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   172
VARDEF uint8 _network_reconnect;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   173
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   174
VARDEF bool _network_udp_server;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   175
VARDEF uint16 _network_udp_broadcast;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   176
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 738
diff changeset
   177
VARDEF byte _network_lan_internet;
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 738
diff changeset
   178
2861
c7e2c8217fed (svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents: 2380
diff changeset
   179
VARDEF bool _network_need_advertise;
c7e2c8217fed (svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents: 2380
diff changeset
   180
VARDEF uint32 _network_last_advertise_frame;
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 738
diff changeset
   181
VARDEF uint8 _network_advertise_retries;
668
346853c8b513 (svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents: 663
diff changeset
   182
690
9f449a6b133e (svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents: 670
diff changeset
   183
VARDEF bool _network_autoclean_companies;
9f449a6b133e (svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents: 670
diff changeset
   184
VARDEF uint8 _network_autoclean_unprotected; // Remove a company after X months
9f449a6b133e (svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents: 670
diff changeset
   185
VARDEF uint8 _network_autoclean_protected;   // Unprotect a company after X months
9f449a6b133e (svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents: 670
diff changeset
   186
4293
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4289
diff changeset
   187
VARDEF Year _network_restart_game_year;      // If this year is reached, the server automaticly restarts
4716
d9ca1be9d04b (svn r6628) - Feature: Add the ability to pause a server if not enough players are connected. The setting for this is 'min_players' and can be set in the config and via the console. If the number of players drops below this number, the server will pause the game.
peter1138
parents: 4344
diff changeset
   188
VARDEF uint8 _network_min_players;           // Minimum number of players for game to unpause
785
e9ca2bcc9c8f (svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents: 774
diff changeset
   189
6167
1475cf991e66 (svn r8543) -Codechange: make a real difference between querying the server via UDP and TCP.
rubidium
parents: 6148
diff changeset
   190
void NetworkTCPQueryServer(const char* host, unsigned short port);
774
258c11431acb (svn r1240) -Fix: OpenTTD once again compiles if ENABLE_NETWORK is disabled.
darkvater
parents: 773
diff changeset
   191
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6504
diff changeset
   192
byte NetworkSpectatorCount();
2944
7c392e7b51c6 (svn r3500) - Workaround the inaccurate count of spectators/companies that can happen in certain border-cases. For now just dynamically get this value when requested so it is always right. To do properly all player/client creation/destruction needs a hook for networking.
Darkvater
parents: 2881
diff changeset
   193
3041
105098f42dfa (svn r3621) - Codechange: Only define the server and bans list if network is enabled. Preparatory work for saving patches/settings to savegame.
Darkvater
parents: 2944
diff changeset
   194
VARDEF char *_network_host_list[10];
105098f42dfa (svn r3621) - Codechange: Only define the server and bans list if network is enabled. Preparatory work for saving patches/settings to savegame.
Darkvater
parents: 2944
diff changeset
   195
VARDEF char *_network_ban_list[25];
105098f42dfa (svn r3621) - Codechange: Only define the server and bans list if network is enabled. Preparatory work for saving patches/settings to savegame.
Darkvater
parents: 2944
diff changeset
   196
4038
b23bbe44d1ba (svn r5298) Hide function declarations and remove function stubs which aren't needed in the !ENABLE_NETWORK case
tron
parents: 4034
diff changeset
   197
void ParseConnectionString(const char **player, const char **port, char *connection_string);
b23bbe44d1ba (svn r5298) Hide function declarations and remove function stubs which aren't needed in the !ENABLE_NETWORK case
tron
parents: 4034
diff changeset
   198
void NetworkUpdateClientInfo(uint16 client_index);
b23bbe44d1ba (svn r5298) Hide function declarations and remove function stubs which aren't needed in the !ENABLE_NETWORK case
tron
parents: 4034
diff changeset
   199
void NetworkAddServer(const char *b);
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6504
diff changeset
   200
void NetworkRebuildHostList();
4038
b23bbe44d1ba (svn r5298) Hide function declarations and remove function stubs which aren't needed in the !ENABLE_NETWORK case
tron
parents: 4034
diff changeset
   201
bool NetworkChangeCompanyPassword(byte argc, char *argv[]);
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6504
diff changeset
   202
void NetworkPopulateCompanyInfo();
5034
f00ac4873c34 (svn r7076) -Codechange: Prefer includes instead of using extern. Move UpdateNetworkGameWindow
Darkvater
parents: 4880
diff changeset
   203
void UpdateNetworkGameWindow(bool unselect);
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6504
diff changeset
   204
void CheckMinPlayers();
6210
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6169
diff changeset
   205
void NetworkStartDebugLog(const char *hostname, uint16 port);
4038
b23bbe44d1ba (svn r5298) Hide function declarations and remove function stubs which aren't needed in the !ENABLE_NETWORK case
tron
parents: 4034
diff changeset
   206
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6504
diff changeset
   207
void NetworkStartUp();
5870
86e55167c9e3 (svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents: 5838
diff changeset
   208
void NetworkUDPCloseAll();
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6504
diff changeset
   209
void NetworkShutDown();
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6504
diff changeset
   210
void NetworkGameLoop();
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6504
diff changeset
   211
void NetworkUDPGameLoop();
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6504
diff changeset
   212
bool NetworkServerStart();
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4830
diff changeset
   213
bool NetworkClientConnectGame(const char *host, uint16 port);
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6504
diff changeset
   214
void NetworkReboot();
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6504
diff changeset
   215
void NetworkDisconnect();
4830
0ff2a14e90be (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   216
6504
5578f2fa1a73 (svn r8949) -Codechange: only test the first NETWORK_REVISION_LENGTH - 1 characters when determining network compatability. This makes it possible to have 'long' branch names while still being able to play network games.
rubidium
parents: 6210
diff changeset
   217
bool IsNetworkCompatibleVersion(const char *version);
5578f2fa1a73 (svn r8949) -Codechange: only test the first NETWORK_REVISION_LENGTH - 1 characters when determining network compatability. This makes it possible to have 'long' branch names while still being able to play network games.
rubidium
parents: 6210
diff changeset
   218
8617
931e0970d509 (svn r11682) -Codechange: move some 'generic' geometry related types into a single file and do not include gfx.h everywhere to get a Point type.
rubidium
parents: 8494
diff changeset
   219
extern bool _networking;         ///< are we in networking mode?
4830
0ff2a14e90be (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   220
VARDEF bool _network_server;     ///< network-server is active
0ff2a14e90be (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   221
VARDEF bool _network_available;  ///< is network mode available?
5962
72d6d787d1f0 (svn r8198) -Codechange: two global variables are not needed when network is disabled.
rubidium
parents: 5870
diff changeset
   222
VARDEF bool _network_dedicated;  ///< are we a dedicated server?
72d6d787d1f0 (svn r8198) -Codechange: two global variables are not needed when network is disabled.
rubidium
parents: 5870
diff changeset
   223
VARDEF bool _network_advertise;  ///< is the server advertising to the master server?
4830
0ff2a14e90be (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   224
0ff2a14e90be (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   225
#else /* ENABLE_NETWORK */
0ff2a14e90be (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   226
/* Network function stubs when networking is disabled */
0ff2a14e90be (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   227
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6504
diff changeset
   228
static inline void NetworkStartUp() {}
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6504
diff changeset
   229
static inline void NetworkShutDown() {}
4830
0ff2a14e90be (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   230
0ff2a14e90be (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   231
#define _networking 0
0ff2a14e90be (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   232
#define _network_server 0
0ff2a14e90be (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   233
#define _network_available 0
5962
72d6d787d1f0 (svn r8198) -Codechange: two global variables are not needed when network is disabled.
rubidium
parents: 5870
diff changeset
   234
#define _network_dedicated 0
72d6d787d1f0 (svn r8198) -Codechange: two global variables are not needed when network is disabled.
rubidium
parents: 5870
diff changeset
   235
#define _network_advertise 0
4830
0ff2a14e90be (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   236
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   237
#endif /* ENABLE_NETWORK */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 239
diff changeset
   238
8617
931e0970d509 (svn r11682) -Codechange: move some 'generic' geometry related types into a single file and do not include gfx.h everywhere to get a Point type.
rubidium
parents: 8494
diff changeset
   239
/* This variable must always be registered! */
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4830
diff changeset
   240
VARDEF PlayerID _network_playas; ///< an id to play as.. (see players.h:Players)
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents:
diff changeset
   241
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents:
diff changeset
   242
#endif /* NETWORK_H */