| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include "client.h" |
| 25 |
|
| 26 |
char *svc_strings[256] = { |
| 27 |
"svc_bad", |
| 28 |
|
| 29 |
"svc_nop", |
| 30 |
"svc_gamestate", |
| 31 |
"svc_configstring", |
| 32 |
"svc_baseline", |
| 33 |
"svc_serverCommand", |
| 34 |
"svc_download", |
| 35 |
"svc_snapshot", |
| 36 |
"svc_EOF", |
| 37 |
"svc_voipSpeex", |
| 38 |
"svc_voipOpus", |
| 39 |
}; |
| 40 |
|
| 41 |
void SHOWNET( msg_t *msg, char *s) { |
| 42 |
if ( cl_shownet->integer >= 2) { |
| 43 |
Com_Printf ("%3i:%s\n", msg->readcount-1, s); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
void CL_DeltaEntity (msg_t *msg, clSnapshot_t *frame, int newnum, entityState_t *old, |
| 65 |
qboolean unchanged) { |
| 66 |
entityState_t *state; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
state = &cl.parseEntities[cl.parseEntitiesNum & (MAX_PARSE_ENTITIES-1)]; |
| 71 |
|
| 72 |
if ( unchanged ) { |
| 73 |
*state = *old; |
| 74 |
} else { |
| 75 |
MSG_ReadDeltaEntity( msg, old, state, newnum ); |
| 76 |
} |
| 77 |
|
| 78 |
if ( state->number == (MAX_GENTITIES-1) ) { |
| 79 |
return; |
| 80 |
} |
| 81 |
cl.parseEntitiesNum++; |
| 82 |
frame->numEntities++; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
void CL_ParsePacketEntities( msg_t *msg, clSnapshot_t *oldframe, clSnapshot_t *newframe) { |
| 92 |
int newnum; |
| 93 |
entityState_t *oldstate; |
| 94 |
int oldindex, oldnum; |
| 95 |
|
| 96 |
newframe->parseEntitiesNum = cl.parseEntitiesNum; |
| 97 |
newframe->numEntities = 0; |
| 98 |
|
| 99 |
|
| 100 |
oldindex = 0; |
| 101 |
oldstate = NULL; |
| 102 |
if (!oldframe) { |
| 103 |
oldnum = 99999; |
| 104 |
} else { |
| 105 |
if ( oldindex >= oldframe->numEntities ) { |
| 106 |
oldnum = 99999; |
| 107 |
} else { |
| 108 |
oldstate = &cl.parseEntities[ |
| 109 |
(oldframe->parseEntitiesNum + oldindex) & (MAX_PARSE_ENTITIES-1)]; |
| 110 |
oldnum = oldstate->number; |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
while ( 1 ) { |
| 115 |
|
| 116 |
newnum = MSG_ReadBits( msg, GENTITYNUM_BITS ); |
| 117 |
|
| 118 |
if ( newnum == (MAX_GENTITIES-1) ) { |
| 119 |
break; |
| 120 |
} |
| 121 |
|
| 122 |
if ( msg->readcount > msg->cursize ) { |
| 123 |
Com_Error (ERR_DROP,"CL_ParsePacketEntities: end of message"); |
| 124 |
} |
| 125 |
|
| 126 |
while ( oldnum < newnum ) { |
| 127 |
|
| 128 |
if ( cl_shownet->integer == 3 ) { |
| 129 |
Com_Printf ("%3i: unchanged: %i\n", msg->readcount, oldnum); |
| 130 |
} |
| 131 |
CL_DeltaEntity( msg, newframe, oldnum, oldstate, qtrue ); |
| 132 |
|
| 133 |
oldindex++; |
| 134 |
|
| 135 |
if ( oldindex >= oldframe->numEntities ) { |
| 136 |
oldnum = 99999; |
| 137 |
} else { |
| 138 |
oldstate = &cl.parseEntities[ |
| 139 |
(oldframe->parseEntitiesNum + oldindex) & (MAX_PARSE_ENTITIES-1)]; |
| 140 |
oldnum = oldstate->number; |
| 141 |
} |
| 142 |
} |
| 143 |
if (oldnum == newnum) { |
| 144 |
|
| 145 |
if ( cl_shownet->integer == 3 ) { |
| 146 |
Com_Printf ("%3i: delta: %i\n", msg->readcount, newnum); |
| 147 |
} |
| 148 |
CL_DeltaEntity( msg, newframe, newnum, oldstate, qfalse ); |
| 149 |
|
| 150 |
oldindex++; |
| 151 |
|
| 152 |
if ( oldindex >= oldframe->numEntities ) { |
| 153 |
oldnum = 99999; |
| 154 |
} else { |
| 155 |
oldstate = &cl.parseEntities[ |
| 156 |
(oldframe->parseEntitiesNum + oldindex) & (MAX_PARSE_ENTITIES-1)]; |
| 157 |
oldnum = oldstate->number; |
| 158 |
} |
| 159 |
continue; |
| 160 |
} |
| 161 |
|
| 162 |
if ( oldnum > newnum ) { |
| 163 |
|
| 164 |
if ( cl_shownet->integer == 3 ) { |
| 165 |
Com_Printf ("%3i: baseline: %i\n", msg->readcount, newnum); |
| 166 |
} |
| 167 |
CL_DeltaEntity( msg, newframe, newnum, &cl.entityBaselines[newnum], qfalse ); |
| 168 |
continue; |
| 169 |
} |
| 170 |
|
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
while ( oldnum != 99999 ) { |
| 175 |
|
| 176 |
if ( cl_shownet->integer == 3 ) { |
| 177 |
Com_Printf ("%3i: unchanged: %i\n", msg->readcount, oldnum); |
| 178 |
} |
| 179 |
CL_DeltaEntity( msg, newframe, oldnum, oldstate, qtrue ); |
| 180 |
|
| 181 |
oldindex++; |
| 182 |
|
| 183 |
if ( oldindex >= oldframe->numEntities ) { |
| 184 |
oldnum = 99999; |
| 185 |
} else { |
| 186 |
oldstate = &cl.parseEntities[ |
| 187 |
(oldframe->parseEntitiesNum + oldindex) & (MAX_PARSE_ENTITIES-1)]; |
| 188 |
oldnum = oldstate->number; |
| 189 |
} |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
void CL_ParseSnapshot( msg_t *msg ) { |
| 204 |
int len; |
| 205 |
clSnapshot_t *old; |
| 206 |
clSnapshot_t newSnap; |
| 207 |
int deltaNum; |
| 208 |
int oldMessageNum; |
| 209 |
int i, packetNum; |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
Com_Memset (&newSnap, 0, sizeof(newSnap)); |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
newSnap.serverCommandNum = clc.serverCommandSequence; |
| 222 |
|
| 223 |
newSnap.serverTime = MSG_ReadLong( msg ); |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
cl_paused->modified = 0; |
| 228 |
|
| 229 |
newSnap.messageNum = clc.serverMessageSequence; |
| 230 |
|
| 231 |
deltaNum = MSG_ReadByte( msg ); |
| 232 |
if ( !deltaNum ) { |
| 233 |
newSnap.deltaNum = -1; |
| 234 |
} else { |
| 235 |
newSnap.deltaNum = newSnap.messageNum - deltaNum; |
| 236 |
} |
| 237 |
newSnap.snapFlags = MSG_ReadByte( msg ); |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
if ( newSnap.deltaNum <= 0 ) { |
| 244 |
newSnap.valid = qtrue; |
| 245 |
old = NULL; |
| 246 |
clc.demowaiting = qfalse; |
| 247 |
} else { |
| 248 |
old = &cl.snapshots[newSnap.deltaNum & PACKET_MASK]; |
| 249 |
if ( !old->valid ) { |
| 250 |
|
| 251 |
Com_Printf ("Delta from invalid frame (not supposed to happen!).\n"); |
| 252 |
} else if ( old->messageNum != newSnap.deltaNum ) { |
| 253 |
|
| 254 |
|
| 255 |
Com_Printf ("Delta frame too old.\n"); |
| 256 |
} else if ( cl.parseEntitiesNum - old->parseEntitiesNum > MAX_PARSE_ENTITIES - MAX_SNAPSHOT_ENTITIES ) { |
| 257 |
Com_Printf ("Delta parseEntitiesNum too old.\n"); |
| 258 |
} else { |
| 259 |
newSnap.valid = qtrue; |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
len = MSG_ReadByte( msg ); |
| 265 |
|
| 266 |
if(len > sizeof(newSnap.areamask)) |
| 267 |
{ |
| 268 |
Com_Error (ERR_DROP,"CL_ParseSnapshot: Invalid size %d for areamask", len); |
| 269 |
return; |
| 270 |
} |
| 271 |
|
| 272 |
MSG_ReadData( msg, &newSnap.areamask, len); |
| 273 |
|
| 274 |
|
| 275 |
SHOWNET( msg, "playerstate" ); |
| 276 |
if ( old ) { |
| 277 |
MSG_ReadDeltaPlayerstate( msg, &old->ps, &newSnap.ps ); |
| 278 |
} else { |
| 279 |
MSG_ReadDeltaPlayerstate( msg, NULL, &newSnap.ps ); |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
SHOWNET( msg, "packet entities" ); |
| 284 |
CL_ParsePacketEntities( msg, old, &newSnap ); |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
if ( !newSnap.valid ) { |
| 289 |
return; |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
oldMessageNum = cl.snap.messageNum + 1; |
| 297 |
|
| 298 |
if ( newSnap.messageNum - oldMessageNum >= PACKET_BACKUP ) { |
| 299 |
oldMessageNum = newSnap.messageNum - ( PACKET_BACKUP - 1 ); |
| 300 |
} |
| 301 |
for ( ; oldMessageNum < newSnap.messageNum ; oldMessageNum++ ) { |
| 302 |
cl.snapshots[oldMessageNum & PACKET_MASK].valid = qfalse; |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
cl.snap = newSnap; |
| 307 |
cl.snap.ping = 999; |
| 308 |
|
| 309 |
for ( i = 0 ; i < PACKET_BACKUP ; i++ ) { |
| 310 |
packetNum = ( clc.netchan.outgoingSequence - 1 - i ) & PACKET_MASK; |
| 311 |
if ( cl.snap.ps.commandTime >= cl.outPackets[ packetNum ].p_serverTime ) { |
| 312 |
cl.snap.ping = cls.realtime - cl.outPackets[ packetNum ].p_realtime; |
| 313 |
break; |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
cl.snapshots[cl.snap.messageNum & PACKET_MASK] = cl.snap; |
| 318 |
|
| 319 |
if (cl_shownet->integer == 3) { |
| 320 |
Com_Printf( " snapshot:%i delta:%i ping:%i\n", cl.snap.messageNum, |
| 321 |
cl.snap.deltaNum, cl.snap.ping ); |
| 322 |
} |
| 323 |
|
| 324 |
cl.newSnapshots = qtrue; |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
int cl_connectedToPureServer; |
| 331 |
int cl_connectedToCheatServer; |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
void CL_SystemInfoChanged( void ) { |
| 343 |
char *systemInfo; |
| 344 |
const char *s, *t; |
| 345 |
char key[BIG_INFO_KEY]; |
| 346 |
char value[BIG_INFO_VALUE]; |
| 347 |
qboolean gameSet; |
| 348 |
|
| 349 |
systemInfo = cl.gameState.stringData + cl.gameState.stringOffsets[ CS_SYSTEMINFO ]; |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
cl.serverId = atoi( Info_ValueForKey( systemInfo, "sv_serverid" ) ); |
| 355 |
|
| 356 |
#ifdef USE_VOIP |
| 357 |
#ifdef LEGACY_PROTOCOL |
| 358 |
if(clc.compat) |
| 359 |
clc.voipEnabled = qfalse; |
| 360 |
else |
| 361 |
#endif |
| 362 |
{ |
| 363 |
s = Info_ValueForKey( systemInfo, "sv_voipProtocol" ); |
| 364 |
clc.voipEnabled = !Q_stricmp(s, "opus"); |
| 365 |
} |
| 366 |
#endif |
| 367 |
|
| 368 |
|
| 369 |
if ( clc.demoplaying ) { |
| 370 |
return; |
| 371 |
} |
| 372 |
|
| 373 |
s = Info_ValueForKey( systemInfo, "sv_cheats" ); |
| 374 |
cl_connectedToCheatServer = atoi( s ); |
| 375 |
if ( !cl_connectedToCheatServer ) { |
| 376 |
Cvar_SetCheatState(); |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
s = Info_ValueForKey( systemInfo, "sv_paks" ); |
| 381 |
t = Info_ValueForKey( systemInfo, "sv_pakNames" ); |
| 382 |
FS_PureServerSetLoadedPaks( s, t ); |
| 383 |
|
| 384 |
s = Info_ValueForKey( systemInfo, "sv_referencedPaks" ); |
| 385 |
t = Info_ValueForKey( systemInfo, "sv_referencedPakNames" ); |
| 386 |
FS_PureServerSetReferencedPaks( s, t ); |
| 387 |
|
| 388 |
gameSet = qfalse; |
| 389 |
|
| 390 |
s = systemInfo; |
| 391 |
while ( s ) { |
| 392 |
int cvar_flags; |
| 393 |
|
| 394 |
Info_NextPair( &s, key, value ); |
| 395 |
if ( !key[0] ) { |
| 396 |
break; |
| 397 |
} |
| 398 |
|
| 399 |
|
| 400 |
if (!Q_stricmp(key, "fs_game")) |
| 401 |
{ |
| 402 |
if(FS_InvalidGameDir(value)) |
| 403 |
{ |
| 404 |
Com_Printf(S_COLOR_YELLOW "WARNING: Server sent invalid fs_game value %s\n", value); |
| 405 |
continue; |
| 406 |
} |
| 407 |
|
| 408 |
gameSet = qtrue; |
| 409 |
} |
| 410 |
|
| 411 |
if((cvar_flags = Cvar_Flags(key)) == CVAR_NONEXISTENT) |
| 412 |
Cvar_Get(key, value, CVAR_SERVER_CREATED | CVAR_ROM); |
| 413 |
else |
| 414 |
{ |
| 415 |
|
| 416 |
if(!(cvar_flags & (CVAR_SYSTEMINFO | CVAR_SERVER_CREATED | CVAR_USER_CREATED))) |
| 417 |
{ |
| •418 |
#if !defined(STANDALONE) || defined(WITH_OPENARENA) |
| 419 |
if(Q_stricmp(key, "g_synchronousClients") && Q_stricmp(key, "pmove_fixed") && |
| •420 |
Q_stricmp(key, "pmove_msec") && Q_stricmp(key, "sv_fps")) |
| 421 |
#endif |
| 422 |
{ |
| 423 |
Com_Printf(S_COLOR_YELLOW "WARNING: server is not allowed to set %s=%s\n", key, value); |
| 424 |
continue; |
| 425 |
} |
| 426 |
} |
| 427 |
|
| 428 |
Cvar_SetSafe(key, value); |
| 429 |
} |
| 430 |
} |
| 431 |
|
| 432 |
if ( !gameSet && *Cvar_VariableString("fs_game") ) { |
| 433 |
Cvar_Set( "fs_game", "" ); |
| 434 |
} |
| 435 |
cl_connectedToPureServer = Cvar_VariableValue( "sv_pure" ); |
| 436 |
} |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
static void CL_ParseServerInfo(void) |
| 444 |
{ |
| 445 |
const char *serverInfo; |
| 446 |
|
| 447 |
serverInfo = cl.gameState.stringData |
| 448 |
+ cl.gameState.stringOffsets[ CS_SERVERINFO ]; |
| 449 |
|
| 450 |
clc.sv_allowDownload = atoi(Info_ValueForKey(serverInfo, |
| 451 |
"sv_allowDownload")); |
| 452 |
Q_strncpyz(clc.sv_dlURL, |
| 453 |
Info_ValueForKey(serverInfo, "sv_dlURL"), |
| 454 |
sizeof(clc.sv_dlURL)); |
| 455 |
} |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
void CL_ParseGamestate( msg_t *msg ) { |
| 463 |
int i; |
| 464 |
entityState_t *es; |
| 465 |
int newnum; |
| 466 |
entityState_t nullstate; |
| 467 |
int cmd; |
| 468 |
char *s; |
| 469 |
char oldGame[MAX_QPATH]; |
| 470 |
|
| 471 |
Con_Close(); |
| 472 |
|
| 473 |
clc.connectPacketCount = 0; |
| 474 |
|
| 475 |
|
| 476 |
CL_ClearState(); |
| 477 |
|
| 478 |
|
| 479 |
clc.serverCommandSequence = MSG_ReadLong( msg ); |
| 480 |
|
| 481 |
|
| 482 |
cl.gameState.dataCount = 1; |
| 483 |
while ( 1 ) { |
| 484 |
cmd = MSG_ReadByte( msg ); |
| 485 |
|
| 486 |
if ( cmd == svc_EOF ) { |
| 487 |
break; |
| 488 |
} |
| 489 |
|
| 490 |
if ( cmd == svc_configstring ) { |
| 491 |
int len; |
| 492 |
|
| 493 |
i = MSG_ReadShort( msg ); |
| 494 |
if ( i < 0 || i >= MAX_CONFIGSTRINGS ) { |
| 495 |
Com_Error( ERR_DROP, "configstring > MAX_CONFIGSTRINGS" ); |
| 496 |
} |
| 497 |
s = MSG_ReadBigString( msg ); |
| 498 |
len = strlen( s ); |
| 499 |
|
| 500 |
if ( len + 1 + cl.gameState.dataCount > MAX_GAMESTATE_CHARS ) { |
| 501 |
Com_Error( ERR_DROP, "MAX_GAMESTATE_CHARS exceeded" ); |
| 502 |
} |
| 503 |
|
| 504 |
|
| 505 |
cl.gameState.stringOffsets[ i ] = cl.gameState.dataCount; |
| 506 |
Com_Memcpy( cl.gameState.stringData + cl.gameState.dataCount, s, len + 1 ); |
| 507 |
cl.gameState.dataCount += len + 1; |
| 508 |
} else if ( cmd == svc_baseline ) { |
| 509 |
newnum = MSG_ReadBits( msg, GENTITYNUM_BITS ); |
| 510 |
if ( newnum < 0 || newnum >= MAX_GENTITIES ) { |
| 511 |
Com_Error( ERR_DROP, "Baseline number out of range: %i", newnum ); |
| 512 |
} |
| 513 |
Com_Memset (&nullstate, 0, sizeof(nullstate)); |
| 514 |
es = &cl.entityBaselines[ newnum ]; |
| 515 |
MSG_ReadDeltaEntity( msg, &nullstate, es, newnum ); |
| 516 |
} else { |
| 517 |
Com_Error( ERR_DROP, "CL_ParseGamestate: bad command byte" ); |
| 518 |
} |
| 519 |
} |
| 520 |
|
| 521 |
clc.clientNum = MSG_ReadLong(msg); |
| 522 |
|
| 523 |
clc.checksumFeed = MSG_ReadLong( msg ); |
| 524 |
|
| 525 |
|
| 526 |
Cvar_VariableStringBuffer("fs_game", oldGame, sizeof(oldGame)); |
| 527 |
|
| 528 |
|
| 529 |
CL_ParseServerInfo(); |
| 530 |
|
| 531 |
|
| 532 |
CL_SystemInfoChanged(); |
| 533 |
|
| 534 |
|
| 535 |
if(cl_autoRecordDemo->integer && clc.demorecording) |
| 536 |
CL_StopRecord_f(); |
| 537 |
|
| 538 |
|
| 539 |
if(!cl_oldGameSet && (Cvar_Flags("fs_game") & CVAR_MODIFIED)) |
| 540 |
{ |
| 541 |
cl_oldGameSet = qtrue; |
| 542 |
Q_strncpyz(cl_oldGame, oldGame, sizeof(cl_oldGame)); |
| 543 |
} |
| 544 |
|
| 545 |
FS_ConditionalRestart(clc.checksumFeed, qfalse); |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
CL_InitDownloads(); |
| 550 |
|
| 551 |
|
| 552 |
Cvar_Set( "cl_paused", "0" ); |
| 553 |
} |
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
void CL_ParseDownload ( msg_t *msg ) { |
| 566 |
int size; |
| 567 |
unsigned char data[MAX_MSGLEN]; |
| 568 |
uint16_t block; |
| 569 |
|
| 570 |
if (!*clc.downloadTempName) { |
| 571 |
Com_Printf("Server sending download, but no download was requested\n"); |
| 572 |
CL_AddReliableCommand("stopdl", qfalse); |
| 573 |
return; |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
block = MSG_ReadShort ( msg ); |
| 578 |
|
| 579 |
if(!block && !clc.downloadBlock) |
| 580 |
{ |
| 581 |
|
| 582 |
clc.downloadSize = MSG_ReadLong ( msg ); |
| 583 |
|
| 584 |
Cvar_SetValue( "cl_downloadSize", clc.downloadSize ); |
| 585 |
|
| 586 |
if (clc.downloadSize < 0) |
| 587 |
{ |
| 588 |
Com_Error( ERR_DROP, "%s", MSG_ReadString( msg ) ); |
| 589 |
return; |
| 590 |
} |
| 591 |
} |
| 592 |
|
| 593 |
size = MSG_ReadShort ( msg ); |
| 594 |
if (size < 0 || size > sizeof(data)) |
| 595 |
{ |
| 596 |
Com_Error(ERR_DROP, "CL_ParseDownload: Invalid size %d for download chunk", size); |
| 597 |
return; |
| 598 |
} |
| 599 |
|
| 600 |
MSG_ReadData(msg, data, size); |
| 601 |
|
| 602 |
if((clc.downloadBlock & 0xFFFF) != block) |
| 603 |
{ |
| 604 |
Com_DPrintf( "CL_ParseDownload: Expected block %d, got %d\n", (clc.downloadBlock & 0xFFFF), block); |
| 605 |
return; |
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
if (!clc.download) |
| 610 |
{ |
| 611 |
clc.download = FS_BaseDir_FOpenFileWrite_HomeData( clc.downloadTempName ); |
| 612 |
|
| 613 |
if (!clc.download) { |
| 614 |
Com_Printf( "Could not create %s\n", clc.downloadTempName ); |
| 615 |
CL_AddReliableCommand("stopdl", qfalse); |
| 616 |
CL_NextDownload(); |
| 617 |
return; |
| 618 |
} |
| 619 |
} |
| 620 |
|
| 621 |
if (size) |
| 622 |
FS_Write( data, size, clc.download ); |
| 623 |
|
| 624 |
CL_AddReliableCommand(va("nextdl %d", clc.downloadBlock), qfalse); |
| 625 |
clc.downloadBlock++; |
| 626 |
|
| 627 |
clc.downloadCount += size; |
| 628 |
|
| 629 |
|
| 630 |
Cvar_SetValue( "cl_downloadCount", clc.downloadCount ); |
| 631 |
|
| 632 |
if (!size) { |
| 633 |
if (clc.download) { |
| 634 |
FS_FCloseFile( clc.download ); |
| 635 |
clc.download = 0; |
| 636 |
|
| 637 |
|
| 638 |
FS_BaseDir_Rename_HomeData ( clc.downloadTempName, clc.downloadName, qfalse ); |
| 639 |
} |
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
CL_WritePacket(); |
| 647 |
CL_WritePacket(); |
| 648 |
|
| 649 |
|
| 650 |
CL_NextDownload (); |
| 651 |
} |
| 652 |
} |
| 653 |
|
| 654 |
#ifdef USE_VOIP |
| 655 |
static |
| 656 |
qboolean CL_ShouldIgnoreVoipSender(int sender) |
| 657 |
{ |
| 658 |
if (!cl_voip->integer) |
| 659 |
return qtrue; |
| 660 |
else if ((sender == clc.clientNum) && (!clc.demoplaying)) |
| 661 |
return qtrue; |
| 662 |
else if (clc.voipMuteAll) |
| 663 |
return qtrue; |
| 664 |
else if (clc.voipIgnore[sender]) |
| 665 |
return qtrue; |
| 666 |
else if (clc.voipGain[sender] == 0.0f) |
| 667 |
return qtrue; |
| 668 |
|
| 669 |
return qfalse; |
| 670 |
} |
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
static void CL_PlayVoip(int sender, int samplecnt, const byte *data, int flags) |
| 681 |
{ |
| 682 |
if(flags & VOIP_DIRECT) |
| 683 |
{ |
| 684 |
S_RawSamples(sender + 1, samplecnt, 48000, 2, 1, |
| 685 |
data, clc.voipGain[sender], -1); |
| 686 |
} |
| 687 |
|
| 688 |
if(flags & VOIP_SPATIAL) |
| 689 |
{ |
| 690 |
S_RawSamples(sender + MAX_CLIENTS + 1, samplecnt, 48000, 2, 1, |
| 691 |
data, 1.0f, sender); |
| 692 |
} |
| 693 |
} |
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
static |
| 703 |
void CL_ParseVoip ( msg_t *msg, qboolean ignoreData ) { |
| 704 |
static short decoded[VOIP_MAX_PACKET_SAMPLES*4]; |
| 705 |
|
| 706 |
const int sender = MSG_ReadShort(msg); |
| 707 |
const int generation = MSG_ReadByte(msg); |
| 708 |
const int sequence = MSG_ReadLong(msg); |
| 709 |
const int frames = MSG_ReadByte(msg); |
| 710 |
const int packetsize = MSG_ReadShort(msg); |
| 711 |
const int flags = MSG_ReadBits(msg, VOIP_FLAGCNT); |
| 712 |
unsigned char encoded[4000]; |
| 713 |
int numSamples; |
| 714 |
int seqdiff; |
| 715 |
int written = 0; |
| 716 |
int i; |
| 717 |
|
| 718 |
Com_DPrintf("VoIP: %d-byte packet from client %d\n", packetsize, sender); |
| 719 |
|
| 720 |
if (sender < 0) |
| 721 |
return; |
| 722 |
else if (generation < 0) |
| 723 |
return; |
| 724 |
else if (sequence < 0) |
| 725 |
return; |
| 726 |
else if (frames < 0) |
| 727 |
return; |
| 728 |
else if (packetsize < 0) |
| 729 |
return; |
| 730 |
|
| 731 |
if (packetsize > sizeof (encoded)) { |
| 732 |
int bytesleft = packetsize; |
| 733 |
while (bytesleft) { |
| 734 |
int br = bytesleft; |
| 735 |
if (br > sizeof (encoded)) |
| 736 |
br = sizeof (encoded); |
| 737 |
MSG_ReadData(msg, encoded, br); |
| 738 |
bytesleft -= br; |
| 739 |
} |
| 740 |
return; |
| 741 |
} |
| 742 |
|
| 743 |
MSG_ReadData(msg, encoded, packetsize); |
| 744 |
|
| 745 |
if (ignoreData) { |
| 746 |
return; |
| 747 |
} else if (!clc.voipCodecInitialized) { |
| 748 |
return; |
| 749 |
} else if (sender >= MAX_CLIENTS) { |
| 750 |
return; |
| 751 |
} else if (CL_ShouldIgnoreVoipSender(sender)) { |
| 752 |
return; |
| 753 |
} |
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
Com_DPrintf("VoIP: packet accepted!\n"); |
| 758 |
|
| 759 |
seqdiff = sequence - clc.voipIncomingSequence[sender]; |
| 760 |
|
| 761 |
|
| 762 |
if (generation != clc.voipIncomingGeneration[sender]) { |
| 763 |
Com_DPrintf("VoIP: new generation %d!\n", generation); |
| 764 |
opus_decoder_ctl(clc.opusDecoder[sender], OPUS_RESET_STATE); |
| 765 |
clc.voipIncomingGeneration[sender] = generation; |
| 766 |
seqdiff = 0; |
| 767 |
} else if (seqdiff < 0) { |
| 768 |
|
| 769 |
Com_DPrintf("VoIP: misordered sequence! %d < %d!\n", |
| 770 |
sequence, clc.voipIncomingSequence[sender]); |
| 771 |
|
| 772 |
opus_decoder_ctl(clc.opusDecoder[sender], OPUS_RESET_STATE); |
| 773 |
seqdiff = 0; |
| 774 |
} else if (seqdiff * VOIP_MAX_PACKET_SAMPLES*2 >= sizeof (decoded)) { |
| 775 |
|
| 776 |
Com_DPrintf("VoIP: Dropped way too many (%d) frames from client #%d\n", |
| 777 |
seqdiff, sender); |
| 778 |
opus_decoder_ctl(clc.opusDecoder[sender], OPUS_RESET_STATE); |
| 779 |
seqdiff = 0; |
| 780 |
} |
| 781 |
|
| 782 |
if (seqdiff != 0) { |
| 783 |
Com_DPrintf("VoIP: Dropped %d frames from client #%d\n", |
| 784 |
seqdiff, sender); |
| 785 |
|
| 786 |
for (i = 0; i < seqdiff; i++) { |
| 787 |
assert((written + VOIP_MAX_PACKET_SAMPLES) * 2 < sizeof (decoded)); |
| 788 |
numSamples = opus_decode(clc.opusDecoder[sender], NULL, 0, decoded + written, VOIP_MAX_PACKET_SAMPLES, 0); |
| 789 |
if ( numSamples <= 0 ) { |
| 790 |
Com_DPrintf("VoIP: Error decoding frame %d from client #%d\n", i, sender); |
| 791 |
continue; |
| 792 |
} |
| 793 |
written += numSamples; |
| 794 |
} |
| 795 |
} |
| 796 |
|
| 797 |
numSamples = opus_decode(clc.opusDecoder[sender], encoded, packetsize, decoded + written, ARRAY_LEN(decoded) - written, 0); |
| 798 |
|
| 799 |
if ( numSamples <= 0 ) { |
| 800 |
Com_DPrintf("VoIP: Error decoding voip data from client #%d\n", sender); |
| 801 |
numSamples = 0; |
| 802 |
} |
| 803 |
|
| 804 |
#if 0 |
| 805 |
static FILE *encio = NULL; |
| 806 |
if (encio == NULL) encio = fopen("voip-incoming-encoded.bin", "wb"); |
| 807 |
if (encio != NULL) { fwrite(encoded, packetsize, 1, encio); fflush(encio); } |
| 808 |
static FILE *decio = NULL; |
| 809 |
if (decio == NULL) decio = fopen("voip-incoming-decoded.bin", "wb"); |
| 810 |
if (decio != NULL) { fwrite(decoded+written, numSamples*2, 1, decio); fflush(decio); } |
| 811 |
#endif |
| 812 |
|
| 813 |
written += numSamples; |
| 814 |
|
| 815 |
Com_DPrintf("VoIP: playback %d bytes, %d samples, %d frames\n", |
| 816 |
written * 2, written, frames); |
| 817 |
|
| 818 |
if(written > 0) |
| 819 |
CL_PlayVoip(sender, written, (const byte *) decoded, flags); |
| 820 |
|
| 821 |
clc.voipIncomingSequence[sender] = sequence + frames; |
| 822 |
} |
| 823 |
#endif |
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
void CL_ParseCommandString( msg_t *msg ) { |
| 835 |
char *s; |
| 836 |
int seq; |
| 837 |
int index; |
| 838 |
|
| 839 |
seq = MSG_ReadLong( msg ); |
| 840 |
s = MSG_ReadString( msg ); |
| 841 |
|
| 842 |
|
| 843 |
if ( clc.serverCommandSequence >= seq ) { |
| 844 |
return; |
| 845 |
} |
| 846 |
clc.serverCommandSequence = seq; |
| 847 |
|
| 848 |
index = seq & (MAX_RELIABLE_COMMANDS-1); |
| 849 |
Q_strncpyz( clc.serverCommands[ index ], s, sizeof( clc.serverCommands[ index ] ) ); |
| 850 |
} |
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
void CL_ParseServerMessage( msg_t *msg ) { |
| 859 |
int cmd; |
| 860 |
|
| 861 |
if ( cl_shownet->integer == 1 ) { |
| 862 |
Com_Printf ("%i ",msg->cursize); |
| 863 |
} else if ( cl_shownet->integer >= 2 ) { |
| 864 |
Com_Printf ("------------------\n"); |
| 865 |
} |
| 866 |
|
| 867 |
MSG_Bitstream(msg); |
| 868 |
|
| 869 |
|
| 870 |
clc.reliableAcknowledge = MSG_ReadLong( msg ); |
| 871 |
|
| 872 |
if ( clc.reliableAcknowledge < clc.reliableSequence - MAX_RELIABLE_COMMANDS ) { |
| 873 |
clc.reliableAcknowledge = clc.reliableSequence; |
| 874 |
} |
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
while ( 1 ) { |
| 880 |
if ( msg->readcount > msg->cursize ) { |
| 881 |
Com_Error (ERR_DROP,"CL_ParseServerMessage: read past end of server message"); |
| 882 |
break; |
| 883 |
} |
| 884 |
|
| 885 |
cmd = MSG_ReadByte( msg ); |
| 886 |
|
| 887 |
if (cmd == svc_EOF) { |
| 888 |
SHOWNET( msg, "END OF MESSAGE" ); |
| 889 |
break; |
| 890 |
} |
| 891 |
|
| 892 |
if ( cl_shownet->integer >= 2 ) { |
| 893 |
if ( (cmd < 0) || (!svc_strings[cmd]) ) { |
| 894 |
Com_Printf( "%3i:BAD CMD %i\n", msg->readcount-1, cmd ); |
| 895 |
} else { |
| 896 |
SHOWNET( msg, svc_strings[cmd] ); |
| 897 |
} |
| 898 |
} |
| 899 |
|
| 900 |
|
| 901 |
switch ( cmd ) { |
| 902 |
default: |
| 903 |
Com_Error (ERR_DROP,"CL_ParseServerMessage: Illegible server message"); |
| 904 |
break; |
| 905 |
case svc_nop: |
| 906 |
break; |
| 907 |
case svc_serverCommand: |
| 908 |
CL_ParseCommandString( msg ); |
| 909 |
break; |
| 910 |
case svc_gamestate: |
| 911 |
CL_ParseGamestate( msg ); |
| 912 |
break; |
| 913 |
case svc_snapshot: |
| 914 |
CL_ParseSnapshot( msg ); |
| 915 |
break; |
| 916 |
case svc_download: |
| 917 |
CL_ParseDownload( msg ); |
| 918 |
break; |
| 919 |
case svc_voipSpeex: |
| 920 |
#ifdef USE_VOIP |
| 921 |
CL_ParseVoip( msg, qtrue ); |
| 922 |
#endif |
| 923 |
break; |
| 924 |
case svc_voipOpus: |
| 925 |
#ifdef USE_VOIP |
| 926 |
CL_ParseVoip( msg, !clc.voipEnabled ); |
| 927 |
#endif |
| 928 |
break; |
| 929 |
} |
| 930 |
} |
| 931 |
} |
| 932 |
|
| 933 |
|