author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1317 | 3c90086ff34f |
child 1602 | 79f98b4b83fc |
permissions | -rw-r--r-- |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1 |
#include "stdafx.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1093
diff
changeset
|
2 |
#include "debug.h" |
1317
3c90086ff34f
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
1309
diff
changeset
|
3 |
#include "string.h" |
1309
4403a69da4f8
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1299
diff
changeset
|
4 |
#include "strings.h" |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
5 |
#include "network_data.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
6 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
7 |
#ifdef ENABLE_NETWORK |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
8 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
9 |
#include "table/strings.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
10 |
#include "network_server.h" |
668
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
667
diff
changeset
|
11 |
#include "network_udp.h" |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
12 |
#include "console.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
13 |
#include "command.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
14 |
#include "gfx.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
15 |
#include "vehicle.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
16 |
#include "station.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
17 |
#include "settings.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
18 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
19 |
// This file handles all the server-commands |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
20 |
|
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
21 |
void NetworkHandleCommandQueue(NetworkClientState *cs); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
22 |
void NetworkPopulateCompanyInfo(void); |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
23 |
void NetworkSendPatchSettings(NetworkClientState *cs); |
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
24 |
|
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
25 |
extern const char _openttd_revision[]; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
26 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
27 |
// Is the network enabled? |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
28 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
29 |
// ********** |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
30 |
// Sending functions |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
31 |
// DEF_SERVER_SEND_COMMAND has parameter: NetworkClientState *cs |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
32 |
// ********** |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
33 |
|
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
34 |
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CLIENT_INFO)(NetworkClientState *cs, NetworkClientInfo *ci) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
35 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
36 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
37 |
// Packet: SERVER_CLIENT_INFO |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
38 |
// Function: Sends info about a client |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
39 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
40 |
// uint16: The index of the client (always unique on a server. 1 = server) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
41 |
// uint8: As which player the client is playing |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
42 |
// String: The name of the client |
602
f0afb4018788
(svn r1026) -Add: [Network] Added unique id, so in network, each client has an
truelight
parents:
571
diff
changeset
|
43 |
// String: The unique id of the client |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
44 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
45 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
46 |
Packet *p; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
47 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
48 |
if (ci->client_index != NETWORK_EMPTY_INDEX) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
49 |
p = NetworkSend_Init(PACKET_SERVER_CLIENT_INFO); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
50 |
NetworkSend_uint16(p, ci->client_index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
51 |
NetworkSend_uint8 (p, ci->client_playas); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
52 |
NetworkSend_string(p, ci->client_name); |
602
f0afb4018788
(svn r1026) -Add: [Network] Added unique id, so in network, each client has an
truelight
parents:
571
diff
changeset
|
53 |
NetworkSend_string(p, ci->unique_id); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
54 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
55 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
56 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
57 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
58 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
59 |
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
60 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
61 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
62 |
// Packet: SERVER_COMPANY_INFO |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
63 |
// Function: Sends info about the companies |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
64 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
65 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
66 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
67 |
int i; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
68 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
69 |
Player *player; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
70 |
Packet *p; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
71 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
72 |
byte active = 0; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
73 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
74 |
FOR_ALL_PLAYERS(player) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
75 |
if (player->is_active) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
76 |
active++; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
77 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
78 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
79 |
if (active == 0) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
80 |
Packet *p = NetworkSend_Init(PACKET_SERVER_COMPANY_INFO); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
81 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
82 |
NetworkSend_uint8 (p, NETWORK_COMPANY_INFO_VERSION); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
83 |
NetworkSend_uint8 (p, active); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
84 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
85 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
86 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
87 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
88 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
89 |
NetworkPopulateCompanyInfo(); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
90 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
91 |
FOR_ALL_PLAYERS(player) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
92 |
if (!player->is_active) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
93 |
continue; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
94 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
95 |
p = NetworkSend_Init(PACKET_SERVER_COMPANY_INFO); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
96 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
97 |
NetworkSend_uint8 (p, NETWORK_COMPANY_INFO_VERSION); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
98 |
NetworkSend_uint8 (p, active); |
734
f4ad2f5805fd
(svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents:
733
diff
changeset
|
99 |
NetworkSend_uint8 (p, player->index); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
100 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
101 |
NetworkSend_string(p, _network_player_info[player->index].company_name); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
102 |
NetworkSend_uint8 (p, _network_player_info[player->index].inaugurated_year); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
103 |
NetworkSend_uint64(p, _network_player_info[player->index].company_value); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
104 |
NetworkSend_uint64(p, _network_player_info[player->index].money); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
105 |
NetworkSend_uint64(p, _network_player_info[player->index].income); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
106 |
NetworkSend_uint16(p, _network_player_info[player->index].performance); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
107 |
|
1011
933efc472c62
(svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents:
970
diff
changeset
|
108 |
/* Send 1 if there is a passord for the company else send 0 */ |
933efc472c62
(svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents:
970
diff
changeset
|
109 |
if (_network_player_info[player->index].password[0] != '\0') { |
933efc472c62
(svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents:
970
diff
changeset
|
110 |
NetworkSend_uint8 (p, 1); |
933efc472c62
(svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents:
970
diff
changeset
|
111 |
} else { |
933efc472c62
(svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents:
970
diff
changeset
|
112 |
NetworkSend_uint8 (p, 0); |
933efc472c62
(svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents:
970
diff
changeset
|
113 |
} |
933efc472c62
(svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents:
970
diff
changeset
|
114 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
115 |
for (i = 0; i < NETWORK_VEHICLE_TYPES; i++) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
116 |
NetworkSend_uint16(p, _network_player_info[player->index].num_vehicle[i]); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
117 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
118 |
for (i = 0; i < NETWORK_STATION_TYPES; i++) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
119 |
NetworkSend_uint16(p, _network_player_info[player->index].num_station[i]); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
120 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
121 |
if (_network_player_info[player->index].players[0] == '\0') |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
122 |
NetworkSend_string(p, "<none>"); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
123 |
else |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
124 |
NetworkSend_string(p, _network_player_info[player->index].players); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
125 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
126 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
127 |
} |
734
f4ad2f5805fd
(svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents:
733
diff
changeset
|
128 |
|
f4ad2f5805fd
(svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents:
733
diff
changeset
|
129 |
p = NetworkSend_Init(PACKET_SERVER_COMPANY_INFO); |
f4ad2f5805fd
(svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents:
733
diff
changeset
|
130 |
|
f4ad2f5805fd
(svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents:
733
diff
changeset
|
131 |
NetworkSend_uint8 (p, NETWORK_COMPANY_INFO_VERSION); |
f4ad2f5805fd
(svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents:
733
diff
changeset
|
132 |
NetworkSend_uint8 (p, 0); |
f4ad2f5805fd
(svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents:
733
diff
changeset
|
133 |
|
f4ad2f5805fd
(svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents:
733
diff
changeset
|
134 |
NetworkSend_Packet(p, cs); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
135 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
136 |
|
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
137 |
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkClientState *cs, NetworkErrorCode error) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
138 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
139 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
140 |
// Packet: SERVER_ERROR |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
141 |
// Function: The client made an error |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
142 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
143 |
// uint8: ErrorID (see network_data.h, NetworkErrorCode) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
144 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
145 |
|
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
146 |
NetworkClientState *new_cs; |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
147 |
char str[100]; |
793
7bee9006a465
(svn r1263) -Fix: [Network] Client-names are limited (serverside) to 25 chars
truelight
parents:
785
diff
changeset
|
148 |
char client_name[NETWORK_CLIENT_NAME_LENGTH]; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
149 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
150 |
Packet *p = NetworkSend_Init(PACKET_SERVER_ERROR); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
151 |
NetworkSend_uint8(p, error); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
152 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
153 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
154 |
// Only send when the current client was in game |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
155 |
if (cs->status > STATUS_AUTH) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
156 |
NetworkGetClientName(client_name, sizeof(client_name), cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
157 |
|
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
158 |
GetString(str, STR_NETWORK_ERR_CLIENT_GENERAL + error); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
159 |
|
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
160 |
DEBUG(net, 2)("[NET] %s made an error (%s) and his connection is closed", client_name, str); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
161 |
|
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
162 |
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, str); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
163 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
164 |
FOR_ALL_CLIENTS(new_cs) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
165 |
if (new_cs->status > STATUS_AUTH && new_cs != cs) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
166 |
// Some errors we filter to a more general error. Clients don't have to know the real |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
167 |
// reason a joining failed. |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
168 |
if (error == NETWORK_ERROR_NOT_AUTHORIZED || error == NETWORK_ERROR_NOT_EXPECTED || error == NETWORK_ERROR_WRONG_REVISION) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
169 |
error = NETWORK_ERROR_ILLEGAL_PACKET; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
170 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
171 |
SEND_COMMAND(PACKET_SERVER_ERROR_QUIT)(new_cs, cs->index, error); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
172 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
173 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
174 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
175 |
DEBUG(net, 2)("[NET] Clientno %d has made an error and his connection is closed", cs->index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
176 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
177 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
178 |
cs->quited = true; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
179 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
180 |
// Make sure the data get's there before we close the connection |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
181 |
NetworkSend_Packets(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
182 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
183 |
// The client made a mistake, so drop his connection now! |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
184 |
NetworkCloseClient(cs); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
185 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
186 |
|
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
187 |
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_NEED_PASSWORD)(NetworkClientState *cs, NetworkPasswordType type) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
188 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
189 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
190 |
// Packet: SERVER_NEED_PASSWORD |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
191 |
// Function: Indication to the client that the server needs a password |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
192 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
193 |
// uint8: Type of password |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
194 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
195 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
196 |
Packet *p = NetworkSend_Init(PACKET_SERVER_NEED_PASSWORD); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
197 |
NetworkSend_uint8(p, type); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
198 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
199 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
200 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
201 |
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WELCOME) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
202 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
203 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
204 |
// Packet: SERVER_WELCOME |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
205 |
// Function: The client is joined and ready to receive his map |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
206 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
207 |
// uint16: Own ClientID |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
208 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
209 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
210 |
Packet *p; |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
211 |
NetworkClientState *new_cs; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
212 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
213 |
// Invalid packet when status is AUTH or higher |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
214 |
if (cs->status >= STATUS_AUTH) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
215 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
216 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
217 |
cs->status = STATUS_AUTH; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
218 |
_network_game_info.clients_on++; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
219 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
220 |
p = NetworkSend_Init(PACKET_SERVER_WELCOME); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
221 |
NetworkSend_uint16(p, cs->index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
222 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
223 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
224 |
// Transmit info about all the active clients |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
225 |
FOR_ALL_CLIENTS(new_cs) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
226 |
if (new_cs != cs && new_cs->status > STATUS_AUTH) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
227 |
SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(cs, DEREF_CLIENT_INFO(new_cs)); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
228 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
229 |
// Also send the info of the server |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
230 |
SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(cs, NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX)); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
231 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
232 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
233 |
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WAIT) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
234 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
235 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
236 |
// Packet: PACKET_SERVER_WAIT |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
237 |
// Function: The client can not receive the map at the moment because |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
238 |
// someone else is already receiving the map |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
239 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
240 |
// uint8: Clients awaiting map |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
241 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
242 |
int waiting = 0; |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
243 |
NetworkClientState *new_cs; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
244 |
Packet *p; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
245 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
246 |
// Count how many players are waiting in the queue |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
247 |
FOR_ALL_CLIENTS(new_cs) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
248 |
if (new_cs->status == STATUS_MAP_WAIT) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
249 |
waiting++; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
250 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
251 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
252 |
p = NetworkSend_Init(PACKET_SERVER_WAIT); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
253 |
NetworkSend_uint8(p, waiting); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
254 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
255 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
256 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
257 |
// This sends the map to the client |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
258 |
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
259 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
260 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
261 |
// Packet: SERVER_MAP |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
262 |
// Function: Sends the map to the client, or a part of it (it is splitted in |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
263 |
// a lot of multiple packets) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
264 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
265 |
// uint8: packet-type (MAP_PACKET_START, MAP_PACKET_NORMAL and MAP_PACKET_END) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
266 |
// if MAP_PACKET_START: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
267 |
// uint32: The current FrameCounter |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
268 |
// if MAP_PACKET_NORMAL: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
269 |
// piece of the map (till max-size of packet) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
270 |
// if MAP_PACKET_END: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
271 |
// uint32: seed0 of player |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
272 |
// uint32: seed1 of player |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
273 |
// last 2 are repeated MAX_PLAYERS time |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
274 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
275 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
276 |
char filename[256]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
277 |
static FILE *file_pointer; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
278 |
static uint sent_packets; // How many packets we did send succecfully last time |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
279 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
280 |
if (cs->status < STATUS_AUTH) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
281 |
// Illegal call, return error and ignore the packet |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
282 |
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_AUTHORIZED); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
283 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
284 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
285 |
if (cs->status == STATUS_AUTH) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
286 |
Packet *p; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
287 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
288 |
// Make a dump of the current game |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
289 |
sprintf(filename, "%s%snetwork_server.tmp", _path.autosave_dir, PATHSEP); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
290 |
if (SaveOrLoad(filename, SL_SAVE) != SL_OK) error("network savedump failed"); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
291 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
292 |
file_pointer = fopen(filename, "rb"); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
293 |
fseek(file_pointer, 0, SEEK_END); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
294 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
295 |
// Now send the _frame_counter and how many packets are coming |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
296 |
p = NetworkSend_Init(PACKET_SERVER_MAP); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
297 |
NetworkSend_uint8(p, MAP_PACKET_START); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
298 |
NetworkSend_uint32(p, _frame_counter); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
299 |
NetworkSend_uint32(p, ftell(file_pointer)); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
300 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
301 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
302 |
fseek(file_pointer, 0, SEEK_SET); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
303 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
304 |
sent_packets = 4; // We start with trying 4 packets |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
305 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
306 |
cs->status = STATUS_MAP; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
307 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
308 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
309 |
if (cs->status == STATUS_MAP) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
310 |
uint i; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
311 |
int res; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
312 |
for (i = 0; i < sent_packets; i++) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
313 |
Packet *p = NetworkSend_Init(PACKET_SERVER_MAP); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
314 |
NetworkSend_uint8(p, MAP_PACKET_NORMAL); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
315 |
res = fread(p->buffer + p->size, 1, SEND_MTU - p->size, file_pointer); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
316 |
if (ferror(file_pointer)) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
317 |
error("Error reading temporary network savegame!"); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
318 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
319 |
p->size += res; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
320 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
321 |
if (feof(file_pointer)) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
322 |
// Done reading! |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
323 |
int i; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
324 |
Packet *p; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
325 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
326 |
// XXX - Delete this when patch-settings are saved in-game |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
327 |
NetworkSendPatchSettings(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
328 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
329 |
p = NetworkSend_Init(PACKET_SERVER_MAP); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
330 |
NetworkSend_uint8(p, MAP_PACKET_END); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
331 |
// Send the player_seeds in this packet |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
332 |
for (i = 0; i < MAX_PLAYERS; i++) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
333 |
NetworkSend_uint32(p, _player_seeds[i][0]); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
334 |
NetworkSend_uint32(p, _player_seeds[i][1]); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
335 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
336 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
337 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
338 |
// Set the status to DONE_MAP, no we will wait for the client |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
339 |
// to send it is ready (maybe that happens like never ;)) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
340 |
cs->status = STATUS_DONE_MAP; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
341 |
fclose(file_pointer); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
342 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
343 |
{ |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
344 |
NetworkClientState *new_cs; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
345 |
bool new_map_client = false; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
346 |
// Check if there is a client waiting for receiving the map |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
347 |
// and start sending him the map |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
348 |
FOR_ALL_CLIENTS(new_cs) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
349 |
if (new_cs->status == STATUS_MAP_WAIT) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
350 |
// Check if we already have a new client to send the map to |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
351 |
if (!new_map_client) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
352 |
// If not, this client will get the map |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
353 |
new_cs->status = STATUS_AUTH; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
354 |
new_map_client = true; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
355 |
SEND_COMMAND(PACKET_SERVER_MAP)(new_cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
356 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
357 |
// Else, send the other clients how many clients are in front of them |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
358 |
SEND_COMMAND(PACKET_SERVER_WAIT)(new_cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
359 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
360 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
361 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
362 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
363 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
364 |
// There is no more data, so break the for |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
365 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
366 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
367 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
368 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
369 |
// Send all packets (forced) and check if we have send it all |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
370 |
NetworkSend_Packets(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
371 |
if (cs->packet_queue == NULL) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
372 |
// All are sent, increase the sent_packets |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
373 |
sent_packets *= 2; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
374 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
375 |
// Not everything is sent, decrease the sent_packets |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
376 |
if (sent_packets > 1) sent_packets /= 2; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
377 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
378 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
379 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
380 |
|
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
381 |
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_JOIN)(NetworkClientState *cs, uint16 client_index) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
382 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
383 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
384 |
// Packet: SERVER_JOIN |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
385 |
// Function: A client is joined (all active clients receive this after a |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
386 |
// PACKET_CLIENT_MAP_OK) Mostly what directly follows is a |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
387 |
// PACKET_SERVER_CLIENT_INFO |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
388 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
389 |
// uint16: Client-Index |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
390 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
391 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
392 |
Packet *p = NetworkSend_Init(PACKET_SERVER_JOIN); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
393 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
394 |
NetworkSend_uint16(p, client_index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
395 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
396 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
397 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
398 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
399 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
400 |
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_FRAME) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
401 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
402 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
403 |
// Packet: SERVER_FRAME |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
404 |
// Function: Sends the current frame-counter to the client |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
405 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
406 |
// uint32: Frame Counter |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
407 |
// uint32: Frame Counter Max (how far may the client walk before the server?) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
408 |
// [uint32: general-seed-1] |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
409 |
// [uint32: general-seed-2] |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
410 |
// (last two depends on compile-settings, and are not default settings) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
411 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
412 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
413 |
Packet *p = NetworkSend_Init(PACKET_SERVER_FRAME); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
414 |
NetworkSend_uint32(p, _frame_counter); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
415 |
NetworkSend_uint32(p, _frame_counter_max); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
416 |
#ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
417 |
NetworkSend_uint32(p, _sync_seed_1); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
418 |
#ifdef NETWORK_SEND_DOUBLE_SEED |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
419 |
NetworkSend_uint32(p, _sync_seed_2); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
420 |
#endif |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
421 |
#endif |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
422 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
423 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
424 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
425 |
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_SYNC) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
426 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
427 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
428 |
// Packet: SERVER_SYNC |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
429 |
// Function: Sends a sync-check to the client |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
430 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
431 |
// uint32: Frame Counter |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
432 |
// uint32: General-seed-1 |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
433 |
// [uint32: general-seed-2] |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
434 |
// (last one depends on compile-settings, and are not default settings) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
435 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
436 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
437 |
Packet *p = NetworkSend_Init(PACKET_SERVER_SYNC); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
438 |
NetworkSend_uint32(p, _frame_counter); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
439 |
NetworkSend_uint32(p, _sync_seed_1); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
440 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
441 |
#ifdef NETWORK_SEND_DOUBLE_SEED |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
442 |
NetworkSend_uint32(p, _sync_seed_2); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
443 |
#endif |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
444 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
445 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
446 |
|
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
447 |
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMMAND)(NetworkClientState *cs, CommandPacket *cp) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
448 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
449 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
450 |
// Packet: SERVER_COMMAND |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
451 |
// Function: Sends a DoCommand to the client |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
452 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
453 |
// uint8: PlayerID (0..MAX_PLAYERS-1) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
454 |
// uint32: CommandID (see command.h) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
455 |
// uint32: P1 (free variables used in DoCommand) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
456 |
// uint32: P2 |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
457 |
// uint32: Tile |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
458 |
// uint32: decode_params |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
459 |
// 10 times the last one (lengthof(cp->dp)) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
460 |
// uint8: CallBackID (see callback_table.c) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
461 |
// uint32: Frame of execution |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
462 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
463 |
|
959
e6a3bbda610f
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
903
diff
changeset
|
464 |
uint i; |
571
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
465 |
char *dparam_char; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
466 |
Packet *p = NetworkSend_Init(PACKET_SERVER_COMMAND); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
467 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
468 |
NetworkSend_uint8(p, cp->player); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
469 |
NetworkSend_uint32(p, cp->cmd); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
470 |
NetworkSend_uint32(p, cp->p1); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
471 |
NetworkSend_uint32(p, cp->p2); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
472 |
NetworkSend_uint32(p, cp->tile); |
571
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
473 |
/* We are going to send them byte by byte, because dparam is misused |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
474 |
for chars (if it is used), and else we have a BigEndian / LittleEndian |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
475 |
problem.. we should fix the misuse of dparam... -- TrueLight */ |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
476 |
dparam_char = (char *)&cp->dp[0]; |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
477 |
for (i = 0; i < lengthof(cp->dp) * 4; i++) { |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
478 |
NetworkSend_uint8(p, *dparam_char); |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
479 |
dparam_char++; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
480 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
481 |
NetworkSend_uint8(p, cp->callback); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
482 |
NetworkSend_uint32(p, cp->frame); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
483 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
484 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
485 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
486 |
|
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
487 |
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHAT)(NetworkClientState *cs, NetworkAction action, uint16 client_index, bool self_send, const char *msg) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
488 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
489 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
490 |
// Packet: SERVER_CHAT |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
491 |
// Function: Sends a chat-packet to the client |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
492 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
493 |
// uint8: ActionID (see network_data.h, NetworkAction) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
494 |
// uint16: Client-index |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
495 |
// String: Message (max MAX_TEXT_MSG_LEN) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
496 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
497 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
498 |
Packet *p = NetworkSend_Init(PACKET_SERVER_CHAT); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
499 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
500 |
NetworkSend_uint8(p, action); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
501 |
NetworkSend_uint16(p, client_index); |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
502 |
NetworkSend_uint8(p, self_send); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
503 |
NetworkSend_string(p, msg); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
504 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
505 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
506 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
507 |
|
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
508 |
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR_QUIT)(NetworkClientState *cs, uint16 client_index, NetworkErrorCode errorno) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
509 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
510 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
511 |
// Packet: SERVER_ERROR_QUIT |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
512 |
// Function: One of the clients made an error and is quiting the game |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
513 |
// This packet informs the other clients of that. |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
514 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
515 |
// uint16: Client-index |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
516 |
// uint8: ErrorID (see network_data.h, NetworkErrorCode) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
517 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
518 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
519 |
Packet *p = NetworkSend_Init(PACKET_SERVER_ERROR_QUIT); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
520 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
521 |
NetworkSend_uint16(p, client_index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
522 |
NetworkSend_uint8(p, errorno); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
523 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
524 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
525 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
526 |
|
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
527 |
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_QUIT)(NetworkClientState *cs, uint16 client_index, const char *leavemsg) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
528 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
529 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
530 |
// Packet: SERVER_ERROR_QUIT |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
531 |
// Function: A client left the game, and this packets informs the other clients |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
532 |
// of that. |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
533 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
534 |
// uint16: Client-index |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
535 |
// String: leave-message |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
536 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
537 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
538 |
Packet *p = NetworkSend_Init(PACKET_SERVER_QUIT); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
539 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
540 |
NetworkSend_uint16(p, client_index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
541 |
NetworkSend_string(p, leavemsg); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
542 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
543 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
544 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
545 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
546 |
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_SHUTDOWN) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
547 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
548 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
549 |
// Packet: SERVER_SHUTDOWN |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
550 |
// Function: Let the clients know that the server is closing |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
551 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
552 |
// <none> |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
553 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
554 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
555 |
Packet *p = NetworkSend_Init(PACKET_SERVER_SHUTDOWN); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
556 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
557 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
558 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
559 |
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_NEWGAME) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
560 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
561 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
562 |
// Packet: PACKET_SERVER_NEWGAME |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
563 |
// Function: Let the clients know that the server is loading a new map |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
564 |
// Data: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
565 |
// <none> |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
566 |
// |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
567 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
568 |
Packet *p = NetworkSend_Init(PACKET_SERVER_NEWGAME); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
569 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
570 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
571 |
|
1026
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
572 |
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_RCON)(NetworkClientState *cs, uint16 color, const char *command) |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
573 |
{ |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
574 |
Packet *p = NetworkSend_Init(PACKET_SERVER_RCON); |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
575 |
|
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
576 |
NetworkSend_uint16(p, color); |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
577 |
NetworkSend_string(p, command); |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
578 |
NetworkSend_Packet(p, cs); |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
579 |
} |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
580 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
581 |
// ********** |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
582 |
// Receiving functions |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
583 |
// DEF_SERVER_RECEIVE_COMMAND has parameter: NetworkClientState *cs, Packet *p |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
584 |
// ********** |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
585 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
586 |
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMPANY_INFO) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
587 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
588 |
SEND_COMMAND(PACKET_SERVER_COMPANY_INFO)(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
589 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
590 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
591 |
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
592 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
593 |
char name[NETWORK_NAME_LENGTH]; |
602
f0afb4018788
(svn r1026) -Add: [Network] Added unique id, so in network, each client has an
truelight
parents:
571
diff
changeset
|
594 |
char unique_id[NETWORK_NAME_LENGTH]; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
595 |
NetworkClientInfo *ci; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
596 |
char test_name[NETWORK_NAME_LENGTH]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
597 |
byte playas; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
598 |
NetworkLanguage client_lang; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
599 |
char client_revision[NETWORK_REVISION_LENGTH]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
600 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
601 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
602 |
NetworkRecv_string(cs, p, client_revision, sizeof(client_revision)); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
603 |
|
692
b9e99d207ca6
(svn r1136) -Fix: [Network] Revision check on windows-servers is working now
truelight
parents:
690
diff
changeset
|
604 |
#if defined(WITH_REV) || defined(WITH_REV_HACK) |
659
a9733f856cd0
(svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
darkvater
parents:
656
diff
changeset
|
605 |
// Check if the client has revision control enabled |
a9733f856cd0
(svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
darkvater
parents:
656
diff
changeset
|
606 |
if (strncmp(NOREV_STRING, client_revision, sizeof(client_revision)) != 0) { |
624
f834e073c2dc
(svn r1054) -Fix: [Network] Redid revision 1024, only a bit more nice this time
truelight
parents:
618
diff
changeset
|
607 |
if (strncmp(_network_game_info.server_revision, client_revision, sizeof(_network_game_info.server_revision) - 1) != 0) { |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
608 |
// Different revisions!! |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
609 |
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_WRONG_REVISION); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
610 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
611 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
612 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
613 |
} |
663
80c66fd07863
(svn r1098) -Fix: server without revision build doesn't care about the client's version. Also moved all revision things where it belongs (network.c)
darkvater
parents:
662
diff
changeset
|
614 |
#endif |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
615 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
616 |
NetworkRecv_string(cs, p, name, sizeof(name)); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
617 |
playas = NetworkRecv_uint8(cs, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
618 |
client_lang = NetworkRecv_uint8(cs, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
619 |
NetworkRecv_string(cs, p, unique_id, sizeof(unique_id)); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
620 |
|
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
621 |
if (cs->quited) |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
622 |
return; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
623 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
624 |
// Check if someone else already has that name |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
625 |
snprintf(test_name, sizeof(test_name), "%s", name); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
626 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
627 |
if (test_name[0] == '\0') { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
628 |
// We need a valid name.. make it Player |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
629 |
snprintf(test_name, sizeof(test_name), "Player"); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
630 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
631 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
632 |
if (!NetworkFindName(test_name)) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
633 |
// We could not create a name for this player |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
634 |
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NAME_IN_USE); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
635 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
636 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
637 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
638 |
ci = DEREF_CLIENT_INFO(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
639 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
640 |
snprintf(ci->client_name, sizeof(ci->client_name), "%s", test_name); |
602
f0afb4018788
(svn r1026) -Add: [Network] Added unique id, so in network, each client has an
truelight
parents:
571
diff
changeset
|
641 |
snprintf(ci->unique_id, sizeof(ci->unique_id), "%s", unique_id); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
642 |
ci->client_playas = playas; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
643 |
ci->client_lang = client_lang; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
644 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
645 |
// We now want a password from the client |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
646 |
// else we do not allow him in! |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
647 |
if (_network_game_info.use_password) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
648 |
SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_GAME_PASSWORD); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
649 |
else { |
1045
01edb6b0cbd6
(svn r1546) -Fix: possible buffer-overflow in network
truelight
parents:
1026
diff
changeset
|
650 |
if (ci->client_playas > 0 && ci->client_playas <= MAX_PLAYERS && _network_player_info[ci->client_playas - 1].password[0] != '\0') { |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
651 |
SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_COMPANY_PASSWORD); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
652 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
653 |
else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
654 |
SEND_COMMAND(PACKET_SERVER_WELCOME)(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
655 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
656 |
} |
690
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
657 |
|
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
658 |
/* Make sure companies to who people try to join are not autocleaned */ |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
659 |
if (playas >= 1 && playas <= MAX_PLAYERS) |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
660 |
_network_player_info[playas-1].months_empty = 0; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
661 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
662 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
663 |
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_PASSWORD) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
664 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
665 |
NetworkPasswordType type; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
666 |
char password[NETWORK_PASSWORD_LENGTH]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
667 |
NetworkClientInfo *ci; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
668 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
669 |
type = NetworkRecv_uint8(cs, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
670 |
NetworkRecv_string(cs, p, password, sizeof(password)); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
671 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
672 |
if (cs->status == STATUS_INACTIVE && type == NETWORK_GAME_PASSWORD) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
673 |
// Check game-password |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
674 |
if (strncmp(password, _network_game_info.server_password, sizeof(password)) != 0) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
675 |
// Password is invalid |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
676 |
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_WRONG_PASSWORD); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
677 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
678 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
679 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
680 |
ci = DEREF_CLIENT_INFO(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
681 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
682 |
if (ci->client_playas <= MAX_PLAYERS && _network_player_info[ci->client_playas - 1].password[0] != '\0') { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
683 |
SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_COMPANY_PASSWORD); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
684 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
685 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
686 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
687 |
// Valid password, allow user |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
688 |
SEND_COMMAND(PACKET_SERVER_WELCOME)(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
689 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
690 |
} else if (cs->status == STATUS_INACTIVE && type == NETWORK_COMPANY_PASSWORD) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
691 |
ci = DEREF_CLIENT_INFO(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
692 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
693 |
if (strncmp(password, _network_player_info[ci->client_playas - 1].password, sizeof(password)) != 0) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
694 |
// Password is invalid |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
695 |
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_WRONG_PASSWORD); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
696 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
697 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
698 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
699 |
SEND_COMMAND(PACKET_SERVER_WELCOME)(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
700 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
701 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
702 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
703 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
704 |
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
705 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
706 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
707 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
708 |
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_GETMAP) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
709 |
{ |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
710 |
NetworkClientState *new_cs; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
711 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
712 |
// The client was never joined.. so this is impossible, right? |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
713 |
// Ignore the packet, give the client a warning, and close his connection |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
714 |
if (cs->status < STATUS_AUTH || cs->quited) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
715 |
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_AUTHORIZED); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
716 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
717 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
718 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
719 |
// Check if someone else is receiving the map |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
720 |
FOR_ALL_CLIENTS(new_cs) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
721 |
if (new_cs->status == STATUS_MAP) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
722 |
// Tell the new client to wait |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
723 |
cs->status = STATUS_MAP_WAIT; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
724 |
SEND_COMMAND(PACKET_SERVER_WAIT)(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
725 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
726 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
727 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
728 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
729 |
// We receive a request to upload the map.. give it to the client! |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
730 |
SEND_COMMAND(PACKET_SERVER_MAP)(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
731 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
732 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
733 |
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_MAP_OK) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
734 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
735 |
// Client has the map, now start syncing |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
736 |
if (cs->status == STATUS_DONE_MAP && !cs->quited) { |
793
7bee9006a465
(svn r1263) -Fix: [Network] Client-names are limited (serverside) to 25 chars
truelight
parents:
785
diff
changeset
|
737 |
char client_name[NETWORK_CLIENT_NAME_LENGTH]; |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
738 |
NetworkClientState *new_cs; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
739 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
740 |
NetworkGetClientName(client_name, sizeof(client_name), cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
741 |
|
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
742 |
NetworkTextMessage(NETWORK_ACTION_JOIN, 1, false, client_name, ""); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
743 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
744 |
// Mark the client as pre-active, and wait for an ACK |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
745 |
// so we know he is done loading and in sync with us |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
746 |
cs->status = STATUS_PRE_ACTIVE; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
747 |
NetworkHandleCommandQueue(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
748 |
SEND_COMMAND(PACKET_SERVER_FRAME)(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
749 |
SEND_COMMAND(PACKET_SERVER_SYNC)(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
750 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
751 |
// This is the frame the client receives |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
752 |
// we need it later on to make sure the client is not too slow |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
753 |
cs->last_frame = _frame_counter; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
754 |
cs->last_frame_server = _frame_counter; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
755 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
756 |
FOR_ALL_CLIENTS(new_cs) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
757 |
if (new_cs->status > STATUS_AUTH) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
758 |
SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(new_cs, DEREF_CLIENT_INFO(cs)); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
759 |
SEND_COMMAND(PACKET_SERVER_JOIN)(new_cs, cs->index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
760 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
761 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
762 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
763 |
// Wrong status for this packet, give a warning to client, and close connection |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
764 |
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
765 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
766 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
767 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
768 |
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
769 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
770 |
// The client has done a command and wants us to handle it |
959
e6a3bbda610f
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
903
diff
changeset
|
771 |
uint i; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
772 |
byte callback; |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
773 |
NetworkClientState *new_cs; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
774 |
NetworkClientInfo *ci; |
571
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
775 |
char *dparam_char; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
776 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
777 |
CommandPacket *cp = malloc(sizeof(CommandPacket)); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
778 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
779 |
// The client was never joined.. so this is impossible, right? |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
780 |
// Ignore the packet, give the client a warning, and close his connection |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
781 |
if (cs->status < STATUS_DONE_MAP || cs->quited) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
782 |
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
783 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
784 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
785 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
786 |
cp->player = NetworkRecv_uint8(cs, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
787 |
cp->cmd = NetworkRecv_uint32(cs, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
788 |
cp->p1 = NetworkRecv_uint32(cs, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
789 |
cp->p2 = NetworkRecv_uint32(cs, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
790 |
cp->tile = NetworkRecv_uint32(cs, p); |
571
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
791 |
/* We are going to send them byte by byte, because dparam is misused |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
792 |
for chars (if it is used), and else we have a BigEndian / LittleEndian |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
793 |
problem.. we should fix the misuse of dparam... -- TrueLight */ |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
794 |
dparam_char = (char *)&cp->dp[0]; |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
795 |
for (i = 0; i < lengthof(cp->dp) * 4; i++) { |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
796 |
*dparam_char = NetworkRecv_uint8(cs, p); |
571
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
797 |
dparam_char++; |
530e8e994d55
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
truelight
parents:
543
diff
changeset
|
798 |
} |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
799 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
800 |
callback = NetworkRecv_uint8(cs, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
801 |
|
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
802 |
if (cs->quited) |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
803 |
return; |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
804 |
|
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
805 |
/* Check if cp->cmd is valid */ |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
806 |
if (!IsValidCommand(cp->cmd)) { |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
807 |
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
808 |
return; |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
809 |
} |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
810 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
811 |
ci = DEREF_CLIENT_INFO(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
812 |
// Only CMD_PLAYER_CTRL is always allowed, for the rest, playas needs |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
813 |
// to match the player in the packet |
686
719f01ca0175
(svn r1127) -Fix: [Network] Protect the network against an illegal PLAYER_CTRL (in
truelight
parents:
668
diff
changeset
|
814 |
if (!(cp->cmd == CMD_PLAYER_CTRL && cp->p1 == 0) && ci->client_playas-1 != cp->player) { |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
815 |
// The player did a command with the wrong player_id.. bad!! |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
816 |
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_PLAYER_MISMATCH); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
817 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
818 |
} |
748
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
819 |
switch (cp->cmd) { |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
820 |
/* Player_ctrl is not always allowed */ |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
821 |
case CMD_PLAYER_CTRL: |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
822 |
{ |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
823 |
/* cp->p1 == 0, is allowed */ |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
824 |
if (cp->p1 == 0) { |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
825 |
// UGLY! p2 is mis-used to get the client-id in CmdPlayerCtrl |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
826 |
cp->p2 = cs - _clients; |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
827 |
} else { |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
828 |
/* The rest are cheats */ |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
829 |
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_CHEATER); |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
830 |
return; |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
831 |
} |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
832 |
} break; |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
833 |
|
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
834 |
/* Don't allow those commands if server == advertising (considered cheating) */ |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
835 |
case CMD_MONEY_CHEAT: |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
836 |
{ |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
837 |
if (_network_advertise) { |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
838 |
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_CHEATER); |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
839 |
return; |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
840 |
} |
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
734
diff
changeset
|
841 |
} break; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
842 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
843 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
844 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
845 |
// The frame can be executed in the same frame as the next frame-packet |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
846 |
// That frame just before that frame is saved in _frame_counter_max |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
847 |
cp->frame = _frame_counter_max + 1; |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
848 |
cp->next = NULL; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
849 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
850 |
// Queue the command for the clients (are send at the end of the frame |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
851 |
// if they can handle it ;)) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
852 |
FOR_ALL_CLIENTS(new_cs) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
853 |
if (new_cs->status > STATUS_AUTH) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
854 |
// Callbacks are only send back to the client who sent them in the |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
855 |
// first place. This filters that out. |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
856 |
if (new_cs != cs) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
857 |
cp->callback = 0; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
858 |
else |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
859 |
cp->callback = callback; |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
860 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
861 |
NetworkAddCommandQueue(new_cs, cp); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
862 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
863 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
864 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
865 |
cp->callback = 0; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
866 |
// Queue the command on the server |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
867 |
if (_local_command_queue == NULL) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
868 |
_local_command_queue = cp; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
869 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
870 |
// Find last packet |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
871 |
CommandPacket *c = _local_command_queue; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
872 |
while (c->next != NULL) c = c->next; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
873 |
c->next = cp; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
874 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
875 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
876 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
877 |
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ERROR) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
878 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
879 |
// This packets means a client noticed an error and is reporting this |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
880 |
// to us. Display the error and report it to the other clients |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
881 |
NetworkClientState *new_cs; |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
882 |
byte errorno = NetworkRecv_uint8(cs, p); |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
883 |
char str[100]; |
793
7bee9006a465
(svn r1263) -Fix: [Network] Client-names are limited (serverside) to 25 chars
truelight
parents:
785
diff
changeset
|
884 |
char client_name[NETWORK_CLIENT_NAME_LENGTH]; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
885 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
886 |
// The client was never joined.. thank the client for the packet, but ignore it |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
887 |
if (cs->status < STATUS_DONE_MAP || cs->quited) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
888 |
cs->quited = true; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
889 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
890 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
891 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
892 |
NetworkGetClientName(client_name, sizeof(client_name), cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
893 |
|
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
894 |
GetString(str, STR_NETWORK_ERR_CLIENT_GENERAL + errorno); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
895 |
|
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
896 |
DEBUG(net, 2)("[NET] %s reported an error and is closing his connection (%s)", client_name, str); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
897 |
|
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
898 |
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, str); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
899 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
900 |
FOR_ALL_CLIENTS(new_cs) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
901 |
if (new_cs->status > STATUS_AUTH) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
902 |
SEND_COMMAND(PACKET_SERVER_ERROR_QUIT)(new_cs, cs->index, errorno); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
903 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
904 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
905 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
906 |
cs->quited = true; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
907 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
908 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
909 |
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_QUIT) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
910 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
911 |
// The client wants to leave. Display this and report it to the other |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
912 |
// clients. |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
913 |
NetworkClientState *new_cs; |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
914 |
char str[100]; |
793
7bee9006a465
(svn r1263) -Fix: [Network] Client-names are limited (serverside) to 25 chars
truelight
parents:
785
diff
changeset
|
915 |
char client_name[NETWORK_CLIENT_NAME_LENGTH]; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
916 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
917 |
// The client was never joined.. thank the client for the packet, but ignore it |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
918 |
if (cs->status < STATUS_DONE_MAP || cs->quited) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
919 |
cs->quited = true; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
920 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
921 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
922 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
923 |
NetworkRecv_string(cs, p, str, 100); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
924 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
925 |
NetworkGetClientName(client_name, sizeof(client_name), cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
926 |
|
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
927 |
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, str); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
928 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
929 |
FOR_ALL_CLIENTS(new_cs) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
930 |
if (new_cs->status > STATUS_AUTH) { |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
931 |
SEND_COMMAND(PACKET_SERVER_QUIT)(new_cs, cs->index, str); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
932 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
933 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
934 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
935 |
cs->quited = true; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
936 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
937 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
938 |
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ACK) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
939 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
940 |
// The client received the frame, make note of it |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
941 |
cs->last_frame = NetworkRecv_uint32(cs, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
942 |
// With those 2 values we can calculate the lag realtime |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
943 |
cs->last_frame_server = _frame_counter; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
944 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
945 |
// The client is now really active |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
946 |
if (cs->status == STATUS_PRE_ACTIVE) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
947 |
cs->status = STATUS_ACTIVE; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
948 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
949 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
950 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
951 |
|
839
107695a38570
(svn r1320) -Fix: fixed chat-bug (that from a certain moment, nobody could talk).. 1
truelight
parents:
826
diff
changeset
|
952 |
void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest, const char *msg, uint16 from_index) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
953 |
{ |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
954 |
NetworkClientState *cs; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
955 |
NetworkClientInfo *ci, *ci_own, *ci_to; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
956 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
957 |
switch (desttype) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
958 |
case DESTTYPE_CLIENT: |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
959 |
/* Are we sending to the server? */ |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
960 |
if (dest == NETWORK_SERVER_INDEX) { |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
961 |
ci = NetworkFindClientInfoFromIndex(from_index); |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
962 |
/* Display the text locally, and that is it */ |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
963 |
if (ci != NULL) |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
964 |
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas-1), false, ci->client_name, "%s", msg); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
965 |
} else { |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
966 |
/* Else find the client to send the message to */ |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
967 |
FOR_ALL_CLIENTS(cs) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
968 |
if (cs->index == dest) { |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
969 |
SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_index, false, msg); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
970 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
971 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
972 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
973 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
974 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
975 |
// Display the message locally (so you know you have sent it) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
976 |
if (from_index != dest) { |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
977 |
if (from_index == NETWORK_SERVER_INDEX) { |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
978 |
ci = NetworkFindClientInfoFromIndex(from_index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
979 |
ci_to = NetworkFindClientInfoFromIndex(dest); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
980 |
if (ci != NULL && ci_to != NULL) |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
981 |
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas-1), true, ci_to->client_name, "%s", msg); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
982 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
983 |
FOR_ALL_CLIENTS(cs) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
984 |
if (cs->index == from_index) { |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
985 |
SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, dest, true, msg); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
986 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
987 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
988 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
989 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
990 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
991 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
992 |
case DESTTYPE_PLAYER: { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
993 |
bool show_local = true; // If this is false, the message is already displayed |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
994 |
// on the client who did sent it. |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
995 |
/* Find all clients that belong to this player */ |
733
ac3d7e1b786e
(svn r1185) -Fix: [Network] Send to team now results in correct company on the sender
truelight
parents:
722
diff
changeset
|
996 |
ci_to = NULL; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
997 |
FOR_ALL_CLIENTS(cs) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
998 |
ci = DEREF_CLIENT_INFO(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
999 |
if (ci->client_playas == dest) { |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
1000 |
SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_index, false, msg); |
733
ac3d7e1b786e
(svn r1185) -Fix: [Network] Send to team now results in correct company on the sender
truelight
parents:
722
diff
changeset
|
1001 |
if (cs->index == from_index) { |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1002 |
show_local = false; |
733
ac3d7e1b786e
(svn r1185) -Fix: [Network] Send to team now results in correct company on the sender
truelight
parents:
722
diff
changeset
|
1003 |
} |
ac3d7e1b786e
(svn r1185) -Fix: [Network] Send to team now results in correct company on the sender
truelight
parents:
722
diff
changeset
|
1004 |
ci_to = ci; // Remember a client that is in the company for company-name |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1005 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1006 |
} |
733
ac3d7e1b786e
(svn r1185) -Fix: [Network] Send to team now results in correct company on the sender
truelight
parents:
722
diff
changeset
|
1007 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1008 |
ci = NetworkFindClientInfoFromIndex(from_index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1009 |
ci_own = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1010 |
if (ci != NULL && ci_own != NULL && ci_own->client_playas == dest) { |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
1011 |
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas-1), false, ci->client_name, "%s", msg); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1012 |
if (from_index == NETWORK_SERVER_INDEX) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1013 |
show_local = false; |
733
ac3d7e1b786e
(svn r1185) -Fix: [Network] Send to team now results in correct company on the sender
truelight
parents:
722
diff
changeset
|
1014 |
ci_to = ci; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1015 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1016 |
|
733
ac3d7e1b786e
(svn r1185) -Fix: [Network] Send to team now results in correct company on the sender
truelight
parents:
722
diff
changeset
|
1017 |
/* There is no such player */ |
ac3d7e1b786e
(svn r1185) -Fix: [Network] Send to team now results in correct company on the sender
truelight
parents:
722
diff
changeset
|
1018 |
if (ci_to == NULL) |
ac3d7e1b786e
(svn r1185) -Fix: [Network] Send to team now results in correct company on the sender
truelight
parents:
722
diff
changeset
|
1019 |
break; |
ac3d7e1b786e
(svn r1185) -Fix: [Network] Send to team now results in correct company on the sender
truelight
parents:
722
diff
changeset
|
1020 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1021 |
// Display the message locally (so you know you have sent it) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1022 |
if (ci != NULL && show_local) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1023 |
if (from_index == NETWORK_SERVER_INDEX) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1024 |
char name[NETWORK_NAME_LENGTH]; |
733
ac3d7e1b786e
(svn r1185) -Fix: [Network] Send to team now results in correct company on the sender
truelight
parents:
722
diff
changeset
|
1025 |
GetString(name, DEREF_PLAYER(ci_to->client_playas-1)->name_1); |
ac3d7e1b786e
(svn r1185) -Fix: [Network] Send to team now results in correct company on the sender
truelight
parents:
722
diff
changeset
|
1026 |
NetworkTextMessage(action, GetDrawStringPlayerColor(ci_own->client_playas-1), true, name, "%s", msg); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1027 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1028 |
FOR_ALL_CLIENTS(cs) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1029 |
if (cs->index == from_index) { |
779
9f1c1091b9c8
(svn r1246) -Fix: [ 1090099 ] Company-messages did crash the game, because
truelight
parents:
748
diff
changeset
|
1030 |
SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, ci_to->client_index, true, msg); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1031 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1032 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1033 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1034 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1035 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1036 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1037 |
default: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1038 |
DEBUG(net, 0)("[NET][Server] Received unknown destination type %d. Doing broadcast instead.\n"); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1039 |
/* fall-through to next case */ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1040 |
case DESTTYPE_BROADCAST: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1041 |
FOR_ALL_CLIENTS(cs) { |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
1042 |
SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_index, false, msg); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1043 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1044 |
ci = NetworkFindClientInfoFromIndex(from_index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1045 |
if (ci != NULL) |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
1046 |
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas-1), false, ci->client_name, "%s", msg); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1047 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1048 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1049 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1050 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1051 |
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_CHAT) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1052 |
{ |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
1053 |
NetworkAction action = NetworkRecv_uint8(cs, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
1054 |
DestType desttype = NetworkRecv_uint8(cs, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
1055 |
int dest = NetworkRecv_uint8(cs, p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1056 |
char msg[MAX_TEXT_MSG_LEN]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1057 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
1058 |
NetworkRecv_string(cs, p, msg, MAX_TEXT_MSG_LEN); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1059 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1060 |
NetworkServer_HandleChat(action, desttype, dest, msg, cs->index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1061 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1062 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1063 |
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_PASSWORD) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1064 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1065 |
char password[NETWORK_PASSWORD_LENGTH]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1066 |
NetworkClientInfo *ci; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1067 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
1068 |
NetworkRecv_string(cs, p, password, sizeof(password)); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1069 |
ci = DEREF_CLIENT_INFO(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1070 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1071 |
if (ci->client_playas <= MAX_PLAYERS) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1072 |
ttd_strlcpy(_network_player_info[ci->client_playas - 1].password, password, sizeof(_network_player_info[ci->client_playas - 1].password)); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1073 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1074 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1075 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1076 |
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_NAME) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1077 |
{ |
793
7bee9006a465
(svn r1263) -Fix: [Network] Client-names are limited (serverside) to 25 chars
truelight
parents:
785
diff
changeset
|
1078 |
char client_name[NETWORK_CLIENT_NAME_LENGTH]; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1079 |
NetworkClientInfo *ci; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1080 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
1081 |
NetworkRecv_string(cs, p, client_name, sizeof(client_name)); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1082 |
ci = DEREF_CLIENT_INFO(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1083 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
1084 |
if (cs->quited) |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
1085 |
return; |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
1086 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1087 |
if (ci != NULL) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1088 |
// Display change |
793
7bee9006a465
(svn r1263) -Fix: [Network] Client-names are limited (serverside) to 25 chars
truelight
parents:
785
diff
changeset
|
1089 |
if (NetworkFindName(client_name)) { |
7bee9006a465
(svn r1263) -Fix: [Network] Client-names are limited (serverside) to 25 chars
truelight
parents:
785
diff
changeset
|
1090 |
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, client_name); |
7bee9006a465
(svn r1263) -Fix: [Network] Client-names are limited (serverside) to 25 chars
truelight
parents:
785
diff
changeset
|
1091 |
ttd_strlcpy(ci->client_name, client_name, sizeof(ci->client_name)); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1092 |
NetworkUpdateClientInfo(ci->client_index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1093 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1094 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1095 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1096 |
|
1026
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1097 |
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_RCON) |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1098 |
{ |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1099 |
char pass[NETWORK_PASSWORD_LENGTH]; |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1100 |
char command[NETWORK_RCONCOMMAND_LENGTH]; |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1101 |
|
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1102 |
if (_network_game_info.rcon_password[0] == '\0') |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1103 |
return; |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1104 |
|
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1105 |
NetworkRecv_string(cs, p, pass, sizeof(pass)); |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1106 |
NetworkRecv_string(cs, p, command, sizeof(command)); |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1107 |
|
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1108 |
if (strncmp(pass, _network_game_info.rcon_password, sizeof(pass)) != 0) { |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1109 |
DEBUG(net, 0)("[RCon] Wrong password from client-id %d", cs->index); |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1110 |
return; |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1111 |
} |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1112 |
|
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1113 |
DEBUG(net, 0)("[RCon] Client-id %d executed: %s", cs->index, command); |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1114 |
|
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1115 |
_redirect_console_to_client = cs->index; |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1116 |
IConsoleCmdExec(command); |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1117 |
_redirect_console_to_client = 0; |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1118 |
return; |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1119 |
} |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1120 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1121 |
// The layout for the receive-functions by the server |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
1122 |
typedef void NetworkServerPacket(NetworkClientState *cs, Packet *p); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1123 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1124 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1125 |
// This array matches PacketType. At an incoming |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1126 |
// packet it is matches against this array |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1127 |
// and that way the right function to handle that |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1128 |
// packet is found. |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1129 |
static NetworkServerPacket* const _network_server_packet[] = { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1130 |
NULL, /*PACKET_SERVER_FULL,*/ |
841
4874b9ce2765
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
839
diff
changeset
|
1131 |
NULL, /*PACKET_SERVER_BANNED,*/ |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1132 |
RECEIVE_COMMAND(PACKET_CLIENT_JOIN), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1133 |
NULL, /*PACKET_SERVER_ERROR,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1134 |
RECEIVE_COMMAND(PACKET_CLIENT_COMPANY_INFO), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1135 |
NULL, /*PACKET_SERVER_COMPANY_INFO,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1136 |
NULL, /*PACKET_SERVER_CLIENT_INFO,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1137 |
NULL, /*PACKET_SERVER_NEED_PASSWORD,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1138 |
RECEIVE_COMMAND(PACKET_CLIENT_PASSWORD), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1139 |
NULL, /*PACKET_SERVER_WELCOME,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1140 |
RECEIVE_COMMAND(PACKET_CLIENT_GETMAP), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1141 |
NULL, /*PACKET_SERVER_WAIT,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1142 |
NULL, /*PACKET_SERVER_MAP,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1143 |
RECEIVE_COMMAND(PACKET_CLIENT_MAP_OK), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1144 |
NULL, /*PACKET_SERVER_JOIN,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1145 |
NULL, /*PACKET_SERVER_FRAME,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1146 |
NULL, /*PACKET_SERVER_SYNC,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1147 |
RECEIVE_COMMAND(PACKET_CLIENT_ACK), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1148 |
RECEIVE_COMMAND(PACKET_CLIENT_COMMAND), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1149 |
NULL, /*PACKET_SERVER_COMMAND,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1150 |
RECEIVE_COMMAND(PACKET_CLIENT_CHAT), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1151 |
NULL, /*PACKET_SERVER_CHAT,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1152 |
RECEIVE_COMMAND(PACKET_CLIENT_SET_PASSWORD), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1153 |
RECEIVE_COMMAND(PACKET_CLIENT_SET_NAME), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1154 |
RECEIVE_COMMAND(PACKET_CLIENT_QUIT), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1155 |
RECEIVE_COMMAND(PACKET_CLIENT_ERROR), |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1156 |
NULL, /*PACKET_SERVER_QUIT,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1157 |
NULL, /*PACKET_SERVER_ERROR_QUIT,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1158 |
NULL, /*PACKET_SERVER_SHUTDOWN,*/ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1159 |
NULL, /*PACKET_SERVER_NEWGAME,*/ |
1026
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1160 |
NULL, /*PACKET_SERVER_RCON,*/ |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1017
diff
changeset
|
1161 |
RECEIVE_COMMAND(PACKET_CLIENT_RCON), |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1162 |
}; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1163 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1164 |
// If this fails, check the array above with network_data.h |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1165 |
assert_compile(lengthof(_network_server_packet) == PACKET_END); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1166 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1167 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1168 |
extern const SettingDesc patch_settings[]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1169 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1170 |
// This is a TEMPORARY solution to get the patch-settings |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1171 |
// to the client. When the patch-settings are saved in the savegame |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1172 |
// this should be removed!! |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
1173 |
void NetworkSendPatchSettings(NetworkClientState *cs) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1174 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1175 |
const SettingDesc *item; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1176 |
Packet *p = NetworkSend_Init(PACKET_SERVER_MAP); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1177 |
NetworkSend_uint8(p, MAP_PACKET_PATCH); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1178 |
// Now send all the patch-settings in a pretty order.. |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1179 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1180 |
item = patch_settings; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1181 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1182 |
while (item->name != NULL) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1183 |
switch (item->flags) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1184 |
case SDT_BOOL: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1185 |
case SDT_INT8: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1186 |
case SDT_UINT8: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1187 |
NetworkSend_uint8(p, *(uint8 *)item->ptr); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1188 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1189 |
case SDT_INT16: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1190 |
case SDT_UINT16: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1191 |
NetworkSend_uint16(p, *(uint16 *)item->ptr); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1192 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1193 |
case SDT_INT32: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1194 |
case SDT_UINT32: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1195 |
NetworkSend_uint32(p, *(uint32 *)item->ptr); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1196 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1197 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1198 |
item++; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1199 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1200 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1201 |
NetworkSend_Packet(p, cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1202 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1203 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1204 |
// This update the company_info-stuff |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1205 |
void NetworkPopulateCompanyInfo(void) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1206 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1207 |
char password[NETWORK_PASSWORD_LENGTH]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1208 |
Player *p; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1209 |
Vehicle *v; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1210 |
Station *s; |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
1211 |
NetworkClientState *cs; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1212 |
NetworkClientInfo *ci; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1213 |
int i; |
690
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1214 |
uint16 months_empty; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1215 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1216 |
FOR_ALL_PLAYERS(p) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1217 |
if (!p->is_active) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1218 |
memset(&_network_player_info[p->index], 0, sizeof(NetworkPlayerInfo)); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1219 |
continue; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1220 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1221 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1222 |
// Clean the info but not the password |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1223 |
ttd_strlcpy(password, _network_player_info[p->index].password, sizeof(password)); |
690
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1224 |
months_empty = _network_player_info[p->index].months_empty; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1225 |
memset(&_network_player_info[p->index], 0, sizeof(NetworkPlayerInfo)); |
690
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1226 |
_network_player_info[p->index].months_empty = months_empty; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1227 |
ttd_strlcpy(_network_player_info[p->index].password, password, sizeof(_network_player_info[p->index].password)); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1228 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1229 |
// Grap the company name |
1017
b09bae77a850
(svn r1518) -Fix: server issue where some company names were wrong
darkvater
parents:
1011
diff
changeset
|
1230 |
SetDParam(0, p->name_1); |
b09bae77a850
(svn r1518) -Fix: server issue where some company names were wrong
darkvater
parents:
1011
diff
changeset
|
1231 |
SetDParam(1, p->name_2); |
b09bae77a850
(svn r1518) -Fix: server issue where some company names were wrong
darkvater
parents:
1011
diff
changeset
|
1232 |
GetString(_network_player_info[p->index].company_name, STR_JUST_STRING); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1233 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1234 |
// Check the income |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1235 |
if (_cur_year - 1 == p->inaugurated_year) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1236 |
// The player is here just 1 year, so display [2], else display[1] |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1237 |
for (i = 0; i < 13; i++) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1238 |
_network_player_info[p->index].income -= p->yearly_expenses[2][i]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1239 |
else |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1240 |
for (i = 0; i < 13; i++) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1241 |
_network_player_info[p->index].income -= p->yearly_expenses[1][i]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1242 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1243 |
// Set some general stuff |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1244 |
_network_player_info[p->index].inaugurated_year = p->inaugurated_year; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1245 |
_network_player_info[p->index].company_value = p->old_economy[0].company_value; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1246 |
_network_player_info[p->index].money = p->money64; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1247 |
_network_player_info[p->index].performance = p->old_economy[0].performance_history; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1248 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1249 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1250 |
// Go through all vehicles and count the type of vehicles |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1251 |
FOR_ALL_VEHICLES(v) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1252 |
if (v->owner < MAX_PLAYERS) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1253 |
switch (v->type) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1254 |
case VEH_Train: |
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1045
diff
changeset
|
1255 |
if (v->subtype == TS_Front_Engine) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1256 |
_network_player_info[v->owner].num_vehicle[0]++; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1257 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1258 |
case VEH_Road: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1259 |
if (v->cargo_type != CT_PASSENGERS) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1260 |
_network_player_info[v->owner].num_vehicle[1]++; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1261 |
else |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1262 |
_network_player_info[v->owner].num_vehicle[2]++; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1263 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1264 |
case VEH_Aircraft: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1265 |
if (v->subtype <= 2) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1266 |
_network_player_info[v->owner].num_vehicle[3]++; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1267 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1268 |
case VEH_Ship: |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1269 |
_network_player_info[v->owner].num_vehicle[4]++; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1270 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1271 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1272 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1273 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1274 |
// Go through all stations and count the types of stations |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1275 |
FOR_ALL_STATIONS(s) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1276 |
if (s->owner < MAX_PLAYERS) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1277 |
if ((s->facilities & FACIL_TRAIN)) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1278 |
_network_player_info[s->owner].num_station[0]++; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1279 |
if ((s->facilities & FACIL_TRUCK_STOP)) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1280 |
_network_player_info[s->owner].num_station[1]++; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1281 |
if ((s->facilities & FACIL_BUS_STOP)) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1282 |
_network_player_info[s->owner].num_station[2]++; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1283 |
if ((s->facilities & FACIL_AIRPORT)) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1284 |
_network_player_info[s->owner].num_station[3]++; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1285 |
if ((s->facilities & FACIL_DOCK)) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1286 |
_network_player_info[s->owner].num_station[4]++; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1287 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1288 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1289 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1290 |
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1291 |
// Register local player (if not dedicated) |
667
c6484d63bbe4
(svn r1104) -Fix: nasty server crash buffer overflow problem when using release build. Big thanks to Truelight for the guidance in fixing this very annoying bug!
darkvater
parents:
663
diff
changeset
|
1292 |
if (ci != NULL && ci->client_playas > 0 && ci->client_playas <= MAX_PLAYERS) |
c6484d63bbe4
(svn r1104) -Fix: nasty server crash buffer overflow problem when using release build. Big thanks to Truelight for the guidance in fixing this very annoying bug!
darkvater
parents:
663
diff
changeset
|
1293 |
ttd_strlcpy(_network_player_info[ci->client_playas-1].players, ci->client_name, sizeof(_network_player_info[ci->client_playas-1].players)); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1294 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1295 |
FOR_ALL_CLIENTS(cs) { |
793
7bee9006a465
(svn r1263) -Fix: [Network] Client-names are limited (serverside) to 25 chars
truelight
parents:
785
diff
changeset
|
1296 |
char client_name[NETWORK_CLIENT_NAME_LENGTH]; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1297 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1298 |
NetworkGetClientName(client_name, sizeof(client_name), cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1299 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1300 |
ci = DEREF_CLIENT_INFO(cs); |
667
c6484d63bbe4
(svn r1104) -Fix: nasty server crash buffer overflow problem when using release build. Big thanks to Truelight for the guidance in fixing this very annoying bug!
darkvater
parents:
663
diff
changeset
|
1301 |
if (ci != NULL && ci->client_playas > 0 && ci->client_playas <= MAX_PLAYERS) { |
c6484d63bbe4
(svn r1104) -Fix: nasty server crash buffer overflow problem when using release build. Big thanks to Truelight for the guidance in fixing this very annoying bug!
darkvater
parents:
663
diff
changeset
|
1302 |
if (strlen(_network_player_info[ci->client_playas-1].players) != 0) |
c6484d63bbe4
(svn r1104) -Fix: nasty server crash buffer overflow problem when using release build. Big thanks to Truelight for the guidance in fixing this very annoying bug!
darkvater
parents:
663
diff
changeset
|
1303 |
strncat(_network_player_info[ci->client_playas-1].players, ", ", sizeof(_network_player_info[ci->client_playas-1].players)); |
668
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
667
diff
changeset
|
1304 |
|
667
c6484d63bbe4
(svn r1104) -Fix: nasty server crash buffer overflow problem when using release build. Big thanks to Truelight for the guidance in fixing this very annoying bug!
darkvater
parents:
663
diff
changeset
|
1305 |
strncat(_network_player_info[ci->client_playas-1].players, client_name, sizeof(_network_player_info[ci->client_playas-1].players)); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1306 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1307 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1308 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1309 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1310 |
// Send a packet to all clients with updated info about this client_index |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1311 |
void NetworkUpdateClientInfo(uint16 client_index) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1312 |
{ |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
1313 |
NetworkClientState *cs; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1314 |
NetworkClientInfo *ci; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1315 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1316 |
ci = NetworkFindClientInfoFromIndex(client_index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1317 |
|
656
e3e435079efa
(svn r1090) -Fix: Made the _openttd_revision variable global, and with that
truelight
parents:
624
diff
changeset
|
1318 |
if (ci == NULL) |
e3e435079efa
(svn r1090) -Fix: Made the _openttd_revision variable global, and with that
truelight
parents:
624
diff
changeset
|
1319 |
return; |
e3e435079efa
(svn r1090) -Fix: Made the _openttd_revision variable global, and with that
truelight
parents:
624
diff
changeset
|
1320 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1321 |
FOR_ALL_CLIENTS(cs) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1322 |
SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(cs, ci); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1323 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1324 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1325 |
|
785
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1326 |
extern void SwitchMode(int new_mode); |
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1327 |
|
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1328 |
/* Check if we want to restart the map */ |
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
1329 |
static void NetworkCheckRestartMap(void) |
785
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1330 |
{ |
970
24abd02b1092
(svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
darkvater
parents:
959
diff
changeset
|
1331 |
if (_network_restart_game_date != 0 && _cur_year + MAX_YEAR_BEGIN_REAL >= _network_restart_game_date) { |
785
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1332 |
_docommand_recursive = 0; |
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1333 |
|
970
24abd02b1092
(svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
darkvater
parents:
959
diff
changeset
|
1334 |
DEBUG(net, 0)("Auto-restarting map. Year %d reached.", _cur_year + MAX_YEAR_BEGIN_REAL); |
785
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1335 |
|
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1336 |
_random_seeds[0][0] = Random(); |
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1337 |
_random_seeds[0][1] = InteractiveRandom(); |
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1338 |
|
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1339 |
SwitchMode(SM_NEWGAME); |
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1340 |
} |
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1341 |
} |
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1342 |
|
690
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1343 |
/* Check if the server has autoclean_companies activated |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1344 |
Two things happen: |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1345 |
1) If a company is not protected, it is closed after 1 year (for example) |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1346 |
2) If a company is protected, protection is disabled after 3 years (for example) |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1347 |
(and item 1. happens a year later) */ |
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
1348 |
static void NetworkAutoCleanCompanies(void) |
690
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1349 |
{ |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
1350 |
NetworkClientState *cs; |
690
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1351 |
NetworkClientInfo *ci; |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1352 |
Player *p; |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1353 |
bool clients_in_company[MAX_PLAYERS]; |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1354 |
|
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1355 |
if (!_network_autoclean_companies) |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1356 |
return; |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1357 |
|
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1358 |
memset(clients_in_company, 0, sizeof(clients_in_company)); |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1359 |
|
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1360 |
/* Detect the active companies */ |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1361 |
FOR_ALL_CLIENTS(cs) { |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1362 |
ci = DEREF_CLIENT_INFO(cs); |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1363 |
if (ci->client_playas >= 1 && ci->client_playas <= MAX_PLAYERS) { |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1364 |
clients_in_company[ci->client_playas-1] = true; |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1365 |
} |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1366 |
} |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1367 |
if (!_network_dedicated) { |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1368 |
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX); |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1369 |
if (ci->client_playas >= 1 && ci->client_playas <= MAX_PLAYERS) { |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1370 |
clients_in_company[ci->client_playas-1] = true; |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1371 |
} |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1372 |
} |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1373 |
|
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1374 |
/* Go through all the comapnies */ |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1375 |
FOR_ALL_PLAYERS(p) { |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1376 |
/* Skip the non-active once */ |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1377 |
if (!p->is_active || p->is_ai) |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1378 |
continue; |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1379 |
|
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1380 |
if (!clients_in_company[p->index]) { |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1381 |
/* The company is empty for one month more */ |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1382 |
_network_player_info[p->index].months_empty++; |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1383 |
|
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1384 |
/* Is the company empty for autoclean_unprotected-months, and is there no protection? */ |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1385 |
if (_network_player_info[p->index].months_empty > _network_autoclean_unprotected && _network_player_info[p->index].password[0] == '\0') { |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1386 |
/* Shut the company down */ |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1387 |
DoCommandP(0, 2, p->index, NULL, CMD_PLAYER_CTRL); |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1388 |
IConsolePrintF(_iconsole_color_default, "Auto-cleaned company #%d", p->index+1); |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1389 |
} |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1390 |
/* Is the compnay empty for autoclean_protected-months, and there is a protection? */ |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1391 |
if (_network_player_info[p->index].months_empty > _network_autoclean_protected && _network_player_info[p->index].password[0] != '\0') { |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1392 |
/* Unprotect the company */ |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1393 |
_network_player_info[p->index].password[0] = '\0'; |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1394 |
IConsolePrintF(_iconsole_color_default, "Auto-removed protection from company #%d", p->index+1); |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1395 |
_network_player_info[p->index].months_empty = 0; |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1396 |
} |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1397 |
} else { |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1398 |
/* It is not empty, reset the date */ |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1399 |
_network_player_info[p->index].months_empty = 0; |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1400 |
} |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1401 |
} |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1402 |
} |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1403 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1404 |
// This function changes new_name to a name that is unique (by adding #1 ...) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1405 |
// and it returns true if that succeeded. |
793
7bee9006a465
(svn r1263) -Fix: [Network] Client-names are limited (serverside) to 25 chars
truelight
parents:
785
diff
changeset
|
1406 |
bool NetworkFindName(char new_name[NETWORK_CLIENT_NAME_LENGTH]) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1407 |
{ |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
1408 |
NetworkClientState *new_cs; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1409 |
NetworkClientInfo *ci; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1410 |
bool found_name = false; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1411 |
byte number = 0; |
793
7bee9006a465
(svn r1263) -Fix: [Network] Client-names are limited (serverside) to 25 chars
truelight
parents:
785
diff
changeset
|
1412 |
char original_name[NETWORK_CLIENT_NAME_LENGTH]; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1413 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1414 |
// We use NETWORK_NAME_LENGTH in here, because new_name is really a pointer |
793
7bee9006a465
(svn r1263) -Fix: [Network] Client-names are limited (serverside) to 25 chars
truelight
parents:
785
diff
changeset
|
1415 |
ttd_strlcpy(original_name, new_name, NETWORK_CLIENT_NAME_LENGTH); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1416 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1417 |
while (!found_name) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1418 |
found_name = true; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1419 |
FOR_ALL_CLIENTS(new_cs) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1420 |
ci = DEREF_CLIENT_INFO(new_cs); |
793
7bee9006a465
(svn r1263) -Fix: [Network] Client-names are limited (serverside) to 25 chars
truelight
parents:
785
diff
changeset
|
1421 |
if (strncmp(ci->client_name, new_name, NETWORK_CLIENT_NAME_LENGTH) == 0) { |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1422 |
// Name already in use |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1423 |
found_name = false; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1424 |
break; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1425 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1426 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1427 |
// Check if it is the same as the server-name |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1428 |
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1429 |
if (ci != NULL) { |
793
7bee9006a465
(svn r1263) -Fix: [Network] Client-names are limited (serverside) to 25 chars
truelight
parents:
785
diff
changeset
|
1430 |
if (strncmp(ci->client_name, new_name, NETWORK_CLIENT_NAME_LENGTH) == 0) { |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1431 |
// Name already in use |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1432 |
found_name = false; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1433 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1434 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1435 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1436 |
if (!found_name) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1437 |
// Try a new name (<name> #1, <name> #2, and so on) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1438 |
|
826 | 1439 |
// Stop if we tried for more than 50 times.. |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1440 |
if (number++ > 50) break; |
793
7bee9006a465
(svn r1263) -Fix: [Network] Client-names are limited (serverside) to 25 chars
truelight
parents:
785
diff
changeset
|
1441 |
snprintf(new_name, NETWORK_CLIENT_NAME_LENGTH, "%s #%d", original_name, number); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1442 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1443 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1444 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1445 |
return found_name; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1446 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1447 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1448 |
// Reads a packet from the stream |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
1449 |
bool NetworkServer_ReadPackets(NetworkClientState *cs) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1450 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1451 |
Packet *p; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1452 |
NetworkRecvStatus res; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1453 |
while((p = NetworkRecv_Packet(cs, &res)) != NULL) { |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
1454 |
byte type = NetworkRecv_uint8(cs, p); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
1455 |
if (type < PACKET_END && _network_server_packet[type] != NULL && !cs->quited) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1456 |
_network_server_packet[type](cs, p); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1457 |
else |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1458 |
DEBUG(net, 0)("[NET][Server] Received invalid packet type %d", type); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1459 |
free(p); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1460 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1461 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1462 |
return true; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1463 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1464 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1465 |
// Handle the local command-queue |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
1466 |
void NetworkHandleCommandQueue(NetworkClientState *cs) { |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1467 |
if (cs->command_queue != NULL) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1468 |
CommandPacket *cp; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1469 |
CommandPacket *cp_prev; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1470 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1471 |
cp = cs->command_queue; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1472 |
cp_prev = NULL; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1473 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1474 |
while (cp != NULL) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1475 |
SEND_COMMAND(PACKET_SERVER_COMMAND)(cs, cp); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1476 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1477 |
if (cp_prev != NULL) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1478 |
cp_prev->next = cp->next; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1479 |
free(cp); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1480 |
cp = cp_prev->next; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1481 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1482 |
// This means we are at our first packet |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1483 |
cs->command_queue = cp->next; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1484 |
free(cp); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1485 |
cp = cs->command_queue; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1486 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1487 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1488 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1489 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1490 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1491 |
// This is called every tick if this is a _network_server |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1492 |
void NetworkServer_Tick(void) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1493 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1494 |
#ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1495 |
static uint32 last_sync_frame = 0; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1496 |
#endif |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
1497 |
NetworkClientState *cs; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1498 |
bool send_frame = false; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1499 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1500 |
// Update max-frame-counter |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1501 |
if (_frame_counter > _frame_counter_max) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1502 |
_frame_counter_max = _frame_counter + _network_frame_freq; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1503 |
send_frame = true; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1504 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1505 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1506 |
// Now we are done with the frame, inform the clients that they can |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1507 |
// do their frame! |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1508 |
FOR_ALL_CLIENTS(cs) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1509 |
// Check if the speed of the client is what we can expect from a client |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1510 |
if (cs->status == STATUS_ACTIVE) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1511 |
// 1 lag-point per day |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1512 |
int lag = NetworkCalculateLag(cs) / DAY_TICKS; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1513 |
if (lag > 0) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1514 |
if (lag > 3) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1515 |
// Client did still not report in after 4 game-day, drop him |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1516 |
// (that is, the 3 of above, + 1 before any lag is counted) |
826 | 1517 |
IConsolePrintF(_iconsole_color_error,"Client #%d is dropped because the client did not respond for more than 4 game-days", cs->index); |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
1518 |
NetworkCloseClient(cs); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1519 |
continue; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1520 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1521 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1522 |
// Report once per time we detect the lag |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1523 |
if (cs->lag_test == 0) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1524 |
IConsolePrintF(_iconsole_color_warning,"[%d] Client #%d is slow, try increasing *net_frame_freq to a higher value!", _frame_counter, cs->index); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1525 |
cs->lag_test = 1; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1526 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1527 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1528 |
cs->lag_test = 0; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1529 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1530 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1531 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1532 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1533 |
// Check if we can send command, and if we have anything in the queue |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1534 |
if (cs->status > STATUS_DONE_MAP) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1535 |
NetworkHandleCommandQueue(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1536 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1537 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1538 |
// Do we need to send the new frame-packet? |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1539 |
if (send_frame && cs->status == STATUS_ACTIVE) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1540 |
SEND_COMMAND(PACKET_SERVER_FRAME)(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1541 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1542 |
#ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1543 |
// Is it time to send a sync-packet to all clients? |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1544 |
if (last_sync_frame + _network_sync_freq < _frame_counter) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1545 |
SEND_COMMAND(PACKET_SERVER_SYNC)(cs); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1546 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1547 |
#endif |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1548 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1549 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1550 |
#ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1551 |
// Update the last_sync_frame if needed! |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1552 |
if (last_sync_frame + _network_sync_freq < _frame_counter) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1553 |
last_sync_frame = _frame_counter; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1554 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1555 |
#endif |
668
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
667
diff
changeset
|
1556 |
|
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
667
diff
changeset
|
1557 |
/* See if we need to advertise */ |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
667
diff
changeset
|
1558 |
NetworkUDPAdvertise(); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1559 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1560 |
|
785
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1561 |
void NetworkServerYearlyLoop(void) |
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1562 |
{ |
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1563 |
NetworkCheckRestartMap(); |
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1564 |
} |
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
779
diff
changeset
|
1565 |
|
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
692
diff
changeset
|
1566 |
void NetworkServerMonthlyLoop(void) |
690
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1567 |
{ |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1568 |
NetworkAutoCleanCompanies(); |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1569 |
} |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
686
diff
changeset
|
1570 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1571 |
#endif /* ENABLE_NETWORK */ |