author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1500 | a66721629bc0 |
child 1797 | fa156be69235 |
permissions | -rw-r--r-- |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1 |
#include "stdafx.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1026
diff
changeset
|
2 |
#include "debug.h" |
1317
3c90086ff34f
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
1309
diff
changeset
|
3 |
#include "string.h" |
1309
4403a69da4f8
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1299
diff
changeset
|
4 |
#include "strings.h" |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
5 |
#include "network_data.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
6 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
7 |
#ifdef ENABLE_NETWORK |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
8 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
9 |
#include "table/strings.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
10 |
#include "network_client.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
11 |
#include "network_gamelist.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
12 |
#include "command.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
13 |
#include "gfx.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
14 |
#include "window.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
15 |
#include "settings.h" |
1026
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
16 |
#include "console.h" |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
17 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
18 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
19 |
// This file handles all the client-commands |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
20 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
21 |
|
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
684
diff
changeset
|
22 |
extern const char _openttd_revision[]; |
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
684
diff
changeset
|
23 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
24 |
// So we don't make too much typos ;) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
25 |
#define MY_CLIENT DEREF_CLIENT(0) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
26 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
27 |
static uint32 last_ack_frame; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
28 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
29 |
void NetworkRecvPatchSettings(NetworkClientState *cs, Packet *p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
30 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
31 |
// ********** |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
32 |
// Sending functions |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
33 |
// DEF_CLIENT_SEND_COMMAND has no parameters |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
34 |
// ********** |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
35 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
36 |
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_COMPANY_INFO) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
37 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
38 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
39 |
// Packet: CLIENT_COMPANY_INFO |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
40 |
// Function: Request company-info (in detail) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
41 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
42 |
// <none> |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
43 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
44 |
Packet *p; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
45 |
_network_join_status = NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
46 |
InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
47 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
48 |
p = NetworkSend_Init(PACKET_CLIENT_COMPANY_INFO); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
49 |
NetworkSend_Packet(p, MY_CLIENT); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
50 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
51 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
52 |
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JOIN) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
53 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
54 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
55 |
// Packet: CLIENT_JOIN |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
56 |
// Function: Try to join the server |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
57 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
58 |
// String: OpenTTD Revision (norev000 if no revision) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
59 |
// String: Player Name (max NETWORK_NAME_LENGTH) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
60 |
// uint8: Play as Player id (1..MAX_PLAYERS) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
61 |
// uint8: Language ID |
602
f0afb4018788
(svn r1026) -Add: [Network] Added unique id, so in network, each client has an
truelight
parents:
571
diff
changeset
|
62 |
// String: Unique id to find the player back in server-listing |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
63 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
64 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
65 |
Packet *p; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
66 |
_network_join_status = NETWORK_JOIN_STATUS_AUTHORIZING; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
67 |
InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
68 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
69 |
p = NetworkSend_Init(PACKET_CLIENT_JOIN); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
70 |
NetworkSend_string(p, _openttd_revision); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
71 |
NetworkSend_string(p, _network_player_name); // Player name |
662
22708a1cbba9
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
72 |
NetworkSend_uint8(p, _network_playas); // PlayAs |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
73 |
NetworkSend_uint8(p, NETLANG_ANY); // Language |
602
f0afb4018788
(svn r1026) -Add: [Network] Added unique id, so in network, each client has an
truelight
parents:
571
diff
changeset
|
74 |
NetworkSend_string(p, _network_unique_id); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
75 |
NetworkSend_Packet(p, MY_CLIENT); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
76 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
77 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
78 |
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_PASSWORD)(NetworkPasswordType type, const char *password) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
79 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
80 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
81 |
// Packet: CLIENT_PASSWORD |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
82 |
// Function: Send a password to the server to authorize |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
83 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
84 |
// uint8: NetworkPasswordType |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
85 |
// String: Password |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
86 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
87 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_PASSWORD); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
88 |
NetworkSend_uint8(p, type); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
89 |
NetworkSend_string(p, password); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
90 |
NetworkSend_Packet(p, MY_CLIENT); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
91 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
92 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
93 |
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_GETMAP) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
94 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
95 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
96 |
// Packet: CLIENT_GETMAP |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
97 |
// Function: Request the map from the server |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
98 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
99 |
// <none> |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
100 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
101 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
102 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_GETMAP); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
103 |
NetworkSend_Packet(p, MY_CLIENT); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
104 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
105 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
106 |
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_MAP_OK) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
107 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
108 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
109 |
// Packet: CLIENT_MAP_OK |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
110 |
// Function: Tell the server that we are done receiving/loading the map |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
111 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
112 |
// <none> |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
113 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
114 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
115 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_MAP_OK); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
116 |
NetworkSend_Packet(p, MY_CLIENT); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
117 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
118 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
119 |
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_ACK) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
120 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
121 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
122 |
// Packet: CLIENT_ACK |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
123 |
// Function: Tell the server we are done with this frame |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
124 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
125 |
// uint32: current FrameCounter of the client |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
126 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
127 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
128 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_ACK); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
129 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
130 |
NetworkSend_uint32(p, _frame_counter); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
131 |
NetworkSend_Packet(p, MY_CLIENT); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
132 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
133 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
134 |
// Send a command packet to the server |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
135 |
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMMAND)(CommandPacket *cp) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
136 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
137 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
138 |
// Packet: CLIENT_COMMAND |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
139 |
// Function: Send a DoCommand to the Server |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
140 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
141 |
// uint8: PlayerID (0..MAX_PLAYERS-1) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
142 |
// uint32: CommandID (see command.h) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
143 |
// uint32: P1 (free variables used in DoCommand) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
144 |
// uint32: P2 |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
145 |
// uint32: Tile |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
146 |
// uint32: decode_params |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
147 |
// 10 times the last one (lengthof(cp->dp)) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
148 |
// uint8: CallBackID (see callback_table.c) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
149 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
150 |
|
959
e6a3bbda610f
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
903
diff
changeset
|
151 |
uint i; |
571
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
152 |
char *dparam_char; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
153 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_COMMAND); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
154 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
155 |
NetworkSend_uint8(p, cp->player); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
156 |
NetworkSend_uint32(p, cp->cmd); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
157 |
NetworkSend_uint32(p, cp->p1); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
158 |
NetworkSend_uint32(p, cp->p2); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
159 |
NetworkSend_uint32(p, (uint32)cp->tile); |
571
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
160 |
/* We are going to send them byte by byte, because dparam is misused |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
161 |
for chars (if it is used), and else we have a BigEndian / LittleEndian |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
162 |
problem.. we should fix the misuse of dparam... -- TrueLight */ |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
163 |
dparam_char = (char *)&cp->dp[0]; |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
164 |
for (i = 0; i < lengthof(cp->dp) * 4; i++) { |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
165 |
NetworkSend_uint8(p, *dparam_char); |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
166 |
dparam_char++; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
167 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
168 |
NetworkSend_uint8(p, cp->callback); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
169 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
170 |
NetworkSend_Packet(p, MY_CLIENT); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
171 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
172 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
173 |
// Send a chat-packet over the network |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
174 |
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_CHAT)(NetworkAction action, DestType desttype, int dest, const char *msg) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
175 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
176 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
177 |
// Packet: CLIENT_CHAT |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
178 |
// Function: Send a chat-packet to the serve |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
179 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
180 |
// uint8: ActionID (see network_data.h, NetworkAction) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
181 |
// uint8: Destination Type (see network_data.h, DestType); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
182 |
// uint8: Destination Player (1..MAX_PLAYERS) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
183 |
// String: Message (max MAX_TEXT_MSG_LEN) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
184 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
185 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
186 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_CHAT); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
187 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
188 |
NetworkSend_uint8(p, action); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
189 |
NetworkSend_uint8(p, desttype); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
190 |
NetworkSend_uint8(p, dest); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
191 |
NetworkSend_string(p, msg); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
192 |
NetworkSend_Packet(p, MY_CLIENT); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
193 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
194 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
195 |
// Send an error-packet over the network |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
196 |
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_ERROR)(NetworkErrorCode errorno) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
197 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
198 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
199 |
// Packet: CLIENT_ERROR |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
200 |
// Function: The client made an error and is quiting the game |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
201 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
202 |
// uint8: ErrorID (see network_data.h, NetworkErrorCode) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
203 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
204 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_ERROR); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
205 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
206 |
NetworkSend_uint8(p, errorno); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
207 |
NetworkSend_Packet(p, MY_CLIENT); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
208 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
209 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
210 |
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_PASSWORD)(const char *password) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
211 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
212 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
213 |
// Packet: PACKET_CLIENT_SET_PASSWORD |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
214 |
// Function: Set the password for the clients current company |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
215 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
216 |
// String: Password |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
217 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
218 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_SET_PASSWORD); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
219 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
220 |
NetworkSend_string(p, password); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
221 |
NetworkSend_Packet(p, MY_CLIENT); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
222 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
223 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
224 |
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_NAME)(const char *name) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
225 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
226 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
227 |
// Packet: PACKET_CLIENT_SET_NAME |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
228 |
// Function: Gives the player a new name |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
229 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
230 |
// String: Name |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
231 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
232 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_SET_NAME); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
233 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
234 |
NetworkSend_string(p, name); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
235 |
NetworkSend_Packet(p, MY_CLIENT); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
236 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
237 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
238 |
// Send an quit-packet over the network |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
239 |
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_QUIT)(const char *leavemsg) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
240 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
241 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
242 |
// Packet: CLIENT_QUIT |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
243 |
// Function: The client is quiting the game |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
244 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
245 |
// String: leave-message |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
246 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
247 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_QUIT); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
248 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
249 |
NetworkSend_string(p, leavemsg); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
250 |
NetworkSend_Packet(p, MY_CLIENT); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
251 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
252 |
|
1026
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
253 |
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_RCON)(const char *pass, const char *command) |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
254 |
{ |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
255 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_RCON); |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
256 |
NetworkSend_string(p, pass); |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
257 |
NetworkSend_string(p, command); |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
258 |
NetworkSend_Packet(p, MY_CLIENT); |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
259 |
} |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
260 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
261 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
262 |
// ********** |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
263 |
// Receiving functions |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
264 |
// DEF_CLIENT_RECEIVE_COMMAND has parameter: Packet *p |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
265 |
// ********** |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
266 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
267 |
extern bool SafeSaveOrLoad(const char *filename, int mode, int newgm); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
268 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
269 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_FULL) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
270 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
271 |
// We try to join a server which is full |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
272 |
_switch_mode_errorstr = STR_NETWORK_ERR_SERVER_FULL; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
273 |
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
274 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
275 |
return NETWORK_RECV_STATUS_SERVER_FULL; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
276 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
277 |
|
841
4874b9ce2765
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
278 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_BANNED) |
4874b9ce2765
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
279 |
{ |
4874b9ce2765
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
280 |
// We try to join a server where we are banned |
4874b9ce2765
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
281 |
_switch_mode_errorstr = STR_NETWORK_ERR_SERVER_BANNED; |
4874b9ce2765
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
282 |
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); |
4874b9ce2765
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
283 |
|
4874b9ce2765
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
284 |
return NETWORK_RECV_STATUS_SERVER_BANNED; |
4874b9ce2765
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
285 |
} |
4874b9ce2765
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
286 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
287 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
288 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
289 |
byte company_info_version; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
290 |
int i; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
291 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
292 |
company_info_version = NetworkRecv_uint8(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
293 |
|
1013 | 294 |
if (!MY_CLIENT->quited && company_info_version == NETWORK_COMPANY_INFO_VERSION) { |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
295 |
byte total; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
296 |
byte current; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
297 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
298 |
total = NetworkRecv_uint8(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
299 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
300 |
// There is no data at all.. |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
301 |
if (total == 0) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
302 |
return NETWORK_RECV_STATUS_CLOSE_QUERY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
303 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
304 |
current = NetworkRecv_uint8(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
305 |
if (current >= MAX_PLAYERS) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
306 |
return NETWORK_RECV_STATUS_CLOSE_QUERY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
307 |
|
734
f4ad2f5805fd
(svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents:
722
diff
changeset
|
308 |
_network_lobby_company_count++; |
f4ad2f5805fd
(svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents:
722
diff
changeset
|
309 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
310 |
NetworkRecv_string(MY_CLIENT, p, _network_player_info[current].company_name, sizeof(_network_player_info[current].company_name)); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
311 |
_network_player_info[current].inaugurated_year = NetworkRecv_uint8(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
312 |
_network_player_info[current].company_value = NetworkRecv_uint64(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
313 |
_network_player_info[current].money = NetworkRecv_uint64(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
314 |
_network_player_info[current].income = NetworkRecv_uint64(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
315 |
_network_player_info[current].performance = NetworkRecv_uint16(MY_CLIENT, p); |
1011
933efc472c62
(svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents:
959
diff
changeset
|
316 |
_network_player_info[current].use_password = NetworkRecv_uint8(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
317 |
for (i = 0; i < NETWORK_VEHICLE_TYPES; i++) |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
318 |
_network_player_info[current].num_vehicle[i] = NetworkRecv_uint16(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
319 |
for (i = 0; i < NETWORK_STATION_TYPES; i++) |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
320 |
_network_player_info[current].num_station[i] = NetworkRecv_uint16(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
321 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
322 |
NetworkRecv_string(MY_CLIENT, p, _network_player_info[current].players, sizeof(_network_player_info[current].players)); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
323 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
324 |
InvalidateWindow(WC_NETWORK_WINDOW, 0); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
325 |
|
734
f4ad2f5805fd
(svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents:
722
diff
changeset
|
326 |
return NETWORK_RECV_STATUS_OKAY; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
327 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
328 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
329 |
return NETWORK_RECV_STATUS_CLOSE_QUERY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
330 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
331 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
332 |
// This packet contains info about the client (playas and name) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
333 |
// as client we save this in NetworkClientInfo, linked via 'index' |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
334 |
// which is always an unique number on a server. |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
335 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
336 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
337 |
NetworkClientInfo *ci; |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
338 |
uint16 index = NetworkRecv_uint16(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
339 |
byte playas = NetworkRecv_uint8(MY_CLIENT, p); |
662
22708a1cbba9
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
340 |
char name[NETWORK_NAME_LENGTH]; |
22708a1cbba9
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
341 |
char unique_id[NETWORK_NAME_LENGTH]; |
22708a1cbba9
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
342 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
343 |
NetworkRecv_string(MY_CLIENT, p, name, sizeof(name)); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
344 |
NetworkRecv_string(MY_CLIENT, p, unique_id, sizeof(unique_id)); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
345 |
|
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
346 |
if (MY_CLIENT->quited) |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
347 |
return NETWORK_RECV_STATUS_CONN_LOST; |
662
22708a1cbba9
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
348 |
|
22708a1cbba9
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
349 |
/* Do we receive a change of data? Most likely we changed playas */ |
22708a1cbba9
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
350 |
if (index == _network_own_client_index) |
22708a1cbba9
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
351 |
_network_playas = playas; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
352 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
353 |
ci = NetworkFindClientInfoFromIndex(index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
354 |
if (ci != NULL) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
355 |
if (playas == ci->client_playas && strcmp(name, ci->client_name) != 0) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
356 |
// Client name changed, display the change |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
357 |
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, name); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
358 |
} else if (playas != ci->client_playas) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
359 |
// The player changed from client-player.. |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
360 |
// Do not display that for now |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
361 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
362 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
363 |
ci->client_playas = playas; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
364 |
ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name)); |
662
22708a1cbba9
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
365 |
|
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
366 |
InvalidateWindow(WC_CLIENT_LIST, 0); |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
367 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
368 |
return NETWORK_RECV_STATUS_OKAY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
369 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
370 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
371 |
// We don't have this index yet, find an empty index, and put the data there |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
372 |
ci = NetworkFindClientInfoFromIndex(NETWORK_EMPTY_INDEX); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
373 |
if (ci != NULL) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
374 |
ci->client_index = index; |
662
22708a1cbba9
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
375 |
ci->client_playas = playas; |
22708a1cbba9
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
376 |
|
22708a1cbba9
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
377 |
ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name)); |
22708a1cbba9
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
378 |
ttd_strlcpy(ci->unique_id, unique_id, sizeof(ci->unique_id)); |
22708a1cbba9
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
379 |
|
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
380 |
InvalidateWindow(WC_CLIENT_LIST, 0); |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
381 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
382 |
return NETWORK_RECV_STATUS_OKAY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
383 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
384 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
385 |
// Here the program should never ever come..... |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
386 |
return NETWORK_RECV_STATUS_MALFORMED_PACKET; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
387 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
388 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
389 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
390 |
{ |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
391 |
NetworkErrorCode error = NetworkRecv_uint8(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
392 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
393 |
if (error == NETWORK_ERROR_NOT_AUTHORIZED || error == NETWORK_ERROR_NOT_EXPECTED || |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
394 |
error == NETWORK_ERROR_PLAYER_MISMATCH) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
395 |
// We made an error in the protocol, and our connection is closed.... :( |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
396 |
_switch_mode_errorstr = STR_NETWORK_ERR_SERVER_ERROR; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
397 |
} else if (error == NETWORK_ERROR_WRONG_REVISION) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
398 |
// Wrong revision :( |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
399 |
_switch_mode_errorstr = STR_NETWORK_ERR_WRONG_REVISION; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
400 |
} else if (error == NETWORK_ERROR_WRONG_PASSWORD) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
401 |
// Wrong password |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
402 |
_switch_mode_errorstr = STR_NETWORK_ERR_WRONG_PASSWORD; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
403 |
} else if (error == NETWORK_ERROR_KICKED) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
404 |
_switch_mode_errorstr = STR_NETWORK_ERR_KICKED; |
748
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
405 |
} else if (error == NETWORK_ERROR_CHEATER) { |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
406 |
_switch_mode_errorstr = STR_NETWORK_ERR_CHEATER; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
407 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
408 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
409 |
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
410 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
411 |
return NETWORK_RECV_STATUS_SERVER_ERROR; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
412 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
413 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
414 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_NEED_PASSWORD) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
415 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
416 |
NetworkPasswordType type; |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
417 |
type = NetworkRecv_uint8(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
418 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
419 |
if (type == NETWORK_GAME_PASSWORD) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
420 |
ShowNetworkNeedGamePassword(); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
421 |
return NETWORK_RECV_STATUS_OKAY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
422 |
} else if (type == NETWORK_COMPANY_PASSWORD) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
423 |
ShowNetworkNeedCompanyPassword(); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
424 |
return NETWORK_RECV_STATUS_OKAY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
425 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
426 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
427 |
return NETWORK_RECV_STATUS_MALFORMED_PACKET; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
428 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
429 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
430 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_WELCOME) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
431 |
{ |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
432 |
_network_own_client_index = NetworkRecv_uint16(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
433 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
434 |
// Start receiving the map |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
435 |
SEND_COMMAND(PACKET_CLIENT_GETMAP)(); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
436 |
return NETWORK_RECV_STATUS_OKAY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
437 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
438 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
439 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_WAIT) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
440 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
441 |
_network_join_status = NETWORK_JOIN_STATUS_WAITING; |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
442 |
_network_join_waiting = NetworkRecv_uint8(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
443 |
InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
444 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
445 |
// We are put on hold for receiving the map.. we need GUI for this ;) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
446 |
DEBUG(net, 1)("[NET] The server is currently busy sending the map to someone else.. please hold..." ); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
447 |
DEBUG(net, 1)("[NET] There are %d clients in front of you", _network_join_waiting); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
448 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
449 |
return NETWORK_RECV_STATUS_OKAY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
450 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
451 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
452 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
453 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
454 |
static char filename[256]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
455 |
static FILE *file_pointer; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
456 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
457 |
byte maptype; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
458 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
459 |
maptype = NetworkRecv_uint8(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
460 |
|
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
461 |
if (MY_CLIENT->quited) |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
462 |
return NETWORK_RECV_STATUS_CONN_LOST; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
463 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
464 |
// First packet, init some stuff |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
465 |
if (maptype == MAP_PACKET_START) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
466 |
// The name for the temp-map |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
467 |
sprintf(filename, "%s%snetwork_client.tmp", _path.autosave_dir, PATHSEP); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
468 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
469 |
file_pointer = fopen(filename, "wb"); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
470 |
if (file_pointer == NULL) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
471 |
_switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
472 |
return NETWORK_RECV_STATUS_SAVEGAME; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
473 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
474 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
475 |
_frame_counter = _frame_counter_server = _frame_counter_max = NetworkRecv_uint32(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
476 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
477 |
_network_join_status = NETWORK_JOIN_STATUS_DOWNLOADING; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
478 |
_network_join_kbytes = 0; |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
479 |
_network_join_kbytes_total = NetworkRecv_uint32(MY_CLIENT, p) / 1024; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
480 |
InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
481 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
482 |
// The first packet does not contain any more data |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
483 |
return NETWORK_RECV_STATUS_OKAY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
484 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
485 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
486 |
if (maptype == MAP_PACKET_NORMAL) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
487 |
// We are still receiving data, put it to the file |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
488 |
fwrite(p->buffer + p->pos, 1, p->size - p->pos, file_pointer); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
489 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
490 |
_network_join_kbytes = ftell(file_pointer) / 1024; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
491 |
InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
492 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
493 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
494 |
if (maptype == MAP_PACKET_PATCH) { |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
495 |
NetworkRecvPatchSettings(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
496 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
497 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
498 |
// Check if this was the last packet |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
499 |
if (maptype == MAP_PACKET_END) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
500 |
// We also get, very nice, the player_seeds in this packet |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
501 |
int i; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
502 |
for (i = 0; i < MAX_PLAYERS; i++) { |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
503 |
_player_seeds[i][0] = NetworkRecv_uint32(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
504 |
_player_seeds[i][1] = NetworkRecv_uint32(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
505 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
506 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
507 |
fclose(file_pointer); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
508 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
509 |
_network_join_status = NETWORK_JOIN_STATUS_PROCESSING; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
510 |
InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
511 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
512 |
// The map is done downloading, load it |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
513 |
// Load the map |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
514 |
if (!SafeSaveOrLoad(filename, SL_LOAD, GM_NORMAL)) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
515 |
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
516 |
_switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
517 |
return NETWORK_RECV_STATUS_SAVEGAME; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
518 |
} |
1500
a66721629bc0
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1317
diff
changeset
|
519 |
|
a66721629bc0
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1317
diff
changeset
|
520 |
_opt_ptr = &_opt; // during a network game you are always in-game |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
521 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
522 |
// Say we received the map and loaded it correctly! |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
523 |
SEND_COMMAND(PACKET_CLIENT_MAP_OK)(); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
524 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
525 |
if (_network_playas == 0 || _network_playas > MAX_PLAYERS || |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
526 |
!DEREF_PLAYER(_network_playas - 1)->is_active) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
527 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
528 |
if (_network_playas == OWNER_SPECTATOR) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
529 |
// The client wants to be a spectator.. |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
530 |
_local_player = OWNER_SPECTATOR; |
670
d164965bb35a
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents:
662
diff
changeset
|
531 |
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
532 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
533 |
// send a command to make a new player |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
534 |
_local_player = 0; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
535 |
NetworkSend_Command(0, 0, 0, CMD_PLAYER_CTRL, NULL); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
536 |
_local_player = OWNER_SPECTATOR; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
537 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
538 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
539 |
// take control over an existing company |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
540 |
_local_player = _network_playas - 1; |
684
639c3ca13086
(svn r1125) -Fix: [Network] You can now safely join a company again
truelight
parents:
670
diff
changeset
|
541 |
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
542 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
543 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
544 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
545 |
return NETWORK_RECV_STATUS_OKAY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
546 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
547 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
548 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_FRAME) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
549 |
{ |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
550 |
_frame_counter_server = NetworkRecv_uint32(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
551 |
_frame_counter_max = NetworkRecv_uint32(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
552 |
#ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
553 |
// Test if the server supports this option |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
554 |
// and if we are at the frame the server is |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
555 |
if (p->pos < p->size) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
556 |
_sync_frame = _frame_counter_server; |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
557 |
_sync_seed_1 = NetworkRecv_uint32(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
558 |
#ifdef NETWORK_SEND_DOUBLE_SEED |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
559 |
_sync_seed_2 = NetworkRecv_uint32(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
560 |
#endif |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
561 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
562 |
#endif |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
563 |
DEBUG(net, 7)("[NET] Received FRAME %d",_frame_counter_server); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
564 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
565 |
// Let the server know that we received this frame correctly |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
566 |
// We do this only once per day, to save some bandwidth ;) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
567 |
if (!_network_first_time && last_ack_frame < _frame_counter) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
568 |
last_ack_frame = _frame_counter + DAY_TICKS; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
569 |
DEBUG(net,6)("[NET] Sent ACK at %d", _frame_counter); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
570 |
SEND_COMMAND(PACKET_CLIENT_ACK)(); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
571 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
572 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
573 |
return NETWORK_RECV_STATUS_OKAY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
574 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
575 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
576 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_SYNC) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
577 |
{ |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
578 |
_sync_frame = NetworkRecv_uint32(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
579 |
_sync_seed_1 = NetworkRecv_uint32(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
580 |
#ifdef NETWORK_SEND_DOUBLE_SEED |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
581 |
_sync_seed_2 = NetworkRecv_uint32(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
582 |
#endif |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
583 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
584 |
return NETWORK_RECV_STATUS_OKAY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
585 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
586 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
587 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMMAND) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
588 |
{ |
959
e6a3bbda610f
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
903
diff
changeset
|
589 |
uint i; |
571
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
590 |
char *dparam_char; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
591 |
CommandPacket *cp = malloc(sizeof(CommandPacket)); |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
592 |
cp->player = NetworkRecv_uint8(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
593 |
cp->cmd = NetworkRecv_uint32(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
594 |
cp->p1 = NetworkRecv_uint32(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
595 |
cp->p2 = NetworkRecv_uint32(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
596 |
cp->tile = NetworkRecv_uint32(MY_CLIENT, p); |
571
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
597 |
/* We are going to send them byte by byte, because dparam is misused |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
598 |
for chars (if it is used), and else we have a BigEndian / LittleEndian |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
599 |
problem.. we should fix the misuse of dparam... -- TrueLight */ |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
600 |
dparam_char = (char *)&cp->dp[0]; |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
601 |
for (i = 0; i < lengthof(cp->dp) * 4; i++) { |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
602 |
*dparam_char = NetworkRecv_uint8(MY_CLIENT, p); |
571
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
603 |
dparam_char++; |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
604 |
} |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
605 |
cp->callback = NetworkRecv_uint8(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
606 |
cp->frame = NetworkRecv_uint32(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
607 |
cp->next = NULL; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
608 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
609 |
// The server did send us this command.. |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
610 |
// queue it in our own queue, so we can handle it in the upcoming frame! |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
611 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
612 |
if (_local_command_queue == NULL) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
613 |
_local_command_queue = cp; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
614 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
615 |
// Find last packet |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
616 |
CommandPacket *c = _local_command_queue; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
617 |
while (c->next != NULL) c = c->next; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
618 |
c->next = cp; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
619 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
620 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
621 |
return NETWORK_RECV_STATUS_OKAY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
622 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
623 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
624 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
625 |
{ |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
626 |
NetworkAction action = NetworkRecv_uint8(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
627 |
char msg[MAX_TEXT_MSG_LEN]; |
774
bb9ec520a1b1
(svn r1240) -Fix: OpenTTD once again compiles if ENABLE_NETWORK is disabled.
darkvater
parents:
748
diff
changeset
|
628 |
NetworkClientInfo *ci = NULL, *ci_to; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
629 |
uint16 index; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
630 |
char name[NETWORK_NAME_LENGTH]; |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
631 |
bool self_send; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
632 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
633 |
index = NetworkRecv_uint16(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
634 |
self_send = NetworkRecv_uint8(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
635 |
NetworkRecv_string(MY_CLIENT, p, msg, MAX_TEXT_MSG_LEN); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
636 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
637 |
ci_to = NetworkFindClientInfoFromIndex(index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
638 |
if (ci_to == NULL) return NETWORK_RECV_STATUS_OKAY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
639 |
|
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
640 |
/* Do we display the action locally? */ |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
641 |
if (self_send) { |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
642 |
switch (action) { |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
643 |
case NETWORK_ACTION_CHAT_CLIENT: |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
644 |
/* For speak to client we need the client-name */ |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
645 |
snprintf(name, sizeof(name), "%s", ci_to->client_name); |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
646 |
ci = NetworkFindClientInfoFromIndex(_network_own_client_index); |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
647 |
break; |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
648 |
case NETWORK_ACTION_CHAT_PLAYER: |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
649 |
case NETWORK_ACTION_GIVE_MONEY: |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
650 |
/* For speak to player or give money, we need the player-name */ |
779
9f1c1091b9c8
(svn r1246) -Fix: [ 1090099 ] Company-messages did crash the game, because
truelight
parents:
774
diff
changeset
|
651 |
if (ci_to->client_playas > MAX_PLAYERS) |
9f1c1091b9c8
(svn r1246) -Fix: [ 1090099 ] Company-messages did crash the game, because
truelight
parents:
774
diff
changeset
|
652 |
return NETWORK_RECV_STATUS_OKAY; // This should never happen |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
653 |
GetString(name, DEREF_PLAYER(ci_to->client_playas-1)->name_1); |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
654 |
ci = NetworkFindClientInfoFromIndex(_network_own_client_index); |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
655 |
break; |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
656 |
default: |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
657 |
/* This should never happen */ |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
658 |
NOT_REACHED(); |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
659 |
break; |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
660 |
} |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
661 |
} else { |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
662 |
/* Display message from somebody else */ |
602
f0afb4018788
(svn r1026) -Add: [Network] Added unique id, so in network, each client has an
truelight
parents:
571
diff
changeset
|
663 |
snprintf(name, sizeof(name), "%s", ci_to->client_name); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
664 |
ci = ci_to; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
665 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
666 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
667 |
if (ci != NULL) |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
668 |
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas-1), self_send, name, "%s", msg); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
669 |
return NETWORK_RECV_STATUS_OKAY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
670 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
671 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
672 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
673 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
674 |
int errorno; |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
675 |
char str[100]; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
676 |
uint16 index; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
677 |
NetworkClientInfo *ci; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
678 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
679 |
index = NetworkRecv_uint16(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
680 |
errorno = NetworkRecv_uint8(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
681 |
|
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
682 |
GetString(str, STR_NETWORK_ERR_CLIENT_GENERAL + errorno); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
683 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
684 |
ci = NetworkFindClientInfoFromIndex(index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
685 |
if (ci != NULL) { |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
686 |
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, ci->client_name, str); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
687 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
688 |
// The client is gone, give the NetworkClientInfo free |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
689 |
ci->client_index = NETWORK_EMPTY_INDEX; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
690 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
691 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
692 |
InvalidateWindow(WC_CLIENT_LIST, 0); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
693 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
694 |
return NETWORK_RECV_STATUS_OKAY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
695 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
696 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
697 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_QUIT) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
698 |
{ |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
699 |
char str[100]; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
700 |
uint16 index; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
701 |
NetworkClientInfo *ci; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
702 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
703 |
index = NetworkRecv_uint16(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
704 |
NetworkRecv_string(MY_CLIENT, p, str, 100); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
705 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
706 |
ci = NetworkFindClientInfoFromIndex(index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
707 |
if (ci != NULL) { |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
708 |
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, ci->client_name, str); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
709 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
710 |
// The client is gone, give the NetworkClientInfo free |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
711 |
ci->client_index = NETWORK_EMPTY_INDEX; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
712 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
713 |
DEBUG(net, 0)("[NET] Error - unknown client (%d) is leaving the game", index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
714 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
715 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
716 |
InvalidateWindow(WC_CLIENT_LIST, 0); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
717 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
718 |
// If we come here it means we could not locate the client.. strange :s |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
719 |
return NETWORK_RECV_STATUS_OKAY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
720 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
721 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
722 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_JOIN) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
723 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
724 |
uint16 index; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
725 |
NetworkClientInfo *ci; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
726 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
727 |
index = NetworkRecv_uint16(MY_CLIENT, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
728 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
729 |
ci = NetworkFindClientInfoFromIndex(index); |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
730 |
if (ci != NULL) |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
731 |
NetworkTextMessage(NETWORK_ACTION_JOIN, 1, false, ci->client_name, ""); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
732 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
733 |
InvalidateWindow(WC_CLIENT_LIST, 0); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
734 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
735 |
return NETWORK_RECV_STATUS_OKAY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
736 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
737 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
738 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_SHUTDOWN) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
739 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
740 |
_switch_mode_errorstr = STR_NETWORK_SERVER_SHUTDOWN; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
741 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
742 |
return NETWORK_RECV_STATUS_SERVER_ERROR; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
743 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
744 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
745 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_NEWGAME) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
746 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
747 |
// To trottle the reconnects a bit, every clients waits |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
748 |
// his _local_player value before reconnecting |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
749 |
// OWNER_SPECTATOR is currently 255, so to avoid long wait periods |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
750 |
// set the max to 10. |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
751 |
_network_reconnect = min(_local_player + 1, 10); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
752 |
_switch_mode_errorstr = STR_NETWORK_SERVER_REBOOT; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
753 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
754 |
return NETWORK_RECV_STATUS_SERVER_ERROR; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
755 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
756 |
|
1026
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
757 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_RCON) |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
758 |
{ |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
759 |
char rcon_out[NETWORK_RCONCOMMAND_LENGTH]; |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
760 |
uint16 color_code; |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
761 |
|
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
762 |
color_code = NetworkRecv_uint16(MY_CLIENT, p); |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
763 |
NetworkRecv_string(MY_CLIENT, p, rcon_out, sizeof(rcon_out)); |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
764 |
|
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
765 |
IConsolePrint(color_code, rcon_out); |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
766 |
|
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
767 |
return NETWORK_RECV_STATUS_OKAY; |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
768 |
} |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
769 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
770 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
771 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
772 |
// The layout for the receive-functions by the client |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
773 |
typedef NetworkRecvStatus NetworkClientPacket(Packet *p); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
774 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
775 |
// This array matches PacketType. At an incoming |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
776 |
// packet it is matches against this array |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
777 |
// and that way the right function to handle that |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
778 |
// packet is found. |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
779 |
static NetworkClientPacket* const _network_client_packet[] = { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
780 |
RECEIVE_COMMAND(PACKET_SERVER_FULL), |
841
4874b9ce2765
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
781 |
RECEIVE_COMMAND(PACKET_SERVER_BANNED), |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
782 |
NULL, /*PACKET_CLIENT_JOIN,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
783 |
RECEIVE_COMMAND(PACKET_SERVER_ERROR), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
784 |
NULL, /*PACKET_CLIENT_COMPANY_INFO,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
785 |
RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
786 |
RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
787 |
RECEIVE_COMMAND(PACKET_SERVER_NEED_PASSWORD), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
788 |
NULL, /*PACKET_CLIENT_PASSWORD,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
789 |
RECEIVE_COMMAND(PACKET_SERVER_WELCOME), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
790 |
NULL, /*PACKET_CLIENT_GETMAP,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
791 |
RECEIVE_COMMAND(PACKET_SERVER_WAIT), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
792 |
RECEIVE_COMMAND(PACKET_SERVER_MAP), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
793 |
NULL, /*PACKET_CLIENT_MAP_OK,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
794 |
RECEIVE_COMMAND(PACKET_SERVER_JOIN), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
795 |
RECEIVE_COMMAND(PACKET_SERVER_FRAME), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
796 |
RECEIVE_COMMAND(PACKET_SERVER_SYNC), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
797 |
NULL, /*PACKET_CLIENT_ACK,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
798 |
NULL, /*PACKET_CLIENT_COMMAND,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
799 |
RECEIVE_COMMAND(PACKET_SERVER_COMMAND), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
800 |
NULL, /*PACKET_CLIENT_CHAT,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
801 |
RECEIVE_COMMAND(PACKET_SERVER_CHAT), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
802 |
NULL, /*PACKET_CLIENT_SET_PASSWORD,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
803 |
NULL, /*PACKET_CLIENT_SET_NAME,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
804 |
NULL, /*PACKET_CLIENT_QUIT,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
805 |
NULL, /*PACKET_CLIENT_ERROR,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
806 |
RECEIVE_COMMAND(PACKET_SERVER_QUIT), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
807 |
RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
808 |
RECEIVE_COMMAND(PACKET_SERVER_SHUTDOWN), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
809 |
RECEIVE_COMMAND(PACKET_SERVER_NEWGAME), |
1026
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
810 |
RECEIVE_COMMAND(PACKET_SERVER_RCON), |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
811 |
NULL, /*PACKET_CLIENT_RCON,*/ |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
812 |
}; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
813 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
814 |
// If this fails, check the array above with network_data.h |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
815 |
assert_compile(lengthof(_network_client_packet) == PACKET_END); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
816 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
817 |
extern const SettingDesc patch_settings[]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
818 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
819 |
// This is a TEMPORARY solution to get the patch-settings |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
820 |
// to the client. When the patch-settings are saved in the savegame |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
821 |
// this should be removed!! |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
822 |
void NetworkRecvPatchSettings(NetworkClientState *cs, Packet *p) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
823 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
824 |
const SettingDesc *item; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
825 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
826 |
item = patch_settings; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
827 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
828 |
while (item->name != NULL) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
829 |
switch (item->flags) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
830 |
case SDT_BOOL: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
831 |
case SDT_INT8: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
832 |
case SDT_UINT8: |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
833 |
*(uint8 *)(item->ptr) = NetworkRecv_uint8(cs, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
834 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
835 |
case SDT_INT16: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
836 |
case SDT_UINT16: |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
837 |
*(uint16 *)(item->ptr) = NetworkRecv_uint16(cs, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
838 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
839 |
case SDT_INT32: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
840 |
case SDT_UINT32: |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
841 |
*(uint32 *)(item->ptr) = NetworkRecv_uint32(cs, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
842 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
843 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
844 |
item++; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
845 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
846 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
847 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
848 |
// Is called after a client is connected to the server |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
849 |
void NetworkClient_Connected(void) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
850 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
851 |
// Set the frame-counter to 0 so nothing happens till we are ready |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
852 |
_frame_counter = 0; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
853 |
_frame_counter_server = 0; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
854 |
last_ack_frame = 0; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
855 |
// Request the game-info |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
856 |
SEND_COMMAND(PACKET_CLIENT_JOIN)(); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
857 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
858 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
859 |
// Reads the packets from the socket-stream, if available |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
684
diff
changeset
|
860 |
NetworkRecvStatus NetworkClient_ReadPackets(NetworkClientState *cs) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
861 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
862 |
Packet *p; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
863 |
NetworkRecvStatus res = NETWORK_RECV_STATUS_OKAY; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
864 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
865 |
while (res == NETWORK_RECV_STATUS_OKAY && (p = NetworkRecv_Packet(cs, &res)) != NULL) { |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
866 |
byte type = NetworkRecv_uint8(MY_CLIENT, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
867 |
if (type < PACKET_END && _network_client_packet[type] != NULL && !MY_CLIENT->quited) { |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
868 |
res = _network_client_packet[type](p); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
869 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
870 |
res = NETWORK_RECV_STATUS_MALFORMED_PACKET; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
871 |
DEBUG(net, 0)("[NET][client] Received invalid packet type %d", type); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
872 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
873 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
874 |
free(p); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
875 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
876 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
877 |
return res; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
878 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
879 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
880 |
#endif /* ENABLE_NETWORK */ |