author | celestar |
Mon, 19 Mar 2007 12:38:16 +0000 | |
branch | gamebalance |
changeset 9895 | 7bd07f43b0e3 |
parent 6169 | 31cdbb4845f1 |
child 6719 | 4cc327ad39d5 |
child 6988 | 76eba6a9cc6f |
child 9360 | c20d0a9e0a5c |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
4826
63b1eb7c966b
(svn r6750) -Codechange: Juggle around some header includes as they're only used when
Darkvater
parents:
4512
diff
changeset
|
3 |
#ifdef ENABLE_NETWORK |
63b1eb7c966b
(svn r6750) -Codechange: Juggle around some header includes as they're only used when
Darkvater
parents:
4512
diff
changeset
|
4 |
|
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5683
diff
changeset
|
5 |
#include "../stdafx.h" |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5683
diff
changeset
|
6 |
#include "../debug.h" |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5683
diff
changeset
|
7 |
#include "../string.h" |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5683
diff
changeset
|
8 |
#include "../strings.h" |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
9 |
#include "network_data.h" |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5683
diff
changeset
|
10 |
#include "core/tcp.h" |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5683
diff
changeset
|
11 |
#include "../date.h" |
5726
8f399788f6c9
(svn r7759) -Merge: makefile rewrite. This merge features:
rubidium
parents:
5720
diff
changeset
|
12 |
#include "table/strings.h" |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5683
diff
changeset
|
13 |
#include "../functions.h" |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
14 |
#include "network_client.h" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
15 |
#include "network_gamelist.h" |
4512
7151d4ee3a0f
(svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents:
4428
diff
changeset
|
16 |
#include "network_gui.h" |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5683
diff
changeset
|
17 |
#include "../saveload.h" |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5683
diff
changeset
|
18 |
#include "../command.h" |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5683
diff
changeset
|
19 |
#include "../window.h" |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5683
diff
changeset
|
20 |
#include "../console.h" |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5683
diff
changeset
|
21 |
#include "../variables.h" |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5683
diff
changeset
|
22 |
#include "../ai/ai.h" |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
23 |
#include "../helpers.hpp" |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
24 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
25 |
// This file handles all the client-commands |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
26 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
27 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
28 |
// So we don't make too much typos ;) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
29 |
#define MY_CLIENT DEREF_CLIENT(0) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
30 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
31 |
static uint32 last_ack_frame; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
32 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
33 |
// ********** |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
34 |
// Sending functions |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
35 |
// DEF_CLIENT_SEND_COMMAND has no parameters |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
36 |
// ********** |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
37 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
38 |
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_COMPANY_INFO) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
39 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
40 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
41 |
// Packet: CLIENT_COMPANY_INFO |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
42 |
// Function: Request company-info (in detail) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
43 |
// Data: |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
44 |
// <none> |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
45 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
46 |
Packet *p; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
47 |
_network_join_status = NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
48 |
InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
49 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
50 |
p = NetworkSend_Init(PACKET_CLIENT_COMPANY_INFO); |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6151
diff
changeset
|
51 |
MY_CLIENT->Send_Packet(p); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
52 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
53 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
54 |
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JOIN) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
55 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
56 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
57 |
// Packet: CLIENT_JOIN |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
58 |
// Function: Try to join the server |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
59 |
// Data: |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
60 |
// String: OpenTTD Revision (norev000 if no revision) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
61 |
// String: Player Name (max NETWORK_NAME_LENGTH) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
62 |
// uint8: Play as Player id (1..MAX_PLAYERS) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
63 |
// uint8: Language ID |
602
9bbe42a9e3ed
(svn r1026) -Add: [Network] Added unique id, so in network, each client has an
truelight
parents:
571
diff
changeset
|
64 |
// String: Unique id to find the player back in server-listing |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
65 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
66 |
|
4840
176bc2a66322
(svn r6766) -Codechange: Move _openttd_revision[] into the functions that use it instead of global
Darkvater
parents:
4826
diff
changeset
|
67 |
extern const char _openttd_revision[]; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
68 |
Packet *p; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
69 |
_network_join_status = NETWORK_JOIN_STATUS_AUTHORIZING; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
70 |
InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
71 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
72 |
p = NetworkSend_Init(PACKET_CLIENT_JOIN); |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
73 |
p->Send_string(_openttd_revision); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
74 |
p->Send_string(_network_player_name); // Player name |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
75 |
p->Send_uint8 (_network_playas); // PlayAs |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
76 |
p->Send_uint8 (NETLANG_ANY); // Language |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
77 |
p->Send_string(_network_unique_id); |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6151
diff
changeset
|
78 |
MY_CLIENT->Send_Packet(p); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
79 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
80 |
|
6123
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
81 |
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED) |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
82 |
{ |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
83 |
// |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
84 |
// Packet: CLIENT_NEWGRFS_CHECKED |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
85 |
// Function: Tell the server that we have the required GRFs |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
86 |
// Data: |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
87 |
// |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
88 |
|
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
89 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_NEWGRFS_CHECKED); |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6151
diff
changeset
|
90 |
MY_CLIENT->Send_Packet(p); |
6123
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
91 |
} |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
92 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
93 |
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_PASSWORD)(NetworkPasswordType type, const char *password) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
94 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
95 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
96 |
// Packet: CLIENT_PASSWORD |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
97 |
// Function: Send a password to the server to authorize |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
98 |
// Data: |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
99 |
// uint8: NetworkPasswordType |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
100 |
// String: Password |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
101 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
102 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_PASSWORD); |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
103 |
p->Send_uint8 (type); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
104 |
p->Send_string(password); |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6151
diff
changeset
|
105 |
MY_CLIENT->Send_Packet(p); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
106 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
107 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
108 |
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_GETMAP) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
109 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
110 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
111 |
// Packet: CLIENT_GETMAP |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
112 |
// Function: Request the map from the server |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
113 |
// Data: |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
114 |
// <none> |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
115 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
116 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
117 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_GETMAP); |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6151
diff
changeset
|
118 |
MY_CLIENT->Send_Packet(p); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
119 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
120 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
121 |
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_MAP_OK) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
122 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
123 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
124 |
// Packet: CLIENT_MAP_OK |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
125 |
// Function: Tell the server that we are done receiving/loading the map |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
126 |
// Data: |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
127 |
// <none> |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
128 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
129 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
130 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_MAP_OK); |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6151
diff
changeset
|
131 |
MY_CLIENT->Send_Packet(p); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
132 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
133 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
134 |
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_ACK) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
135 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
136 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
137 |
// Packet: CLIENT_ACK |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
138 |
// Function: Tell the server we are done with this frame |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
139 |
// Data: |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
140 |
// uint32: current FrameCounter of the client |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
141 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
142 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
143 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_ACK); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
144 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
145 |
p->Send_uint32(_frame_counter); |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6151
diff
changeset
|
146 |
MY_CLIENT->Send_Packet(p); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
147 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
148 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
149 |
// Send a command packet to the server |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
150 |
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMMAND)(CommandPacket *cp) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
151 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
152 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
153 |
// Packet: CLIENT_COMMAND |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
154 |
// Function: Send a DoCommand to the Server |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
155 |
// Data: |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
156 |
// uint8: PlayerID (0..MAX_PLAYERS-1) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
157 |
// uint32: CommandID (see command.h) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
158 |
// uint32: P1 (free variables used in DoCommand) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
159 |
// uint32: P2 |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
160 |
// uint32: Tile |
1820
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1797
diff
changeset
|
161 |
// string: text |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
162 |
// uint8: CallBackID (see callback_table.c) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
163 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
164 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
165 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_COMMAND); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
166 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
167 |
p->Send_uint8 (cp->player); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
168 |
p->Send_uint32(cp->cmd); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
169 |
p->Send_uint32(cp->p1); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
170 |
p->Send_uint32(cp->p2); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
171 |
p->Send_uint32((uint32)cp->tile); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
172 |
p->Send_string(cp->text); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
173 |
p->Send_uint8 (cp->callback); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
174 |
|
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6151
diff
changeset
|
175 |
MY_CLIENT->Send_Packet(p); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
176 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
177 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
178 |
// Send a chat-packet over the network |
4906
8a10678a62a3
(svn r6876) -Codechange: Change the naming of _PLAYER in DESTTYPE_PLAYER/NETWORK_ACTION_CHAT_PLAYER
Darkvater
parents:
4880
diff
changeset
|
179 |
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_CHAT)(NetworkAction action, DestType type, int dest, const char *msg) |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
180 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
181 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
182 |
// Packet: CLIENT_CHAT |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
183 |
// Function: Send a chat-packet to the serve |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
184 |
// Data: |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
185 |
// uint8: ActionID (see network_data.h, NetworkAction) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
186 |
// uint8: Destination Type (see network_data.h, DestType); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
187 |
// uint8: Destination Player (1..MAX_PLAYERS) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
188 |
// String: Message (max MAX_TEXT_MSG_LEN) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
189 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
190 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
191 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_CHAT); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
192 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
193 |
p->Send_uint8 (action); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
194 |
p->Send_uint8 (type); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
195 |
p->Send_uint8 (dest); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
196 |
p->Send_string(msg); |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6151
diff
changeset
|
197 |
MY_CLIENT->Send_Packet(p); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
198 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
199 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
200 |
// Send an error-packet over the network |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
201 |
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_ERROR)(NetworkErrorCode errorno) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
202 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
203 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
204 |
// Packet: CLIENT_ERROR |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
205 |
// Function: The client made an error and is quiting the game |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
206 |
// Data: |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
207 |
// uint8: ErrorID (see network_data.h, NetworkErrorCode) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
208 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
209 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_ERROR); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
210 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
211 |
p->Send_uint8(errorno); |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6151
diff
changeset
|
212 |
MY_CLIENT->Send_Packet(p); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
213 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
214 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
215 |
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_PASSWORD)(const char *password) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
216 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
217 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
218 |
// Packet: PACKET_CLIENT_SET_PASSWORD |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
219 |
// Function: Set the password for the clients current company |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
220 |
// Data: |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
221 |
// String: Password |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
222 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
223 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_SET_PASSWORD); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
224 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
225 |
p->Send_string(password); |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6151
diff
changeset
|
226 |
MY_CLIENT->Send_Packet(p); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
227 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
228 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
229 |
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_NAME)(const char *name) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
230 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
231 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
232 |
// Packet: PACKET_CLIENT_SET_NAME |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
233 |
// Function: Gives the player a new name |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
234 |
// Data: |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
235 |
// String: Name |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
236 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
237 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_SET_NAME); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
238 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
239 |
p->Send_string(name); |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6151
diff
changeset
|
240 |
MY_CLIENT->Send_Packet(p); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
241 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
242 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
243 |
// Send an quit-packet over the network |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
244 |
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_QUIT)(const char *leavemsg) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
245 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
246 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
247 |
// Packet: CLIENT_QUIT |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
248 |
// Function: The client is quiting the game |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
249 |
// Data: |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
250 |
// String: leave-message |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
251 |
// |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
252 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_QUIT); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
253 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
254 |
p->Send_string(leavemsg); |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6151
diff
changeset
|
255 |
MY_CLIENT->Send_Packet(p); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
256 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
257 |
|
1026
5b2681cad645
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
258 |
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_RCON)(const char *pass, const char *command) |
5b2681cad645
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
259 |
{ |
5b2681cad645
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
260 |
Packet *p = NetworkSend_Init(PACKET_CLIENT_RCON); |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
261 |
p->Send_string(pass); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
262 |
p->Send_string(command); |
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6151
diff
changeset
|
263 |
MY_CLIENT->Send_Packet(p); |
1026
5b2681cad645
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
264 |
} |
5b2681cad645
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
265 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
266 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
267 |
// ********** |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
268 |
// Receiving functions |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
269 |
// DEF_CLIENT_RECEIVE_COMMAND has parameter: Packet *p |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
270 |
// ********** |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
271 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
272 |
extern bool SafeSaveOrLoad(const char *filename, int mode, int newgm); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
273 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
274 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_FULL) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
275 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
276 |
// We try to join a server which is full |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
277 |
_switch_mode_errorstr = STR_NETWORK_ERR_SERVER_FULL; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
278 |
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
279 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
280 |
return NETWORK_RECV_STATUS_SERVER_FULL; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
281 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
282 |
|
841
8f0a68c6f43b
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
283 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_BANNED) |
8f0a68c6f43b
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
284 |
{ |
8f0a68c6f43b
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
285 |
// We try to join a server where we are banned |
8f0a68c6f43b
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
286 |
_switch_mode_errorstr = STR_NETWORK_ERR_SERVER_BANNED; |
8f0a68c6f43b
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
287 |
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); |
8f0a68c6f43b
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
288 |
|
8f0a68c6f43b
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
289 |
return NETWORK_RECV_STATUS_SERVER_BANNED; |
8f0a68c6f43b
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
290 |
} |
8f0a68c6f43b
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
291 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
292 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
293 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
294 |
byte company_info_version; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
295 |
int i; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
296 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
297 |
company_info_version = p->Recv_uint8(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
298 |
|
4880
0708f34e3586
(svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents:
4878
diff
changeset
|
299 |
if (!MY_CLIENT->has_quit && company_info_version == NETWORK_COMPANY_INFO_VERSION) { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
300 |
byte total; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
301 |
PlayerID current; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
302 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
303 |
total = p->Recv_uint8(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
304 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
305 |
// There is no data at all.. |
4880
0708f34e3586
(svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents:
4878
diff
changeset
|
306 |
if (total == 0) return NETWORK_RECV_STATUS_CLOSE_QUERY; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
307 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
308 |
current = (Owner)p->Recv_uint8(); |
4880
0708f34e3586
(svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents:
4878
diff
changeset
|
309 |
if (!IsValidPlayer(current)) return NETWORK_RECV_STATUS_CLOSE_QUERY; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
310 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
311 |
p->Recv_string(_network_player_info[current].company_name, sizeof(_network_player_info[current].company_name)); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
312 |
_network_player_info[current].inaugurated_year = p->Recv_uint32(); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
313 |
_network_player_info[current].company_value = p->Recv_uint64(); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
314 |
_network_player_info[current].money = p->Recv_uint64(); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
315 |
_network_player_info[current].income = p->Recv_uint64(); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
316 |
_network_player_info[current].performance = p->Recv_uint16(); |
6169
31cdbb4845f1
(svn r8546) -Codechange: add a seperate (wrapper) functions to send/receive booleans.
rubidium
parents:
6153
diff
changeset
|
317 |
_network_player_info[current].use_password = p->Recv_bool(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
318 |
for (i = 0; i < NETWORK_VEHICLE_TYPES; i++) |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
319 |
_network_player_info[current].num_vehicle[i] = p->Recv_uint16(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
320 |
for (i = 0; i < NETWORK_STATION_TYPES; i++) |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
321 |
_network_player_info[current].num_station[i] = p->Recv_uint16(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
322 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
323 |
p->Recv_string(_network_player_info[current].players, sizeof(_network_player_info[current].players)); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
324 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
325 |
InvalidateWindow(WC_NETWORK_WINDOW, 0); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
326 |
|
734
018e549265ed
(svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents:
722
diff
changeset
|
327 |
return NETWORK_RECV_STATUS_OKAY; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
328 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
329 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
330 |
return NETWORK_RECV_STATUS_CLOSE_QUERY; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
331 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
332 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
333 |
// This packet contains info about the client (playas and name) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
334 |
// as client we save this in NetworkClientInfo, linked via 'index' |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
335 |
// which is always an unique number on a server. |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
336 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
337 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
338 |
NetworkClientInfo *ci; |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
339 |
uint16 index = p->Recv_uint16(); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
340 |
PlayerID playas = (Owner)p->Recv_uint8(); |
662
029d67bd54e6
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
341 |
char name[NETWORK_NAME_LENGTH]; |
029d67bd54e6
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
342 |
char unique_id[NETWORK_NAME_LENGTH]; |
029d67bd54e6
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
343 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
344 |
p->Recv_string(name, sizeof(name)); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
345 |
p->Recv_string(unique_id, sizeof(unique_id)); |
903
f860c7234167
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
346 |
|
4880
0708f34e3586
(svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents:
4878
diff
changeset
|
347 |
if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_CONN_LOST; |
662
029d67bd54e6
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
348 |
|
029d67bd54e6
(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 */ |
4880
0708f34e3586
(svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents:
4878
diff
changeset
|
350 |
if (index == _network_own_client_index) _network_playas = playas; |
2684
8aba54c245cc
(svn r3226) -Fix: GPMI implementation had minor glitches
truelight
parents:
2373
diff
changeset
|
351 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
352 |
ci = NetworkFindClientInfoFromIndex(index); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
353 |
if (ci != NULL) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
354 |
if (playas == ci->client_playas && strcmp(name, ci->client_name) != 0) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
355 |
// Client name changed, display the change |
2373
f06403621870
(svn r2899) -Fix: Several format string vulnerabilities and buffer overflows in the network code
tron
parents:
2293
diff
changeset
|
356 |
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, "%s", name); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
357 |
} else if (playas != ci->client_playas) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
358 |
// The player changed from client-player.. |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
359 |
// Do not display that for now |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
360 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
361 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
362 |
ci->client_playas = playas; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
363 |
ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name)); |
662
029d67bd54e6
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
364 |
|
722
d0b031be5232
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
365 |
InvalidateWindow(WC_CLIENT_LIST, 0); |
d0b031be5232
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
366 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
367 |
return NETWORK_RECV_STATUS_OKAY; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
368 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
369 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
370 |
// We don't have this index yet, find an empty index, and put the data there |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
371 |
ci = NetworkFindClientInfoFromIndex(NETWORK_EMPTY_INDEX); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
372 |
if (ci != NULL) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
373 |
ci->client_index = index; |
662
029d67bd54e6
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
374 |
ci->client_playas = playas; |
029d67bd54e6
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
375 |
|
029d67bd54e6
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
376 |
ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name)); |
029d67bd54e6
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
377 |
ttd_strlcpy(ci->unique_id, unique_id, sizeof(ci->unique_id)); |
029d67bd54e6
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents:
659
diff
changeset
|
378 |
|
722
d0b031be5232
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
379 |
InvalidateWindow(WC_CLIENT_LIST, 0); |
d0b031be5232
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
380 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
381 |
return NETWORK_RECV_STATUS_OKAY; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
382 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
383 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
384 |
// Here the program should never ever come..... |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
385 |
return NETWORK_RECV_STATUS_MALFORMED_PACKET; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
386 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
387 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
388 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
389 |
{ |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
390 |
NetworkErrorCode error = (NetworkErrorCode)p->Recv_uint8(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
391 |
|
2879
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
392 |
switch (error) { |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
393 |
/* We made an error in the protocol, and our connection is closed.... */ |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
394 |
case NETWORK_ERROR_NOT_AUTHORIZED: |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
395 |
case NETWORK_ERROR_NOT_EXPECTED: |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
396 |
case NETWORK_ERROR_PLAYER_MISMATCH: |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
397 |
_switch_mode_errorstr = STR_NETWORK_ERR_SERVER_ERROR; |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
398 |
break; |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
399 |
case NETWORK_ERROR_FULL: |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
400 |
_switch_mode_errorstr = STR_NETWORK_ERR_SERVER_FULL; |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
401 |
break; |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
402 |
case NETWORK_ERROR_WRONG_REVISION: |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
403 |
_switch_mode_errorstr = STR_NETWORK_ERR_WRONG_REVISION; |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
404 |
break; |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
405 |
case NETWORK_ERROR_WRONG_PASSWORD: |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
406 |
_switch_mode_errorstr = STR_NETWORK_ERR_WRONG_PASSWORD; |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
407 |
break; |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
408 |
case NETWORK_ERROR_KICKED: |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
409 |
_switch_mode_errorstr = STR_NETWORK_ERR_KICKED; |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
410 |
break; |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
411 |
case NETWORK_ERROR_CHEATER: |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
412 |
_switch_mode_errorstr = STR_NETWORK_ERR_CHEATER; |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
413 |
break; |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
414 |
default: |
d270cb37c0ec
(svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents:
2817
diff
changeset
|
415 |
_switch_mode_errorstr = STR_NETWORK_ERR_LOSTCONNECTION; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
416 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
417 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
418 |
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
419 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
420 |
return NETWORK_RECV_STATUS_SERVER_ERROR; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
421 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
422 |
|
6123
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
423 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHECK_NEWGRFS) |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
424 |
{ |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
425 |
uint grf_count = p->Recv_uint8(); |
6123
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
426 |
NetworkRecvStatus ret = NETWORK_RECV_STATUS_OKAY; |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
427 |
|
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
428 |
/* Check all GRFs */ |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
429 |
for (; grf_count > 0; grf_count--) { |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
430 |
GRFConfig c; |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
431 |
MY_CLIENT->Recv_GRFIdentifier(p, &c); |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
432 |
|
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
433 |
/* Check whether we know this GRF */ |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
434 |
const GRFConfig *f = FindGRFConfig(c.grfid, c.md5sum); |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
435 |
if (f == NULL) { |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
436 |
/* We do not know this GRF, bail out of initialization */ |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
437 |
char buf[sizeof(c.md5sum) * 2 + 1]; |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
438 |
md5sumToString(buf, lastof(buf), c.md5sum); |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
439 |
DEBUG(grf, 0, "NewGRF %08X not found; checksum %s", BSWAP32(c.grfid), buf); |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
440 |
ret = NETWORK_RECV_STATUS_NEWGRF_MISMATCH; |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
441 |
} |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
442 |
} |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
443 |
|
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
444 |
if (ret == NETWORK_RECV_STATUS_OKAY) { |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
445 |
/* Start receiving the map */ |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
446 |
SEND_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED)(); |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
447 |
} else { |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
448 |
/* NewGRF mismatch, bail out */ |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
449 |
_switch_mode_errorstr = STR_NETWORK_ERR_NEWGRF_MISMATCH; |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
450 |
} |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
451 |
return ret; |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
452 |
} |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
453 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
454 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_NEED_PASSWORD) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
455 |
{ |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
456 |
NetworkPasswordType type = (NetworkPasswordType)p->Recv_uint8(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
457 |
|
4512
7151d4ee3a0f
(svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents:
4428
diff
changeset
|
458 |
switch (type) { |
7151d4ee3a0f
(svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents:
4428
diff
changeset
|
459 |
case NETWORK_GAME_PASSWORD: |
7151d4ee3a0f
(svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents:
4428
diff
changeset
|
460 |
case NETWORK_COMPANY_PASSWORD: |
7151d4ee3a0f
(svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents:
4428
diff
changeset
|
461 |
ShowNetworkNeedPassword(type); |
7151d4ee3a0f
(svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents:
4428
diff
changeset
|
462 |
return NETWORK_RECV_STATUS_OKAY; |
7151d4ee3a0f
(svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents:
4428
diff
changeset
|
463 |
|
7151d4ee3a0f
(svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents:
4428
diff
changeset
|
464 |
default: return NETWORK_RECV_STATUS_MALFORMED_PACKET; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
465 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
466 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
467 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
468 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_WELCOME) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
469 |
{ |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
470 |
_network_own_client_index = p->Recv_uint16(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
471 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
472 |
// Start receiving the map |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
473 |
SEND_COMMAND(PACKET_CLIENT_GETMAP)(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
474 |
return NETWORK_RECV_STATUS_OKAY; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
475 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
476 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
477 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_WAIT) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
478 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
479 |
_network_join_status = NETWORK_JOIN_STATUS_WAITING; |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
480 |
_network_join_waiting = p->Recv_uint8(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
481 |
InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
482 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
483 |
// We are put on hold for receiving the map.. we need GUI for this ;) |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5564
diff
changeset
|
484 |
DEBUG(net, 1, "The server is currently busy sending the map to someone else, please wait..." ); |
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5564
diff
changeset
|
485 |
DEBUG(net, 1, "There are %d clients in front of you", _network_join_waiting); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
486 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
487 |
return NETWORK_RECV_STATUS_OKAY; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
488 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
489 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
490 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
491 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
492 |
static char filename[256]; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
493 |
static FILE *file_pointer; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
494 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
495 |
byte maptype; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
496 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
497 |
maptype = p->Recv_uint8(); |
903
f860c7234167
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
498 |
|
4880
0708f34e3586
(svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents:
4878
diff
changeset
|
499 |
if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_CONN_LOST; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
500 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
501 |
// First packet, init some stuff |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
502 |
if (maptype == MAP_PACKET_START) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
503 |
// The name for the temp-map |
5296
6a4aaa66eed3
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5170
diff
changeset
|
504 |
snprintf(filename, lengthof(filename), "%s%snetwork_client.tmp", _paths.autosave_dir, PATHSEP); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
505 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
506 |
file_pointer = fopen(filename, "wb"); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
507 |
if (file_pointer == NULL) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
508 |
_switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
509 |
return NETWORK_RECV_STATUS_SAVEGAME; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
510 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
511 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
512 |
_frame_counter = _frame_counter_server = _frame_counter_max = p->Recv_uint32(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
513 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
514 |
_network_join_kbytes = 0; |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
515 |
_network_join_kbytes_total = p->Recv_uint32() / 1024; |
5954
5100190669ac
(svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents:
5875
diff
changeset
|
516 |
|
5100190669ac
(svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents:
5875
diff
changeset
|
517 |
/* If the network connection has been closed due to loss of connection |
5100190669ac
(svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents:
5875
diff
changeset
|
518 |
* or when _network_join_kbytes_total is 0, the join status window will |
5100190669ac
(svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents:
5875
diff
changeset
|
519 |
* do a division by zero. When the connection is lost, we just return |
5100190669ac
(svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents:
5875
diff
changeset
|
520 |
* that. If kbytes_total is 0, the packet must be malformed as a |
5100190669ac
(svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents:
5875
diff
changeset
|
521 |
* savegame less than 1 kilobyte is practically impossible. */ |
5100190669ac
(svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents:
5875
diff
changeset
|
522 |
if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_CONN_LOST; |
5100190669ac
(svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents:
5875
diff
changeset
|
523 |
if (_network_join_kbytes_total == 0) return NETWORK_RECV_STATUS_MALFORMED_PACKET; |
5100190669ac
(svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents:
5875
diff
changeset
|
524 |
|
5100190669ac
(svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents:
5875
diff
changeset
|
525 |
_network_join_status = NETWORK_JOIN_STATUS_DOWNLOADING; |
5100190669ac
(svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents:
5875
diff
changeset
|
526 |
InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
527 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
528 |
// The first packet does not contain any more data |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
529 |
return NETWORK_RECV_STATUS_OKAY; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
530 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
531 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
532 |
if (maptype == MAP_PACKET_NORMAL) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
533 |
// We are still receiving data, put it to the file |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
534 |
fwrite(p->buffer + p->pos, 1, p->size - p->pos, file_pointer); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
535 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
536 |
_network_join_kbytes = ftell(file_pointer) / 1024; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
537 |
InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
538 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
539 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
540 |
// Check if this was the last packet |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
541 |
if (maptype == MAP_PACKET_END) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
542 |
fclose(file_pointer); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
543 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
544 |
_network_join_status = NETWORK_JOIN_STATUS_PROCESSING; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
545 |
InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
546 |
|
5664 | 547 |
/* The map is done downloading, load it */ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
548 |
if (!SafeSaveOrLoad(filename, SL_LOAD, GM_NORMAL)) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
549 |
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
550 |
_switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
551 |
return NETWORK_RECV_STATUS_SAVEGAME; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
552 |
} |
5683
dca046ba7aa3
(svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents:
5664
diff
changeset
|
553 |
/* If the savegame has successfully loaded, ALL windows have been removed, |
dca046ba7aa3
(svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents:
5664
diff
changeset
|
554 |
* only toolbar/statusbar and gamefield are visible */ |
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1317
diff
changeset
|
555 |
|
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1317
diff
changeset
|
556 |
_opt_ptr = &_opt; // during a network game you are always in-game |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
557 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
558 |
// Say we received the map and loaded it correctly! |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
559 |
SEND_COMMAND(PACKET_CLIENT_MAP_OK)(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
560 |
|
4880
0708f34e3586
(svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents:
4878
diff
changeset
|
561 |
/* New company/spectator (invalid player) or company we want to join is not active |
0708f34e3586
(svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents:
4878
diff
changeset
|
562 |
* Switch local player to spectator and await the server's judgement */ |
4878
744717de172e
(svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents:
4861
diff
changeset
|
563 |
if (_network_playas == PLAYER_NEW_COMPANY || !IsValidPlayer(_network_playas) || |
744717de172e
(svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents:
4861
diff
changeset
|
564 |
!GetPlayer(_network_playas)->is_active) { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
565 |
|
5564
6e1b3ea1ba7f
(svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents:
5296
diff
changeset
|
566 |
SetLocalPlayer(PLAYER_SPECTATOR); |
4880
0708f34e3586
(svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents:
4878
diff
changeset
|
567 |
|
5683
dca046ba7aa3
(svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents:
5664
diff
changeset
|
568 |
if (_network_playas != PLAYER_SPECTATOR) { |
1797
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1500
diff
changeset
|
569 |
/* We have arrived and ready to start playing; send a command to make a new player; |
a19c4181f1b7
(svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents:
1500
diff
changeset
|
570 |
* the server will give us a client-id and let us in */ |
5683
dca046ba7aa3
(svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents:
5664
diff
changeset
|
571 |
_network_join_status = NETWORK_JOIN_STATUS_REGISTERING; |
dca046ba7aa3
(svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents:
5664
diff
changeset
|
572 |
ShowJoinStatusWindow(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
573 |
NetworkSend_Command(0, 0, 0, CMD_PLAYER_CTRL, NULL); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
574 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
575 |
} else { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
576 |
// take control over an existing company |
5564
6e1b3ea1ba7f
(svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents:
5296
diff
changeset
|
577 |
SetLocalPlayer(_network_playas); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
578 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
579 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
580 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
581 |
return NETWORK_RECV_STATUS_OKAY; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
582 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
583 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
584 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_FRAME) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
585 |
{ |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
586 |
_frame_counter_server = p->Recv_uint32(); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
587 |
_frame_counter_max = p->Recv_uint32(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
588 |
#ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
589 |
// Test if the server supports this option |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
590 |
// and if we are at the frame the server is |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
591 |
if (p->pos < p->size) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
592 |
_sync_frame = _frame_counter_server; |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
593 |
_sync_seed_1 = p->Recv_uint32(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
594 |
#ifdef NETWORK_SEND_DOUBLE_SEED |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
595 |
_sync_seed_2 = p->Recv_uint32(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
596 |
#endif |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
597 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
598 |
#endif |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5564
diff
changeset
|
599 |
DEBUG(net, 5, "Received FRAME %d", _frame_counter_server); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
600 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
601 |
// Let the server know that we received this frame correctly |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
602 |
// We do this only once per day, to save some bandwidth ;) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
603 |
if (!_network_first_time && last_ack_frame < _frame_counter) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
604 |
last_ack_frame = _frame_counter + DAY_TICKS; |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5564
diff
changeset
|
605 |
DEBUG(net, 4, "Sent ACK at %d", _frame_counter); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
606 |
SEND_COMMAND(PACKET_CLIENT_ACK)(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
607 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
608 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
609 |
return NETWORK_RECV_STATUS_OKAY; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
610 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
611 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
612 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_SYNC) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
613 |
{ |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
614 |
_sync_frame = p->Recv_uint32(); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
615 |
_sync_seed_1 = p->Recv_uint32(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
616 |
#ifdef NETWORK_SEND_DOUBLE_SEED |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
617 |
_sync_seed_2 = p->Recv_uint32(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
618 |
#endif |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
619 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
620 |
return NETWORK_RECV_STATUS_OKAY; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
621 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
622 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
623 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMMAND) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
624 |
{ |
5860
7fdc9b423ba1
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5838
diff
changeset
|
625 |
CommandPacket *cp = MallocT<CommandPacket>(1); |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
626 |
cp->player = (PlayerID)p->Recv_uint8(); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
627 |
cp->cmd = p->Recv_uint32(); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
628 |
cp->p1 = p->Recv_uint32(); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
629 |
cp->p2 = p->Recv_uint32(); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
630 |
cp->tile = p->Recv_uint32(); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
631 |
p->Recv_string(cp->text, sizeof(cp->text)); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
632 |
cp->callback = p->Recv_uint8(); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
633 |
cp->frame = p->Recv_uint32(); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
634 |
cp->next = NULL; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
635 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
636 |
// The server did send us this command.. |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
637 |
// queue it in our own queue, so we can handle it in the upcoming frame! |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
638 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
639 |
if (_local_command_queue == NULL) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
640 |
_local_command_queue = cp; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
641 |
} else { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
642 |
// Find last packet |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
643 |
CommandPacket *c = _local_command_queue; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
644 |
while (c->next != NULL) c = c->next; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
645 |
c->next = cp; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
646 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
647 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
648 |
return NETWORK_RECV_STATUS_OKAY; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
649 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
650 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
651 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
652 |
{ |
4946
42acc5fef0af
(svn r6934) -Cleanup: Some minor cleanup for network_client and removing 'stupid' comment
Darkvater
parents:
4945
diff
changeset
|
653 |
char name[NETWORK_NAME_LENGTH], msg[MAX_TEXT_MSG_LEN]; |
4880
0708f34e3586
(svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents:
4878
diff
changeset
|
654 |
const NetworkClientInfo *ci = NULL, *ci_to; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
655 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
656 |
NetworkAction action = (NetworkAction)p->Recv_uint8(); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
657 |
uint16 index = p->Recv_uint16(); |
6169
31cdbb4845f1
(svn r8546) -Codechange: add a seperate (wrapper) functions to send/receive booleans.
rubidium
parents:
6153
diff
changeset
|
658 |
bool self_send = p->Recv_bool(); |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
659 |
p->Recv_string(msg, MAX_TEXT_MSG_LEN); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
660 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
661 |
ci_to = NetworkFindClientInfoFromIndex(index); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
662 |
if (ci_to == NULL) return NETWORK_RECV_STATUS_OKAY; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
663 |
|
4946
42acc5fef0af
(svn r6934) -Cleanup: Some minor cleanup for network_client and removing 'stupid' comment
Darkvater
parents:
4945
diff
changeset
|
664 |
/* Did we initiate the action locally? */ |
722
d0b031be5232
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
665 |
if (self_send) { |
d0b031be5232
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
666 |
switch (action) { |
d0b031be5232
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
667 |
case NETWORK_ACTION_CHAT_CLIENT: |
4946
42acc5fef0af
(svn r6934) -Cleanup: Some minor cleanup for network_client and removing 'stupid' comment
Darkvater
parents:
4945
diff
changeset
|
668 |
/* For speaking to client we need the client-name */ |
722
d0b031be5232
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
669 |
snprintf(name, sizeof(name), "%s", ci_to->client_name); |
d0b031be5232
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
670 |
ci = NetworkFindClientInfoFromIndex(_network_own_client_index); |
d0b031be5232
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
671 |
break; |
4945
c5c9bfb156fb
(svn r6933) -Feature: Allow spectators to speak to eachother (team)
Darkvater
parents:
4912
diff
changeset
|
672 |
|
c5c9bfb156fb
(svn r6933) -Feature: Allow spectators to speak to eachother (team)
Darkvater
parents:
4912
diff
changeset
|
673 |
/* For speaking to company or giving money, we need the player-name */ |
722
d0b031be5232
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
674 |
case NETWORK_ACTION_GIVE_MONEY: |
4945
c5c9bfb156fb
(svn r6933) -Feature: Allow spectators to speak to eachother (team)
Darkvater
parents:
4912
diff
changeset
|
675 |
if (!IsValidPlayer(ci_to->client_playas)) return NETWORK_RECV_STATUS_OKAY; |
c5c9bfb156fb
(svn r6933) -Feature: Allow spectators to speak to eachother (team)
Darkvater
parents:
4912
diff
changeset
|
676 |
/* fallthrough */ |
c5c9bfb156fb
(svn r6933) -Feature: Allow spectators to speak to eachother (team)
Darkvater
parents:
4912
diff
changeset
|
677 |
case NETWORK_ACTION_CHAT_COMPANY: { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
678 |
StringID str = IsValidPlayer(ci_to->client_playas) ? GetPlayer(ci_to->client_playas)->name_1 : (uint16)STR_NETWORK_SPECTATORS; |
4878
744717de172e
(svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents:
4861
diff
changeset
|
679 |
|
4945
c5c9bfb156fb
(svn r6933) -Feature: Allow spectators to speak to eachother (team)
Darkvater
parents:
4912
diff
changeset
|
680 |
GetString(name, str, lastof(name)); |
722
d0b031be5232
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
681 |
ci = NetworkFindClientInfoFromIndex(_network_own_client_index); |
4945
c5c9bfb156fb
(svn r6933) -Feature: Allow spectators to speak to eachother (team)
Darkvater
parents:
4912
diff
changeset
|
682 |
} break; |
4946
42acc5fef0af
(svn r6934) -Cleanup: Some minor cleanup for network_client and removing 'stupid' comment
Darkvater
parents:
4945
diff
changeset
|
683 |
|
42acc5fef0af
(svn r6934) -Cleanup: Some minor cleanup for network_client and removing 'stupid' comment
Darkvater
parents:
4945
diff
changeset
|
684 |
default: NOT_REACHED(); break; |
722
d0b031be5232
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
685 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
686 |
} else { |
722
d0b031be5232
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
687 |
/* Display message from somebody else */ |
602
9bbe42a9e3ed
(svn r1026) -Add: [Network] Added unique id, so in network, each client has an
truelight
parents:
571
diff
changeset
|
688 |
snprintf(name, sizeof(name), "%s", ci_to->client_name); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
689 |
ci = ci_to; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
690 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
691 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
692 |
if (ci != NULL) |
4878
744717de172e
(svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents:
4861
diff
changeset
|
693 |
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas), self_send, name, "%s", msg); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
694 |
return NETWORK_RECV_STATUS_OKAY; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
695 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
696 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
697 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
698 |
{ |
722
d0b031be5232
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
699 |
char str[100]; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
700 |
uint16 index; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
701 |
NetworkClientInfo *ci; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
702 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
703 |
index = p->Recv_uint16(); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
704 |
GetNetworkErrorMsg(str, (NetworkErrorCode)p->Recv_uint8(), lastof(str)); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
705 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
706 |
ci = NetworkFindClientInfoFromIndex(index); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
707 |
if (ci != NULL) { |
2373
f06403621870
(svn r2899) -Fix: Several format string vulnerabilities and buffer overflows in the network code
tron
parents:
2293
diff
changeset
|
708 |
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, ci->client_name, "%s", str); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
709 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
710 |
// The client is gone, give the NetworkClientInfo free |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
711 |
ci->client_index = NETWORK_EMPTY_INDEX; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
712 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
713 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
714 |
InvalidateWindow(WC_CLIENT_LIST, 0); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
715 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
716 |
return NETWORK_RECV_STATUS_OKAY; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
717 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
718 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
719 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_QUIT) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
720 |
{ |
722
d0b031be5232
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
721 |
char str[100]; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
722 |
uint16 index; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
723 |
NetworkClientInfo *ci; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
724 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
725 |
index = p->Recv_uint16(); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
726 |
p->Recv_string(str, lengthof(str)); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
727 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
728 |
ci = NetworkFindClientInfoFromIndex(index); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
729 |
if (ci != NULL) { |
2373
f06403621870
(svn r2899) -Fix: Several format string vulnerabilities and buffer overflows in the network code
tron
parents:
2293
diff
changeset
|
730 |
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, ci->client_name, "%s", str); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
731 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
732 |
// The client is gone, give the NetworkClientInfo free |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
733 |
ci->client_index = NETWORK_EMPTY_INDEX; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
734 |
} else { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5564
diff
changeset
|
735 |
DEBUG(net, 0, "Unknown client (%d) is leaving the game", index); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
736 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
737 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
738 |
InvalidateWindow(WC_CLIENT_LIST, 0); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
739 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
740 |
// If we come here it means we could not locate the client.. strange :s |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
741 |
return NETWORK_RECV_STATUS_OKAY; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
742 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
743 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
744 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_JOIN) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
745 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
746 |
uint16 index; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
747 |
NetworkClientInfo *ci; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
748 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
749 |
index = p->Recv_uint16(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
750 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
751 |
ci = NetworkFindClientInfoFromIndex(index); |
722
d0b031be5232
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
752 |
if (ci != NULL) |
d0b031be5232
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
717
diff
changeset
|
753 |
NetworkTextMessage(NETWORK_ACTION_JOIN, 1, false, ci->client_name, ""); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
754 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
755 |
InvalidateWindow(WC_CLIENT_LIST, 0); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
756 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
757 |
return NETWORK_RECV_STATUS_OKAY; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
758 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
759 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
760 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_SHUTDOWN) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
761 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
762 |
_switch_mode_errorstr = STR_NETWORK_SERVER_SHUTDOWN; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
763 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
764 |
return NETWORK_RECV_STATUS_SERVER_ERROR; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
765 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
766 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
767 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_NEWGAME) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
768 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
769 |
// To trottle the reconnects a bit, every clients waits |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
770 |
// his _local_player value before reconnecting |
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4840
diff
changeset
|
771 |
// PLAYER_SPECTATOR is currently 255, so to avoid long wait periods |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
772 |
// set the max to 10. |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
773 |
_network_reconnect = min(_local_player + 1, 10); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
774 |
_switch_mode_errorstr = STR_NETWORK_SERVER_REBOOT; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
775 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
776 |
return NETWORK_RECV_STATUS_SERVER_ERROR; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
777 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
778 |
|
1026
5b2681cad645
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
779 |
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_RCON) |
5b2681cad645
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
780 |
{ |
5b2681cad645
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
781 |
char rcon_out[NETWORK_RCONCOMMAND_LENGTH]; |
5b2681cad645
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
782 |
uint16 color_code; |
5b2681cad645
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
783 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
784 |
color_code = p->Recv_uint16(); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
785 |
p->Recv_string(rcon_out, sizeof(rcon_out)); |
1026
5b2681cad645
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
786 |
|
5b2681cad645
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
787 |
IConsolePrint(color_code, rcon_out); |
5b2681cad645
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
788 |
|
5b2681cad645
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
789 |
return NETWORK_RECV_STATUS_OKAY; |
5b2681cad645
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
790 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
791 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
792 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
793 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
794 |
// The layout for the receive-functions by the client |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
795 |
typedef NetworkRecvStatus NetworkClientPacket(Packet *p); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
796 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
797 |
// This array matches PacketType. At an incoming |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
798 |
// packet it is matches against this array |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
799 |
// and that way the right function to handle that |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
800 |
// packet is found. |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
801 |
static NetworkClientPacket* const _network_client_packet[] = { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
802 |
RECEIVE_COMMAND(PACKET_SERVER_FULL), |
841
8f0a68c6f43b
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
779
diff
changeset
|
803 |
RECEIVE_COMMAND(PACKET_SERVER_BANNED), |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
804 |
NULL, /*PACKET_CLIENT_JOIN,*/ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
805 |
RECEIVE_COMMAND(PACKET_SERVER_ERROR), |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
806 |
NULL, /*PACKET_CLIENT_COMPANY_INFO,*/ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
807 |
RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO), |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
808 |
RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO), |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
809 |
RECEIVE_COMMAND(PACKET_SERVER_NEED_PASSWORD), |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
810 |
NULL, /*PACKET_CLIENT_PASSWORD,*/ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
811 |
RECEIVE_COMMAND(PACKET_SERVER_WELCOME), |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
812 |
NULL, /*PACKET_CLIENT_GETMAP,*/ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
813 |
RECEIVE_COMMAND(PACKET_SERVER_WAIT), |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
814 |
RECEIVE_COMMAND(PACKET_SERVER_MAP), |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
815 |
NULL, /*PACKET_CLIENT_MAP_OK,*/ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
816 |
RECEIVE_COMMAND(PACKET_SERVER_JOIN), |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
817 |
RECEIVE_COMMAND(PACKET_SERVER_FRAME), |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
818 |
RECEIVE_COMMAND(PACKET_SERVER_SYNC), |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
819 |
NULL, /*PACKET_CLIENT_ACK,*/ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
820 |
NULL, /*PACKET_CLIENT_COMMAND,*/ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
821 |
RECEIVE_COMMAND(PACKET_SERVER_COMMAND), |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
822 |
NULL, /*PACKET_CLIENT_CHAT,*/ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
823 |
RECEIVE_COMMAND(PACKET_SERVER_CHAT), |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
824 |
NULL, /*PACKET_CLIENT_SET_PASSWORD,*/ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
825 |
NULL, /*PACKET_CLIENT_SET_NAME,*/ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
826 |
NULL, /*PACKET_CLIENT_QUIT,*/ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
827 |
NULL, /*PACKET_CLIENT_ERROR,*/ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
828 |
RECEIVE_COMMAND(PACKET_SERVER_QUIT), |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
829 |
RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT), |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
830 |
RECEIVE_COMMAND(PACKET_SERVER_SHUTDOWN), |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
831 |
RECEIVE_COMMAND(PACKET_SERVER_NEWGAME), |
1026
5b2681cad645
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
832 |
RECEIVE_COMMAND(PACKET_SERVER_RCON), |
5b2681cad645
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1013
diff
changeset
|
833 |
NULL, /*PACKET_CLIENT_RCON,*/ |
6123
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
834 |
RECEIVE_COMMAND(PACKET_SERVER_CHECK_NEWGRFS), |
87aa45c64f8f
(svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents:
5954
diff
changeset
|
835 |
NULL, /*PACKET_CLIENT_NEWGRFS_CHECKED,*/ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
836 |
}; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
837 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
838 |
// If this fails, check the array above with network_data.h |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
839 |
assert_compile(lengthof(_network_client_packet) == PACKET_END); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
840 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
841 |
// Is called after a client is connected to the server |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6169
diff
changeset
|
842 |
void NetworkClient_Connected() |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
843 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
844 |
// Set the frame-counter to 0 so nothing happens till we are ready |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
845 |
_frame_counter = 0; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
846 |
_frame_counter_server = 0; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
847 |
last_ack_frame = 0; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
848 |
// Request the game-info |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
849 |
SEND_COMMAND(PACKET_CLIENT_JOIN)(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
850 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
851 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
852 |
// Reads the packets from the socket-stream, if available |
5875
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5860
diff
changeset
|
853 |
NetworkRecvStatus NetworkClient_ReadPackets(NetworkTCPSocketHandler *cs) |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
854 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
855 |
Packet *p; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
856 |
NetworkRecvStatus res = NETWORK_RECV_STATUS_OKAY; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
857 |
|
6153
2ecdbf81caa7
(svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents:
6151
diff
changeset
|
858 |
while (res == NETWORK_RECV_STATUS_OKAY && (p = cs->Recv_Packet(&res)) != NULL) { |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
859 |
byte type = p->Recv_uint8(); |
4880
0708f34e3586
(svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents:
4878
diff
changeset
|
860 |
if (type < PACKET_END && _network_client_packet[type] != NULL && !MY_CLIENT->has_quit) { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
861 |
res = _network_client_packet[type](p); |
2026 | 862 |
} else { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
863 |
res = NETWORK_RECV_STATUS_MALFORMED_PACKET; |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5564
diff
changeset
|
864 |
DEBUG(net, 0, "[client] received invalid packet type %d", type); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
865 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
866 |
|
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6123
diff
changeset
|
867 |
delete p; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
868 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
869 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
870 |
return res; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
871 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
872 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
873 |
#endif /* ENABLE_NETWORK */ |