forked from haithun/CoD4X17a_testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sv_net_chan.c
225 lines (165 loc) · 6.17 KB
/
sv_net_chan.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
===========================================================================
Copyright (C) 2010-2013 Ninja and TheKelm of the IceOps-Team
Copyright (C) 1999-2005 Id Software, Inc.
This file is part of CoD4X17a-Server source code.
CoD4X17a-Server source code is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
CoD4X17a-Server source code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
===========================================================================
*/
#include "q_shared.h"
#include "netchan.h"
#include "server.h"
#include <string.h>
/*
fileHandle_t commanddump;
void SV_DumpCommands( client_t *client, byte *cmd, int size, qboolean cl_to_servercmd) {
if(!com_developer || com_developer->integer < 2)
return;
msg_t msg;
byte buffer[20400];
MSG_Init(&msg, buffer, sizeof(buffer));
*/
/* if(cl_to_servercmd){
Com_sprintf((char*)buffer, sizeof(buffer), "\nDir: Cl -> Sv, Cl: %i, T: %i, NA: %i, Len %i, Msg: ",
client - svs.clients, svs.time ,client->reliableSequence - client->reliableAcknowledge, size);
}else{
Com_sprintf((char*)buffer, sizeof(buffer), "\nDir: Sv -> Cl, Cl: %i, T: %i, NA: %i, Len %i, Msg: ",
client - svs.clients, svs.time ,client->reliableSequence - client->reliableAcknowledge, size);
}
*/
/* int lenbeginstr = strlen((char*)buffer);
MSG_ReadBitsCompress(cmd, &buffer[lenbeginstr], size);
buffer[size+lenbeginstr-1] = '\n';
Sys_EnterCriticalSection(5);
if ( com_logfile && com_logfile->integer ) {
// TTimo: only open the qconsole.log if the filesystem is in an initialized state
// also, avoid recursing in the qconsole.log opening (i.e. if fs_debug is on)
if ( !commanddump && FS_Initialized()) {
struct tm *newtime;
time_t aclock;
time( &aclock );
newtime = localtime( &aclock );
commanddump = FS_FOpenFileWrite( "reliableupdateCmds.log" );
if ( com_logfile->integer > 1 && commanddump) {
// force it to not buffer so we get valid
// data even if we are crashing
FS_ForceFlush(commanddump);
}
if ( commanddump ) FS_Write(va("\nLogfile opened on %s\n", asctime( newtime )), strlen(va("\nLogfile opened on %s\n", asctime( newtime ))), commanddump);
}
if (commanddump && FS_Initialized()) {
FS_Write("\nUncompressed: ", 15, commanddump);
FS_Write(buffer, 300, commanddump);
FS_Write("\nCompressed: ", 13, commanddump);
FS_Write(cmd, size, commanddump);
}
}
Sys_LeaveCriticalSection(5);
}
*/
/*
==============
SV_Netchan_Decode
// first 12 bytes of the data are always:
long serverId;
long messageAcknowledge;
long reliableAcknowledge;
==============
*/
void SV_Netchan_Decode( client_t *client, byte *data, int remaining ) {
int i, index;
byte key, *string;
// extclient_t *extcl = &svs.extclients[ client - svs.clients ];
// string = (byte *)extcl->reliableCommands[ client->reliableAcknowledge & ( MAX_RELIABLE_COMMANDS - 1 ) ].command;
string = (byte *)client->reliableCommands[ client->reliableAcknowledge & ( MAX_RELIABLE_COMMANDS - 1 ) ].command;
if(!remaining) return;
key = client->challenge ^ client->serverId ^ client->messageAcknowledge;
for ( i=0, index=0; i < remaining; i++ ) {
if ( !string[index] ) {
index = 0;
}
// modify the key with the last sent and acknowledged server command
key ^= string[index] << ( i & 1 );
data[i] ^= key;
index++;
}
}
/*
==============
SV_Netchan_Encode
// first four bytes of the data are always:
long reliableAcknowledge;
==============
*/
void SV_Netchan_Encode( client_t *client, byte *data, int cursize ) {
int i, index;
byte key, *string;
string = (byte *)client->lastClientCommandString;
key = client->challenge ^ client->netchan.outgoingSequence;
for ( i = 0, index = 0; i < cursize - 4; i++ ) {
if ( !string[index] ) {
index = 0;
}
// modify the key with the last sent and acknowledged server command
key ^= string[index] << ( i & 1 );
data[i+4] ^= key;
index++;
}
}
/*
===============
SV_Netchan_Transmit
TTimo
show_bug.cgi?id=462
if there are some unsent fragments (which may happen if the snapshots
and the gamestate are fragmenting, and collide on send for instance)
then buffer them and make sure they get sent in correct order
================
*/
qboolean SV_Netchan_Transmit( client_t *client, byte *data, int cursize) { //int length, const byte *data ) {
qboolean nt_ret;
int i;
// SV_DumpCommands(client, (byte*)data, cursize, qfalse);
if(cursize - 4){
SV_Netchan_Encode(client, data, cursize);
}
nt_ret = Netchan_Transmit( &client->netchan, cursize, data );
if(client->netchan.unsentFragments){
return nt_ret;
}
i = client->netchan.outgoingSequence & 31;
Com_Memset(&client->frames[i], 0, sizeof(clientSnapshot_t));
client->frames[i].first_entity = svs.nextSnapshotEntities;
client->frames[i].first_client = svs.nextSnapshotClients;
return nt_ret;
}
/*
===============
SV_Netchan_TransmitNextFragment
TTimo
show_bug.cgi?id=462
if there are some unsent fragments (which may happen if the snapshots
and the gamestate are fragmenting, and collide on send for instance)
then buffer them and make sure they get sent in correct order
================
*/
__cdecl qboolean SV_Netchan_TransmitNextFragment( client_t *client ) { //int length, const byte *data ) {
int i;
Netchan_TransmitNextFragment( &client->netchan );
if(client->netchan.unsentFragments)
return qtrue; //Return true if we have still unsent fragments
i = client->netchan.outgoingSequence & 31;
Com_Memset(&client->frames[i], 0, sizeof(clientSnapshot_t));
client->frames[i].first_entity = svs.nextSnapshotEntities;
client->frames[i].first_client = svs.nextSnapshotClients;
return qfalse; //No more unsent fragments, this was the last fragment
}