| 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 |
#include <limits.h> |
| 26 |
|
| 27 |
#include "../sys/sys_local.h" |
| 28 |
#include "../sys/sys_loadlib.h" |
| 29 |
|
| 30 |
#ifdef USE_MUMBLE |
| 31 |
#include "libmumblelink.h" |
| 32 |
#endif |
| 33 |
|
| 34 |
#ifdef USE_MUMBLE |
| 35 |
cvar_t *cl_useMumble; |
| 36 |
cvar_t *cl_mumbleScale; |
| 37 |
#endif |
| 38 |
|
| 39 |
#ifdef USE_VOIP |
| 40 |
cvar_t *cl_voipUseVAD; |
| 41 |
cvar_t *cl_voipVADThreshold; |
| 42 |
cvar_t *cl_voipSend; |
| 43 |
cvar_t *cl_voipSendTarget; |
| 44 |
cvar_t *cl_voipGainDuringCapture; |
| 45 |
cvar_t *cl_voipCaptureMult; |
| 46 |
cvar_t *cl_voipShowMeter; |
| 47 |
cvar_t *cl_voipProtocol; |
| 48 |
cvar_t *cl_voip; |
| 49 |
#endif |
| 50 |
|
| 51 |
#ifdef USE_RENDERER_DLOPEN |
| 52 |
cvar_t *cl_renderer; |
| 53 |
#endif |
| 54 |
|
| 55 |
cvar_t *cl_nodelta; |
| 56 |
cvar_t *cl_debugMove; |
| 57 |
|
| 58 |
cvar_t *cl_noprint; |
| 59 |
#ifdef UPDATE_SERVER_NAME |
| 60 |
cvar_t *cl_motd; |
| 61 |
#endif |
| 62 |
|
| 63 |
cvar_t *rcon_client_password; |
| 64 |
cvar_t *rconAddress; |
| 65 |
|
| 66 |
cvar_t *cl_timeout; |
| 67 |
cvar_t *cl_maxpackets; |
| 68 |
cvar_t *cl_packetdup; |
| 69 |
cvar_t *cl_timeNudge; |
| 70 |
cvar_t *cl_showTimeDelta; |
| 71 |
cvar_t *cl_freezeDemo; |
| 72 |
|
| 73 |
cvar_t *cl_shownet; |
| 74 |
cvar_t *cl_showSend; |
| 75 |
cvar_t *cl_timedemo; |
| 76 |
cvar_t *cl_timedemoLog; |
| 77 |
cvar_t *cl_autoRecordDemo; |
| 78 |
cvar_t *cl_aviFrameRate; |
| 79 |
cvar_t *cl_aviMotionJpeg; |
| 80 |
cvar_t *cl_forceavidemo; |
| 81 |
|
| 82 |
cvar_t *cl_freelook; |
| 83 |
cvar_t *cl_sensitivity; |
| 84 |
|
| 85 |
cvar_t *cl_mouseAccel; |
| 86 |
cvar_t *cl_mouseAccelOffset; |
| 87 |
cvar_t *cl_mouseAccelStyle; |
| 88 |
cvar_t *cl_showMouseRate; |
| 89 |
|
| 90 |
cvar_t *m_pitch; |
| 91 |
cvar_t *m_yaw; |
| 92 |
cvar_t *m_forward; |
| 93 |
cvar_t *m_side; |
| 94 |
cvar_t *m_filter; |
| 95 |
|
| 96 |
cvar_t *j_pitch; |
| 97 |
cvar_t *j_yaw; |
| 98 |
cvar_t *j_forward; |
| 99 |
cvar_t *j_side; |
| 100 |
cvar_t *j_up; |
| 101 |
cvar_t *j_pitch_axis; |
| 102 |
cvar_t *j_yaw_axis; |
| 103 |
cvar_t *j_forward_axis; |
| 104 |
cvar_t *j_side_axis; |
| 105 |
cvar_t *j_up_axis; |
| 106 |
|
| 107 |
cvar_t *cl_activeAction; |
| 108 |
|
| 109 |
cvar_t *cl_motdString; |
| 110 |
|
| 111 |
cvar_t *cl_allowDownload; |
| 112 |
cvar_t *cl_conXOffset; |
| 113 |
cvar_t *cl_inGameVideo; |
| 114 |
|
| 115 |
cvar_t *cl_serverStatusResendTime; |
| 116 |
|
| 117 |
cvar_t *cl_lanForcePackets; |
| 118 |
|
| 119 |
cvar_t *cl_guidServerUniq; |
| 120 |
|
| 121 |
cvar_t *cl_consoleKeys; |
| 122 |
|
| 123 |
cvar_t *cl_rate; |
| 124 |
|
| 125 |
clientActive_t cl; |
| 126 |
clientConnection_t clc; |
| 127 |
clientStatic_t cls; |
| 128 |
vm_t *cgvm; |
| 129 |
|
| 130 |
char cl_reconnectArgs[MAX_OSPATH]; |
| 131 |
char cl_oldGame[MAX_QPATH]; |
| 132 |
qboolean cl_oldGameSet; |
| 133 |
|
| 134 |
|
| 135 |
refexport_t re; |
| 136 |
#ifdef USE_RENDERER_DLOPEN |
| 137 |
static void *rendererLib = NULL; |
| 138 |
#endif |
| 139 |
|
| 140 |
ping_t cl_pinglist[MAX_PINGREQUESTS]; |
| 141 |
|
| 142 |
typedef struct serverStatus_s |
| 143 |
{ |
| 144 |
char string[BIG_INFO_STRING]; |
| 145 |
netadr_t address; |
| 146 |
int time, startTime; |
| 147 |
qboolean pending; |
| 148 |
qboolean print; |
| 149 |
qboolean retrieved; |
| 150 |
} serverStatus_t; |
| 151 |
|
| 152 |
serverStatus_t cl_serverStatusList[MAX_SERVERSTATUSREQUESTS]; |
| 153 |
|
| 154 |
#if defined __USEA3D && defined __A3D_GEOM |
| 155 |
void hA3Dg_ExportRenderGeom (refexport_t *incoming_re); |
| 156 |
#endif |
| 157 |
|
| 158 |
static int noGameRestart = qfalse; |
| 159 |
|
| 160 |
extern void SV_BotFrame( int time ); |
| 161 |
void CL_CheckForResend( void ); |
| 162 |
void CL_ShowIP_f(void); |
| 163 |
void CL_ServerStatus_f(void); |
| 164 |
void CL_ServerStatusResponse( netadr_t from, msg_t *msg ); |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
void CL_CDDialog( void ) { |
| 174 |
cls.cddialog = qtrue; |
| 175 |
} |
| 176 |
|
| 177 |
#ifdef USE_MUMBLE |
| 178 |
static |
| 179 |
void CL_UpdateMumble(void) |
| 180 |
{ |
| 181 |
vec3_t pos, forward, up; |
| 182 |
float scale = cl_mumbleScale->value; |
| 183 |
float tmp; |
| 184 |
|
| 185 |
if(!cl_useMumble->integer) |
| 186 |
return; |
| 187 |
|
| 188 |
|
| 189 |
AngleVectors( cl.snap.ps.viewangles, forward, NULL, up); |
| 190 |
|
| 191 |
pos[0] = cl.snap.ps.origin[0] * scale; |
| 192 |
pos[1] = cl.snap.ps.origin[2] * scale; |
| 193 |
pos[2] = cl.snap.ps.origin[1] * scale; |
| 194 |
|
| 195 |
tmp = forward[1]; |
| 196 |
forward[1] = forward[2]; |
| 197 |
forward[2] = tmp; |
| 198 |
|
| 199 |
tmp = up[1]; |
| 200 |
up[1] = up[2]; |
| 201 |
up[2] = tmp; |
| 202 |
|
| 203 |
if(cl_useMumble->integer > 1) { |
| 204 |
fprintf(stderr, "%f %f %f, %f %f %f, %f %f %f\n", |
| 205 |
pos[0], pos[1], pos[2], |
| 206 |
forward[0], forward[1], forward[2], |
| 207 |
up[0], up[1], up[2]); |
| 208 |
} |
| 209 |
|
| 210 |
mumble_update_coordinates(pos, forward, up); |
| 211 |
} |
| 212 |
#endif |
| 213 |
|
| 214 |
|
| 215 |
#ifdef USE_VOIP |
| 216 |
static |
| 217 |
void CL_UpdateVoipIgnore(const char *idstr, qboolean ignore) |
| 218 |
{ |
| 219 |
if ((*idstr >= '0') && (*idstr <= '9')) { |
| 220 |
const int id = atoi(idstr); |
| 221 |
if ((id >= 0) && (id < MAX_CLIENTS)) { |
| 222 |
clc.voipIgnore[id] = ignore; |
| 223 |
CL_AddReliableCommand(va("voip %s %d", |
| 224 |
ignore ? "ignore" : "unignore", id), qfalse); |
| 225 |
Com_Printf("VoIP: %s ignoring player #%d\n", |
| 226 |
ignore ? "Now" : "No longer", id); |
| 227 |
return; |
| 228 |
} |
| 229 |
} |
| 230 |
Com_Printf("VoIP: invalid player ID#\n"); |
| 231 |
} |
| 232 |
|
| 233 |
static |
| 234 |
void CL_UpdateVoipGain(const char *idstr, float gain) |
| 235 |
{ |
| 236 |
if ((*idstr >= '0') && (*idstr <= '9')) { |
| 237 |
const int id = atoi(idstr); |
| 238 |
if (gain < 0.0f) |
| 239 |
gain = 0.0f; |
| 240 |
if ((id >= 0) && (id < MAX_CLIENTS)) { |
| 241 |
clc.voipGain[id] = gain; |
| 242 |
Com_Printf("VoIP: player #%d gain now set to %f\n", id, gain); |
| 243 |
} |
| 244 |
} |
| 245 |
} |
| 246 |
|
| 247 |
void CL_Voip_f( void ) |
| 248 |
{ |
| 249 |
const char *cmd = Cmd_Argv(1); |
| 250 |
const char *reason = NULL; |
| 251 |
|
| 252 |
if (clc.state != CA_ACTIVE) |
| 253 |
reason = "Not connected to a server"; |
| 254 |
else if (!clc.voipCodecInitialized) |
| 255 |
reason = "Voip codec not initialized"; |
| 256 |
else if (!clc.voipEnabled) |
| 257 |
reason = "Server doesn't support VoIP"; |
| 258 |
else if (!clc.demoplaying && (Cvar_VariableValue( "g_gametype" ) == GT_SINGLE_PLAYER || Cvar_VariableValue("ui_singlePlayerActive"))) |
| 259 |
reason = "running in single-player mode"; |
| 260 |
|
| 261 |
if (reason != NULL) { |
| 262 |
Com_Printf("VoIP: command ignored: %s\n", reason); |
| 263 |
return; |
| 264 |
} |
| 265 |
|
| 266 |
if (strcmp(cmd, "ignore") == 0) { |
| 267 |
CL_UpdateVoipIgnore(Cmd_Argv(2), qtrue); |
| 268 |
} else if (strcmp(cmd, "unignore") == 0) { |
| 269 |
CL_UpdateVoipIgnore(Cmd_Argv(2), qfalse); |
| 270 |
} else if (strcmp(cmd, "gain") == 0) { |
| 271 |
if (Cmd_Argc() > 3) { |
| 272 |
CL_UpdateVoipGain(Cmd_Argv(2), atof(Cmd_Argv(3))); |
| 273 |
} else if (Q_isanumber(Cmd_Argv(2))) { |
| 274 |
int id = atoi(Cmd_Argv(2)); |
| 275 |
if (id >= 0 && id < MAX_CLIENTS) { |
| 276 |
Com_Printf("VoIP: current gain for player #%d " |
| 277 |
"is %f\n", id, clc.voipGain[id]); |
| 278 |
} else { |
| 279 |
Com_Printf("VoIP: invalid player ID#\n"); |
| 280 |
} |
| 281 |
} else { |
| 282 |
Com_Printf("usage: voip gain <playerID#> [value]\n"); |
| 283 |
} |
| 284 |
} else if (strcmp(cmd, "muteall") == 0) { |
| 285 |
Com_Printf("VoIP: muting incoming voice\n"); |
| 286 |
CL_AddReliableCommand("voip muteall", qfalse); |
| 287 |
clc.voipMuteAll = qtrue; |
| 288 |
} else if (strcmp(cmd, "unmuteall") == 0) { |
| 289 |
Com_Printf("VoIP: unmuting incoming voice\n"); |
| 290 |
CL_AddReliableCommand("voip unmuteall", qfalse); |
| 291 |
clc.voipMuteAll = qfalse; |
| 292 |
} else { |
| 293 |
Com_Printf("usage: voip [un]ignore <playerID#>\n" |
| 294 |
" voip [un]muteall\n" |
| 295 |
" voip gain <playerID#> [value]\n"); |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
static |
| 301 |
void CL_VoipNewGeneration(void) |
| 302 |
{ |
| 303 |
|
| 304 |
|
| 305 |
clc.voipOutgoingGeneration++; |
| 306 |
if (clc.voipOutgoingGeneration <= 0) |
| 307 |
clc.voipOutgoingGeneration = 1; |
| 308 |
clc.voipPower = 0.0f; |
| 309 |
clc.voipOutgoingSequence = 0; |
| 310 |
|
| 311 |
opus_encoder_ctl(clc.opusEncoder, OPUS_RESET_STATE); |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
void CL_VoipParseTargets(void) |
| 324 |
{ |
| 325 |
const char *target = cl_voipSendTarget->string; |
| 326 |
char *end; |
| 327 |
int val; |
| 328 |
|
| 329 |
Com_Memset(clc.voipTargets, 0, sizeof(clc.voipTargets)); |
| 330 |
clc.voipFlags &= ~VOIP_SPATIAL; |
| 331 |
|
| 332 |
while(target) |
| 333 |
{ |
| 334 |
while(*target == ',' || *target == ' ') |
| 335 |
target++; |
| 336 |
|
| 337 |
if(!*target) |
| 338 |
break; |
| 339 |
|
| 340 |
if(isdigit(*target)) |
| 341 |
{ |
| 342 |
val = strtol(target, &end, 10); |
| 343 |
target = end; |
| 344 |
} |
| 345 |
else |
| 346 |
{ |
| 347 |
if(!Q_stricmpn(target, "all", 3)) |
| 348 |
{ |
| 349 |
Com_Memset(clc.voipTargets, ~0, sizeof(clc.voipTargets)); |
| 350 |
return; |
| 351 |
} |
| 352 |
if(!Q_stricmpn(target, "spatial", 7)) |
| 353 |
{ |
| 354 |
clc.voipFlags |= VOIP_SPATIAL; |
| 355 |
target += 7; |
| 356 |
continue; |
| 357 |
} |
| 358 |
else |
| 359 |
{ |
| 360 |
if(!Q_stricmpn(target, "attacker", 8)) |
| 361 |
{ |
| 362 |
val = VM_Call(cgvm, CG_LAST_ATTACKER); |
| 363 |
target += 8; |
| 364 |
} |
| 365 |
else if(!Q_stricmpn(target, "crosshair", 9)) |
| 366 |
{ |
| 367 |
val = VM_Call(cgvm, CG_CROSSHAIR_PLAYER); |
| 368 |
target += 9; |
| 369 |
} |
| 370 |
else |
| 371 |
{ |
| 372 |
while(*target && *target != ',' && *target != ' ') |
| 373 |
target++; |
| 374 |
|
| 375 |
continue; |
| 376 |
} |
| 377 |
|
| 378 |
if(val < 0) |
| 379 |
continue; |
| 380 |
} |
| 381 |
} |
| 382 |
|
| 383 |
if(val < 0 || val >= MAX_CLIENTS) |
| 384 |
{ |
| 385 |
Com_Printf(S_COLOR_YELLOW "WARNING: VoIP " |
| 386 |
"target %d is not a valid client " |
| 387 |
"number\n", val); |
| 388 |
|
| 389 |
continue; |
| 390 |
} |
| 391 |
|
| 392 |
clc.voipTargets[val / 8] |= 1 << (val % 8); |
| 393 |
} |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
static |
| 405 |
void CL_CaptureVoip(void) |
| 406 |
{ |
| 407 |
const float audioMult = cl_voipCaptureMult->value; |
| 408 |
const qboolean useVad = (cl_voipUseVAD->integer != 0); |
| 409 |
qboolean initialFrame = qfalse; |
| 410 |
qboolean finalFrame = qfalse; |
| 411 |
|
| 412 |
#if USE_MUMBLE |
| 413 |
|
| 414 |
if (cl_useMumble->integer) |
| 415 |
return; |
| 416 |
#endif |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
if (cl_voip->modified || cl_rate->modified) { |
| 424 |
if ((cl_voip->integer) && (cl_rate->integer < 25000)) { |
| 425 |
Com_Printf(S_COLOR_YELLOW "Your network rate is too slow for VoIP.\n"); |
| 426 |
Com_Printf("Set 'Data Rate' to 'LAN/Cable/xDSL' in 'Setup/System/Network'.\n"); |
| 427 |
Com_Printf("Until then, VoIP is disabled.\n"); |
| 428 |
Cvar_Set("cl_voip", "0"); |
| 429 |
} |
| 430 |
Cvar_Set("cl_voipProtocol", cl_voip->integer ? "opus" : ""); |
| 431 |
cl_voip->modified = qfalse; |
| 432 |
cl_rate->modified = qfalse; |
| 433 |
} |
| 434 |
|
| 435 |
if (!clc.voipCodecInitialized) |
| 436 |
return; |
| 437 |
|
| 438 |
if (clc.voipOutgoingDataSize > 0) |
| 439 |
return; |
| 440 |
|
| 441 |
if (cl_voipUseVAD->modified) { |
| 442 |
Cvar_Set("cl_voipSend", (useVad) ? "1" : "0"); |
| 443 |
cl_voipUseVAD->modified = qfalse; |
| 444 |
} |
| 445 |
|
| 446 |
if ((useVad) && (!cl_voipSend->integer)) |
| 447 |
Cvar_Set("cl_voipSend", "1"); |
| 448 |
|
| 449 |
if (cl_voipSend->modified) { |
| 450 |
qboolean dontCapture = qfalse; |
| 451 |
if (clc.state != CA_ACTIVE) |
| 452 |
dontCapture = qtrue; |
| 453 |
else if (!clc.voipEnabled) |
| 454 |
dontCapture = qtrue; |
| 455 |
else if (clc.demoplaying) |
| 456 |
dontCapture = qtrue; |
| 457 |
else if ( cl_voip->integer == 0 ) |
| 458 |
dontCapture = qtrue; |
| 459 |
else if ( audioMult == 0.0f ) |
| 460 |
dontCapture = qtrue; |
| 461 |
|
| 462 |
cl_voipSend->modified = qfalse; |
| 463 |
|
| 464 |
if(dontCapture) |
| 465 |
{ |
| 466 |
Cvar_Set("cl_voipSend", "0"); |
| 467 |
return; |
| 468 |
} |
| 469 |
|
| 470 |
if (cl_voipSend->integer) { |
| 471 |
initialFrame = qtrue; |
| 472 |
} else { |
| 473 |
finalFrame = qtrue; |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
if (initialFrame) { |
| 480 |
S_MasterGain(Com_Clamp(0.0f, 1.0f, cl_voipGainDuringCapture->value)); |
| 481 |
S_StartCapture(); |
| 482 |
CL_VoipNewGeneration(); |
| 483 |
CL_VoipParseTargets(); |
| 484 |
} |
| 485 |
|
| 486 |
if ((cl_voipSend->integer) || (finalFrame)) { |
| 487 |
int samples = S_AvailableCaptureSamples(); |
| 488 |
const int packetSamples = (finalFrame) ? VOIP_MAX_FRAME_SAMPLES : VOIP_MAX_PACKET_SAMPLES; |
| 489 |
|
| 490 |
|
| 491 |
if (samples >= packetSamples) { |
| 492 |
|
| 493 |
static int16_t sampbuffer[VOIP_MAX_PACKET_SAMPLES]; |
| 494 |
float voipPower = 0.0f; |
| 495 |
int voipFrames; |
| 496 |
int i, bytes; |
| 497 |
|
| 498 |
if (samples > VOIP_MAX_PACKET_SAMPLES) |
| 499 |
samples = VOIP_MAX_PACKET_SAMPLES; |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
samples -= samples % VOIP_MAX_FRAME_SAMPLES; |
| 505 |
if (samples != 120 && samples != 240 && samples != 480 && samples != 960 && samples != 1920 && samples != 2880 ) { |
| 506 |
Com_Printf("Voip: bad number of samples %d\n", samples); |
| 507 |
return; |
| 508 |
} |
| 509 |
voipFrames = samples / VOIP_MAX_FRAME_SAMPLES; |
| 510 |
|
| 511 |
S_Capture(samples, (byte *) sampbuffer); |
| 512 |
|
| 513 |
|
| 514 |
for (i = 0; i < samples; i++) { |
| 515 |
const float flsamp = (float) sampbuffer[i]; |
| 516 |
const float s = fabs(flsamp); |
| 517 |
voipPower += s * s; |
| 518 |
sampbuffer[i] = (int16_t) ((flsamp) * audioMult); |
| 519 |
} |
| 520 |
|
| 521 |
|
| 522 |
bytes = opus_encode(clc.opusEncoder, sampbuffer, samples, |
| 523 |
(unsigned char *) clc.voipOutgoingData, |
| 524 |
sizeof (clc.voipOutgoingData)); |
| 525 |
if ( bytes <= 0 ) { |
| 526 |
Com_DPrintf("VoIP: Error encoding %d samples\n", samples); |
| 527 |
bytes = 0; |
| 528 |
} |
| 529 |
|
| 530 |
clc.voipPower = (voipPower / (32768.0f * 32768.0f * |
| 531 |
((float) samples))) * 100.0f; |
| 532 |
|
| 533 |
if ((useVad) && (clc.voipPower < cl_voipVADThreshold->value)) { |
| 534 |
CL_VoipNewGeneration(); |
| 535 |
} else { |
| 536 |
clc.voipOutgoingDataSize = bytes; |
| 537 |
clc.voipOutgoingDataFrames = voipFrames; |
| 538 |
|
| 539 |
Com_DPrintf("VoIP: Send %d frames, %d bytes, %f power\n", |
| 540 |
voipFrames, bytes, clc.voipPower); |
| 541 |
|
| 542 |
#if 0 |
| 543 |
static FILE *encio = NULL; |
| 544 |
if (encio == NULL) encio = fopen("voip-outgoing-encoded.bin", "wb"); |
| 545 |
if (encio != NULL) { fwrite(clc.voipOutgoingData, bytes, 1, encio); fflush(encio); } |
| 546 |
static FILE *decio = NULL; |
| 547 |
if (decio == NULL) decio = fopen("voip-outgoing-decoded.bin", "wb"); |
| 548 |
if (decio != NULL) { fwrite(sampbuffer, voipFrames * VOIP_MAX_FRAME_SAMPLES * 2, 1, decio); fflush(decio); } |
| 549 |
#endif |
| 550 |
} |
| 551 |
} |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
if (finalFrame) { |
| 557 |
S_StopCapture(); |
| 558 |
S_MasterGain(1.0f); |
| 559 |
clc.voipPower = 0.0f; |
| 560 |
} |
| 561 |
} |
| 562 |
#endif |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
void CL_AddReliableCommand(const char *cmd, qboolean isDisconnectCmd) |
| 581 |
{ |
| 582 |
int unacknowledged = clc.reliableSequence - clc.reliableAcknowledge; |
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
if ((isDisconnectCmd && unacknowledged > MAX_RELIABLE_COMMANDS) || |
| 589 |
(!isDisconnectCmd && unacknowledged >= MAX_RELIABLE_COMMANDS)) |
| 590 |
{ |
| 591 |
if(com_errorEntered) |
| 592 |
return; |
| 593 |
else |
| 594 |
Com_Error(ERR_DROP, "Client command overflow"); |
| 595 |
} |
| 596 |
|
| 597 |
Q_strncpyz(clc.reliableCommands[++clc.reliableSequence & (MAX_RELIABLE_COMMANDS - 1)], |
| 598 |
cmd, sizeof(*clc.reliableCommands)); |
| 599 |
} |
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
void CL_WriteDemoMessage ( msg_t *msg, int headerBytes ) { |
| 618 |
int len, swlen; |
| 619 |
|
| 620 |
|
| 621 |
len = clc.serverMessageSequence; |
| 622 |
swlen = LittleLong( len ); |
| 623 |
FS_Write (&swlen, 4, clc.demofile); |
| 624 |
|
| 625 |
len = msg->cursize - headerBytes; |
| 626 |
swlen = LittleLong(len); |
| 627 |
FS_Write (&swlen, 4, clc.demofile); |
| 628 |
FS_Write ( msg->data + headerBytes, len, clc.demofile ); |
| 629 |
} |
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
void CL_StopRecord_f( void ) { |
| 640 |
int len; |
| 641 |
|
| 642 |
if ( !clc.demorecording ) { |
| 643 |
Com_Printf ("Not recording a demo.\n"); |
| 644 |
return; |
| 645 |
} |
| 646 |
|
| 647 |
|
| 648 |
len = -1; |
| 649 |
FS_Write (&len, 4, clc.demofile); |
| 650 |
FS_Write (&len, 4, clc.demofile); |
| 651 |
FS_FCloseFile (clc.demofile); |
| 652 |
clc.demofile = 0; |
| 653 |
clc.demorecording = qfalse; |
| 654 |
clc.spDemoRecording = qfalse; |
| 655 |
Com_Printf ("Stopped demo.\n"); |
| 656 |
} |
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
void CL_DemoFilename( int number, char *fileName, int fileNameSize ) { |
| 664 |
int a,b,c,d; |
| 665 |
|
| 666 |
if(number < 0 || number > 9999) |
| 667 |
number = 9999; |
| 668 |
|
| 669 |
a = number / 1000; |
| 670 |
number -= a*1000; |
| 671 |
b = number / 100; |
| 672 |
number -= b*100; |
| 673 |
c = number / 10; |
| 674 |
number -= c*10; |
| 675 |
d = number; |
| 676 |
|
| 677 |
Com_sprintf( fileName, fileNameSize, "demo%i%i%i%i" |
| 678 |
, a, b, c, d ); |
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
static char demoName[MAX_QPATH]; |
| 691 |
void CL_Record_f( void ) { |
| 692 |
char name[MAX_OSPATH]; |
| 693 |
byte bufData[MAX_MSGLEN]; |
| 694 |
msg_t buf; |
| 695 |
int i; |
| 696 |
int len; |
| 697 |
entityState_t *ent; |
| 698 |
entityState_t nullstate; |
| 699 |
char *s; |
| 700 |
|
| 701 |
if ( Cmd_Argc() > 2 ) { |
| 702 |
Com_Printf ("record <demoname>\n"); |
| 703 |
return; |
| 704 |
} |
| 705 |
|
| 706 |
if ( clc.demorecording ) { |
| 707 |
if (!clc.spDemoRecording) { |
| 708 |
Com_Printf ("Already recording.\n"); |
| 709 |
} |
| 710 |
return; |
| 711 |
} |
| 712 |
|
| 713 |
if ( clc.state != CA_ACTIVE ) { |
| 714 |
Com_Printf ("You must be in a level to record.\n"); |
| 715 |
return; |
| 716 |
} |
| 717 |
|
| 718 |
|
| 719 |
if ( NET_IsLocalAddress( clc.serverAddress ) && !Cvar_VariableValue( "g_synchronousClients" ) ) { |
| 720 |
Com_Printf (S_COLOR_YELLOW "WARNING: You should set 'g_synchronousClients 1' for smoother demo recording\n"); |
| 721 |
} |
| 722 |
|
| 723 |
if ( Cmd_Argc() == 2 ) { |
| 724 |
s = Cmd_Argv(1); |
| 725 |
Q_strncpyz( demoName, s, sizeof( demoName ) ); |
| 726 |
#ifdef LEGACY_PROTOCOL |
| 727 |
if(clc.compat) |
| 728 |
Com_sprintf(name, sizeof(name), "demos/%s.%s%d", demoName, DEMOEXT, com_legacyprotocol->integer); |
| 729 |
else |
| 730 |
#endif |
| 731 |
Com_sprintf(name, sizeof(name), "demos/%s.%s%d", demoName, DEMOEXT, com_protocol->integer); |
| 732 |
} else { |
| 733 |
int number; |
| 734 |
|
| 735 |
|
| 736 |
for ( number = 0 ; number <= 9999 ; number++ ) { |
| 737 |
CL_DemoFilename( number, demoName, sizeof( demoName ) ); |
| 738 |
#ifdef LEGACY_PROTOCOL |
| 739 |
if(clc.compat) |
| 740 |
Com_sprintf(name, sizeof(name), "demos/%s.%s%d", demoName, DEMOEXT, com_legacyprotocol->integer); |
| 741 |
else |
| 742 |
#endif |
| 743 |
Com_sprintf(name, sizeof(name), "demos/%s.%s%d", demoName, DEMOEXT, com_protocol->integer); |
| 744 |
|
| 745 |
if (!FS_FileExists_HomeData(name)) |
| 746 |
break; |
| 747 |
} |
| 748 |
} |
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
Com_Printf ("recording to %s.\n", name); |
| 753 |
clc.demofile = FS_FOpenFileWrite_HomeData( name ); |
| 754 |
if ( !clc.demofile ) { |
| 755 |
Com_Printf ("ERROR: couldn't open.\n"); |
| 756 |
return; |
| 757 |
} |
| 758 |
clc.demorecording = qtrue; |
| 759 |
if (Cvar_VariableValue("ui_recordSPDemo")) { |
| 760 |
clc.spDemoRecording = qtrue; |
| 761 |
} else { |
| 762 |
clc.spDemoRecording = qfalse; |
| 763 |
} |
| 764 |
|
| 765 |
Q_strncpyz( clc.demoName, demoName, sizeof( clc.demoName ) ); |
| 766 |
|
| 767 |
|
| 768 |
clc.demowaiting = qtrue; |
| 769 |
|
| 770 |
|
| 771 |
MSG_Init (&buf, bufData, sizeof(bufData)); |
| 772 |
MSG_Bitstream(&buf); |
| 773 |
|
| 774 |
|
| 775 |
MSG_WriteLong( &buf, clc.reliableSequence ); |
| 776 |
|
| 777 |
MSG_WriteByte (&buf, svc_gamestate); |
| 778 |
MSG_WriteLong (&buf, clc.serverCommandSequence ); |
| 779 |
|
| 780 |
|
| 781 |
for ( i = 0 ; i < MAX_CONFIGSTRINGS ; i++ ) { |
| 782 |
if ( !cl.gameState.stringOffsets[i] ) { |
| 783 |
continue; |
| 784 |
} |
| 785 |
s = cl.gameState.stringData + cl.gameState.stringOffsets[i]; |
| 786 |
MSG_WriteByte (&buf, svc_configstring); |
| 787 |
MSG_WriteShort (&buf, i); |
| 788 |
MSG_WriteBigString (&buf, s); |
| 789 |
} |
| 790 |
|
| 791 |
|
| 792 |
Com_Memset (&nullstate, 0, sizeof(nullstate)); |
| 793 |
for ( i = 0; i < MAX_GENTITIES ; i++ ) { |
| 794 |
ent = &cl.entityBaselines[i]; |
| 795 |
if ( !ent->number ) { |
| 796 |
continue; |
| 797 |
} |
| 798 |
MSG_WriteByte (&buf, svc_baseline); |
| 799 |
MSG_WriteDeltaEntity (&buf, &nullstate, ent, qtrue ); |
| 800 |
} |
| 801 |
|
| 802 |
MSG_WriteByte( &buf, svc_EOF ); |
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
MSG_WriteLong(&buf, clc.clientNum); |
| 808 |
|
| 809 |
MSG_WriteLong(&buf, clc.checksumFeed); |
| 810 |
|
| 811 |
|
| 812 |
MSG_WriteByte( &buf, svc_EOF ); |
| 813 |
|
| 814 |
|
| 815 |
len = LittleLong( clc.serverMessageSequence - 1 ); |
| 816 |
FS_Write (&len, 4, clc.demofile); |
| 817 |
|
| 818 |
len = LittleLong (buf.cursize); |
| 819 |
FS_Write (&len, 4, clc.demofile); |
| 820 |
FS_Write (buf.data, buf.cursize, clc.demofile); |
| 821 |
|
| 822 |
|
| 823 |
} |
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
static float CL_DemoFrameDurationSDev( void ) |
| 839 |
{ |
| 840 |
int i; |
| 841 |
int numFrames; |
| 842 |
float mean = 0.0f; |
| 843 |
float variance = 0.0f; |
| 844 |
|
| 845 |
if( ( clc.timeDemoFrames - 1 ) > MAX_TIMEDEMO_DURATIONS ) |
| 846 |
numFrames = MAX_TIMEDEMO_DURATIONS; |
| 847 |
else |
| 848 |
numFrames = clc.timeDemoFrames - 1; |
| 849 |
|
| 850 |
for( i = 0; i < numFrames; i++ ) |
| 851 |
mean += clc.timeDemoDurations[ i ]; |
| 852 |
mean /= numFrames; |
| 853 |
|
| 854 |
for( i = 0; i < numFrames; i++ ) |
| 855 |
{ |
| 856 |
float x = clc.timeDemoDurations[ i ]; |
| 857 |
|
| 858 |
variance += ( ( x - mean ) * ( x - mean ) ); |
| 859 |
} |
| 860 |
variance /= numFrames; |
| 861 |
|
| 862 |
return sqrt( variance ); |
| 863 |
} |
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
void CL_DemoCompleted( void ) |
| 871 |
{ |
| 872 |
char buffer[ MAX_STRING_CHARS ]; |
| 873 |
|
| 874 |
if( cl_timedemo && cl_timedemo->integer ) |
| 875 |
{ |
| 876 |
int time; |
| 877 |
|
| 878 |
time = Sys_Milliseconds() - clc.timeDemoStart; |
| 879 |
if( time > 0 ) |
| 880 |
{ |
| 881 |
|
| 882 |
|
| 883 |
Com_sprintf( buffer, sizeof( buffer ), |
| 884 |
"%i frames %3.1f seconds %3.1f fps %d.0/%.1f/%d.0/%.1f ms\n", |
| 885 |
clc.timeDemoFrames, |
| 886 |
time/1000.0, |
| 887 |
clc.timeDemoFrames*1000.0 / time, |
| 888 |
clc.timeDemoMinDuration, |
| 889 |
time / (float)clc.timeDemoFrames, |
| 890 |
clc.timeDemoMaxDuration, |
| 891 |
CL_DemoFrameDurationSDev( ) ); |
| 892 |
Com_Printf( "%s", buffer ); |
| 893 |
|
| 894 |
|
| 895 |
if( cl_timedemoLog && strlen( cl_timedemoLog->string ) > 0 ) |
| 896 |
{ |
| 897 |
int i; |
| 898 |
int numFrames; |
| 899 |
fileHandle_t f; |
| 900 |
|
| 901 |
if( ( clc.timeDemoFrames - 1 ) > MAX_TIMEDEMO_DURATIONS ) |
| 902 |
numFrames = MAX_TIMEDEMO_DURATIONS; |
| 903 |
else |
| 904 |
numFrames = clc.timeDemoFrames - 1; |
| 905 |
|
| 906 |
f = FS_FOpenFileWrite_HomeData( cl_timedemoLog->string ); |
| 907 |
if( f ) |
| 908 |
{ |
| 909 |
FS_Printf( f, "# %s", buffer ); |
| 910 |
|
| 911 |
for( i = 0; i < numFrames; i++ ) |
| 912 |
FS_Printf( f, "%d\n", clc.timeDemoDurations[ i ] ); |
| 913 |
|
| 914 |
FS_FCloseFile( f ); |
| 915 |
Com_Printf( "%s written\n", cl_timedemoLog->string ); |
| 916 |
} |
| 917 |
else |
| 918 |
{ |
| 919 |
Com_Printf( "Couldn't open %s for writing\n", |
| 920 |
cl_timedemoLog->string ); |
| 921 |
} |
| 922 |
} |
| 923 |
} |
| 924 |
} |
| 925 |
|
| 926 |
CL_Disconnect( qtrue ); |
| 927 |
CL_NextDemo(); |
| 928 |
} |
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
void CL_ReadDemoMessage( void ) { |
| 936 |
int r; |
| 937 |
msg_t buf; |
| 938 |
byte bufData[ MAX_MSGLEN ]; |
| 939 |
int s; |
| 940 |
|
| 941 |
if ( !clc.demofile ) { |
| 942 |
CL_DemoCompleted (); |
| 943 |
return; |
| 944 |
} |
| 945 |
|
| 946 |
|
| 947 |
r = FS_Read( &s, 4, clc.demofile); |
| 948 |
if ( r != 4 ) { |
| 949 |
CL_DemoCompleted (); |
| 950 |
return; |
| 951 |
} |
| 952 |
clc.serverMessageSequence = LittleLong( s ); |
| 953 |
|
| 954 |
|
| 955 |
MSG_Init( &buf, bufData, sizeof( bufData ) ); |
| 956 |
|
| 957 |
|
| 958 |
r = FS_Read (&buf.cursize, 4, clc.demofile); |
| 959 |
if ( r != 4 ) { |
| 960 |
CL_DemoCompleted (); |
| 961 |
return; |
| 962 |
} |
| 963 |
buf.cursize = LittleLong( buf.cursize ); |
| 964 |
if ( buf.cursize == -1 ) { |
| 965 |
CL_DemoCompleted (); |
| 966 |
return; |
| 967 |
} |
| 968 |
if ( buf.cursize > buf.maxsize ) { |
| 969 |
Com_Error (ERR_DROP, "CL_ReadDemoMessage: demoMsglen > MAX_MSGLEN"); |
| 970 |
} |
| 971 |
r = FS_Read( buf.data, buf.cursize, clc.demofile ); |
| 972 |
if ( r != buf.cursize ) { |
| 973 |
Com_Printf( "Demo file was truncated.\n"); |
| 974 |
CL_DemoCompleted (); |
| 975 |
return; |
| 976 |
} |
| 977 |
|
| 978 |
clc.lastPacketTime = cls.realtime; |
| 979 |
buf.readcount = 0; |
| 980 |
CL_ParseServerMessage( &buf ); |
| 981 |
} |
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
static int CL_WalkDemoExt(char *arg, char *name, int *demofile) |
| 989 |
{ |
| 990 |
int i = 0; |
| 991 |
*demofile = 0; |
| 992 |
|
| 993 |
#ifdef LEGACY_PROTOCOL |
| 994 |
if(com_legacyprotocol->integer > 0) |
| 995 |
{ |
| 996 |
Com_sprintf(name, MAX_OSPATH, "demos/%s.%s%d", arg, DEMOEXT, com_legacyprotocol->integer); |
| 997 |
FS_FOpenFileRead(name, demofile, qtrue); |
| 998 |
|
| 999 |
if (*demofile) |
| 1000 |
{ |
| 1001 |
Com_Printf("Demo file: %s\n", name); |
| 1002 |
return com_legacyprotocol->integer; |
| 1003 |
} |
| 1004 |
} |
| 1005 |
|
| 1006 |
if(com_protocol->integer != com_legacyprotocol->integer) |
| 1007 |
#endif |
| 1008 |
{ |
| 1009 |
Com_sprintf(name, MAX_OSPATH, "demos/%s.%s%d", arg, DEMOEXT, com_protocol->integer); |
| 1010 |
FS_FOpenFileRead(name, demofile, qtrue); |
| 1011 |
|
| 1012 |
if (*demofile) |
| 1013 |
{ |
| 1014 |
Com_Printf("Demo file: %s\n", name); |
| 1015 |
return com_protocol->integer; |
| 1016 |
} |
| 1017 |
} |
| 1018 |
|
| 1019 |
Com_Printf("Not found: %s\n", name); |
| 1020 |
|
| 1021 |
while(demo_protocols[i]) |
| 1022 |
{ |
| 1023 |
#ifdef LEGACY_PROTOCOL |
| 1024 |
if(demo_protocols[i] == com_legacyprotocol->integer) |
| 1025 |
continue; |
| 1026 |
#endif |
| 1027 |
if(demo_protocols[i] == com_protocol->integer) |
| 1028 |
continue; |
| 1029 |
|
| 1030 |
Com_sprintf (name, MAX_OSPATH, "demos/%s.%s%d", arg, DEMOEXT, demo_protocols[i]); |
| 1031 |
FS_FOpenFileRead( name, demofile, qtrue ); |
| 1032 |
if (*demofile) |
| 1033 |
{ |
| 1034 |
Com_Printf("Demo file: %s\n", name); |
| 1035 |
|
| 1036 |
return demo_protocols[i]; |
| 1037 |
} |
| 1038 |
else |
| 1039 |
Com_Printf("Not found: %s\n", name); |
| 1040 |
i++; |
| 1041 |
} |
| 1042 |
|
| 1043 |
return -1; |
| 1044 |
} |
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
static void CL_CompleteDemoName( char *args, int argNum ) |
| 1052 |
{ |
| 1053 |
if( argNum == 2 ) |
| 1054 |
{ |
| 1055 |
char demoFilter[ 16 ]; |
| 1056 |
|
| 1057 |
Com_sprintf( demoFilter, sizeof(demoFilter), "*.%s*", DEMOEXT ); |
| 1058 |
Field_CompleteFilename( "demos", "", demoFilter, qfalse, qtrue ); |
| 1059 |
} |
| 1060 |
} |
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
void CL_PlayDemo_f( void ) { |
| 1071 |
char name[MAX_OSPATH]; |
| 1072 |
char arg[MAX_OSPATH]; |
| 1073 |
char *ext_test; |
| 1074 |
int protocol, i; |
| 1075 |
char retry[MAX_OSPATH]; |
| 1076 |
|
| 1077 |
if (Cmd_Argc() != 2) { |
| 1078 |
Com_Printf ("demo <demoname>\n"); |
| 1079 |
return; |
| 1080 |
} |
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
Cvar_Set( "sv_killserver", "2" ); |
| 1085 |
|
| 1086 |
|
| 1087 |
Q_strncpyz( arg, Cmd_Argv(1), sizeof( arg ) ); |
| 1088 |
|
| 1089 |
CL_Disconnect( qtrue ); |
| 1090 |
|
| 1091 |
|
| 1092 |
ext_test = strrchr(arg, '.'); |
| 1093 |
|
| 1094 |
if(ext_test && !Q_stricmpn(ext_test + 1, DEMOEXT, ARRAY_LEN(DEMOEXT) - 1)) |
| 1095 |
{ |
| 1096 |
protocol = atoi(ext_test + ARRAY_LEN(DEMOEXT)); |
| 1097 |
|
| 1098 |
for(i = 0; demo_protocols[i]; i++) |
| 1099 |
{ |
| 1100 |
if(demo_protocols[i] == protocol) |
| 1101 |
break; |
| 1102 |
} |
| 1103 |
|
| 1104 |
if(demo_protocols[i] || protocol == com_protocol->integer |
| 1105 |
#ifdef LEGACY_PROTOCOL |
| 1106 |
|| protocol == com_legacyprotocol->integer |
| 1107 |
#endif |
| 1108 |
) |
| 1109 |
{ |
| 1110 |
Com_sprintf(name, sizeof(name), "demos/%s", arg); |
| 1111 |
FS_FOpenFileRead(name, &clc.demofile, qtrue); |
| 1112 |
} |
| 1113 |
else |
| 1114 |
{ |
| 1115 |
int len; |
| 1116 |
|
| 1117 |
Com_Printf("Protocol %d not supported for demos\n", protocol); |
| 1118 |
len = ext_test - arg; |
| 1119 |
|
| 1120 |
if(len >= ARRAY_LEN(retry)) |
| 1121 |
len = ARRAY_LEN(retry) - 1; |
| 1122 |
|
| 1123 |
Q_strncpyz(retry, arg, len + 1); |
| 1124 |
retry[len] = '\0'; |
| 1125 |
protocol = CL_WalkDemoExt(retry, name, &clc.demofile); |
| 1126 |
} |
| 1127 |
} |
| 1128 |
else |
| 1129 |
protocol = CL_WalkDemoExt(arg, name, &clc.demofile); |
| 1130 |
|
| 1131 |
if (!clc.demofile) { |
| 1132 |
Com_Error( ERR_DROP, "couldn't open %s", name); |
| 1133 |
return; |
| 1134 |
} |
| 1135 |
Q_strncpyz( clc.demoName, arg, sizeof( clc.demoName ) ); |
| 1136 |
|
| 1137 |
Con_Close(); |
| 1138 |
|
| 1139 |
clc.state = CA_CONNECTED; |
| 1140 |
clc.demoplaying = qtrue; |
| 1141 |
Q_strncpyz( clc.servername, arg, sizeof( clc.servername ) ); |
| 1142 |
|
| 1143 |
#ifdef LEGACY_PROTOCOL |
| 1144 |
if(protocol <= com_legacyprotocol->integer) |
| 1145 |
clc.compat = qtrue; |
| 1146 |
else |
| 1147 |
clc.compat = qfalse; |
| 1148 |
#endif |
| 1149 |
|
| 1150 |
|
| 1151 |
while ( clc.state >= CA_CONNECTED && clc.state < CA_PRIMED ) { |
| 1152 |
CL_ReadDemoMessage(); |
| 1153 |
} |
| 1154 |
|
| 1155 |
|
| 1156 |
clc.firstDemoFrameSkipped = qfalse; |
| 1157 |
} |
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
void CL_StartDemoLoop( void ) { |
| 1168 |
|
| 1169 |
Cbuf_AddText ("d1\n"); |
| 1170 |
Key_SetCatcher( 0 ); |
| 1171 |
} |
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
void CL_NextDemo( void ) { |
| 1182 |
char v[MAX_STRING_CHARS]; |
| 1183 |
|
| 1184 |
Q_strncpyz( v, Cvar_VariableString ("nextdemo"), sizeof(v) ); |
| 1185 |
v[MAX_STRING_CHARS-1] = 0; |
| 1186 |
Com_DPrintf("CL_NextDemo: %s\n", v ); |
| 1187 |
if (!v[0]) { |
| 1188 |
return; |
| 1189 |
} |
| 1190 |
|
| 1191 |
Cvar_Set ("nextdemo",""); |
| 1192 |
Cbuf_AddText (v); |
| 1193 |
Cbuf_AddText ("\n"); |
| 1194 |
Cbuf_Execute(); |
| 1195 |
} |
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
void CL_ShutdownAll(qboolean shutdownRef) |
| 1206 |
{ |
| 1207 |
if(CL_VideoRecording()) |
| 1208 |
CL_CloseAVI(); |
| 1209 |
|
| 1210 |
if(clc.demorecording) |
| 1211 |
CL_StopRecord_f(); |
| 1212 |
|
| 1213 |
|
| 1214 |
S_DisableSounds(); |
| 1215 |
|
| 1216 |
CL_ShutdownCGame(); |
| 1217 |
|
| 1218 |
CL_ShutdownUI(); |
| 1219 |
|
| 1220 |
|
| 1221 |
if(shutdownRef) |
| 1222 |
CL_ShutdownRef(); |
| 1223 |
else if(re.Shutdown) |
| 1224 |
re.Shutdown(qfalse); |
| 1225 |
|
| 1226 |
cls.uiStarted = qfalse; |
| 1227 |
cls.cgameStarted = qfalse; |
| 1228 |
cls.rendererStarted = qfalse; |
| 1229 |
cls.soundRegistered = qfalse; |
| 1230 |
} |
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
void CL_ClearMemory(qboolean shutdownRef) |
| 1240 |
{ |
| 1241 |
|
| 1242 |
CL_ShutdownAll(shutdownRef); |
| 1243 |
|
| 1244 |
|
| 1245 |
if ( !com_sv_running || !com_sv_running->integer ) { |
| 1246 |
|
| 1247 |
Hunk_Clear(); |
| 1248 |
|
| 1249 |
CM_ClearMap(); |
| 1250 |
} |
| 1251 |
else { |
| 1252 |
|
| 1253 |
Hunk_ClearToMark(); |
| 1254 |
} |
| 1255 |
} |
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
void CL_FlushMemory(void) |
| 1267 |
{ |
| 1268 |
CL_ClearMemory(qfalse); |
| 1269 |
CL_StartHunkUsers(qfalse); |
| 1270 |
} |
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
void CL_MapLoading( void ) { |
| 1282 |
if ( com_dedicated->integer ) { |
| 1283 |
clc.state = CA_DISCONNECTED; |
| 1284 |
Key_SetCatcher( KEYCATCH_CONSOLE ); |
| 1285 |
return; |
| 1286 |
} |
| 1287 |
|
| 1288 |
if ( !com_cl_running->integer ) { |
| 1289 |
return; |
| 1290 |
} |
| 1291 |
|
| 1292 |
Con_Close(); |
| 1293 |
Key_SetCatcher( 0 ); |
| 1294 |
|
| 1295 |
|
| 1296 |
if ( clc.state >= CA_CONNECTED && !Q_stricmp( clc.servername, "localhost" ) ) { |
| 1297 |
clc.state = CA_CONNECTED; |
| 1298 |
Com_Memset( cls.updateInfoString, 0, sizeof( cls.updateInfoString ) ); |
| 1299 |
Com_Memset( clc.serverMessage, 0, sizeof( clc.serverMessage ) ); |
| 1300 |
Com_Memset( &cl.gameState, 0, sizeof( cl.gameState ) ); |
| 1301 |
clc.lastPacketSentTime = -9999; |
| 1302 |
SCR_UpdateScreen(); |
| 1303 |
} else { |
| 1304 |
|
| 1305 |
Cvar_Set( "nextmap", "" ); |
| 1306 |
CL_Disconnect( qtrue ); |
| 1307 |
Q_strncpyz( clc.servername, "localhost", sizeof(clc.servername) ); |
| 1308 |
clc.state = CA_CHALLENGING; |
| 1309 |
Key_SetCatcher( 0 ); |
| 1310 |
SCR_UpdateScreen(); |
| 1311 |
clc.connectTime = -RETRANSMIT_TIMEOUT; |
| 1312 |
NET_StringToAdr( clc.servername, &clc.serverAddress, NA_UNSPEC); |
| 1313 |
|
| 1314 |
|
| 1315 |
CL_CheckForResend(); |
| 1316 |
} |
| 1317 |
} |
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
void CL_ClearState (void) { |
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
Com_Memset( &cl, 0, sizeof( cl ) ); |
| 1331 |
} |
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
static void CL_UpdateGUID( const char *prefix, int prefix_len ) |
| 1341 |
{ |
| 1342 |
fileHandle_t f; |
| 1343 |
int len; |
| 1344 |
|
| 1345 |
len = FS_BaseDir_FOpenFileRead( QKEY_FILE, &f ); |
| 1346 |
FS_FCloseFile( f ); |
| 1347 |
|
| 1348 |
if( len != QKEY_SIZE ) |
| 1349 |
Cvar_Set( "cl_guid", "" ); |
| 1350 |
else |
| 1351 |
Cvar_Set( "cl_guid", Com_MD5File( QKEY_FILE, QKEY_SIZE, |
| 1352 |
prefix, prefix_len ) ); |
| 1353 |
} |
| 1354 |
|
| 1355 |
static void CL_OldGame(void) |
| 1356 |
{ |
| 1357 |
if(cl_oldGameSet) |
| 1358 |
{ |
| 1359 |
|
| 1360 |
cl_oldGameSet = qfalse; |
| 1361 |
Cvar_Set2("fs_game", cl_oldGame, qtrue); |
| 1362 |
FS_ConditionalRestart(clc.checksumFeed, qfalse); |
| 1363 |
} |
| 1364 |
} |
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
void CL_Disconnect( qboolean showMainMenu ) { |
| 1377 |
if ( !com_cl_running || !com_cl_running->integer ) { |
| 1378 |
return; |
| 1379 |
} |
| 1380 |
|
| 1381 |
|
| 1382 |
Cvar_Set("r_uiFullScreen", "1"); |
| 1383 |
|
| 1384 |
if ( clc.demorecording ) { |
| 1385 |
CL_StopRecord_f (); |
| 1386 |
} |
| 1387 |
|
| 1388 |
if (clc.download) { |
| 1389 |
FS_FCloseFile( clc.download ); |
| 1390 |
clc.download = 0; |
| 1391 |
} |
| 1392 |
*clc.downloadTempName = *clc.downloadName = 0; |
| 1393 |
Cvar_Set( "cl_downloadName", "" ); |
| 1394 |
|
| 1395 |
#ifdef USE_MUMBLE |
| 1396 |
if (cl_useMumble->integer && mumble_islinked()) { |
| 1397 |
Com_Printf("Mumble: Unlinking from Mumble application\n"); |
| 1398 |
mumble_unlink(); |
| 1399 |
} |
| 1400 |
#endif |
| 1401 |
|
| 1402 |
#ifdef USE_VOIP |
| 1403 |
if (cl_voipSend->integer) { |
| 1404 |
int tmp = cl_voipUseVAD->integer; |
| 1405 |
cl_voipUseVAD->integer = 0; |
| 1406 |
clc.voipOutgoingDataSize = 0; |
| 1407 |
Cvar_Set("cl_voipSend", "0"); |
| 1408 |
CL_CaptureVoip(); |
| 1409 |
cl_voipUseVAD->integer = tmp; |
| 1410 |
} |
| 1411 |
|
| 1412 |
if (clc.voipCodecInitialized) { |
| 1413 |
int i; |
| 1414 |
opus_encoder_destroy(clc.opusEncoder); |
| 1415 |
for (i = 0; i < MAX_CLIENTS; i++) { |
| 1416 |
opus_decoder_destroy(clc.opusDecoder[i]); |
| 1417 |
} |
| 1418 |
clc.voipCodecInitialized = qfalse; |
| 1419 |
} |
| 1420 |
Cmd_RemoveCommand ("voip"); |
| 1421 |
#endif |
| 1422 |
|
| 1423 |
if ( clc.demofile ) { |
| 1424 |
FS_FCloseFile( clc.demofile ); |
| 1425 |
clc.demofile = 0; |
| 1426 |
} |
| 1427 |
|
| 1428 |
if ( uivm && showMainMenu ) { |
| 1429 |
VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_NONE ); |
| 1430 |
} |
| 1431 |
|
| 1432 |
SCR_StopCinematic (); |
| 1433 |
S_ClearSoundBuffer(); |
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
if ( clc.state >= CA_CONNECTED ) { |
| 1438 |
CL_AddReliableCommand("disconnect", qtrue); |
| 1439 |
CL_WritePacket(); |
| 1440 |
CL_WritePacket(); |
| 1441 |
CL_WritePacket(); |
| 1442 |
} |
| 1443 |
|
| 1444 |
|
| 1445 |
FS_PureServerSetLoadedPaks("", ""); |
| 1446 |
FS_PureServerSetReferencedPaks( "", "" ); |
| 1447 |
|
| 1448 |
CL_ClearState (); |
| 1449 |
|
| 1450 |
|
| 1451 |
Com_Memset( &clc, 0, sizeof( clc ) ); |
| 1452 |
|
| 1453 |
clc.state = CA_DISCONNECTED; |
| 1454 |
|
| 1455 |
|
| 1456 |
Cvar_Set( "sv_cheats", "1" ); |
| 1457 |
|
| 1458 |
|
| 1459 |
cl_connectedToPureServer = qfalse; |
| 1460 |
|
| 1461 |
#ifdef USE_VOIP |
| 1462 |
|
| 1463 |
clc.voipEnabled = qfalse; |
| 1464 |
#endif |
| 1465 |
|
| 1466 |
|
| 1467 |
if( CL_VideoRecording( ) ) { |
| 1468 |
|
| 1469 |
SCR_UpdateScreen( ); |
| 1470 |
CL_CloseAVI( ); |
| 1471 |
} |
| 1472 |
|
| 1473 |
CL_UpdateGUID( NULL, 0 ); |
| 1474 |
|
| 1475 |
if(!noGameRestart) |
| 1476 |
CL_OldGame(); |
| 1477 |
else |
| 1478 |
noGameRestart = qfalse; |
| 1479 |
} |
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
void CL_ForwardCommandToServer( const char *string ) { |
| 1492 |
char *cmd; |
| 1493 |
|
| 1494 |
cmd = Cmd_Argv(0); |
| 1495 |
|
| 1496 |
|
| 1497 |
if ( cmd[0] == '-' ) { |
| 1498 |
return; |
| 1499 |
} |
| 1500 |
|
| 1501 |
if ( clc.demoplaying || clc.state < CA_CONNECTED || cmd[0] == '+' ) { |
| 1502 |
Com_Printf ("Unknown command \"%s" S_COLOR_WHITE "\"\n", cmd); |
| 1503 |
return; |
| 1504 |
} |
| 1505 |
|
| 1506 |
if ( Cmd_Argc() > 1 ) { |
| 1507 |
CL_AddReliableCommand(string, qfalse); |
| 1508 |
} else { |
| 1509 |
CL_AddReliableCommand(cmd, qfalse); |
| 1510 |
} |
| 1511 |
} |
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
void CL_RequestMotd( void ) { |
| 1520 |
#ifdef UPDATE_SERVER_NAME |
| 1521 |
char info[MAX_INFO_STRING]; |
| 1522 |
|
| 1523 |
if ( !cl_motd->integer ) { |
| 1524 |
return; |
| 1525 |
} |
| 1526 |
Com_Printf( "Resolving %s\n", UPDATE_SERVER_NAME ); |
| 1527 |
if ( !NET_StringToAdr( UPDATE_SERVER_NAME, &cls.updateServer, NA_IP ) ) { |
| 1528 |
Com_Printf( "Couldn't resolve address\n" ); |
| 1529 |
return; |
| 1530 |
} |
| 1531 |
cls.updateServer.port = BigShort( PORT_UPDATE ); |
| 1532 |
Com_Printf( "%s resolved to %i.%i.%i.%i:%i\n", UPDATE_SERVER_NAME, |
| 1533 |
cls.updateServer.ip[0], cls.updateServer.ip[1], |
| 1534 |
cls.updateServer.ip[2], cls.updateServer.ip[3], |
| 1535 |
BigShort( cls.updateServer.port ) ); |
| 1536 |
|
| 1537 |
info[0] = 0; |
| 1538 |
|
| 1539 |
Com_sprintf( cls.updateChallenge, sizeof( cls.updateChallenge ), "%i", (int)((((unsigned int)rand() << 16) ^ (unsigned int)rand()) ^ Com_Milliseconds())); |
| 1540 |
|
| 1541 |
Info_SetValueForKey( info, "challenge", cls.updateChallenge ); |
| 1542 |
Info_SetValueForKey( info, "renderer", cls.glconfig.renderer_string ); |
| 1543 |
Info_SetValueForKey( info, "version", com_version->string ); |
| 1544 |
|
| 1545 |
NET_OutOfBandPrint( NS_CLIENT, cls.updateServer, "getmotd \"%s\"\n", info ); |
| 1546 |
#endif |
| 1547 |
} |
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
#ifndef STANDALONE |
| 1588 |
void CL_RequestAuthorization( void ) { |
| 1589 |
char nums[64]; |
| 1590 |
int i, j, l; |
| 1591 |
cvar_t *fs; |
| 1592 |
|
| 1593 |
if ( !cls.authorizeServer.port ) { |
| 1594 |
Com_Printf( "Resolving %s\n", AUTHORIZE_SERVER_NAME ); |
| 1595 |
if ( !NET_StringToAdr( AUTHORIZE_SERVER_NAME, &cls.authorizeServer, NA_IP ) ) { |
| 1596 |
Com_Printf( "Couldn't resolve address\n" ); |
| 1597 |
return; |
| 1598 |
} |
| 1599 |
|
| 1600 |
cls.authorizeServer.port = BigShort( PORT_AUTHORIZE ); |
| 1601 |
Com_Printf( "%s resolved to %i.%i.%i.%i:%i\n", AUTHORIZE_SERVER_NAME, |
| 1602 |
cls.authorizeServer.ip[0], cls.authorizeServer.ip[1], |
| 1603 |
cls.authorizeServer.ip[2], cls.authorizeServer.ip[3], |
| 1604 |
BigShort( cls.authorizeServer.port ) ); |
| 1605 |
} |
| 1606 |
if ( cls.authorizeServer.type == NA_BAD ) { |
| 1607 |
return; |
| 1608 |
} |
| 1609 |
|
| 1610 |
|
| 1611 |
j = 0; |
| 1612 |
l = strlen( cl_cdkey ); |
| 1613 |
if ( l > 32 ) { |
| 1614 |
l = 32; |
| 1615 |
} |
| 1616 |
for ( i = 0 ; i < l ; i++ ) { |
| 1617 |
if ( ( cl_cdkey[i] >= '0' && cl_cdkey[i] <= '9' ) |
| 1618 |
|| ( cl_cdkey[i] >= 'a' && cl_cdkey[i] <= 'z' ) |
| 1619 |
|| ( cl_cdkey[i] >= 'A' && cl_cdkey[i] <= 'Z' ) |
| 1620 |
) { |
| 1621 |
nums[j] = cl_cdkey[i]; |
| 1622 |
j++; |
| 1623 |
} |
| 1624 |
} |
| 1625 |
nums[j] = 0; |
| 1626 |
|
| 1627 |
fs = Cvar_Get ("cl_anonymous", "0", CVAR_INIT|CVAR_SYSTEMINFO ); |
| 1628 |
|
| 1629 |
NET_OutOfBandPrint(NS_CLIENT, cls.authorizeServer, "getKeyAuthorize %i %s", fs->integer, nums ); |
| 1630 |
} |
| 1631 |
#endif |
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
void CL_ForwardToServer_f( void ) { |
| 1646 |
if ( clc.state != CA_ACTIVE || clc.demoplaying ) { |
| 1647 |
Com_Printf ("Not connected to a server.\n"); |
| 1648 |
return; |
| 1649 |
} |
| 1650 |
|
| 1651 |
|
| 1652 |
if ( Cmd_Argc() > 1 ) { |
| 1653 |
CL_AddReliableCommand(Cmd_Args(), qfalse); |
| 1654 |
} |
| 1655 |
} |
| 1656 |
|
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
void CL_Disconnect_f( void ) { |
| 1663 |
SCR_StopCinematic(); |
| 1664 |
Cvar_Set("ui_singlePlayerActive", "0"); |
| 1665 |
if ( clc.state != CA_DISCONNECTED && clc.state != CA_CINEMATIC ) { |
| 1666 |
Com_Error (ERR_DISCONNECT, "Disconnected from server"); |
| 1667 |
} |
| 1668 |
} |
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
void CL_Reconnect_f( void ) { |
| 1678 |
if ( !strlen( cl_reconnectArgs ) ) |
| 1679 |
return; |
| 1680 |
Cvar_Set("ui_singlePlayerActive", "0"); |
| 1681 |
Cbuf_AddText( va("connect %s\n", cl_reconnectArgs ) ); |
| 1682 |
} |
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
void CL_Connect_f( void ) { |
| 1691 |
char server[MAX_OSPATH]; |
| 1692 |
const char *serverString; |
| 1693 |
int argc = Cmd_Argc(); |
| 1694 |
netadrtype_t family = NA_UNSPEC; |
| 1695 |
|
| 1696 |
if ( argc != 2 && argc != 3 ) { |
| 1697 |
Com_Printf( "usage: connect [-4|-6] server\n"); |
| 1698 |
return; |
| 1699 |
} |
| 1700 |
|
| 1701 |
if(argc == 2) |
| 1702 |
Q_strncpyz( server, Cmd_Argv(1), sizeof( server ) ); |
| 1703 |
else |
| 1704 |
{ |
| 1705 |
if(!strcmp(Cmd_Argv(1), "-4")) |
| 1706 |
family = NA_IP; |
| 1707 |
else if(!strcmp(Cmd_Argv(1), "-6")) |
| 1708 |
family = NA_IP6; |
| 1709 |
else |
| 1710 |
Com_Printf( "warning: only -4 or -6 as address type understood.\n"); |
| 1711 |
|
| 1712 |
Q_strncpyz( server, Cmd_Argv(2), sizeof( server ) ); |
| 1713 |
} |
| 1714 |
|
| 1715 |
|
| 1716 |
Q_strncpyz( cl_reconnectArgs, Cmd_Args(), sizeof( cl_reconnectArgs ) ); |
| 1717 |
|
| 1718 |
Cvar_Set("ui_singlePlayerActive", "0"); |
| 1719 |
|
| 1720 |
|
| 1721 |
CL_RequestMotd(); |
| 1722 |
|
| 1723 |
|
| 1724 |
clc.serverMessage[0] = 0; |
| 1725 |
|
| 1726 |
if ( com_sv_running->integer && !strcmp( server, "localhost" ) ) { |
| 1727 |
|
| 1728 |
SV_Shutdown( "Server quit" ); |
| 1729 |
} |
| 1730 |
|
| 1731 |
|
| 1732 |
Cvar_Set( "sv_killserver", "1" ); |
| 1733 |
SV_Frame( 0 ); |
| 1734 |
|
| 1735 |
noGameRestart = qtrue; |
| 1736 |
CL_Disconnect( qtrue ); |
| 1737 |
Con_Close(); |
| 1738 |
|
| 1739 |
Q_strncpyz( clc.servername, server, sizeof(clc.servername) ); |
| 1740 |
|
| 1741 |
if (!NET_StringToAdr(clc.servername, &clc.serverAddress, family) ) { |
| 1742 |
Com_Printf ("Bad server address\n"); |
| 1743 |
clc.state = CA_DISCONNECTED; |
| 1744 |
return; |
| 1745 |
} |
| 1746 |
if (clc.serverAddress.port == 0) { |
| 1747 |
clc.serverAddress.port = BigShort( PORT_SERVER ); |
| 1748 |
} |
| 1749 |
|
| 1750 |
serverString = NET_AdrToStringwPort(clc.serverAddress); |
| 1751 |
|
| 1752 |
Com_Printf( "%s resolved to %s\n", clc.servername, serverString); |
| 1753 |
|
| 1754 |
if( cl_guidServerUniq->integer ) |
| 1755 |
CL_UpdateGUID( serverString, strlen( serverString ) ); |
| 1756 |
else |
| 1757 |
CL_UpdateGUID( NULL, 0 ); |
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
if(NET_IsLocalAddress(clc.serverAddress)) |
| 1762 |
clc.state = CA_CHALLENGING; |
| 1763 |
else |
| 1764 |
{ |
| 1765 |
clc.state = CA_CONNECTING; |
| 1766 |
|
| 1767 |
|
| 1768 |
clc.challenge = (((unsigned int)rand() << 16) ^ (unsigned int)rand()) ^ Com_Milliseconds(); |
| 1769 |
} |
| 1770 |
|
| 1771 |
Key_SetCatcher( 0 ); |
| 1772 |
clc.connectTime = -99999; |
| 1773 |
clc.connectPacketCount = 0; |
| 1774 |
|
| 1775 |
|
| 1776 |
Cvar_Set( "cl_currentServerAddress", server ); |
| 1777 |
} |
| 1778 |
|
| 1779 |
#define MAX_RCON_MESSAGE 1024 |
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
|
| 1786 |
static void CL_CompleteRcon( char *args, int argNum ) |
| 1787 |
{ |
| 1788 |
if( argNum == 2 ) |
| 1789 |
{ |
| 1790 |
|
| 1791 |
char *p = Com_SkipTokens( args, 1, " " ); |
| 1792 |
|
| 1793 |
if( p > args ) |
| 1794 |
Field_CompleteCommand( p, qtrue, qtrue ); |
| 1795 |
} |
| 1796 |
} |
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
static void CL_CompletePlayerName( char *args, int argNum ) |
| 1804 |
{ |
| 1805 |
if( argNum == 2 ) |
| 1806 |
{ |
| 1807 |
char names[MAX_CLIENTS][MAX_NAME_LENGTH]; |
| 1808 |
const char *namesPtr[MAX_CLIENTS]; |
| 1809 |
int i; |
| 1810 |
int clientCount; |
| 1811 |
int nameCount; |
| 1812 |
const char *info; |
| 1813 |
const char *name; |
| 1814 |
|
| 1815 |
|
| 1816 |
info = cl.gameState.stringData + cl.gameState.stringOffsets[CS_SERVERINFO]; |
| 1817 |
clientCount = atoi( Info_ValueForKey( info, "sv_maxclients" ) ); |
| 1818 |
|
| 1819 |
nameCount = 0; |
| 1820 |
|
| 1821 |
for( i = 0; i < clientCount; i++ ) { |
| 1822 |
if( i == clc.clientNum ) |
| 1823 |
continue; |
| 1824 |
|
| 1825 |
info = cl.gameState.stringData + cl.gameState.stringOffsets[CS_PLAYERS+i]; |
| 1826 |
|
| 1827 |
name = Info_ValueForKey( info, "n" ); |
| 1828 |
if( name[0] == '\0' ) |
| 1829 |
continue; |
| 1830 |
Q_strncpyz( names[nameCount], name, sizeof(names[nameCount]) ); |
| 1831 |
Q_CleanStr( names[nameCount] ); |
| 1832 |
|
| 1833 |
namesPtr[nameCount] = names[nameCount]; |
| 1834 |
nameCount++; |
| 1835 |
} |
| 1836 |
qsort( (void*)namesPtr, nameCount, sizeof( namesPtr[0] ), Com_strCompare ); |
| 1837 |
|
| 1838 |
Field_CompletePlayerName( namesPtr, nameCount ); |
| 1839 |
} |
| 1840 |
} |
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
void CL_Rcon_f( void ) { |
| 1851 |
char message[MAX_RCON_MESSAGE]; |
| 1852 |
netadr_t to; |
| 1853 |
|
| 1854 |
if ( !rcon_client_password->string[0] ) { |
| 1855 |
Com_Printf ("You must set 'rconpassword' before\n" |
| 1856 |
"issuing an rcon command.\n"); |
| 1857 |
return; |
| 1858 |
} |
| 1859 |
|
| 1860 |
message[0] = -1; |
| 1861 |
message[1] = -1; |
| 1862 |
message[2] = -1; |
| 1863 |
message[3] = -1; |
| 1864 |
message[4] = 0; |
| 1865 |
|
| 1866 |
Q_strcat (message, MAX_RCON_MESSAGE, "rcon "); |
| 1867 |
|
| 1868 |
Q_strcat (message, MAX_RCON_MESSAGE, rcon_client_password->string); |
| 1869 |
Q_strcat (message, MAX_RCON_MESSAGE, " "); |
| 1870 |
|
| 1871 |
|
| 1872 |
Q_strcat (message, MAX_RCON_MESSAGE, Cmd_Cmd()+5); |
| 1873 |
|
| 1874 |
if ( clc.state >= CA_CONNECTED ) { |
| 1875 |
to = clc.netchan.remoteAddress; |
| 1876 |
} else { |
| 1877 |
if (!strlen(rconAddress->string)) { |
| 1878 |
Com_Printf ("You must either be connected,\n" |
| 1879 |
"or set the 'rconAddress' cvar\n" |
| 1880 |
"to issue rcon commands\n"); |
| 1881 |
|
| 1882 |
return; |
| 1883 |
} |
| 1884 |
NET_StringToAdr (rconAddress->string, &to, NA_UNSPEC); |
| 1885 |
if (to.port == 0) { |
| 1886 |
to.port = BigShort (PORT_SERVER); |
| 1887 |
} |
| 1888 |
} |
| 1889 |
|
| 1890 |
NET_SendPacket (NS_CLIENT, strlen(message)+1, message, to); |
| 1891 |
cls.rconAddress = to; |
| 1892 |
} |
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
void CL_SendPureChecksums( void ) { |
| 1900 |
char cMsg[MAX_INFO_VALUE]; |
| 1901 |
|
| 1902 |
|
| 1903 |
Com_sprintf(cMsg, sizeof(cMsg), "cp %d %s", cl.serverId, FS_ReferencedPakPureChecksums()); |
| 1904 |
|
| 1905 |
CL_AddReliableCommand(cMsg, qfalse); |
| 1906 |
} |
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
void CL_ResetPureClientAtServer( void ) { |
| 1914 |
CL_AddReliableCommand("vdr", qfalse); |
| 1915 |
} |
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
void CL_Vid_Restart_f( void ) { |
| 1928 |
|
| 1929 |
|
| 1930 |
if( CL_VideoRecording( ) ) { |
| 1931 |
CL_CloseAVI( ); |
| 1932 |
} |
| 1933 |
|
| 1934 |
if(clc.demorecording) |
| 1935 |
CL_StopRecord_f(); |
| 1936 |
|
| 1937 |
|
| 1938 |
S_StopAllSounds(); |
| 1939 |
|
| 1940 |
if(!FS_ConditionalRestart(clc.checksumFeed, qtrue)) |
| 1941 |
{ |
| 1942 |
|
| 1943 |
if(com_sv_running->integer) |
| 1944 |
{ |
| 1945 |
|
| 1946 |
Hunk_ClearToMark(); |
| 1947 |
} |
| 1948 |
else |
| 1949 |
{ |
| 1950 |
|
| 1951 |
Hunk_Clear(); |
| 1952 |
} |
| 1953 |
|
| 1954 |
|
| 1955 |
CL_ShutdownUI(); |
| 1956 |
|
| 1957 |
CL_ShutdownCGame(); |
| 1958 |
|
| 1959 |
CL_ShutdownRef(); |
| 1960 |
|
| 1961 |
CL_ResetPureClientAtServer(); |
| 1962 |
|
| 1963 |
FS_ClearPakReferences( FS_UI_REF | FS_CGAME_REF ); |
| 1964 |
|
| 1965 |
|
| 1966 |
cls.rendererStarted = qfalse; |
| 1967 |
cls.uiStarted = qfalse; |
| 1968 |
cls.cgameStarted = qfalse; |
| 1969 |
cls.soundRegistered = qfalse; |
| 1970 |
|
| 1971 |
|
| 1972 |
Cvar_Set("cl_paused", "0"); |
| 1973 |
|
| 1974 |
|
| 1975 |
CL_InitRef(); |
| 1976 |
|
| 1977 |
|
| 1978 |
CL_StartHunkUsers(qfalse); |
| 1979 |
|
| 1980 |
|
| 1981 |
if(clc.state > CA_CONNECTED && clc.state != CA_CINEMATIC) |
| 1982 |
{ |
| 1983 |
cls.cgameStarted = qtrue; |
| 1984 |
CL_InitCGame(); |
| 1985 |
|
| 1986 |
CL_SendPureChecksums(); |
| 1987 |
} |
| 1988 |
} |
| 1989 |
} |
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
void CL_Snd_Shutdown(void) |
| 1999 |
{ |
| 2000 |
S_Shutdown(); |
| 2001 |
cls.soundStarted = qfalse; |
| 2002 |
} |
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
void CL_Snd_Restart_f(void) |
| 2014 |
{ |
| 2015 |
CL_Snd_Shutdown(); |
| 2016 |
|
| 2017 |
CL_Vid_Restart_f(); |
| 2018 |
} |
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
void CL_OpenedPK3List_f( void ) { |
| 2027 |
Com_Printf("Opened PK3 Names: %s\n", FS_LoadedPakNames()); |
| 2028 |
} |
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
|
| 2035 |
void CL_ReferencedPK3List_f( void ) { |
| 2036 |
Com_Printf("Referenced PK3 Names: %s\n", FS_ReferencedPakNames()); |
| 2037 |
} |
| 2038 |
|
| 2039 |
|
| 2040 |
|
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
void CL_Configstrings_f( void ) { |
| 2045 |
int i; |
| 2046 |
int ofs; |
| 2047 |
|
| 2048 |
if ( clc.state != CA_ACTIVE ) { |
| 2049 |
Com_Printf( "Not connected to a server.\n"); |
| 2050 |
return; |
| 2051 |
} |
| 2052 |
|
| 2053 |
for ( i = 0 ; i < MAX_CONFIGSTRINGS ; i++ ) { |
| 2054 |
ofs = cl.gameState.stringOffsets[ i ]; |
| 2055 |
if ( !ofs ) { |
| 2056 |
continue; |
| 2057 |
} |
| 2058 |
Com_Printf( "%4i: %s\n", i, cl.gameState.stringData + ofs ); |
| 2059 |
} |
| 2060 |
} |
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
void CL_Clientinfo_f( void ) { |
| 2068 |
Com_Printf( "--------- Client Information ---------\n" ); |
| 2069 |
Com_Printf( "state: %i\n", clc.state ); |
| 2070 |
Com_Printf( "Server: %s\n", clc.servername ); |
| 2071 |
Com_Printf ("User info settings:\n"); |
| 2072 |
Info_Print( Cvar_InfoString( CVAR_USERINFO ) ); |
| 2073 |
Com_Printf( "--------------------------------------\n" ); |
| 2074 |
} |
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
void CL_DownloadsComplete( void ) { |
| 2087 |
|
| 2088 |
#ifdef USE_HTTP |
| 2089 |
|
| 2090 |
if(clc.httpUsed) { |
| 2091 |
clc.httpUsed = qfalse; |
| 2092 |
if( clc.disconnectedForHttpDownload ) { |
| 2093 |
if(clc.downloadRestart) { |
| 2094 |
FS_Restart(clc.checksumFeed); |
| 2095 |
clc.downloadRestart = qfalse; |
| 2096 |
} |
| 2097 |
clc.disconnectedForHttpDownload = qfalse; |
| 2098 |
CL_Reconnect_f(); |
| 2099 |
return; |
| 2100 |
} |
| 2101 |
} |
| 2102 |
#endif |
| 2103 |
|
| 2104 |
|
| 2105 |
if (clc.downloadRestart) { |
| 2106 |
clc.downloadRestart = qfalse; |
| 2107 |
|
| 2108 |
FS_Restart(clc.checksumFeed); |
| 2109 |
|
| 2110 |
|
| 2111 |
CL_AddReliableCommand("donedl", qfalse); |
| 2112 |
|
| 2113 |
|
| 2114 |
|
| 2115 |
return; |
| 2116 |
} |
| 2117 |
|
| 2118 |
|
| 2119 |
clc.state = CA_LOADING; |
| 2120 |
|
| 2121 |
|
| 2122 |
Com_EventLoop(); |
| 2123 |
|
| 2124 |
|
| 2125 |
|
| 2126 |
if ( clc.state != CA_LOADING ) { |
| 2127 |
return; |
| 2128 |
} |
| 2129 |
|
| 2130 |
|
| 2131 |
Cvar_Set("r_uiFullScreen", "0"); |
| 2132 |
|
| 2133 |
|
| 2134 |
|
| 2135 |
|
| 2136 |
|
| 2137 |
CL_FlushMemory(); |
| 2138 |
|
| 2139 |
|
| 2140 |
cls.cgameStarted = qtrue; |
| 2141 |
CL_InitCGame(); |
| 2142 |
|
| 2143 |
|
| 2144 |
CL_SendPureChecksums(); |
| 2145 |
|
| 2146 |
CL_WritePacket(); |
| 2147 |
CL_WritePacket(); |
| 2148 |
CL_WritePacket(); |
| 2149 |
} |
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
|
| 2156 |
static void CL_InitDownload( const char *localName ) { |
| 2157 |
Q_strncpyz ( clc.downloadName, localName, sizeof(clc.downloadName) ); |
| 2158 |
Com_sprintf( clc.downloadTempName, sizeof(clc.downloadTempName), "%s.tmp", localName ); |
| 2159 |
|
| 2160 |
|
| 2161 |
Cvar_Set( "cl_downloadName", localName ); |
| 2162 |
Cvar_Set( "cl_downloadSize", "0" ); |
| 2163 |
Cvar_Set( "cl_downloadCount", "0" ); |
| 2164 |
Cvar_SetValue( "cl_downloadTime", cls.realtime ); |
| 2165 |
|
| 2166 |
clc.downloadBlock = 0; |
| 2167 |
clc.downloadCount = 0; |
| 2168 |
} |
| 2169 |
|
| 2170 |
|
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
|
| 2175 |
|
| 2176 |
|
| 2177 |
|
| 2178 |
static void CL_BeginDownload( const char *remoteName ) { |
| 2179 |
CL_AddReliableCommand(va("download %s", remoteName), qfalse); |
| 2180 |
} |
| 2181 |
|
| 2182 |
#ifdef USE_HTTP |
| 2183 |
|
| 2184 |
|
| 2185 |
|
| 2186 |
|
| 2187 |
|
| 2188 |
static void CL_BeginHttpDownload( const char *remoteURL ) { |
| 2189 |
if(Q_strncmp(remoteURL, "http://", strlen("http://")) != 0 && |
| 2190 |
Q_strncmp(remoteURL, "https://", strlen("https://")) != 0) { |
| 2191 |
Com_Error(ERR_DROP, "Download Error: %s is a malformed/" |
| 2192 |
"unsupported URL", remoteURL); |
| 2193 |
} |
| 2194 |
|
| 2195 |
Com_Printf("URL: %s\n", remoteURL); |
| 2196 |
|
| 2197 |
CL_HTTP_BeginDownload(remoteURL); |
| 2198 |
Q_strncpyz(clc.downloadURL, remoteURL, sizeof(clc.downloadURL)); |
| 2199 |
|
| 2200 |
clc.download = FS_BaseDir_FOpenFileWrite_HomeData(clc.downloadTempName); |
| 2201 |
if(!clc.download) { |
| 2202 |
Com_Error(ERR_DROP, "CL_BeginHTTPDownload: failed to open " |
| 2203 |
"%s for writing", clc.downloadTempName); |
| 2204 |
} |
| 2205 |
|
| 2206 |
if(!(clc.sv_allowDownload & DLF_NO_DISCONNECT) && |
| 2207 |
!clc.disconnectedForHttpDownload) { |
| 2208 |
|
| 2209 |
CL_AddReliableCommand("disconnect", qtrue); |
| 2210 |
CL_WritePacket(); |
| 2211 |
CL_WritePacket(); |
| 2212 |
CL_WritePacket(); |
| 2213 |
clc.disconnectedForHttpDownload = qtrue; |
| 2214 |
} |
| 2215 |
|
| 2216 |
clc.httpUsed = qtrue; |
| 2217 |
} |
| 2218 |
#endif |
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
void CL_NextDownload(void) |
| 2228 |
{ |
| 2229 |
char *s; |
| 2230 |
char *remoteName, *localName; |
| 2231 |
qboolean usedHTTP = qfalse; |
| 2232 |
|
| 2233 |
|
| 2234 |
if(*clc.downloadName) |
| 2235 |
{ |
| 2236 |
char *zippath = FS_BaseDir_BuildOSPath(Cvar_VariableString("fs_homedatapath"), clc.downloadName); |
| 2237 |
|
| 2238 |
if(!FS_CompareZipChecksum(zippath)) |
| 2239 |
Com_Error(ERR_DROP, "Incorrect checksum for file: %s", clc.downloadName); |
| 2240 |
} |
| 2241 |
|
| 2242 |
*clc.downloadTempName = *clc.downloadName = 0; |
| 2243 |
Cvar_Set("cl_downloadName", ""); |
| 2244 |
|
| 2245 |
|
| 2246 |
if (*clc.downloadList) { |
| 2247 |
s = clc.downloadList; |
| 2248 |
|
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
if (*s == '@') |
| 2253 |
s++; |
| 2254 |
remoteName = s; |
| 2255 |
|
| 2256 |
if ( (s = strchr(s, '@')) == NULL ) { |
| 2257 |
CL_DownloadsComplete(); |
| 2258 |
return; |
| 2259 |
} |
| 2260 |
|
| 2261 |
*s++ = 0; |
| 2262 |
localName = s; |
| 2263 |
if ( (s = strchr(s, '@')) != NULL ) |
| 2264 |
*s++ = 0; |
| 2265 |
else |
| 2266 |
s = localName + strlen(localName); |
| 2267 |
#ifdef USE_HTTP |
| 2268 |
if(!(cl_allowDownload->integer & DLF_NO_REDIRECT)) { |
| 2269 |
if(clc.sv_allowDownload & DLF_NO_REDIRECT) { |
| 2270 |
Com_Printf("WARNING: server does not " |
| 2271 |
"allow download redirection " |
| 2272 |
"(sv_allowDownload is %d)\n", |
| 2273 |
clc.sv_allowDownload); |
| 2274 |
} |
| 2275 |
else if(!*clc.sv_dlURL) { |
| 2276 |
Com_Printf("WARNING: server allows " |
| 2277 |
"download redirection, but does not " |
| 2278 |
"have sv_dlURL set\n"); |
| 2279 |
} |
| 2280 |
else if(CL_HTTP_Available()) { |
| 2281 |
CL_InitDownload(localName); |
| 2282 |
CL_BeginHttpDownload(va("%s/%s", |
| 2283 |
clc.sv_dlURL, remoteName)); |
| 2284 |
|
| 2285 |
usedHTTP = qtrue; |
| 2286 |
} |
| 2287 |
} |
| 2288 |
else if(!(clc.sv_allowDownload & DLF_NO_REDIRECT)) { |
| 2289 |
Com_Printf("WARNING: server allows download " |
| 2290 |
"redirection, but it disabled by client " |
| 2291 |
"configuration (cl_allowDownload is %d)\n", |
| 2292 |
cl_allowDownload->integer); |
| 2293 |
} |
| 2294 |
#endif |
| 2295 |
if(!usedHTTP) { |
| 2296 |
if((cl_allowDownload->integer & DLF_NO_UDP)) { |
| 2297 |
Com_Error(ERR_DROP, "UDP Downloads are " |
| 2298 |
"disabled on your client. " |
| 2299 |
"(cl_allowDownload is %d)", |
| 2300 |
cl_allowDownload->integer); |
| 2301 |
return; |
| 2302 |
} |
| 2303 |
else { |
| 2304 |
CL_InitDownload( localName ); |
| 2305 |
CL_BeginDownload( remoteName ); |
| 2306 |
} |
| 2307 |
} |
| 2308 |
clc.downloadRestart = qtrue; |
| 2309 |
|
| 2310 |
|
| 2311 |
memmove( clc.downloadList, s, strlen(s) + 1); |
| 2312 |
|
| 2313 |
return; |
| 2314 |
} |
| 2315 |
|
| 2316 |
CL_DownloadsComplete(); |
| 2317 |
} |
| 2318 |
|
| 2319 |
|
| 2320 |
|
| 2321 |
|
| 2322 |
|
| 2323 |
|
| 2324 |
|
| 2325 |
|
| 2326 |
|
| 2327 |
void CL_InitDownloads(void) { |
| 2328 |
char missingfiles[1024]; |
| 2329 |
|
| 2330 |
if ( !(cl_allowDownload->integer & DLF_ENABLE) ) |
| 2331 |
{ |
| 2332 |
|
| 2333 |
|
| 2334 |
if (FS_ComparePaks( missingfiles, sizeof( missingfiles ), qfalse ) ) |
| 2335 |
{ |
| 2336 |
|
| 2337 |
|
| 2338 |
Com_Printf( "\nWARNING: You are missing some files referenced by the server:\n%s" |
| 2339 |
"You might not be able to join the game\n" |
| 2340 |
"Go to the setting menu to turn on autodownload, or get the file elsewhere\n\n", missingfiles ); |
| 2341 |
} |
| 2342 |
} |
| 2343 |
else if ( FS_ComparePaks( clc.downloadList, sizeof( clc.downloadList ) , qtrue ) ) { |
| 2344 |
|
| 2345 |
Com_Printf("Need paks: %s\n", clc.downloadList ); |
| 2346 |
|
| 2347 |
if ( *clc.downloadList ) { |
| 2348 |
|
| 2349 |
clc.state = CA_CONNECTED; |
| 2350 |
|
| 2351 |
*clc.downloadTempName = *clc.downloadName = 0; |
| 2352 |
Cvar_Set( "cl_downloadName", "" ); |
| 2353 |
|
| 2354 |
CL_NextDownload(); |
| 2355 |
return; |
| 2356 |
} |
| 2357 |
|
| 2358 |
} |
| 2359 |
|
| 2360 |
CL_DownloadsComplete(); |
| 2361 |
} |
| 2362 |
|
| 2363 |
|
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
|
| 2368 |
|
| 2369 |
|
| 2370 |
void CL_CheckForResend( void ) { |
| 2371 |
int port; |
| 2372 |
char info[MAX_INFO_STRING]; |
| 2373 |
char data[MAX_INFO_STRING + 10]; |
| 2374 |
|
| 2375 |
|
| 2376 |
if ( clc.demoplaying ) { |
| 2377 |
return; |
| 2378 |
} |
| 2379 |
|
| 2380 |
|
| 2381 |
if ( clc.state != CA_CONNECTING && clc.state != CA_CHALLENGING ) { |
| 2382 |
return; |
| 2383 |
} |
| 2384 |
|
| 2385 |
if ( cls.realtime - clc.connectTime < RETRANSMIT_TIMEOUT ) { |
| 2386 |
return; |
| 2387 |
} |
| 2388 |
|
| 2389 |
clc.connectTime = cls.realtime; |
| 2390 |
clc.connectPacketCount++; |
| 2391 |
|
| 2392 |
|
| 2393 |
switch ( clc.state ) { |
| 2394 |
case CA_CONNECTING: |
| 2395 |
|
| 2396 |
#ifndef STANDALONE |
| 2397 |
if (!com_standalone->integer && clc.serverAddress.type == NA_IP && !Sys_IsLANAddress( clc.serverAddress ) ) |
| 2398 |
CL_RequestAuthorization(); |
| 2399 |
#endif |
| 2400 |
|
| 2401 |
|
| 2402 |
|
| 2403 |
|
| 2404 |
Com_sprintf(data, sizeof(data), "getchallenge %d %s", clc.challenge, com_gamename->string); |
| 2405 |
|
| 2406 |
NET_OutOfBandPrint(NS_CLIENT, clc.serverAddress, "%s", data); |
| 2407 |
break; |
| 2408 |
|
| 2409 |
case CA_CHALLENGING: |
| 2410 |
|
| 2411 |
port = Cvar_VariableValue ("net_qport"); |
| 2412 |
|
| 2413 |
Q_strncpyz( info, Cvar_InfoString( CVAR_USERINFO ), sizeof( info ) ); |
| 2414 |
|
| 2415 |
#ifdef LEGACY_PROTOCOL |
| 2416 |
if(com_legacyprotocol->integer == com_protocol->integer) |
| 2417 |
clc.compat = qtrue; |
| 2418 |
|
| 2419 |
if(clc.compat) |
| 2420 |
Info_SetValueForKey(info, "protocol", va("%i", com_legacyprotocol->integer)); |
| 2421 |
else |
| 2422 |
#endif |
| 2423 |
Info_SetValueForKey(info, "protocol", va("%i", com_protocol->integer)); |
| 2424 |
Info_SetValueForKey( info, "qport", va("%i", port ) ); |
| 2425 |
Info_SetValueForKey( info, "challenge", va("%i", clc.challenge ) ); |
| 2426 |
|
| 2427 |
Com_sprintf( data, sizeof(data), "connect \"%s\"", info ); |
| 2428 |
NET_OutOfBandData( NS_CLIENT, clc.serverAddress, (byte *) data, strlen ( data ) ); |
| 2429 |
|
| 2430 |
|
| 2431 |
cvar_modifiedFlags &= ~CVAR_USERINFO; |
| 2432 |
break; |
| 2433 |
|
| 2434 |
default: |
| 2435 |
Com_Error( ERR_FATAL, "CL_CheckForResend: bad clc.state" ); |
| 2436 |
} |
| 2437 |
} |
| 2438 |
|
| 2439 |
|
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
|
| 2445 |
|
| 2446 |
void CL_MotdPacket( netadr_t from ) { |
| 2447 |
#ifdef UPDATE_SERVER_NAME |
| 2448 |
char *challenge; |
| 2449 |
char *info; |
| 2450 |
|
| 2451 |
|
| 2452 |
if ( !NET_CompareAdr( from, cls.updateServer ) ) { |
| 2453 |
return; |
| 2454 |
} |
| 2455 |
|
| 2456 |
info = Cmd_Argv(1); |
| 2457 |
|
| 2458 |
|
| 2459 |
challenge = Info_ValueForKey( info, "challenge" ); |
| 2460 |
if ( strcmp( challenge, cls.updateChallenge ) ) { |
| 2461 |
return; |
| 2462 |
} |
| 2463 |
|
| 2464 |
challenge = Info_ValueForKey( info, "motd" ); |
| 2465 |
|
| 2466 |
Q_strncpyz( cls.updateInfoString, info, sizeof( cls.updateInfoString ) ); |
| 2467 |
Cvar_Set( "cl_motdString", challenge ); |
| 2468 |
#endif |
| 2469 |
} |
| 2470 |
|
| 2471 |
|
| 2472 |
|
| 2473 |
|
| 2474 |
|
| 2475 |
|
| 2476 |
void CL_InitServerInfo( serverInfo_t *server, netadr_t *address ) { |
| 2477 |
server->adr = *address; |
| 2478 |
server->clients = 0; |
| 2479 |
server->hostName[0] = '\0'; |
| 2480 |
server->mapName[0] = '\0'; |
| 2481 |
server->maxClients = 0; |
| 2482 |
server->maxPing = 0; |
| 2483 |
server->minPing = 0; |
| 2484 |
server->ping = -1; |
| 2485 |
server->game[0] = '\0'; |
| 2486 |
server->gameType = 0; |
| 2487 |
server->netType = 0; |
| 2488 |
server->punkbuster = 0; |
| 2489 |
server->g_humanplayers = 0; |
| 2490 |
server->g_needpass = 0; |
| 2491 |
} |
| 2492 |
|
| 2493 |
#define MAX_SERVERSPERPACKET 256 |
| 2494 |
|
| 2495 |
|
| 2496 |
|
| 2497 |
|
| 2498 |
|
| 2499 |
|
| 2500 |
void CL_ServersResponsePacket( const netadr_t* from, msg_t *msg, qboolean extended ) { |
| 2501 |
int i, j, count, total; |
| 2502 |
netadr_t addresses[MAX_SERVERSPERPACKET]; |
| 2503 |
int numservers; |
| 2504 |
byte* buffptr; |
| 2505 |
byte* buffend; |
| 2506 |
|
| 2507 |
Com_Printf("CL_ServersResponsePacket from %s\n", NET_AdrToStringwPort(*from)); |
| 2508 |
|
| 2509 |
if (cls.numglobalservers == -1) { |
| 2510 |
|
| 2511 |
cls.numglobalservers = 0; |
| 2512 |
cls.numGlobalServerAddresses = 0; |
| 2513 |
} |
| 2514 |
|
| 2515 |
|
| 2516 |
numservers = 0; |
| 2517 |
buffptr = msg->data; |
| 2518 |
buffend = buffptr + msg->cursize; |
| 2519 |
|
| 2520 |
|
| 2521 |
do |
| 2522 |
{ |
| 2523 |
if(*buffptr == '\\' || (extended && *buffptr == '/')) |
| 2524 |
break; |
| 2525 |
|
| 2526 |
buffptr++; |
| 2527 |
} while (buffptr < buffend); |
| 2528 |
|
| 2529 |
while (buffptr + 1 < buffend) |
| 2530 |
{ |
| 2531 |
|
| 2532 |
if (*buffptr == '\\') |
| 2533 |
{ |
| 2534 |
buffptr++; |
| 2535 |
|
| 2536 |
if (buffend - buffptr < sizeof(addresses[numservers].ip) + sizeof(addresses[numservers].port) + 1) |
| 2537 |
break; |
| 2538 |
|
| 2539 |
for(i = 0; i < sizeof(addresses[numservers].ip); i++) |
| 2540 |
addresses[numservers].ip[i] = *buffptr++; |
| 2541 |
|
| 2542 |
addresses[numservers].type = NA_IP; |
| 2543 |
} |
| 2544 |
|
| 2545 |
else if (extended && *buffptr == '/') |
| 2546 |
{ |
| 2547 |
buffptr++; |
| 2548 |
|
| 2549 |
if (buffend - buffptr < sizeof(addresses[numservers].ip6) + sizeof(addresses[numservers].port) + 1) |
| 2550 |
break; |
| 2551 |
|
| 2552 |
for(i = 0; i < sizeof(addresses[numservers].ip6); i++) |
| 2553 |
addresses[numservers].ip6[i] = *buffptr++; |
| 2554 |
|
| 2555 |
addresses[numservers].type = NA_IP6; |
| 2556 |
addresses[numservers].scope_id = from->scope_id; |
| 2557 |
} |
| 2558 |
else |
| 2559 |
|
| 2560 |
break; |
| 2561 |
|
| 2562 |
|
| 2563 |
addresses[numservers].port = (*buffptr++) << 8; |
| 2564 |
addresses[numservers].port += *buffptr++; |
| 2565 |
addresses[numservers].port = BigShort( addresses[numservers].port ); |
| 2566 |
|
| 2567 |
|
| 2568 |
if (*buffptr != '\\' && *buffptr != '/') |
| 2569 |
break; |
| 2570 |
|
| 2571 |
numservers++; |
| 2572 |
if (numservers >= MAX_SERVERSPERPACKET) |
| 2573 |
break; |
| 2574 |
} |
| 2575 |
|
| 2576 |
count = cls.numglobalservers; |
| 2577 |
|
| 2578 |
for (i = 0; i < numservers && count < MAX_GLOBAL_SERVERS; i++) { |
| 2579 |
|
| 2580 |
serverInfo_t *server = &cls.globalServers[count]; |
| 2581 |
|
| 2582 |
|
| 2583 |
|
| 2584 |
|
| 2585 |
for (j = 0; j < count; j++) |
| 2586 |
{ |
| 2587 |
if (NET_CompareAdr(cls.globalServers[j].adr, addresses[i])) |
| 2588 |
break; |
| 2589 |
} |
| 2590 |
|
| 2591 |
if (j < count) |
| 2592 |
continue; |
| 2593 |
|
| 2594 |
CL_InitServerInfo( server, &addresses[i] ); |
| 2595 |
|
| 2596 |
count++; |
| 2597 |
} |
| 2598 |
|
| 2599 |
|
| 2600 |
if ( count >= MAX_GLOBAL_SERVERS && cls.numGlobalServerAddresses < MAX_GLOBAL_SERVERS ) |
| 2601 |
{ |
| 2602 |
|
| 2603 |
for (; i < numservers && cls.numGlobalServerAddresses < MAX_GLOBAL_SERVERS; i++) |
| 2604 |
{ |
| 2605 |
|
| 2606 |
cls.globalServerAddresses[cls.numGlobalServerAddresses++] = addresses[i]; |
| 2607 |
} |
| 2608 |
} |
| 2609 |
|
| 2610 |
cls.numglobalservers = count; |
| 2611 |
total = count + cls.numGlobalServerAddresses; |
| 2612 |
|
| 2613 |
Com_Printf("%d servers parsed (total %d)\n", numservers, total); |
| 2614 |
} |
| 2615 |
|
| 2616 |
|
| 2617 |
|
| 2618 |
|
| 2619 |
|
| 2620 |
|
| 2621 |
|
| 2622 |
|
| 2623 |
void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) { |
| 2624 |
char *s; |
| 2625 |
char *c; |
| 2626 |
int challenge = 0; |
| 2627 |
|
| 2628 |
MSG_BeginReadingOOB( msg ); |
| 2629 |
MSG_ReadLong( msg ); |
| 2630 |
|
| 2631 |
s = MSG_ReadStringLine( msg ); |
| 2632 |
|
| 2633 |
Cmd_TokenizeString( s ); |
| 2634 |
|
| 2635 |
c = Cmd_Argv(0); |
| 2636 |
|
| 2637 |
Com_DPrintf ("CL packet %s: %s\n", NET_AdrToStringwPort(from), c); |
| 2638 |
|
| 2639 |
|
| 2640 |
if (!Q_stricmp(c, "challengeResponse")) |
| 2641 |
{ |
| 2642 |
char *strver; |
| 2643 |
int ver; |
| 2644 |
|
| 2645 |
if (clc.state != CA_CONNECTING) |
| 2646 |
{ |
| 2647 |
Com_DPrintf("Unwanted challenge response received. Ignored.\n"); |
| 2648 |
return; |
| 2649 |
} |
| 2650 |
|
| 2651 |
c = Cmd_Argv(2); |
| 2652 |
if(*c) |
| 2653 |
challenge = atoi(c); |
| 2654 |
|
| 2655 |
strver = Cmd_Argv(3); |
| 2656 |
if(*strver) |
| 2657 |
{ |
| 2658 |
ver = atoi(strver); |
| 2659 |
|
| 2660 |
if(ver != com_protocol->integer) |
| 2661 |
{ |
| 2662 |
#ifdef LEGACY_PROTOCOL |
| 2663 |
if(com_legacyprotocol->integer > 0) |
| 2664 |
{ |
| 2665 |
|
| 2666 |
|
| 2667 |
clc.compat = qtrue; |
| 2668 |
|
| 2669 |
Com_Printf(S_COLOR_YELLOW "Warning: Server reports protocol version %d, " |
| 2670 |
"we have %d. Trying legacy protocol %d.\n", |
| 2671 |
ver, com_protocol->integer, com_legacyprotocol->integer); |
| 2672 |
} |
| 2673 |
else |
| 2674 |
#endif |
| 2675 |
{ |
| 2676 |
Com_Printf(S_COLOR_YELLOW "Warning: Server reports protocol version %d, we have %d. " |
| 2677 |
"Trying anyways.\n", ver, com_protocol->integer); |
| 2678 |
} |
| 2679 |
} |
| 2680 |
} |
| 2681 |
#ifdef LEGACY_PROTOCOL |
| 2682 |
else |
| 2683 |
clc.compat = qtrue; |
| 2684 |
|
| 2685 |
if(clc.compat) |
| 2686 |
{ |
| 2687 |
if(!NET_CompareAdr(from, clc.serverAddress)) |
| 2688 |
{ |
| 2689 |
|
| 2690 |
|
| 2691 |
|
| 2692 |
|
| 2693 |
if(!*c || challenge != clc.challenge) |
| 2694 |
{ |
| 2695 |
Com_DPrintf("Challenge response received from unexpected source. Ignored.\n"); |
| 2696 |
return; |
| 2697 |
} |
| 2698 |
} |
| 2699 |
} |
| 2700 |
else |
| 2701 |
#endif |
| 2702 |
{ |
| 2703 |
if(!*c || challenge != clc.challenge) |
| 2704 |
{ |
| 2705 |
Com_Printf("Bad challenge for challengeResponse. Ignored.\n"); |
| 2706 |
return; |
| 2707 |
} |
| 2708 |
} |
| 2709 |
|
| 2710 |
|
| 2711 |
clc.challenge = atoi(Cmd_Argv(1)); |
| 2712 |
clc.state = CA_CHALLENGING; |
| 2713 |
clc.connectPacketCount = 0; |
| 2714 |
clc.connectTime = -99999; |
| 2715 |
|
| 2716 |
|
| 2717 |
|
| 2718 |
clc.serverAddress = from; |
| 2719 |
Com_DPrintf ("challengeResponse: %d\n", clc.challenge); |
| 2720 |
return; |
| 2721 |
} |
| 2722 |
|
| 2723 |
|
| 2724 |
if ( !Q_stricmp(c, "connectResponse") ) { |
| 2725 |
if ( clc.state >= CA_CONNECTED ) { |
| 2726 |
Com_Printf ("Dup connect received. Ignored.\n"); |
| 2727 |
return; |
| 2728 |
} |
| 2729 |
if ( clc.state != CA_CHALLENGING ) { |
| 2730 |
Com_Printf ("connectResponse packet while not connecting. Ignored.\n"); |
| 2731 |
return; |
| 2732 |
} |
| 2733 |
if ( !NET_CompareAdr( from, clc.serverAddress ) ) { |
| 2734 |
Com_Printf( "connectResponse from wrong address. Ignored.\n" ); |
| 2735 |
return; |
| 2736 |
} |
| 2737 |
|
| 2738 |
#ifdef LEGACY_PROTOCOL |
| 2739 |
if(!clc.compat) |
| 2740 |
#endif |
| 2741 |
{ |
| 2742 |
c = Cmd_Argv(1); |
| 2743 |
|
| 2744 |
if(*c) |
| 2745 |
challenge = atoi(c); |
| 2746 |
else |
| 2747 |
{ |
| 2748 |
Com_Printf("Bad connectResponse received. Ignored.\n"); |
| 2749 |
return; |
| 2750 |
} |
| 2751 |
|
| 2752 |
if(challenge != clc.challenge) |
| 2753 |
{ |
| 2754 |
Com_Printf("ConnectResponse with bad challenge received. Ignored.\n"); |
| 2755 |
return; |
| 2756 |
} |
| 2757 |
} |
| 2758 |
|
| 2759 |
#ifdef LEGACY_PROTOCOL |
| 2760 |
Netchan_Setup(NS_CLIENT, &clc.netchan, from, Cvar_VariableValue("net_qport"), |
| 2761 |
clc.challenge, clc.compat); |
| 2762 |
#else |
| 2763 |
Netchan_Setup(NS_CLIENT, &clc.netchan, from, Cvar_VariableValue("net_qport"), |
| 2764 |
clc.challenge, qfalse); |
| 2765 |
#endif |
| 2766 |
|
| 2767 |
clc.state = CA_CONNECTED; |
| 2768 |
clc.lastPacketSentTime = -9999; |
| 2769 |
return; |
| 2770 |
} |
| 2771 |
|
| 2772 |
|
| 2773 |
if ( !Q_stricmp(c, "infoResponse") ) { |
| 2774 |
CL_ServerInfoPacket( from, msg ); |
| 2775 |
return; |
| 2776 |
} |
| 2777 |
|
| 2778 |
|
| 2779 |
if ( !Q_stricmp(c, "statusResponse") ) { |
| 2780 |
CL_ServerStatusResponse( from, msg ); |
| 2781 |
return; |
| 2782 |
} |
| 2783 |
|
| 2784 |
|
| 2785 |
if ( !Q_stricmp(c, "echo") ) { |
| 2786 |
|
| 2787 |
if ( NET_CompareAdr( from, clc.serverAddress ) || NET_CompareAdr( from, cls.rconAddress ) ) { |
| 2788 |
NET_OutOfBandPrint( NS_CLIENT, from, "%s", Cmd_Argv(1) ); |
| 2789 |
} |
| 2790 |
return; |
| 2791 |
} |
| 2792 |
|
| 2793 |
|
| 2794 |
if ( !Q_stricmp(c, "keyAuthorize") ) { |
| 2795 |
|
| 2796 |
return; |
| 2797 |
} |
| 2798 |
|
| 2799 |
|
| 2800 |
if ( !Q_stricmp(c, "motd") ) { |
| 2801 |
CL_MotdPacket( from ); |
| 2802 |
return; |
| 2803 |
} |
| 2804 |
|
| 2805 |
|
| 2806 |
if ( !Q_stricmp(c, "print") ) { |
| 2807 |
|
| 2808 |
if ( NET_CompareAdr( from, clc.serverAddress ) || NET_CompareAdr( from, cls.rconAddress ) ) { |
| 2809 |
s = MSG_ReadString( msg ); |
| 2810 |
|
| 2811 |
Q_strncpyz( clc.serverMessage, s, sizeof( clc.serverMessage ) ); |
| 2812 |
Com_Printf( "%s", s ); |
| 2813 |
} |
| 2814 |
return; |
| 2815 |
} |
| 2816 |
|
| 2817 |
|
| 2818 |
if ( !Q_strncmp(c, "getserversResponse", 18) ) { |
| 2819 |
CL_ServersResponsePacket( &from, msg, qfalse ); |
| 2820 |
return; |
| 2821 |
} |
| 2822 |
|
| 2823 |
|
| 2824 |
if ( !Q_strncmp(c, "getserversExtResponse", 21) ) { |
| 2825 |
CL_ServersResponsePacket( &from, msg, qtrue ); |
| 2826 |
return; |
| 2827 |
} |
| 2828 |
|
| 2829 |
Com_DPrintf ("Unknown connectionless packet command.\n"); |
| 2830 |
} |
| 2831 |
|
| 2832 |
|
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
|
| 2838 |
|
| 2839 |
|
| 2840 |
void CL_PacketEvent( netadr_t from, msg_t *msg ) { |
| 2841 |
int headerBytes; |
| 2842 |
|
| 2843 |
clc.lastPacketTime = cls.realtime; |
| 2844 |
|
| 2845 |
if ( msg->cursize >= 4 && *(int *)msg->data == -1 ) { |
| 2846 |
CL_ConnectionlessPacket( from, msg ); |
| 2847 |
return; |
| 2848 |
} |
| 2849 |
|
| 2850 |
if ( clc.state < CA_CONNECTED ) { |
| 2851 |
return; |
| 2852 |
} |
| 2853 |
|
| 2854 |
if ( msg->cursize < 4 ) { |
| 2855 |
Com_Printf ("%s: Runt packet\n", NET_AdrToStringwPort( from )); |
| 2856 |
return; |
| 2857 |
} |
| 2858 |
|
| 2859 |
|
| 2860 |
|
| 2861 |
|
| 2862 |
if ( !NET_CompareAdr( from, clc.netchan.remoteAddress ) ) { |
| 2863 |
Com_DPrintf ("%s:sequenced packet without connection\n" |
| 2864 |
, NET_AdrToStringwPort( from ) ); |
| 2865 |
|
| 2866 |
return; |
| 2867 |
} |
| 2868 |
|
| 2869 |
if (!CL_Netchan_Process( &clc.netchan, msg) ) { |
| 2870 |
return; |
| 2871 |
} |
| 2872 |
|
| 2873 |
|
| 2874 |
headerBytes = msg->readcount; |
| 2875 |
|
| 2876 |
|
| 2877 |
|
| 2878 |
|
| 2879 |
clc.serverMessageSequence = LittleLong( *(int *)msg->data ); |
| 2880 |
|
| 2881 |
clc.lastPacketTime = cls.realtime; |
| 2882 |
CL_ParseServerMessage( msg ); |
| 2883 |
|
| 2884 |
|
| 2885 |
|
| 2886 |
|
| 2887 |
|
| 2888 |
if ( clc.demorecording && !clc.demowaiting ) { |
| 2889 |
CL_WriteDemoMessage( msg, headerBytes ); |
| 2890 |
} |
| 2891 |
} |
| 2892 |
|
| 2893 |
|
| 2894 |
|
| 2895 |
|
| 2896 |
|
| 2897 |
|
| 2898 |
|
| 2899 |
void CL_CheckTimeout( void ) { |
| 2900 |
|
| 2901 |
|
| 2902 |
|
| 2903 |
if ( ( !CL_CheckPaused() || !sv_paused->integer ) |
| 2904 |
&& clc.state >= CA_CONNECTED && clc.state != CA_CINEMATIC |
| 2905 |
&& cls.realtime - clc.lastPacketTime > cl_timeout->value*1000) { |
| 2906 |
if (++cl.timeoutcount > 5) { |
| 2907 |
Com_Printf ("\nServer connection timed out.\n"); |
| 2908 |
CL_Disconnect( qtrue ); |
| 2909 |
return; |
| 2910 |
} |
| 2911 |
} else { |
| 2912 |
cl.timeoutcount = 0; |
| 2913 |
} |
| 2914 |
} |
| 2915 |
|
| 2916 |
|
| 2917 |
|
| 2918 |
|
| 2919 |
|
| 2920 |
|
| 2921 |
|
| 2922 |
qboolean CL_CheckPaused(void) |
| 2923 |
{ |
| 2924 |
|
| 2925 |
|
| 2926 |
|
| 2927 |
if(cl_paused->integer || cl_paused->modified) |
| 2928 |
return qtrue; |
| 2929 |
|
| 2930 |
return qfalse; |
| 2931 |
} |
| 2932 |
|
| 2933 |
|
| 2934 |
|
| 2935 |
|
| 2936 |
|
| 2937 |
|
| 2938 |
|
| 2939 |
|
| 2940 |
|
| 2941 |
void CL_CheckUserinfo( void ) { |
| 2942 |
|
| 2943 |
if(clc.state < CA_CONNECTED) |
| 2944 |
return; |
| 2945 |
|
| 2946 |
|
| 2947 |
if(CL_CheckPaused()) |
| 2948 |
return; |
| 2949 |
|
| 2950 |
|
| 2951 |
if(cvar_modifiedFlags & CVAR_USERINFO) |
| 2952 |
{ |
| 2953 |
cvar_modifiedFlags &= ~CVAR_USERINFO; |
| 2954 |
CL_AddReliableCommand(va("userinfo \"%s\"", Cvar_InfoString( CVAR_USERINFO ) ), qfalse); |
| 2955 |
} |
| 2956 |
} |
| 2957 |
|
| 2958 |
|
| 2959 |
|
| 2960 |
|
| 2961 |
|
| 2962 |
|
| 2963 |
|
| 2964 |
void CL_Frame ( int msec ) { |
| 2965 |
|
| 2966 |
if ( !com_cl_running->integer ) { |
| 2967 |
return; |
| 2968 |
} |
| 2969 |
|
| 2970 |
#ifdef USE_HTTP |
| 2971 |
if(clc.httpUsed) { |
| 2972 |
qboolean finished = CL_HTTP_PerformDownload(); |
| 2973 |
|
| 2974 |
if(finished) { |
| 2975 |
if(clc.download) { |
| 2976 |
FS_FCloseFile(clc.download); |
| 2977 |
clc.download = 0; |
| 2978 |
} |
| 2979 |
|
| 2980 |
FS_BaseDir_Rename_HomeData(clc.downloadTempName, clc.downloadName, qfalse); |
| 2981 |
clc.downloadRestart = qtrue; |
| 2982 |
CL_NextDownload(); |
| 2983 |
} |
| 2984 |
|
| 2985 |
|
| 2986 |
|
| 2987 |
|
| 2988 |
if(clc.disconnectedForHttpDownload) { |
| 2989 |
cls.realFrametime = msec; |
| 2990 |
cls.frametime = msec; |
| 2991 |
cls.realtime += cls.frametime; |
| 2992 |
SCR_UpdateScreen(); |
| 2993 |
S_Update(); |
| 2994 |
Con_RunConsole(); |
| 2995 |
cls.framecount++; |
| 2996 |
return; |
| 2997 |
} |
| 2998 |
} |
| 2999 |
#endif |
| 3000 |
|
| 3001 |
if ( cls.cddialog ) { |
| 3002 |
|
| 3003 |
cls.cddialog = qfalse; |
| 3004 |
VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_NEED_CD ); |
| 3005 |
} else if ( clc.state == CA_DISCONNECTED && !( Key_GetCatcher( ) & KEYCATCH_UI ) |
| 3006 |
&& !com_sv_running->integer && uivm ) { |
| 3007 |
|
| 3008 |
S_StopAllSounds(); |
| 3009 |
VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_MAIN ); |
| 3010 |
} |
| 3011 |
|
| 3012 |
|
| 3013 |
if ( CL_VideoRecording( ) && cl_aviFrameRate->integer && msec) { |
| 3014 |
|
| 3015 |
if ( clc.state == CA_ACTIVE || cl_forceavidemo->integer) { |
| 3016 |
float fps = MIN(cl_aviFrameRate->value * com_timescale->value, 1000.0f); |
| 3017 |
float frameDuration = MAX(1000.0f / fps, 1.0f) + clc.aviVideoFrameRemainder; |
| 3018 |
|
| 3019 |
CL_TakeVideoFrame( ); |
| 3020 |
|
| 3021 |
msec = (int)frameDuration; |
| 3022 |
clc.aviVideoFrameRemainder = frameDuration - msec; |
| 3023 |
} |
| 3024 |
} |
| 3025 |
|
| 3026 |
if( cl_autoRecordDemo->integer ) { |
| 3027 |
if( clc.state == CA_ACTIVE && !clc.demorecording && !clc.demoplaying ) { |
| 3028 |
|
| 3029 |
qtime_t now; |
| 3030 |
char *nowString; |
| 3031 |
char *p; |
| 3032 |
char mapName[ MAX_QPATH ]; |
| 3033 |
char serverName[ MAX_OSPATH ]; |
| 3034 |
|
| 3035 |
Com_RealTime( &now ); |
| 3036 |
nowString = va( "%04d%02d%02d%02d%02d%02d", |
| 3037 |
1900 + now.tm_year, |
| 3038 |
1 + now.tm_mon, |
| 3039 |
now.tm_mday, |
| 3040 |
now.tm_hour, |
| 3041 |
now.tm_min, |
| 3042 |
now.tm_sec ); |
| 3043 |
|
| 3044 |
Q_strncpyz( serverName, clc.servername, MAX_OSPATH ); |
| 3045 |
|
| 3046 |
|
| 3047 |
p = strstr( serverName, ":" ); |
| 3048 |
if( p ) { |
| 3049 |
*p = '.'; |
| 3050 |
} |
| 3051 |
|
| 3052 |
Q_strncpyz( mapName, COM_SkipPath( cl.mapname ), sizeof( cl.mapname ) ); |
| 3053 |
COM_StripExtension(mapName, mapName, sizeof(mapName)); |
| 3054 |
|
| 3055 |
Cbuf_ExecuteText( EXEC_NOW, |
| 3056 |
va( "record %s-%s-%s", nowString, serverName, mapName ) ); |
| 3057 |
} |
| 3058 |
else if( clc.state != CA_ACTIVE && clc.demorecording ) { |
| 3059 |
|
| 3060 |
CL_StopRecord_f( ); |
| 3061 |
} |
| 3062 |
} |
| 3063 |
|
| 3064 |
|
| 3065 |
cls.realFrametime = msec; |
| 3066 |
|
| 3067 |
|
| 3068 |
cls.frametime = msec; |
| 3069 |
|
| 3070 |
cls.realtime += cls.frametime; |
| 3071 |
|
| 3072 |
if ( cl_timegraph->integer ) { |
| 3073 |
SCR_DebugGraph ( cls.realFrametime * 0.25 ); |
| 3074 |
} |
| 3075 |
|
| 3076 |
|
| 3077 |
CL_CheckUserinfo(); |
| 3078 |
|
| 3079 |
|
| 3080 |
|
| 3081 |
CL_CheckTimeout(); |
| 3082 |
|
| 3083 |
|
| 3084 |
CL_SendCmd(); |
| 3085 |
|
| 3086 |
|
| 3087 |
CL_CheckForResend(); |
| 3088 |
|
| 3089 |
|
| 3090 |
CL_SetCGameTime(); |
| 3091 |
|
| 3092 |
|
| 3093 |
SCR_UpdateScreen(); |
| 3094 |
|
| 3095 |
|
| 3096 |
S_Update(); |
| 3097 |
|
| 3098 |
#ifdef USE_VOIP |
| 3099 |
CL_CaptureVoip(); |
| 3100 |
#endif |
| 3101 |
|
| 3102 |
#ifdef USE_MUMBLE |
| 3103 |
CL_UpdateMumble(); |
| 3104 |
#endif |
| 3105 |
|
| 3106 |
|
| 3107 |
SCR_RunCinematic(); |
| 3108 |
|
| 3109 |
Con_RunConsole(); |
| 3110 |
|
| 3111 |
cls.framecount++; |
| 3112 |
} |
| 3113 |
|
| 3114 |
|
| 3115 |
|
| 3116 |
|
| 3117 |
|
| 3118 |
|
| 3119 |
|
| 3120 |
|
| 3121 |
|
| 3122 |
|
| 3123 |
|
| 3124 |
static Q_PRINTF_FUNC(2, 3) void QDECL CL_RefPrintf( int print_level, const char *fmt, ...) { |
| 3125 |
va_list argptr; |
| 3126 |
char msg[MAXPRINTMSG]; |
| 3127 |
|
| 3128 |
va_start (argptr,fmt); |
| 3129 |
Q_vsnprintf (msg, sizeof(msg), fmt, argptr); |
| 3130 |
va_end (argptr); |
| 3131 |
|
| 3132 |
if ( print_level == PRINT_ALL ) { |
| 3133 |
Com_Printf ("%s", msg); |
| 3134 |
} else if ( print_level == PRINT_WARNING ) { |
| 3135 |
Com_Printf (S_COLOR_YELLOW "%s", msg); |
| 3136 |
} else if ( print_level == PRINT_ERROR ) { |
| 3137 |
Com_Printf (S_COLOR_RED "%s", msg); |
| 3138 |
} else if ( print_level == PRINT_DEVELOPER ) { |
| 3139 |
Com_DPrintf (S_COLOR_RED "%s", msg); |
| 3140 |
} |
| 3141 |
} |
| 3142 |
|
| 3143 |
|
| 3144 |
|
| 3145 |
|
| 3146 |
|
| 3147 |
|
| 3148 |
|
| 3149 |
|
| 3150 |
void CL_ShutdownRef( void ) { |
| 3151 |
if ( re.Shutdown ) { |
| 3152 |
re.Shutdown( qtrue ); |
| 3153 |
} |
| 3154 |
|
| 3155 |
Com_Memset( &re, 0, sizeof( re ) ); |
| 3156 |
|
| 3157 |
#ifdef USE_RENDERER_DLOPEN |
| 3158 |
if ( rendererLib ) { |
| 3159 |
Sys_UnloadLibrary( rendererLib ); |
| 3160 |
rendererLib = NULL; |
| 3161 |
} |
| 3162 |
#endif |
| 3163 |
} |
| 3164 |
|
| 3165 |
|
| 3166 |
|
| 3167 |
|
| 3168 |
|
| 3169 |
|
| 3170 |
void CL_InitRenderer( void ) { |
| 3171 |
|
| 3172 |
re.BeginRegistration( &cls.glconfig ); |
| 3173 |
|
| 3174 |
|
| 3175 |
cls.charSetShader = re.RegisterShader( "gfx/2d/bigchars" ); |
| 3176 |
cls.whiteShader = re.RegisterShader( "white" ); |
| 3177 |
cls.consoleShader = re.RegisterShader( "console" ); |
| 3178 |
g_console_field_width = cls.glconfig.vidWidth / g_smallchar_width - 2; |
| 3179 |
g_consoleField.widthInChars = g_console_field_width; |
| 3180 |
} |
| 3181 |
|
| 3182 |
|
| 3183 |
|
| 3184 |
|
| 3185 |
|
| 3186 |
|
| 3187 |
|
| 3188 |
|
| 3189 |
|
| 3190 |
void CL_StartHunkUsers( qboolean rendererOnly ) { |
| 3191 |
if (!com_cl_running) { |
| 3192 |
return; |
| 3193 |
} |
| 3194 |
|
| 3195 |
if ( !com_cl_running->integer ) { |
| 3196 |
return; |
| 3197 |
} |
| 3198 |
|
| 3199 |
if ( !cls.rendererStarted ) { |
| 3200 |
cls.rendererStarted = qtrue; |
| 3201 |
CL_InitRenderer(); |
| 3202 |
} |
| 3203 |
|
| 3204 |
if ( rendererOnly ) { |
| 3205 |
return; |
| 3206 |
} |
| 3207 |
|
| 3208 |
if ( !cls.soundStarted ) { |
| 3209 |
cls.soundStarted = qtrue; |
| 3210 |
S_Init(); |
| 3211 |
} |
| 3212 |
|
| 3213 |
if ( !cls.soundRegistered ) { |
| 3214 |
cls.soundRegistered = qtrue; |
| 3215 |
S_BeginRegistration(); |
| 3216 |
} |
| 3217 |
|
| 3218 |
if( com_dedicated->integer ) { |
| 3219 |
return; |
| 3220 |
} |
| 3221 |
|
| 3222 |
if ( !cls.uiStarted ) { |
| 3223 |
cls.uiStarted = qtrue; |
| 3224 |
CL_InitUI(); |
| 3225 |
} |
| 3226 |
} |
| 3227 |
|
| 3228 |
|
| 3229 |
|
| 3230 |
|
| 3231 |
|
| 3232 |
|
| 3233 |
void *CL_RefMalloc( int size ) { |
| 3234 |
return Z_TagMalloc( size, TAG_RENDERER ); |
| 3235 |
} |
| 3236 |
|
| 3237 |
int CL_ScaledMilliseconds(void) { |
| 3238 |
return Sys_Milliseconds()*com_timescale->value; |
| 3239 |
} |
| 3240 |
|
| 3241 |
|
| 3242 |
|
| 3243 |
|
| 3244 |
|
| 3245 |
|
| 3246 |
void CL_InitRef( void ) { |
| 3247 |
refimport_t ri; |
| 3248 |
refexport_t *ret; |
| 3249 |
#ifdef USE_RENDERER_DLOPEN |
| 3250 |
GetRefAPI_t GetRefAPI; |
| 3251 |
char dllName[MAX_OSPATH]; |
| 3252 |
#endif |
| 3253 |
|
| 3254 |
Com_Printf( "----- Initializing Renderer ----\n" ); |
| 3255 |
|
| 3256 |
#ifdef USE_RENDERER_DLOPEN |
| 3257 |
cl_renderer = Cvar_Get("cl_renderer", "opengl2", CVAR_ARCHIVE | CVAR_LATCH); |
| 3258 |
|
| 3259 |
Com_sprintf(dllName, sizeof(dllName), "renderer_%s" DLL_EXT, cl_renderer->string); |
| 3260 |
|
| 3261 |
if(!(rendererLib = Sys_LoadDll(dllName, qfalse)) && strcmp(cl_renderer->string, cl_renderer->resetString)) |
| 3262 |
{ |
| 3263 |
Com_Printf("failed:\n\"%s\"\n", Sys_LibraryError()); |
| 3264 |
Cvar_ForceReset("cl_renderer"); |
| 3265 |
|
| 3266 |
Com_sprintf(dllName, sizeof(dllName), "renderer_%s" DLL_EXT, cl_renderer->resetString); |
| 3267 |
rendererLib = Sys_LoadDll(dllName, qfalse); |
| 3268 |
} |
| 3269 |
|
| 3270 |
if(!rendererLib) |
| 3271 |
{ |
| 3272 |
Com_Printf("failed:\n\"%s\"\n", Sys_LibraryError()); |
| 3273 |
Com_Error(ERR_FATAL, "Failed to load renderer"); |
| 3274 |
} |
| 3275 |
|
| 3276 |
GetRefAPI = Sys_LoadFunction(rendererLib, "GetRefAPI"); |
| 3277 |
if(!GetRefAPI) |
| 3278 |
{ |
| 3279 |
Com_Error(ERR_FATAL, "Can't load symbol GetRefAPI: '%s'", Sys_LibraryError()); |
| 3280 |
} |
| 3281 |
#endif |
| 3282 |
|
| 3283 |
ri.Cmd_AddCommand = Cmd_AddCommand; |
| 3284 |
ri.Cmd_RemoveCommand = Cmd_RemoveCommand; |
| 3285 |
ri.Cmd_Argc = Cmd_Argc; |
| 3286 |
ri.Cmd_Argv = Cmd_Argv; |
| 3287 |
ri.Cmd_ExecuteText = Cbuf_ExecuteText; |
| 3288 |
ri.Printf = CL_RefPrintf; |
| 3289 |
ri.Error = Com_Error; |
| 3290 |
ri.Milliseconds = CL_ScaledMilliseconds; |
| 3291 |
ri.Malloc = CL_RefMalloc; |
| 3292 |
ri.Free = Z_Free; |
| 3293 |
#ifdef HUNK_DEBUG |
| 3294 |
ri.Hunk_AllocDebug = Hunk_AllocDebug; |
| 3295 |
#else |
| 3296 |
ri.Hunk_Alloc = Hunk_Alloc; |
| 3297 |
#endif |
| 3298 |
ri.Hunk_AllocateTempMemory = Hunk_AllocateTempMemory; |
| 3299 |
ri.Hunk_FreeTempMemory = Hunk_FreeTempMemory; |
| 3300 |
|
| 3301 |
ri.CM_ClusterPVS = CM_ClusterPVS; |
| 3302 |
ri.CM_DrawDebugSurface = CM_DrawDebugSurface; |
| 3303 |
|
| 3304 |
ri.FS_ReadFile = FS_ReadFile; |
| 3305 |
ri.FS_FreeFile = FS_FreeFile; |
| 3306 |
ri.FS_WriteFile = FS_WriteFile; |
| 3307 |
ri.FS_FreeFileList = FS_FreeFileList; |
| 3308 |
ri.FS_ListFiles = FS_ListFiles; |
| 3309 |
ri.FS_FileIsInPAK = FS_FileIsInPAK; |
| 3310 |
ri.FS_FileExists = FS_FileExists_HomeData; |
| 3311 |
ri.Cvar_Get = Cvar_Get; |
| 3312 |
ri.Cvar_Set = Cvar_Set; |
| 3313 |
ri.Cvar_SetValue = Cvar_SetValue; |
| 3314 |
ri.Cvar_CheckRange = Cvar_CheckRange; |
| 3315 |
ri.Cvar_SetDescription = Cvar_SetDescription; |
| 3316 |
ri.Cvar_VariableIntegerValue = Cvar_VariableIntegerValue; |
| 3317 |
|
| 3318 |
|
| 3319 |
|
| 3320 |
ri.CIN_UploadCinematic = CIN_UploadCinematic; |
| 3321 |
ri.CIN_PlayCinematic = CIN_PlayCinematic; |
| 3322 |
ri.CIN_RunCinematic = CIN_RunCinematic; |
| 3323 |
|
| 3324 |
ri.CL_WriteAVIVideoFrame = CL_WriteAVIVideoFrame; |
| 3325 |
|
| 3326 |
ri.IN_Init = IN_Init; |
| 3327 |
ri.IN_Shutdown = IN_Shutdown; |
| 3328 |
ri.IN_Restart = IN_Restart; |
| 3329 |
|
| 3330 |
ri.ftol = Q_ftol; |
| 3331 |
|
| 3332 |
ri.Sys_SetEnv = Sys_SetEnv; |
| 3333 |
ri.Sys_GLimpSafeInit = Sys_GLimpSafeInit; |
| 3334 |
ri.Sys_GLimpInit = Sys_GLimpInit; |
| 3335 |
ri.Sys_LowPhysicalMemory = Sys_LowPhysicalMemory; |
| 3336 |
|
| 3337 |
ret = GetRefAPI( REF_API_VERSION, &ri ); |
| 3338 |
|
| 3339 |
#if defined __USEA3D && defined __A3D_GEOM |
| 3340 |
hA3Dg_ExportRenderGeom (ret); |
| 3341 |
#endif |
| 3342 |
|
| 3343 |
Com_Printf( "-------------------------------\n"); |
| 3344 |
|
| 3345 |
if ( !ret ) { |
| 3346 |
Com_Error (ERR_FATAL, "Couldn't initialize refresh" ); |
| 3347 |
} |
| 3348 |
|
| 3349 |
re = *ret; |
| 3350 |
|
| 3351 |
|
| 3352 |
Cvar_Set( "cl_paused", "0" ); |
| 3353 |
} |
| 3354 |
|
| 3355 |
|
| 3356 |
|
| 3357 |
|
| 3358 |
|
| 3359 |
void CL_SetModel_f( void ) { |
| 3360 |
char *arg; |
| 3361 |
char name[256]; |
| 3362 |
|
| 3363 |
arg = Cmd_Argv( 1 ); |
| 3364 |
if (arg[0]) { |
| 3365 |
Cvar_Set( "model", arg ); |
| 3366 |
Cvar_Set( "headmodel", arg ); |
| 3367 |
} else { |
| 3368 |
Cvar_VariableStringBuffer( "model", name, sizeof(name) ); |
| 3369 |
Com_Printf("model is set to %s\n", name); |
| 3370 |
} |
| 3371 |
} |
| 3372 |
|
| 3373 |
|
| 3374 |
|
| 3375 |
|
| 3376 |
|
| 3377 |
|
| 3378 |
|
| 3379 |
|
| 3380 |
|
| 3381 |
|
| 3382 |
|
| 3383 |
|
| 3384 |
|
| 3385 |
void CL_Video_f( void ) |
| 3386 |
{ |
| 3387 |
char filename[ MAX_OSPATH ]; |
| 3388 |
int i, last; |
| 3389 |
|
| 3390 |
if( !clc.demoplaying ) |
| 3391 |
{ |
| 3392 |
Com_Printf( "The video command can only be used when playing back demos\n" ); |
| 3393 |
return; |
| 3394 |
} |
| 3395 |
|
| 3396 |
if( Cmd_Argc( ) == 2 ) |
| 3397 |
{ |
| 3398 |
|
| 3399 |
Com_sprintf( filename, MAX_OSPATH, "videos/%s.avi", Cmd_Argv( 1 ) ); |
| 3400 |
} |
| 3401 |
else |
| 3402 |
{ |
| 3403 |
|
| 3404 |
for( i = 0; i <= 9999; i++ ) |
| 3405 |
{ |
| 3406 |
int a, b, c, d; |
| 3407 |
|
| 3408 |
last = i; |
| 3409 |
|
| 3410 |
a = last / 1000; |
| 3411 |
last -= a * 1000; |
| 3412 |
b = last / 100; |
| 3413 |
last -= b * 100; |
| 3414 |
c = last / 10; |
| 3415 |
last -= c * 10; |
| 3416 |
d = last; |
| 3417 |
|
| 3418 |
Com_sprintf( filename, MAX_OSPATH, "videos/video%d%d%d%d.avi", |
| 3419 |
a, b, c, d ); |
| 3420 |
|
| 3421 |
if( !FS_FileExists_HomeData( filename ) ) |
| 3422 |
break; |
| 3423 |
} |
| 3424 |
|
| 3425 |
if( i > 9999 ) |
| 3426 |
{ |
| 3427 |
Com_Printf( S_COLOR_RED "ERROR: no free file names to create video\n" ); |
| 3428 |
return; |
| 3429 |
} |
| 3430 |
} |
| 3431 |
|
| 3432 |
CL_OpenAVIForWriting( filename ); |
| 3433 |
} |
| 3434 |
|
| 3435 |
|
| 3436 |
|
| 3437 |
|
| 3438 |
|
| 3439 |
|
| 3440 |
void CL_StopVideo_f( void ) |
| 3441 |
{ |
| 3442 |
CL_CloseAVI( ); |
| 3443 |
} |
| 3444 |
|
| 3445 |
|
| 3446 |
|
| 3447 |
|
| 3448 |
|
| 3449 |
|
| 3450 |
|
| 3451 |
|
| 3452 |
|
| 3453 |
static void CL_GenerateQKey(void) |
| 3454 |
{ |
| 3455 |
int len = 0; |
| 3456 |
unsigned char buff[ QKEY_SIZE ]; |
| 3457 |
fileHandle_t f; |
| 3458 |
|
| 3459 |
len = FS_BaseDir_FOpenFileRead( QKEY_FILE, &f ); |
| 3460 |
FS_FCloseFile( f ); |
| 3461 |
if( len == QKEY_SIZE ) { |
| 3462 |
Com_Printf( "QKEY found.\n" ); |
| 3463 |
return; |
| 3464 |
} |
| 3465 |
else { |
| 3466 |
if( len > 0 ) { |
| 3467 |
Com_Printf( "QKEY file size != %d, regenerating\n", |
| 3468 |
QKEY_SIZE ); |
| 3469 |
} |
| 3470 |
|
| 3471 |
Com_Printf( "QKEY building random string\n" ); |
| 3472 |
Com_RandomBytes( buff, sizeof(buff) ); |
| 3473 |
|
| 3474 |
f = FS_BaseDir_FOpenFileWrite_HomeState( QKEY_FILE ); |
| 3475 |
if( !f ) { |
| 3476 |
Com_Printf( "QKEY could not open %s for write\n", |
| 3477 |
QKEY_FILE ); |
| 3478 |
return; |
| 3479 |
} |
| 3480 |
FS_Write( buff, sizeof(buff), f ); |
| 3481 |
FS_FCloseFile( f ); |
| 3482 |
Com_Printf( "QKEY generated\n" ); |
| 3483 |
} |
| 3484 |
} |
| 3485 |
|
| 3486 |
void CL_Sayto_f( void ) { |
| 3487 |
char *rawname; |
| 3488 |
char name[MAX_NAME_LENGTH]; |
| 3489 |
char cleanName[MAX_NAME_LENGTH]; |
| 3490 |
const char *info; |
| 3491 |
int count; |
| 3492 |
int i; |
| 3493 |
int clientNum; |
| 3494 |
char *p; |
| 3495 |
|
| 3496 |
if ( Cmd_Argc() < 3 ) { |
| 3497 |
Com_Printf ("sayto <player name> <text>\n"); |
| 3498 |
return; |
| 3499 |
} |
| 3500 |
|
| 3501 |
rawname = Cmd_Argv(1); |
| 3502 |
|
| 3503 |
Com_FieldStringToPlayerName( name, MAX_NAME_LENGTH, rawname ); |
| 3504 |
|
| 3505 |
info = cl.gameState.stringData + cl.gameState.stringOffsets[CS_SERVERINFO]; |
| 3506 |
count = atoi( Info_ValueForKey( info, "sv_maxclients" ) ); |
| 3507 |
|
| 3508 |
clientNum = -1; |
| 3509 |
for( i = 0; i < count; i++ ) { |
| 3510 |
|
| 3511 |
info = cl.gameState.stringData + cl.gameState.stringOffsets[CS_PLAYERS+i]; |
| 3512 |
Q_strncpyz( cleanName, Info_ValueForKey( info, "n" ), sizeof(cleanName) ); |
| 3513 |
Q_CleanStr( cleanName ); |
| 3514 |
|
| 3515 |
if ( !Q_stricmp( cleanName, name ) ) { |
| 3516 |
clientNum = i; |
| 3517 |
break; |
| 3518 |
} |
| 3519 |
} |
| 3520 |
if( clientNum <= -1 ) |
| 3521 |
{ |
| 3522 |
Com_Printf ("No such player name: %s.\n", name); |
| 3523 |
return; |
| 3524 |
} |
| 3525 |
|
| 3526 |
p = Cmd_ArgsFrom(2); |
| 3527 |
|
| 3528 |
if ( *p == '"' ) { |
| 3529 |
p++; |
| 3530 |
p[strlen(p)-1] = 0; |
| 3531 |
} |
| 3532 |
|
| 3533 |
CL_AddReliableCommand(va("tell %i \"%s\"", clientNum, p ), qfalse); |
| 3534 |
} |
| 3535 |
|
| 3536 |
|
| 3537 |
|
| 3538 |
|
| 3539 |
|
| 3540 |
|
| 3541 |
void CL_Init( void ) { |
| 3542 |
Com_Printf( "----- Client Initialization -----\n" ); |
| 3543 |
|
| 3544 |
Con_Init (); |
| 3545 |
|
| 3546 |
if(!com_fullyInitialized) |
| 3547 |
{ |
| 3548 |
CL_ClearState(); |
| 3549 |
clc.state = CA_DISCONNECTED; |
| 3550 |
cl_oldGameSet = qfalse; |
| 3551 |
} |
| 3552 |
|
| 3553 |
cls.realtime = 0; |
| 3554 |
|
| 3555 |
CL_InitInput (); |
| 3556 |
|
| 3557 |
|
| 3558 |
|
| 3559 |
|
| 3560 |
cl_noprint = Cvar_Get( "cl_noprint", "0", 0 ); |
| 3561 |
#ifdef UPDATE_SERVER_NAME |
| 3562 |
cl_motd = Cvar_Get ("cl_motd", "1", 0); |
| 3563 |
#endif |
| 3564 |
|
| 3565 |
cl_timeout = Cvar_Get ("cl_timeout", "200", 0); |
| 3566 |
|
| 3567 |
cl_timeNudge = Cvar_Get ("cl_timeNudge", "0", CVAR_TEMP ); |
| 3568 |
cl_shownet = Cvar_Get ("cl_shownet", "0", CVAR_TEMP ); |
| 3569 |
cl_showSend = Cvar_Get ("cl_showSend", "0", CVAR_TEMP ); |
| 3570 |
cl_showTimeDelta = Cvar_Get ("cl_showTimeDelta", "0", CVAR_TEMP ); |
| 3571 |
cl_freezeDemo = Cvar_Get ("cl_freezeDemo", "0", CVAR_TEMP ); |
| 3572 |
rcon_client_password = Cvar_Get ("rconPassword", "", CVAR_TEMP ); |
| 3573 |
cl_activeAction = Cvar_Get( "activeAction", "", CVAR_TEMP ); |
| 3574 |
|
| 3575 |
cl_timedemo = Cvar_Get ("timedemo", "0", 0); |
| 3576 |
cl_timedemoLog = Cvar_Get ("cl_timedemoLog", "", CVAR_ARCHIVE); |
| 3577 |
cl_autoRecordDemo = Cvar_Get ("cl_autoRecordDemo", "0", CVAR_ARCHIVE); |
| 3578 |
cl_aviFrameRate = Cvar_Get ("cl_aviFrameRate", "25", CVAR_ARCHIVE); |
| 3579 |
cl_aviMotionJpeg = Cvar_Get ("cl_aviMotionJpeg", "1", CVAR_ARCHIVE); |
| 3580 |
cl_forceavidemo = Cvar_Get ("cl_forceavidemo", "0", 0); |
| 3581 |
|
| 3582 |
rconAddress = Cvar_Get ("rconAddress", "", 0); |
| 3583 |
|
| 3584 |
cl_yawspeed = Cvar_Get ("cl_yawspeed", "140", CVAR_ARCHIVE); |
| 3585 |
cl_pitchspeed = Cvar_Get ("cl_pitchspeed", "140", CVAR_ARCHIVE); |
| 3586 |
cl_anglespeedkey = Cvar_Get ("cl_anglespeedkey", "1.5", 0); |
| 3587 |
|
| 3588 |
cl_maxpackets = Cvar_Get ("cl_maxpackets", "30", CVAR_ARCHIVE ); |
| 3589 |
cl_packetdup = Cvar_Get ("cl_packetdup", "1", CVAR_ARCHIVE ); |
| 3590 |
|
| 3591 |
cl_run = Cvar_Get ("cl_run", "1", CVAR_ARCHIVE); |
| 3592 |
cl_sensitivity = Cvar_Get ("sensitivity", "5", CVAR_ARCHIVE); |
| 3593 |
cl_mouseAccel = Cvar_Get ("cl_mouseAccel", "0", CVAR_ARCHIVE); |
| 3594 |
cl_freelook = Cvar_Get( "cl_freelook", "1", CVAR_ARCHIVE ); |
| 3595 |
|
| 3596 |
|
| 3597 |
|
| 3598 |
cl_mouseAccelStyle = Cvar_Get( "cl_mouseAccelStyle", "0", CVAR_ARCHIVE ); |
| 3599 |
|
| 3600 |
|
| 3601 |
cl_mouseAccelOffset = Cvar_Get( "cl_mouseAccelOffset", "5", CVAR_ARCHIVE ); |
| 3602 |
Cvar_CheckRange(cl_mouseAccelOffset, 0.001f, 50000.0f, qfalse); |
| 3603 |
|
| 3604 |
cl_showMouseRate = Cvar_Get ("cl_showmouserate", "0", 0); |
| 3605 |
|
| 3606 |
cl_allowDownload = Cvar_Get ("cl_allowDownload", "0", CVAR_ARCHIVE); |
| 3607 |
|
| 3608 |
cl_conXOffset = Cvar_Get ("cl_conXOffset", "0", 0); |
| 3609 |
#ifdef __APPLE__ |
| 3610 |
|
| 3611 |
cl_inGameVideo = Cvar_Get ("r_inGameVideo", "0", CVAR_ARCHIVE); |
| 3612 |
#else |
| 3613 |
cl_inGameVideo = Cvar_Get ("r_inGameVideo", "1", CVAR_ARCHIVE); |
| 3614 |
#endif |
| 3615 |
|
| 3616 |
cl_serverStatusResendTime = Cvar_Get ("cl_serverStatusResendTime", "750", 0); |
| 3617 |
|
| 3618 |
|
| 3619 |
|
| 3620 |
Cvar_Get ("cg_autoswitch", "1", CVAR_ARCHIVE); |
| 3621 |
|
| 3622 |
m_pitch = Cvar_Get ("m_pitch", "0.022", CVAR_ARCHIVE); |
| 3623 |
m_yaw = Cvar_Get ("m_yaw", "0.022", CVAR_ARCHIVE); |
| 3624 |
m_forward = Cvar_Get ("m_forward", "0.25", CVAR_ARCHIVE); |
| 3625 |
m_side = Cvar_Get ("m_side", "0.25", CVAR_ARCHIVE); |
| 3626 |
#ifdef __APPLE__ |
| 3627 |
|
| 3628 |
m_filter = Cvar_Get ("m_filter", "1", CVAR_ARCHIVE); |
| 3629 |
#else |
| 3630 |
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE); |
| 3631 |
#endif |
| 3632 |
|
| 3633 |
j_pitch = Cvar_Get ("j_pitch", "0.022", CVAR_ARCHIVE); |
| 3634 |
j_yaw = Cvar_Get ("j_yaw", "-0.022", CVAR_ARCHIVE); |
| 3635 |
j_forward = Cvar_Get ("j_forward", "-0.25", CVAR_ARCHIVE); |
| 3636 |
j_side = Cvar_Get ("j_side", "0.25", CVAR_ARCHIVE); |
| 3637 |
j_up = Cvar_Get ("j_up", "0", CVAR_ARCHIVE); |
| 3638 |
|
| 3639 |
j_pitch_axis = Cvar_Get ("j_pitch_axis", "3", CVAR_ARCHIVE); |
| 3640 |
j_yaw_axis = Cvar_Get ("j_yaw_axis", "2", CVAR_ARCHIVE); |
| 3641 |
j_forward_axis = Cvar_Get ("j_forward_axis", "1", CVAR_ARCHIVE); |
| 3642 |
j_side_axis = Cvar_Get ("j_side_axis", "0", CVAR_ARCHIVE); |
| 3643 |
j_up_axis = Cvar_Get ("j_up_axis", "4", CVAR_ARCHIVE); |
| 3644 |
|
| 3645 |
Cvar_CheckRange(j_pitch_axis, 0, MAX_JOYSTICK_AXIS-1, qtrue); |
| 3646 |
Cvar_CheckRange(j_yaw_axis, 0, MAX_JOYSTICK_AXIS-1, qtrue); |
| 3647 |
Cvar_CheckRange(j_forward_axis, 0, MAX_JOYSTICK_AXIS-1, qtrue); |
| 3648 |
Cvar_CheckRange(j_side_axis, 0, MAX_JOYSTICK_AXIS-1, qtrue); |
| 3649 |
Cvar_CheckRange(j_up_axis, 0, MAX_JOYSTICK_AXIS-1, qtrue); |
| 3650 |
|
| 3651 |
cl_motdString = Cvar_Get( "cl_motdString", "", CVAR_ROM ); |
| 3652 |
|
| 3653 |
Cvar_Get( "cl_maxPing", "800", CVAR_ARCHIVE ); |
| 3654 |
|
| 3655 |
cl_lanForcePackets = Cvar_Get ("cl_lanForcePackets", "1", CVAR_ARCHIVE); |
| 3656 |
|
| 3657 |
cl_guidServerUniq = Cvar_Get ("cl_guidServerUniq", "1", CVAR_ARCHIVE); |
| 3658 |
|
| 3659 |
|
| 3660 |
cl_consoleKeys = Cvar_Get( "cl_consoleKeys", "~ ` 0x7e 0x60", CVAR_ARCHIVE); |
| 3661 |
|
| 3662 |
|
| 3663 |
Cvar_Get ("name", "UnnamedPlayer", CVAR_USERINFO | CVAR_ARCHIVE ); |
| 3664 |
cl_rate = Cvar_Get ("rate", "25000", CVAR_USERINFO | CVAR_ARCHIVE ); |
| 3665 |
Cvar_Get ("snaps", "20", CVAR_USERINFO | CVAR_ARCHIVE ); |
| 3666 |
Cvar_Get ("model", "sarge", CVAR_USERINFO | CVAR_ARCHIVE ); |
| 3667 |
Cvar_Get ("headmodel", "sarge", CVAR_USERINFO | CVAR_ARCHIVE ); |
| 3668 |
Cvar_Get ("team_model", "james", CVAR_USERINFO | CVAR_ARCHIVE ); |
| 3669 |
Cvar_Get ("team_headmodel", "*james", CVAR_USERINFO | CVAR_ARCHIVE ); |
| 3670 |
Cvar_Get ("g_redTeam", "Stroggs", CVAR_SERVERINFO | CVAR_ARCHIVE); |
| 3671 |
Cvar_Get ("g_blueTeam", "Pagans", CVAR_SERVERINFO | CVAR_ARCHIVE); |
| 3672 |
Cvar_Get ("color1", "4", CVAR_USERINFO | CVAR_ARCHIVE ); |
| 3673 |
Cvar_Get ("color2", "5", CVAR_USERINFO | CVAR_ARCHIVE ); |
| 3674 |
Cvar_Get ("handicap", "100", CVAR_USERINFO | CVAR_ARCHIVE ); |
| 3675 |
Cvar_Get ("teamtask", "0", CVAR_USERINFO ); |
| 3676 |
Cvar_Get ("sex", "male", CVAR_USERINFO | CVAR_ARCHIVE ); |
| 3677 |
Cvar_Get ("cl_anonymous", "0", CVAR_USERINFO | CVAR_ARCHIVE ); |
| 3678 |
|
| 3679 |
Cvar_Get ("password", "", CVAR_USERINFO); |
| 3680 |
Cvar_Get ("cg_predictItems", "1", CVAR_USERINFO | CVAR_ARCHIVE ); |
| 3681 |
|
| 3682 |
#ifdef USE_MUMBLE |
| 3683 |
cl_useMumble = Cvar_Get ("cl_useMumble", "0", CVAR_ARCHIVE | CVAR_LATCH); |
| 3684 |
cl_mumbleScale = Cvar_Get ("cl_mumbleScale", "0.0254", CVAR_ARCHIVE); |
| 3685 |
#endif |
| 3686 |
|
| 3687 |
#ifdef USE_VOIP |
| 3688 |
cl_voipSend = Cvar_Get ("cl_voipSend", "0", 0); |
| 3689 |
cl_voipSendTarget = Cvar_Get ("cl_voipSendTarget", "spatial", 0); |
| 3690 |
cl_voipGainDuringCapture = Cvar_Get ("cl_voipGainDuringCapture", "0.2", CVAR_ARCHIVE); |
| 3691 |
cl_voipCaptureMult = Cvar_Get ("cl_voipCaptureMult", "2.0", CVAR_ARCHIVE); |
| 3692 |
cl_voipUseVAD = Cvar_Get ("cl_voipUseVAD", "0", CVAR_ARCHIVE); |
| 3693 |
cl_voipVADThreshold = Cvar_Get ("cl_voipVADThreshold", "0.25", CVAR_ARCHIVE); |
| 3694 |
cl_voipShowMeter = Cvar_Get ("cl_voipShowMeter", "1", CVAR_ARCHIVE); |
| 3695 |
|
| 3696 |
cl_voip = Cvar_Get ("cl_voip", "1", CVAR_ARCHIVE); |
| 3697 |
Cvar_CheckRange( cl_voip, 0, 1, qtrue ); |
| 3698 |
cl_voipProtocol = Cvar_Get ("cl_voipProtocol", cl_voip->integer ? "opus" : "", CVAR_USERINFO | CVAR_ROM); |
| 3699 |
#endif |
| 3700 |
|
| 3701 |
#ifdef USE_HTTP |
| 3702 |
if(!CL_HTTP_Init()) { |
| 3703 |
Com_Printf("WARNING: couldn't initialize HTTP download support\n"); |
| 3704 |
} |
| 3705 |
#endif |
| 3706 |
|
| 3707 |
|
| 3708 |
Cvar_Get ("cg_viewsize", "100", CVAR_ARCHIVE ); |
| 3709 |
|
| 3710 |
Cvar_Get ("cg_stereoSeparation", "0", CVAR_ROM); |
| 3711 |
|
| 3712 |
|
| 3713 |
|
| 3714 |
|
| 3715 |
Cmd_AddCommand ("cmd", CL_ForwardToServer_f); |
| 3716 |
Cmd_AddCommand ("configstrings", CL_Configstrings_f); |
| 3717 |
Cmd_AddCommand ("clientinfo", CL_Clientinfo_f); |
| 3718 |
Cmd_AddCommand ("snd_restart", CL_Snd_Restart_f); |
| 3719 |
Cmd_AddCommand ("vid_restart", CL_Vid_Restart_f); |
| 3720 |
Cmd_AddCommand ("disconnect", CL_Disconnect_f); |
| 3721 |
Cmd_AddCommand ("record", CL_Record_f); |
| 3722 |
Cmd_AddCommand ("demo", CL_PlayDemo_f); |
| 3723 |
Cmd_SetCommandCompletionFunc( "demo", CL_CompleteDemoName ); |
| 3724 |
Cmd_AddCommand ("cinematic", CL_PlayCinematic_f); |
| 3725 |
Cmd_AddCommand ("stoprecord", CL_StopRecord_f); |
| 3726 |
Cmd_AddCommand ("connect", CL_Connect_f); |
| 3727 |
Cmd_AddCommand ("reconnect", CL_Reconnect_f); |
| 3728 |
Cmd_AddCommand ("localservers", CL_LocalServers_f); |
| 3729 |
Cmd_AddCommand ("globalservers", CL_GlobalServers_f); |
| 3730 |
Cmd_AddCommand ("rcon", CL_Rcon_f); |
| 3731 |
Cmd_SetCommandCompletionFunc( "rcon", CL_CompleteRcon ); |
| 3732 |
Cmd_AddCommand ("ping", CL_Ping_f ); |
| 3733 |
Cmd_AddCommand ("serverstatus", CL_ServerStatus_f ); |
| 3734 |
Cmd_AddCommand ("showip", CL_ShowIP_f ); |
| 3735 |
Cmd_AddCommand ("fs_openedList", CL_OpenedPK3List_f ); |
| 3736 |
Cmd_AddCommand ("fs_referencedList", CL_ReferencedPK3List_f ); |
| 3737 |
Cmd_AddCommand ("model", CL_SetModel_f ); |
| 3738 |
Cmd_AddCommand ("video", CL_Video_f ); |
| 3739 |
Cmd_AddCommand ("stopvideo", CL_StopVideo_f ); |
| 3740 |
if( !com_dedicated->integer ) { |
| 3741 |
Cmd_AddCommand ("sayto", CL_Sayto_f ); |
| 3742 |
Cmd_SetCommandCompletionFunc( "sayto", CL_CompletePlayerName ); |
| 3743 |
} |
| 3744 |
CL_InitRef(); |
| 3745 |
|
| 3746 |
SCR_Init (); |
| 3747 |
|
| 3748 |
|
| 3749 |
|
| 3750 |
Cvar_Set( "cl_running", "1" ); |
| 3751 |
|
| 3752 |
CL_GenerateQKey(); |
| 3753 |
Cvar_Get( "cl_guid", "", CVAR_USERINFO | CVAR_ROM ); |
| 3754 |
CL_UpdateGUID( NULL, 0 ); |
| 3755 |
|
| 3756 |
Com_Printf( "----- Client Initialization Complete -----\n" ); |
| 3757 |
} |
| 3758 |
|
| 3759 |
|
| 3760 |
|
| 3761 |
|
| 3762 |
|
| 3763 |
|
| 3764 |
|
| 3765 |
|
| 3766 |
void CL_Shutdown(char *finalmsg, qboolean disconnect, qboolean quit) |
| 3767 |
{ |
| 3768 |
static qboolean recursive = qfalse; |
| 3769 |
|
| 3770 |
|
| 3771 |
if(!(com_cl_running && com_cl_running->integer)) |
| 3772 |
return; |
| 3773 |
|
| 3774 |
Com_Printf( "----- Client Shutdown (%s) -----\n", finalmsg ); |
| 3775 |
|
| 3776 |
if ( recursive ) { |
| 3777 |
Com_Printf( "WARNING: Recursive shutdown\n" ); |
| 3778 |
return; |
| 3779 |
} |
| 3780 |
recursive = qtrue; |
| 3781 |
|
| 3782 |
noGameRestart = quit; |
| 3783 |
|
| 3784 |
if(disconnect) |
| 3785 |
CL_Disconnect(qtrue); |
| 3786 |
|
| 3787 |
CL_ClearMemory(qtrue); |
| 3788 |
CL_Snd_Shutdown(); |
| 3789 |
|
| 3790 |
#ifdef USE_HTTP |
| 3791 |
CL_HTTP_Shutdown(); |
| 3792 |
#endif |
| 3793 |
|
| 3794 |
Cmd_RemoveCommand ("cmd"); |
| 3795 |
Cmd_RemoveCommand ("configstrings"); |
| 3796 |
Cmd_RemoveCommand ("clientinfo"); |
| 3797 |
Cmd_RemoveCommand ("snd_restart"); |
| 3798 |
Cmd_RemoveCommand ("vid_restart"); |
| 3799 |
Cmd_RemoveCommand ("disconnect"); |
| 3800 |
Cmd_RemoveCommand ("record"); |
| 3801 |
Cmd_RemoveCommand ("demo"); |
| 3802 |
Cmd_RemoveCommand ("cinematic"); |
| 3803 |
Cmd_RemoveCommand ("stoprecord"); |
| 3804 |
Cmd_RemoveCommand ("connect"); |
| 3805 |
Cmd_RemoveCommand ("reconnect"); |
| 3806 |
Cmd_RemoveCommand ("localservers"); |
| 3807 |
Cmd_RemoveCommand ("globalservers"); |
| 3808 |
Cmd_RemoveCommand ("rcon"); |
| 3809 |
Cmd_RemoveCommand ("ping"); |
| 3810 |
Cmd_RemoveCommand ("serverstatus"); |
| 3811 |
Cmd_RemoveCommand ("showip"); |
| 3812 |
Cmd_RemoveCommand ("fs_openedList"); |
| 3813 |
Cmd_RemoveCommand ("fs_referencedList"); |
| 3814 |
Cmd_RemoveCommand ("model"); |
| 3815 |
Cmd_RemoveCommand ("video"); |
| 3816 |
Cmd_RemoveCommand ("stopvideo"); |
| 3817 |
|
| 3818 |
CL_ShutdownInput(); |
| 3819 |
Con_Shutdown(); |
| 3820 |
|
| 3821 |
Cvar_Set( "cl_running", "0" ); |
| 3822 |
|
| 3823 |
recursive = qfalse; |
| 3824 |
|
| 3825 |
Com_Memset( &cls, 0, sizeof( cls ) ); |
| 3826 |
Key_SetCatcher( 0 ); |
| 3827 |
|
| 3828 |
Com_Printf( "-----------------------\n" ); |
| 3829 |
|
| 3830 |
} |
| 3831 |
|
| 3832 |
static void CL_SetServerInfo(serverInfo_t *server, const char *info, int ping) { |
| 3833 |
if (server) { |
| 3834 |
if (info) { |
| 3835 |
server->clients = atoi(Info_ValueForKey(info, "clients")); |
| 3836 |
Q_strncpyz(server->hostName,Info_ValueForKey(info, "hostname"), MAX_HOSTNAME_LENGTH); |
| 3837 |
Q_strncpyz(server->mapName, Info_ValueForKey(info, "mapname"), MAX_NAME_LENGTH); |
| 3838 |
server->maxClients = atoi(Info_ValueForKey(info, "sv_maxclients")); |
| 3839 |
Q_strncpyz(server->game,Info_ValueForKey(info, "game"), MAX_NAME_LENGTH); |
| 3840 |
server->gameType = atoi(Info_ValueForKey(info, "gametype")); |
| 3841 |
server->netType = atoi(Info_ValueForKey(info, "nettype")); |
| 3842 |
server->minPing = atoi(Info_ValueForKey(info, "minping")); |
| 3843 |
server->maxPing = atoi(Info_ValueForKey(info, "maxping")); |
| 3844 |
server->punkbuster = atoi(Info_ValueForKey(info, "punkbuster")); |
| 3845 |
server->g_humanplayers = atoi(Info_ValueForKey(info, "g_humanplayers")); |
| 3846 |
server->g_needpass = atoi(Info_ValueForKey(info, "g_needpass")); |
| 3847 |
} |
| 3848 |
server->ping = ping; |
| 3849 |
} |
| 3850 |
} |
| 3851 |
|
| 3852 |
static void CL_SetServerInfoByAddress(netadr_t from, const char *info, int ping) { |
| 3853 |
int i; |
| 3854 |
|
| 3855 |
for (i = 0; i < MAX_OTHER_SERVERS; i++) { |
| 3856 |
if (NET_CompareAdr(from, cls.localServers[i].adr)) { |
| 3857 |
CL_SetServerInfo(&cls.localServers[i], info, ping); |
| 3858 |
} |
| 3859 |
} |
| 3860 |
|
| 3861 |
for (i = 0; i < MAX_GLOBAL_SERVERS; i++) { |
| 3862 |
if (NET_CompareAdr(from, cls.globalServers[i].adr)) { |
| 3863 |
CL_SetServerInfo(&cls.globalServers[i], info, ping); |
| 3864 |
} |
| 3865 |
} |
| 3866 |
|
| 3867 |
for (i = 0; i < MAX_OTHER_SERVERS; i++) { |
| 3868 |
if (NET_CompareAdr(from, cls.favoriteServers[i].adr)) { |
| 3869 |
CL_SetServerInfo(&cls.favoriteServers[i], info, ping); |
| 3870 |
} |
| 3871 |
} |
| 3872 |
|
| 3873 |
} |
| 3874 |
|
| 3875 |
|
| 3876 |
|
| 3877 |
|
| 3878 |
|
| 3879 |
|
| 3880 |
void CL_ServerInfoPacket( netadr_t from, msg_t *msg ) { |
| 3881 |
int i, type; |
| 3882 |
char info[MAX_INFO_STRING]; |
| 3883 |
char *infoString; |
| 3884 |
int prot; |
| 3885 |
char *gamename; |
| 3886 |
qboolean gameMismatch; |
| 3887 |
|
| 3888 |
infoString = MSG_ReadString( msg ); |
| 3889 |
|
| 3890 |
|
| 3891 |
gamename = Info_ValueForKey( infoString, "gamename" ); |
| 3892 |
|
| 3893 |
#ifdef LEGACY_PROTOCOL |
| 3894 |
|
| 3895 |
if (com_legacyprotocol->integer && !*gamename) |
| 3896 |
gameMismatch = qfalse; |
| 3897 |
else |
| 3898 |
#endif |
| 3899 |
gameMismatch = !*gamename || strcmp(gamename, com_gamename->string) != 0; |
| 3900 |
|
| 3901 |
if (gameMismatch) |
| 3902 |
{ |
| 3903 |
Com_DPrintf( "Game mismatch in info packet: %s\n", infoString ); |
| 3904 |
return; |
| 3905 |
} |
| 3906 |
|
| 3907 |
|
| 3908 |
prot = atoi( Info_ValueForKey( infoString, "protocol" ) ); |
| 3909 |
|
| 3910 |
if(prot != com_protocol->integer |
| 3911 |
#ifdef LEGACY_PROTOCOL |
| 3912 |
&& prot != com_legacyprotocol->integer |
| 3913 |
#endif |
| 3914 |
) |
| 3915 |
{ |
| 3916 |
Com_DPrintf( "Different protocol info packet: %s\n", infoString ); |
| 3917 |
return; |
| 3918 |
} |
| 3919 |
|
| 3920 |
|
| 3921 |
for (i=0; i<MAX_PINGREQUESTS; i++) |
| 3922 |
{ |
| 3923 |
if ( cl_pinglist[i].adr.port && !cl_pinglist[i].time && NET_CompareAdr( from, cl_pinglist[i].adr ) ) |
| 3924 |
{ |
| 3925 |
|
| 3926 |
cl_pinglist[i].time = Sys_Milliseconds() - cl_pinglist[i].start; |
| 3927 |
Com_DPrintf( "ping time %dms from %s\n", cl_pinglist[i].time, NET_AdrToString( from ) ); |
| 3928 |
|
| 3929 |
|
| 3930 |
Q_strncpyz( cl_pinglist[i].info, infoString, sizeof( cl_pinglist[i].info ) ); |
| 3931 |
|
| 3932 |
|
| 3933 |
|
| 3934 |
switch (from.type) |
| 3935 |
{ |
| 3936 |
case NA_BROADCAST: |
| 3937 |
case NA_IP: |
| 3938 |
type = 1; |
| 3939 |
break; |
| 3940 |
case NA_IP6: |
| 3941 |
type = 2; |
| 3942 |
break; |
| 3943 |
default: |
| 3944 |
type = 0; |
| 3945 |
break; |
| 3946 |
} |
| 3947 |
Info_SetValueForKey( cl_pinglist[i].info, "nettype", va("%d", type) ); |
| 3948 |
CL_SetServerInfoByAddress(from, infoString, cl_pinglist[i].time); |
| 3949 |
|
| 3950 |
return; |
| 3951 |
} |
| 3952 |
} |
| 3953 |
|
| 3954 |
|
| 3955 |
if (cls.pingUpdateSource != AS_LOCAL) { |
| 3956 |
return; |
| 3957 |
} |
| 3958 |
|
| 3959 |
for ( i = 0 ; i < MAX_OTHER_SERVERS ; i++ ) { |
| 3960 |
|
| 3961 |
if ( cls.localServers[i].adr.port == 0 ) { |
| 3962 |
break; |
| 3963 |
} |
| 3964 |
|
| 3965 |
|
| 3966 |
if ( NET_CompareAdr( from, cls.localServers[i].adr ) ) { |
| 3967 |
return; |
| 3968 |
} |
| 3969 |
} |
| 3970 |
|
| 3971 |
if ( i == MAX_OTHER_SERVERS ) { |
| 3972 |
Com_DPrintf( "MAX_OTHER_SERVERS hit, dropping infoResponse\n" ); |
| 3973 |
return; |
| 3974 |
} |
| 3975 |
|
| 3976 |
|
| 3977 |
cls.numlocalservers = i+1; |
| 3978 |
CL_InitServerInfo( &cls.localServers[i], &from ); |
| 3979 |
|
| 3980 |
Q_strncpyz( info, MSG_ReadString( msg ), MAX_INFO_STRING ); |
| 3981 |
if (strlen(info)) { |
| 3982 |
if (info[strlen(info)-1] != '\n') { |
| 3983 |
Q_strcat(info, sizeof(info), "\n"); |
| 3984 |
} |
| 3985 |
Com_Printf( "%s: %s", NET_AdrToStringwPort( from ), info ); |
| 3986 |
} |
| 3987 |
} |
| 3988 |
|
| 3989 |
|
| 3990 |
|
| 3991 |
|
| 3992 |
|
| 3993 |
|
| 3994 |
serverStatus_t *CL_GetServerStatus( netadr_t from ) { |
| 3995 |
int i, oldest, oldestTime; |
| 3996 |
|
| 3997 |
for (i = 0; i < MAX_SERVERSTATUSREQUESTS; i++) { |
| 3998 |
if ( NET_CompareAdr( from, cl_serverStatusList[i].address ) ) { |
| 3999 |
return &cl_serverStatusList[i]; |
| 4000 |
} |
| 4001 |
} |
| 4002 |
for (i = 0; i < MAX_SERVERSTATUSREQUESTS; i++) { |
| 4003 |
if ( cl_serverStatusList[i].retrieved ) { |
| 4004 |
return &cl_serverStatusList[i]; |
| 4005 |
} |
| 4006 |
} |
| 4007 |
oldest = -1; |
| 4008 |
oldestTime = 0; |
| 4009 |
for (i = 0; i < MAX_SERVERSTATUSREQUESTS; i++) { |
| 4010 |
if (oldest == -1 || cl_serverStatusList[i].startTime < oldestTime) { |
| 4011 |
oldest = i; |
| 4012 |
oldestTime = cl_serverStatusList[i].startTime; |
| 4013 |
} |
| 4014 |
} |
| 4015 |
return &cl_serverStatusList[oldest]; |
| 4016 |
} |
| 4017 |
|
| 4018 |
|
| 4019 |
|
| 4020 |
|
| 4021 |
|
| 4022 |
|
| 4023 |
int CL_ServerStatus( char *serverAddress, char *serverStatusString, int maxLen ) { |
| 4024 |
int i; |
| 4025 |
netadr_t to; |
| 4026 |
serverStatus_t *serverStatus; |
| 4027 |
|
| 4028 |
|
| 4029 |
if ( !serverAddress ) { |
| 4030 |
for (i = 0; i < MAX_SERVERSTATUSREQUESTS; i++) { |
| 4031 |
cl_serverStatusList[i].address.port = 0; |
| 4032 |
cl_serverStatusList[i].retrieved = qtrue; |
| 4033 |
} |
| 4034 |
return qfalse; |
| 4035 |
} |
| 4036 |
|
| 4037 |
if ( !NET_StringToAdr( serverAddress, &to, NA_UNSPEC) ) { |
| 4038 |
return qfalse; |
| 4039 |
} |
| 4040 |
serverStatus = CL_GetServerStatus( to ); |
| 4041 |
|
| 4042 |
if ( !serverStatusString ) { |
| 4043 |
serverStatus->retrieved = qtrue; |
| 4044 |
return qfalse; |
| 4045 |
} |
| 4046 |
|
| 4047 |
|
| 4048 |
if ( NET_CompareAdr( to, serverStatus->address) ) { |
| 4049 |
|
| 4050 |
if (!serverStatus->pending) { |
| 4051 |
Q_strncpyz(serverStatusString, serverStatus->string, maxLen); |
| 4052 |
serverStatus->retrieved = qtrue; |
| 4053 |
serverStatus->startTime = 0; |
| 4054 |
return qtrue; |
| 4055 |
} |
| 4056 |
|
| 4057 |
else if ( serverStatus->startTime < Com_Milliseconds() - cl_serverStatusResendTime->integer ) { |
| 4058 |
serverStatus->print = qfalse; |
| 4059 |
serverStatus->pending = qtrue; |
| 4060 |
serverStatus->retrieved = qfalse; |
| 4061 |
serverStatus->time = 0; |
| 4062 |
serverStatus->startTime = Com_Milliseconds(); |
| 4063 |
NET_OutOfBandPrint( NS_CLIENT, to, "getstatus" ); |
| 4064 |
return qfalse; |
| 4065 |
} |
| 4066 |
} |
| 4067 |
|
| 4068 |
else if ( serverStatus->retrieved ) { |
| 4069 |
serverStatus->address = to; |
| 4070 |
serverStatus->print = qfalse; |
| 4071 |
serverStatus->pending = qtrue; |
| 4072 |
serverStatus->retrieved = qfalse; |
| 4073 |
serverStatus->startTime = Com_Milliseconds(); |
| 4074 |
serverStatus->time = 0; |
| 4075 |
NET_OutOfBandPrint( NS_CLIENT, to, "getstatus" ); |
| 4076 |
return qfalse; |
| 4077 |
} |
| 4078 |
return qfalse; |
| 4079 |
} |
| 4080 |
|
| 4081 |
|
| 4082 |
|
| 4083 |
|
| 4084 |
|
| 4085 |
|
| 4086 |
void CL_ServerStatusResponse( netadr_t from, msg_t *msg ) { |
| 4087 |
char *s; |
| 4088 |
char info[MAX_INFO_STRING]; |
| 4089 |
int i, l, score, ping; |
| 4090 |
int len; |
| 4091 |
serverStatus_t *serverStatus; |
| 4092 |
|
| 4093 |
serverStatus = NULL; |
| 4094 |
for (i = 0; i < MAX_SERVERSTATUSREQUESTS; i++) { |
| 4095 |
if ( NET_CompareAdr( from, cl_serverStatusList[i].address ) ) { |
| 4096 |
serverStatus = &cl_serverStatusList[i]; |
| 4097 |
break; |
| 4098 |
} |
| 4099 |
} |
| 4100 |
|
| 4101 |
if (!serverStatus) { |
| 4102 |
return; |
| 4103 |
} |
| 4104 |
|
| 4105 |
s = MSG_ReadStringLine( msg ); |
| 4106 |
|
| 4107 |
len = 0; |
| 4108 |
Com_sprintf(&serverStatus->string[len], sizeof(serverStatus->string)-len, "%s", s); |
| 4109 |
|
| 4110 |
if (serverStatus->print) { |
| 4111 |
Com_Printf("Server settings:\n"); |
| 4112 |
|
| 4113 |
while (*s) { |
| 4114 |
for (i = 0; i < 2 && *s; i++) { |
| 4115 |
if (*s == '\\') |
| 4116 |
s++; |
| 4117 |
l = 0; |
| 4118 |
while (*s) { |
| 4119 |
info[l++] = *s; |
| 4120 |
if (l >= MAX_INFO_STRING-1) |
| 4121 |
break; |
| 4122 |
s++; |
| 4123 |
if (*s == '\\') { |
| 4124 |
break; |
| 4125 |
} |
| 4126 |
} |
| 4127 |
info[l] = '\0'; |
| 4128 |
if (i) { |
| 4129 |
Com_Printf("%s\n", info); |
| 4130 |
} |
| 4131 |
else { |
| 4132 |
Com_Printf("%-24s", info); |
| 4133 |
} |
| 4134 |
} |
| 4135 |
} |
| 4136 |
} |
| 4137 |
|
| 4138 |
len = strlen(serverStatus->string); |
| 4139 |
Com_sprintf(&serverStatus->string[len], sizeof(serverStatus->string)-len, "\\"); |
| 4140 |
|
| 4141 |
if (serverStatus->print) { |
| 4142 |
Com_Printf("\nPlayers:\n"); |
| 4143 |
Com_Printf("num: score: ping: name:\n"); |
| 4144 |
} |
| 4145 |
for (i = 0, s = MSG_ReadStringLine( msg ); *s; s = MSG_ReadStringLine( msg ), i++) { |
| 4146 |
|
| 4147 |
len = strlen(serverStatus->string); |
| 4148 |
Com_sprintf(&serverStatus->string[len], sizeof(serverStatus->string)-len, "\\%s", s); |
| 4149 |
|
| 4150 |
if (serverStatus->print) { |
| 4151 |
score = ping = 0; |
| 4152 |
sscanf(s, "%d %d", &score, &ping); |
| 4153 |
s = strchr(s, ' '); |
| 4154 |
if (s) |
| 4155 |
s = strchr(s+1, ' '); |
| 4156 |
if (s) |
| 4157 |
s++; |
| 4158 |
else |
| 4159 |
s = "unknown"; |
| 4160 |
Com_Printf("%-2d %-3d %-3d %s\n", i, score, ping, s ); |
| 4161 |
} |
| 4162 |
} |
| 4163 |
len = strlen(serverStatus->string); |
| 4164 |
Com_sprintf(&serverStatus->string[len], sizeof(serverStatus->string)-len, "\\"); |
| 4165 |
|
| 4166 |
serverStatus->time = Com_Milliseconds(); |
| 4167 |
serverStatus->address = from; |
| 4168 |
serverStatus->pending = qfalse; |
| 4169 |
if (serverStatus->print) { |
| 4170 |
serverStatus->retrieved = qtrue; |
| 4171 |
} |
| 4172 |
} |
| 4173 |
|
| 4174 |
|
| 4175 |
|
| 4176 |
|
| 4177 |
|
| 4178 |
|
| 4179 |
void CL_LocalServers_f( void ) { |
| 4180 |
char *message; |
| 4181 |
int i, j; |
| 4182 |
netadr_t to; |
| 4183 |
|
| 4184 |
Com_Printf( "Scanning for servers on the local network...\n"); |
| 4185 |
|
| 4186 |
|
| 4187 |
cls.numlocalservers = 0; |
| 4188 |
cls.pingUpdateSource = AS_LOCAL; |
| 4189 |
|
| 4190 |
for (i = 0; i < MAX_OTHER_SERVERS; i++) { |
| 4191 |
qboolean b = cls.localServers[i].visible; |
| 4192 |
Com_Memset(&cls.localServers[i], 0, sizeof(cls.localServers[i])); |
| 4193 |
cls.localServers[i].visible = b; |
| 4194 |
} |
| 4195 |
Com_Memset( &to, 0, sizeof( to ) ); |
| 4196 |
|
| 4197 |
|
| 4198 |
|
| 4199 |
|
| 4200 |
message = "\377\377\377\377getinfo xxx"; |
| 4201 |
|
| 4202 |
|
| 4203 |
for ( i = 0 ; i < 2 ; i++ ) { |
| 4204 |
|
| 4205 |
|
| 4206 |
|
| 4207 |
for ( j = 0 ; j < NUM_SERVER_PORTS ; j++ ) { |
| 4208 |
to.port = BigShort( (short)(PORT_SERVER + j) ); |
| 4209 |
|
| 4210 |
to.type = NA_BROADCAST; |
| 4211 |
NET_SendPacket( NS_CLIENT, strlen( message ), message, to ); |
| 4212 |
to.type = NA_MULTICAST6; |
| 4213 |
NET_SendPacket( NS_CLIENT, strlen( message ), message, to ); |
| 4214 |
} |
| 4215 |
} |
| 4216 |
} |
| 4217 |
|
| 4218 |
|
| 4219 |
|
| 4220 |
|
| 4221 |
|
| 4222 |
|
| 4223 |
|
| 4224 |
|
| 4225 |
|
| 4226 |
|
| 4227 |
void CL_GlobalServers_f( void ) { |
| 4228 |
netadr_t to; |
| 4229 |
int count, i, masterNum; |
| 4230 |
char command[1024], *masteraddress; |
| 4231 |
|
| 4232 |
if ((count = Cmd_Argc()) < 3 || (masterNum = atoi(Cmd_Argv(1))) < 0 || masterNum > MAX_MASTER_SERVERS) |
| 4233 |
{ |
| 4234 |
Com_Printf("usage: globalservers <master# 0-%d> <protocol> [keywords]\n", MAX_MASTER_SERVERS); |
| 4235 |
return; |
| 4236 |
} |
| 4237 |
|
| 4238 |
|
| 4239 |
if ( masterNum == 0 ) { |
| 4240 |
int numAddress = 0; |
| 4241 |
|
| 4242 |
for ( i = 1; i <= MAX_MASTER_SERVERS; i++ ) { |
| 4243 |
sprintf(command, "sv_master%d", i); |
| 4244 |
masteraddress = Cvar_VariableString(command); |
| 4245 |
|
| 4246 |
if(!*masteraddress) |
| 4247 |
continue; |
| 4248 |
|
| 4249 |
numAddress++; |
| 4250 |
|
| 4251 |
Com_sprintf(command, sizeof(command), "globalservers %d %s %s\n", i, Cmd_Argv(2), Cmd_ArgsFrom(3)); |
| 4252 |
Cbuf_AddText(command); |
| 4253 |
} |
| 4254 |
|
| 4255 |
if ( !numAddress ) { |
| 4256 |
Com_Printf( "CL_GlobalServers_f: Error: No master server addresses.\n"); |
| 4257 |
} |
| 4258 |
return; |
| 4259 |
} |
| 4260 |
|
| 4261 |
sprintf(command, "sv_master%d", masterNum); |
| 4262 |
masteraddress = Cvar_VariableString(command); |
| 4263 |
|
| 4264 |
if(!*masteraddress) |
| 4265 |
{ |
| 4266 |
Com_Printf( "CL_GlobalServers_f: Error: No master server address given.\n"); |
| 4267 |
return; |
| 4268 |
} |
| 4269 |
|
| 4270 |
|
| 4271 |
|
| 4272 |
|
| 4273 |
i = NET_StringToAdr(masteraddress, &to, NA_UNSPEC); |
| 4274 |
|
| 4275 |
if(!i) |
| 4276 |
{ |
| 4277 |
Com_Printf( "CL_GlobalServers_f: Error: could not resolve address of master %s\n", masteraddress); |
| 4278 |
return; |
| 4279 |
} |
| 4280 |
else if(i == 2) |
| 4281 |
to.port = BigShort(PORT_MASTER); |
| 4282 |
|
| 4283 |
Com_Printf("Requesting servers from %s (%s)...\n", masteraddress, NET_AdrToStringwPort(to)); |
| 4284 |
|
| 4285 |
cls.numglobalservers = -1; |
| 4286 |
cls.pingUpdateSource = AS_GLOBAL; |
| 4287 |
|
| 4288 |
|
| 4289 |
if (to.type == NA_IP6 || to.type == NA_MULTICAST6) |
| 4290 |
{ |
| 4291 |
int v4enabled = Cvar_VariableIntegerValue("net_enabled") & NET_ENABLEV4; |
| 4292 |
|
| 4293 |
if(v4enabled) |
| 4294 |
{ |
| 4295 |
Com_sprintf(command, sizeof(command), "getserversExt %s %s", |
| 4296 |
com_gamename->string, Cmd_Argv(2)); |
| 4297 |
} |
| 4298 |
else |
| 4299 |
{ |
| 4300 |
Com_sprintf(command, sizeof(command), "getserversExt %s %s ipv6", |
| 4301 |
com_gamename->string, Cmd_Argv(2)); |
| 4302 |
} |
| 4303 |
} |
| 4304 |
else if ( !Q_stricmp( com_gamename->string, LEGACY_MASTER_GAMENAME ) ) |
| 4305 |
Com_sprintf(command, sizeof(command), "getservers %s", |
| 4306 |
Cmd_Argv(2)); |
| 4307 |
else |
| 4308 |
Com_sprintf(command, sizeof(command), "getservers %s %s", |
| 4309 |
com_gamename->string, Cmd_Argv(2)); |
| 4310 |
|
| 4311 |
for (i=3; i < count; i++) |
| 4312 |
{ |
| 4313 |
Q_strcat(command, sizeof(command), " "); |
| 4314 |
Q_strcat(command, sizeof(command), Cmd_Argv(i)); |
| 4315 |
} |
| 4316 |
|
| 4317 |
NET_OutOfBandPrint( NS_SERVER, to, "%s", command ); |
| 4318 |
} |
| 4319 |
|
| 4320 |
|
| 4321 |
|
| 4322 |
|
| 4323 |
|
| 4324 |
|
| 4325 |
|
| 4326 |
void CL_GetPing( int n, char *buf, int buflen, int *pingtime ) |
| 4327 |
{ |
| 4328 |
const char *str; |
| 4329 |
int time; |
| 4330 |
int maxPing; |
| 4331 |
|
| 4332 |
if (n < 0 || n >= MAX_PINGREQUESTS || !cl_pinglist[n].adr.port) |
| 4333 |
{ |
| 4334 |
|
| 4335 |
buf[0] = '\0'; |
| 4336 |
*pingtime = 0; |
| 4337 |
return; |
| 4338 |
} |
| 4339 |
|
| 4340 |
str = NET_AdrToStringwPort( cl_pinglist[n].adr ); |
| 4341 |
Q_strncpyz( buf, str, buflen ); |
| 4342 |
|
| 4343 |
time = cl_pinglist[n].time; |
| 4344 |
if (!time) |
| 4345 |
{ |
| 4346 |
|
| 4347 |
time = Sys_Milliseconds() - cl_pinglist[n].start; |
| 4348 |
maxPing = Cvar_VariableIntegerValue( "cl_maxPing" ); |
| 4349 |
if( maxPing < 100 ) { |
| 4350 |
maxPing = 100; |
| 4351 |
} |
| 4352 |
if (time < maxPing) |
| 4353 |
{ |
| 4354 |
|
| 4355 |
time = 0; |
| 4356 |
} |
| 4357 |
} |
| 4358 |
|
| 4359 |
CL_SetServerInfoByAddress(cl_pinglist[n].adr, cl_pinglist[n].info, cl_pinglist[n].time); |
| 4360 |
|
| 4361 |
*pingtime = time; |
| 4362 |
} |
| 4363 |
|
| 4364 |
|
| 4365 |
|
| 4366 |
|
| 4367 |
|
| 4368 |
|
| 4369 |
void CL_GetPingInfo( int n, char *buf, int buflen ) |
| 4370 |
{ |
| 4371 |
if (n < 0 || n >= MAX_PINGREQUESTS || !cl_pinglist[n].adr.port) |
| 4372 |
{ |
| 4373 |
|
| 4374 |
if (buflen) |
| 4375 |
buf[0] = '\0'; |
| 4376 |
return; |
| 4377 |
} |
| 4378 |
|
| 4379 |
Q_strncpyz( buf, cl_pinglist[n].info, buflen ); |
| 4380 |
} |
| 4381 |
|
| 4382 |
|
| 4383 |
|
| 4384 |
|
| 4385 |
|
| 4386 |
|
| 4387 |
void CL_ClearPing( int n ) |
| 4388 |
{ |
| 4389 |
if (n < 0 || n >= MAX_PINGREQUESTS) |
| 4390 |
return; |
| 4391 |
|
| 4392 |
cl_pinglist[n].adr.port = 0; |
| 4393 |
} |
| 4394 |
|
| 4395 |
|
| 4396 |
|
| 4397 |
|
| 4398 |
|
| 4399 |
|
| 4400 |
int CL_GetPingQueueCount( void ) |
| 4401 |
{ |
| 4402 |
int i; |
| 4403 |
int count; |
| 4404 |
ping_t* pingptr; |
| 4405 |
|
| 4406 |
count = 0; |
| 4407 |
pingptr = cl_pinglist; |
| 4408 |
|
| 4409 |
for (i=0; i<MAX_PINGREQUESTS; i++, pingptr++ ) { |
| 4410 |
if (pingptr->adr.port) { |
| 4411 |
count++; |
| 4412 |
} |
| 4413 |
} |
| 4414 |
|
| 4415 |
return (count); |
| 4416 |
} |
| 4417 |
|
| 4418 |
|
| 4419 |
|
| 4420 |
|
| 4421 |
|
| 4422 |
|
| 4423 |
ping_t* CL_GetFreePing( void ) |
| 4424 |
{ |
| 4425 |
ping_t* pingptr; |
| 4426 |
ping_t* best; |
| 4427 |
int oldest; |
| 4428 |
int i; |
| 4429 |
int time; |
| 4430 |
|
| 4431 |
pingptr = cl_pinglist; |
| 4432 |
for (i=0; i<MAX_PINGREQUESTS; i++, pingptr++ ) |
| 4433 |
{ |
| 4434 |
|
| 4435 |
if (pingptr->adr.port) |
| 4436 |
{ |
| 4437 |
if (!pingptr->time) |
| 4438 |
{ |
| 4439 |
if (Sys_Milliseconds() - pingptr->start < 500) |
| 4440 |
{ |
| 4441 |
|
| 4442 |
continue; |
| 4443 |
} |
| 4444 |
} |
| 4445 |
else if (pingptr->time < 500) |
| 4446 |
{ |
| 4447 |
|
| 4448 |
continue; |
| 4449 |
} |
| 4450 |
} |
| 4451 |
|
| 4452 |
|
| 4453 |
pingptr->adr.port = 0; |
| 4454 |
return (pingptr); |
| 4455 |
} |
| 4456 |
|
| 4457 |
|
| 4458 |
pingptr = cl_pinglist; |
| 4459 |
best = cl_pinglist; |
| 4460 |
oldest = INT_MIN; |
| 4461 |
for (i=0; i<MAX_PINGREQUESTS; i++, pingptr++ ) |
| 4462 |
{ |
| 4463 |
|
| 4464 |
time = Sys_Milliseconds() - pingptr->start; |
| 4465 |
if (time > oldest) |
| 4466 |
{ |
| 4467 |
oldest = time; |
| 4468 |
best = pingptr; |
| 4469 |
} |
| 4470 |
} |
| 4471 |
|
| 4472 |
return (best); |
| 4473 |
} |
| 4474 |
|
| 4475 |
|
| 4476 |
|
| 4477 |
|
| 4478 |
|
| 4479 |
|
| 4480 |
void CL_Ping_f( void ) { |
| 4481 |
netadr_t to; |
| 4482 |
ping_t* pingptr; |
| 4483 |
char* server; |
| 4484 |
int argc; |
| 4485 |
netadrtype_t family = NA_UNSPEC; |
| 4486 |
|
| 4487 |
argc = Cmd_Argc(); |
| 4488 |
|
| 4489 |
if ( argc != 2 && argc != 3 ) { |
| 4490 |
Com_Printf( "usage: ping [-4|-6] server\n"); |
| 4491 |
return; |
| 4492 |
} |
| 4493 |
|
| 4494 |
if(argc == 2) |
| 4495 |
server = Cmd_Argv(1); |
| 4496 |
else |
| 4497 |
{ |
| 4498 |
if(!strcmp(Cmd_Argv(1), "-4")) |
| 4499 |
family = NA_IP; |
| 4500 |
else if(!strcmp(Cmd_Argv(1), "-6")) |
| 4501 |
family = NA_IP6; |
| 4502 |
else |
| 4503 |
Com_Printf( "warning: only -4 or -6 as address type understood.\n"); |
| 4504 |
|
| 4505 |
server = Cmd_Argv(2); |
| 4506 |
} |
| 4507 |
|
| 4508 |
Com_Memset( &to, 0, sizeof(netadr_t) ); |
| 4509 |
|
| 4510 |
if ( !NET_StringToAdr( server, &to, family ) ) { |
| 4511 |
return; |
| 4512 |
} |
| 4513 |
|
| 4514 |
pingptr = CL_GetFreePing(); |
| 4515 |
|
| 4516 |
memcpy( &pingptr->adr, &to, sizeof (netadr_t) ); |
| 4517 |
pingptr->start = Sys_Milliseconds(); |
| 4518 |
pingptr->time = 0; |
| 4519 |
|
| 4520 |
CL_SetServerInfoByAddress(pingptr->adr, NULL, 0); |
| 4521 |
|
| 4522 |
NET_OutOfBandPrint( NS_CLIENT, to, "getinfo xxx" ); |
| 4523 |
} |
| 4524 |
|
| 4525 |
|
| 4526 |
|
| 4527 |
|
| 4528 |
|
| 4529 |
|
| 4530 |
qboolean CL_UpdateVisiblePings_f(int source) { |
| 4531 |
int slots, i; |
| 4532 |
char buff[MAX_STRING_CHARS]; |
| 4533 |
int pingTime; |
| 4534 |
int max; |
| 4535 |
qboolean status = qfalse; |
| 4536 |
|
| 4537 |
if (source < 0 || source > AS_FAVORITES) { |
| 4538 |
return qfalse; |
| 4539 |
} |
| 4540 |
|
| 4541 |
cls.pingUpdateSource = source; |
| 4542 |
|
| 4543 |
slots = CL_GetPingQueueCount(); |
| 4544 |
if (slots < MAX_PINGREQUESTS) { |
| 4545 |
serverInfo_t *server = NULL; |
| 4546 |
|
| 4547 |
switch (source) { |
| 4548 |
case AS_LOCAL : |
| 4549 |
server = &cls.localServers[0]; |
| 4550 |
max = cls.numlocalservers; |
| 4551 |
break; |
| 4552 |
case AS_GLOBAL : |
| 4553 |
server = &cls.globalServers[0]; |
| 4554 |
max = cls.numglobalservers; |
| 4555 |
break; |
| 4556 |
case AS_FAVORITES : |
| 4557 |
server = &cls.favoriteServers[0]; |
| 4558 |
max = cls.numfavoriteservers; |
| 4559 |
break; |
| 4560 |
default: |
| 4561 |
return qfalse; |
| 4562 |
} |
| 4563 |
for (i = 0; i < max; i++) { |
| 4564 |
if (server[i].visible) { |
| 4565 |
if (server[i].ping == -1) { |
| 4566 |
int j; |
| 4567 |
|
| 4568 |
if (slots >= MAX_PINGREQUESTS) { |
| 4569 |
break; |
| 4570 |
} |
| 4571 |
for (j = 0; j < MAX_PINGREQUESTS; j++) { |
| 4572 |
if (!cl_pinglist[j].adr.port) { |
| 4573 |
continue; |
| 4574 |
} |
| 4575 |
if (NET_CompareAdr( cl_pinglist[j].adr, server[i].adr)) { |
| 4576 |
|
| 4577 |
break; |
| 4578 |
} |
| 4579 |
} |
| 4580 |
if (j >= MAX_PINGREQUESTS) { |
| 4581 |
status = qtrue; |
| 4582 |
for (j = 0; j < MAX_PINGREQUESTS; j++) { |
| 4583 |
if (!cl_pinglist[j].adr.port) { |
| 4584 |
break; |
| 4585 |
} |
| 4586 |
} |
| 4587 |
memcpy(&cl_pinglist[j].adr, &server[i].adr, sizeof(netadr_t)); |
| 4588 |
cl_pinglist[j].start = Sys_Milliseconds(); |
| 4589 |
cl_pinglist[j].time = 0; |
| 4590 |
NET_OutOfBandPrint( NS_CLIENT, cl_pinglist[j].adr, "getinfo xxx" ); |
| 4591 |
slots++; |
| 4592 |
} |
| 4593 |
} |
| 4594 |
|
| 4595 |
|
| 4596 |
else if (server[i].ping == 0) { |
| 4597 |
|
| 4598 |
if (source == AS_GLOBAL) { |
| 4599 |
|
| 4600 |
if ( cls.numGlobalServerAddresses > 0 ) { |
| 4601 |
|
| 4602 |
cls.numGlobalServerAddresses--; |
| 4603 |
CL_InitServerInfo(&server[i], &cls.globalServerAddresses[cls.numGlobalServerAddresses]); |
| 4604 |
|
| 4605 |
} |
| 4606 |
} |
| 4607 |
} |
| 4608 |
} |
| 4609 |
} |
| 4610 |
} |
| 4611 |
|
| 4612 |
if (slots) { |
| 4613 |
status = qtrue; |
| 4614 |
} |
| 4615 |
for (i = 0; i < MAX_PINGREQUESTS; i++) { |
| 4616 |
if (!cl_pinglist[i].adr.port) { |
| 4617 |
continue; |
| 4618 |
} |
| 4619 |
CL_GetPing( i, buff, MAX_STRING_CHARS, &pingTime ); |
| 4620 |
if (pingTime != 0) { |
| 4621 |
CL_ClearPing(i); |
| 4622 |
status = qtrue; |
| 4623 |
} |
| 4624 |
} |
| 4625 |
|
| 4626 |
return status; |
| 4627 |
} |
| 4628 |
|
| 4629 |
|
| 4630 |
|
| 4631 |
|
| 4632 |
|
| 4633 |
|
| 4634 |
void CL_ServerStatus_f(void) { |
| 4635 |
netadr_t to, *toptr = NULL; |
| 4636 |
char *server; |
| 4637 |
serverStatus_t *serverStatus; |
| 4638 |
int argc; |
| 4639 |
netadrtype_t family = NA_UNSPEC; |
| 4640 |
|
| 4641 |
argc = Cmd_Argc(); |
| 4642 |
|
| 4643 |
if ( argc != 2 && argc != 3 ) |
| 4644 |
{ |
| 4645 |
if (clc.state != CA_ACTIVE || clc.demoplaying) |
| 4646 |
{ |
| 4647 |
Com_Printf ("Not connected to a server.\n"); |
| 4648 |
Com_Printf( "usage: serverstatus [-4|-6] server\n"); |
| 4649 |
return; |
| 4650 |
} |
| 4651 |
|
| 4652 |
toptr = &clc.serverAddress; |
| 4653 |
} |
| 4654 |
|
| 4655 |
if(!toptr) |
| 4656 |
{ |
| 4657 |
Com_Memset( &to, 0, sizeof(netadr_t) ); |
| 4658 |
|
| 4659 |
if(argc == 2) |
| 4660 |
server = Cmd_Argv(1); |
| 4661 |
else |
| 4662 |
{ |
| 4663 |
if(!strcmp(Cmd_Argv(1), "-4")) |
| 4664 |
family = NA_IP; |
| 4665 |
else if(!strcmp(Cmd_Argv(1), "-6")) |
| 4666 |
family = NA_IP6; |
| 4667 |
else |
| 4668 |
Com_Printf( "warning: only -4 or -6 as address type understood.\n"); |
| 4669 |
|
| 4670 |
server = Cmd_Argv(2); |
| 4671 |
} |
| 4672 |
|
| 4673 |
toptr = &to; |
| 4674 |
if ( !NET_StringToAdr( server, toptr, family ) ) |
| 4675 |
return; |
| 4676 |
} |
| 4677 |
|
| 4678 |
NET_OutOfBandPrint( NS_CLIENT, *toptr, "getstatus" ); |
| 4679 |
|
| 4680 |
serverStatus = CL_GetServerStatus( *toptr ); |
| 4681 |
serverStatus->address = *toptr; |
| 4682 |
serverStatus->print = qtrue; |
| 4683 |
serverStatus->pending = qtrue; |
| 4684 |
} |
| 4685 |
|
| 4686 |
|
| 4687 |
|
| 4688 |
|
| 4689 |
|
| 4690 |
|
| 4691 |
void CL_ShowIP_f(void) { |
| 4692 |
Sys_ShowIP(); |
| 4693 |
} |
| 4694 |
|
| 4695 |
|
| 4696 |
|
| 4697 |
|
| 4698 |
|
| 4699 |
|
| 4700 |
qboolean CL_CDKeyValidate( const char *key, const char *checksum ) { |
| 4701 |
#ifdef STANDALONE |
| 4702 |
return qtrue; |
| 4703 |
#else |
| 4704 |
char ch; |
| 4705 |
byte sum; |
| 4706 |
char chs[3]; |
| 4707 |
int i, len; |
| 4708 |
|
| 4709 |
len = strlen(key); |
| 4710 |
if( len != CDKEY_LEN ) { |
| 4711 |
return qfalse; |
| 4712 |
} |
| 4713 |
|
| 4714 |
if( checksum && strlen( checksum ) != CDCHKSUM_LEN ) { |
| 4715 |
return qfalse; |
| 4716 |
} |
| 4717 |
|
| 4718 |
sum = 0; |
| 4719 |
|
| 4720 |
for (i = 0; i < len; i++) { |
| 4721 |
ch = *key++; |
| 4722 |
switch(tolower(ch)) { |
| 4723 |
case '2': |
| 4724 |
case '3': |
| 4725 |
case '7': |
| 4726 |
case 'a': |
| 4727 |
case 'b': |
| 4728 |
case 'c': |
| 4729 |
case 'd': |
| 4730 |
case 'g': |
| 4731 |
case 'h': |
| 4732 |
case 'j': |
| 4733 |
case 'l': |
| 4734 |
case 'p': |
| 4735 |
case 'r': |
| 4736 |
case 's': |
| 4737 |
case 't': |
| 4738 |
case 'w': |
| 4739 |
sum += ch; |
| 4740 |
continue; |
| 4741 |
default: |
| 4742 |
return qfalse; |
| 4743 |
} |
| 4744 |
} |
| 4745 |
|
| 4746 |
sprintf(chs, "%02x", sum); |
| 4747 |
|
| 4748 |
if (checksum && !Q_stricmp(chs, checksum)) { |
| 4749 |
return qtrue; |
| 4750 |
} |
| 4751 |
|
| 4752 |
if (!checksum) { |
| 4753 |
return qtrue; |
| 4754 |
} |
| 4755 |
|
| 4756 |
return qfalse; |
| 4757 |
#endif |
| 4758 |
} |