| 1 |
/* |
| 2 |
=========================================================================== |
| 3 |
Copyright (C) 1999-2005 Id Software, Inc. |
| 4 |
|
| 5 |
This file is part of Quake III Arena source code. |
| 6 |
|
| 7 |
Quake III Arena source code is free software; you can redistribute it |
| 8 |
and/or modify it under the terms of the GNU General Public License as |
| 9 |
published by the Free Software Foundation; either version 2 of the License, |
| 10 |
or (at your option) any later version. |
| 11 |
|
| 12 |
Quake III Arena source code is distributed in the hope that it will be |
| 13 |
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with Quake III Arena source code; if not, write to the Free Software |
| 19 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
=========================================================================== |
| 21 |
*/ |
| 22 |
// |
| 23 |
#include "g_local.h" |
| 24 |
|
| 25 |
// g_client.c -- client functions that don't happen every frame |
| 26 |
|
| 27 |
static vec3_t playerMins = {-15, -15, -24}; |
| 28 |
static vec3_t playerMaxs = {15, 15, 32}; |
| 29 |
|
| 30 |
/*QUAKED info_player_deathmatch (1 0 1) (-16 -16 -24) (16 16 32) initial |
| 31 |
potential spawning position for deathmatch games. |
| 32 |
The first time a player enters the game, they will be at an 'initial' spot. |
| 33 |
Targets will be fired when someone spawns in on them. |
| 34 |
"nobots" will prevent bots from using this spot. |
| 35 |
"nohumans" will prevent non-bots from using this spot. |
| 36 |
*/ |
| 37 |
void SP_info_player_deathmatch( gentity_t *ent ) { |
| 38 |
int i; |
| 39 |
|
| 40 |
G_SpawnInt( "nobots", "0", &i); |
| 41 |
if ( i ) { |
| 42 |
ent->flags |= FL_NO_BOTS; |
| 43 |
} |
| 44 |
G_SpawnInt( "nohumans", "0", &i ); |
| 45 |
if ( i ) { |
| 46 |
ent->flags |= FL_NO_HUMANS; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
/*QUAKED info_player_start (1 0 0) (-16 -16 -24) (16 16 32) |
| 51 |
equivelant to info_player_deathmatch |
| 52 |
*/ |
| 53 |
void SP_info_player_start(gentity_t *ent) { |
| 54 |
ent->classname = "info_player_deathmatch"; |
| 55 |
SP_info_player_deathmatch( ent ); |
| 56 |
} |
| 57 |
|
| 58 |
//Three for Double_D |
| 59 |
void SP_info_player_dd(gentity_t *ent) { |
| 60 |
} |
| 61 |
void SP_info_player_dd_red(gentity_t *ent) { |
| 62 |
} |
| 63 |
void SP_info_player_dd_blue(gentity_t *ent) { |
| 64 |
} |
| 65 |
|
| 66 |
//One for Standard Domination, not really a player spawn point |
| 67 |
void SP_domination_point(gentity_t *ent) { |
| 68 |
} |
| 69 |
|
| 70 |
/*QUAKED info_player_intermission (1 0 1) (-16 -16 -24) (16 16 32) |
| 71 |
The intermission will be viewed from this point. Target an info_notnull for the view direction. |
| 72 |
*/ |
| 73 |
void SP_info_player_intermission( gentity_t *ent ) { |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
/* |
| 80 |
======================================================================= |
| 81 |
|
| 82 |
SelectSpawnPoint |
| 83 |
|
| 84 |
======================================================================= |
| 85 |
*/ |
| 86 |
|
| 87 |
/* |
| 88 |
================ |
| 89 |
SpotWouldTelefrag |
| 90 |
|
| 91 |
================ |
| 92 |
*/ |
| 93 |
qboolean SpotWouldTelefrag( gentity_t *spot ) { |
| 94 |
int i, num; |
| 95 |
int touch[MAX_GENTITIES]; |
| 96 |
gentity_t *hit; |
| 97 |
vec3_t mins, maxs; |
| 98 |
|
| 99 |
VectorAdd( spot->s.origin, playerMins, mins ); |
| 100 |
VectorAdd( spot->s.origin, playerMaxs, maxs ); |
| 101 |
num = trap_EntitiesInBox( mins, maxs, touch, MAX_GENTITIES ); |
| 102 |
|
| 103 |
for (i=0 ; i<num ; i++) { |
| 104 |
hit = &g_entities[touch[i]]; |
| 105 |
//if ( hit->client && hit->client->ps.stats[STAT_HEALTH] > 0 ) { |
| 106 |
if ( hit->client) { |
| 107 |
return qtrue; |
| 108 |
} |
| 109 |
|
| 110 |
} |
| 111 |
|
| 112 |
return qfalse; |
| 113 |
} |
| 114 |
|
| 115 |
/* |
| 116 |
================ |
| 117 |
SelectNearestDeathmatchSpawnPoint |
| 118 |
|
| 119 |
Find the spot that we DON'T want to use |
| 120 |
================ |
| 121 |
*/ |
| 122 |
#define MAX_SPAWN_POINTS 128 |
| 123 |
gentity_t *SelectNearestDeathmatchSpawnPoint( vec3_t from ) { |
| 124 |
gentity_t *spot; |
| 125 |
vec3_t delta; |
| 126 |
float dist, nearestDist; |
| 127 |
gentity_t *nearestSpot; |
| 128 |
|
| 129 |
nearestDist = 999999; |
| 130 |
nearestSpot = NULL; |
| 131 |
spot = NULL; |
| 132 |
|
| 133 |
while ((spot = G_Find (spot, FOFS(classname), "info_player_deathmatch")) != NULL) { |
| 134 |
|
| 135 |
VectorSubtract( spot->s.origin, from, delta ); |
| 136 |
dist = VectorLength( delta ); |
| 137 |
if ( dist < nearestDist ) { |
| 138 |
nearestDist = dist; |
| 139 |
nearestSpot = spot; |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
return nearestSpot; |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
/* |
| 148 |
================ |
| 149 |
SelectRandomDeathmatchSpawnPoint |
| 150 |
|
| 151 |
go to a random point that doesn't telefrag |
| 152 |
================ |
| 153 |
*/ |
| 154 |
#define MAX_SPAWN_POINTS 128 |
| 155 |
gentity_t *SelectRandomDeathmatchSpawnPoint( void ) { |
| 156 |
gentity_t *spot; |
| 157 |
int count; |
| 158 |
int selection; |
| 159 |
gentity_t *spots[MAX_SPAWN_POINTS]; |
| 160 |
|
| 161 |
count = 0; |
| 162 |
spot = NULL; |
| 163 |
|
| 164 |
while ((spot = G_Find (spot, FOFS(classname), "info_player_deathmatch")) != NULL) { |
| 165 |
if ( SpotWouldTelefrag( spot ) ) { |
| 166 |
continue; |
| 167 |
} |
| 168 |
spots[ count ] = spot; |
| 169 |
count++; |
| 170 |
} |
| 171 |
|
| 172 |
if ( !count ) { // no spots that won't telefrag |
| 173 |
return G_Find( NULL, FOFS(classname), "info_player_deathmatch"); |
| 174 |
} |
| 175 |
|
| 176 |
selection = rand() % count; |
| 177 |
return spots[ selection ]; |
| 178 |
} |
| 179 |
|
| 180 |
/* |
| 181 |
=========== |
| 182 |
SelectRandomFurthestSpawnPoint |
| 183 |
|
| 184 |
Chooses a player start, deathmatch start, etc |
| 185 |
============ |
| 186 |
*/ |
| 187 |
gentity_t *SelectRandomFurthestSpawnPoint ( vec3_t avoidPoint, vec3_t origin, vec3_t angles ) { |
| 188 |
gentity_t *spot; |
| 189 |
vec3_t delta; |
| 190 |
float dist; |
| 191 |
float list_dist[64]; |
| 192 |
gentity_t *list_spot[64]; |
| 193 |
int numSpots, rnd, i, j; |
| 194 |
|
| 195 |
numSpots = 0; |
| 196 |
spot = NULL; |
| 197 |
|
| 198 |
while ((spot = G_Find (spot, FOFS(classname), "info_player_deathmatch")) != NULL) { |
| 199 |
if ( SpotWouldTelefrag( spot ) ) { |
| 200 |
continue; |
| 201 |
} |
| 202 |
VectorSubtract( spot->s.origin, avoidPoint, delta ); |
| 203 |
dist = VectorLength( delta ); |
| 204 |
for (i = 0; i < numSpots; i++) { |
| 205 |
if ( dist > list_dist[i] ) { |
| 206 |
if ( numSpots >= 64 ) |
| 207 |
numSpots = 64-1; |
| 208 |
for (j = numSpots; j > i; j--) { |
| 209 |
list_dist[j] = list_dist[j-1]; |
| 210 |
list_spot[j] = list_spot[j-1]; |
| 211 |
} |
| 212 |
list_dist[i] = dist; |
| 213 |
list_spot[i] = spot; |
| 214 |
numSpots++; |
| 215 |
if (numSpots > 64) |
| 216 |
numSpots = 64; |
| 217 |
break; |
| 218 |
} |
| 219 |
} |
| 220 |
if (i >= numSpots && numSpots < 64) { |
| 221 |
list_dist[numSpots] = dist; |
| 222 |
list_spot[numSpots] = spot; |
| 223 |
numSpots++; |
| 224 |
} |
| 225 |
} |
| 226 |
if (!numSpots) { |
| 227 |
spot = G_Find( NULL, FOFS(classname), "info_player_deathmatch"); |
| 228 |
if (!spot) |
| 229 |
G_Error( "Couldn't find a spawn point" ); |
| 230 |
VectorCopy (spot->s.origin, origin); |
| 231 |
origin[2] += 9; |
| 232 |
VectorCopy (spot->s.angles, angles); |
| 233 |
return spot; |
| 234 |
} |
| 235 |
|
| 236 |
// select a random spot from the spawn points furthest away |
| 237 |
rnd = random() * (numSpots / 2); |
| 238 |
|
| 239 |
VectorCopy (list_spot[rnd]->s.origin, origin); |
| 240 |
origin[2] += 9; |
| 241 |
VectorCopy (list_spot[rnd]->s.angles, angles); |
| 242 |
|
| 243 |
return list_spot[rnd]; |
| 244 |
} |
| 245 |
|
| 246 |
/* |
| 247 |
=========== |
| 248 |
SelectSpawnPoint |
| 249 |
|
| 250 |
Chooses a player start, deathmatch start, etc |
| 251 |
============ |
| 252 |
*/ |
| 253 |
gentity_t *SelectSpawnPoint ( vec3_t avoidPoint, vec3_t origin, vec3_t angles ) { |
| 254 |
//return SelectRandomFurthestSpawnPoint( avoidPoint, origin, angles ); |
| 255 |
|
| 256 |
|
| 257 |
gentity_t *spot; |
| 258 |
gentity_t *nearestSpot; |
| 259 |
|
| 260 |
nearestSpot = SelectNearestDeathmatchSpawnPoint( avoidPoint ); |
| 261 |
|
| 262 |
spot = SelectRandomDeathmatchSpawnPoint ( ); |
| 263 |
if ( spot == nearestSpot ) { |
| 264 |
// roll again if it would be real close to point of death |
| 265 |
spot = SelectRandomDeathmatchSpawnPoint ( ); |
| 266 |
if ( spot == nearestSpot ) { |
| 267 |
// last try |
| 268 |
spot = SelectRandomDeathmatchSpawnPoint ( ); |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
// find a single player start spot |
| 273 |
if (!spot) { |
| 274 |
G_Error( "Couldn't find a spawn point" ); |
| 275 |
} |
| 276 |
|
| 277 |
VectorCopy (spot->s.origin, origin); |
| 278 |
origin[2] += 9; |
| 279 |
VectorCopy (spot->s.angles, angles); |
| 280 |
|
| 281 |
return spot; |
| 282 |
} |
| 283 |
|
| 284 |
/* |
| 285 |
=========== |
| 286 |
SelectInitialSpawnPoint |
| 287 |
|
| 288 |
Try to find a spawn point marked 'initial', otherwise |
| 289 |
use normal spawn selection. |
| 290 |
============ |
| 291 |
*/ |
| 292 |
gentity_t *SelectInitialSpawnPoint( vec3_t origin, vec3_t angles ) { |
| 293 |
gentity_t *spot; |
| 294 |
|
| 295 |
spot = NULL; |
| 296 |
while ((spot = G_Find (spot, FOFS(classname), "info_player_deathmatch")) != NULL) { |
| 297 |
if ( spot->spawnflags & 1 ) { |
| 298 |
break; |
| 299 |
} |
| 300 |
} |
| 301 |
|
| 302 |
if ( !spot || SpotWouldTelefrag( spot ) ) { |
| 303 |
return SelectSpawnPoint( vec3_origin, origin, angles ); |
| 304 |
} |
| 305 |
|
| 306 |
VectorCopy (spot->s.origin, origin); |
| 307 |
origin[2] += 9; |
| 308 |
VectorCopy (spot->s.angles, angles); |
| 309 |
|
| 310 |
return spot; |
| 311 |
} |
| 312 |
|
| 313 |
/* |
| 314 |
=========== |
| 315 |
SelectSpectatorSpawnPoint |
| 316 |
|
| 317 |
============ |
| 318 |
*/ |
| 319 |
gentity_t *SelectSpectatorSpawnPoint( vec3_t origin, vec3_t angles ) { |
| 320 |
//gentity_t *spot; |
| 321 |
|
| 322 |
FindIntermissionPoint(); |
| 323 |
|
| 324 |
VectorCopy( level.intermission_origin, origin ); |
| 325 |
VectorCopy( level.intermission_angle, angles ); |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
//for some reason we need to return an specific point in elimination (this might not be neccecary anymore but to be sure...) |
| 330 |
//if(g_gametype.integer == GT_ELIMINATION) |
| 331 |
// return SelectSpawnPoint( vec3_origin, origin, angles ); |
| 332 |
|
| 333 |
//VectorCopy (origin,spot->s.origin); |
| 334 |
//spot->s.origin[2] += 9; |
| 335 |
//VectorCopy (angles, spot->s.angles); |
| 336 |
|
| 337 |
return NULL; //spot; |
| 338 |
} |
| 339 |
|
| 340 |
/* |
| 341 |
======================================================================= |
| 342 |
|
| 343 |
BODYQUE |
| 344 |
|
| 345 |
======================================================================= |
| 346 |
*/ |
| 347 |
|
| 348 |
/* |
| 349 |
=============== |
| 350 |
InitBodyQue |
| 351 |
=============== |
| 352 |
*/ |
| 353 |
void InitBodyQue (void) { |
| 354 |
int i; |
| 355 |
gentity_t *ent; |
| 356 |
|
| 357 |
level.bodyQueIndex = 0; |
| 358 |
for (i=0; i<BODY_QUEUE_SIZE ; i++) { |
| 359 |
ent = G_Spawn(); |
| 360 |
ent->classname = "bodyque"; |
| 361 |
ent->neverFree = qtrue; |
| 362 |
level.bodyQue[i] = ent; |
| 363 |
} |
| 364 |
} |
| 365 |
|
| 366 |
/* |
| 367 |
============= |
| 368 |
BodySink |
| 369 |
|
| 370 |
After sitting around for five seconds, fall into the ground and dissapear |
| 371 |
============= |
| 372 |
*/ |
| 373 |
void BodySink( gentity_t *ent ) { |
| 374 |
if ( level.time - ent->timestamp > 6500 ) { |
| 375 |
|
| 376 |
|
| 377 |
// the body ques are never actually freed, they are just unlinked |
| 378 |
trap_UnlinkEntity( ent ); |
| 379 |
ent->physicsObject = qfalse; |
| 380 |
return; |
| 381 |
} |
| 382 |
ent->nextthink = level.time + 100; |
| 383 |
ent->s.pos.trBase[2] -= 1; |
| 384 |
} |
| 385 |
|
| 386 |
/* |
| 387 |
============= |
| 388 |
CopyToBodyQue |
| 389 |
|
| 390 |
A player is respawning, so make an entity that looks |
| 391 |
just like the existing corpse to leave behind. |
| 392 |
============= |
| 393 |
*/ |
| 394 |
void CopyToBodyQue( gentity_t *ent ) { |
| 395 |
gentity_t *e; |
| 396 |
int i; |
| 397 |
gentity_t *body; |
| 398 |
int contents; |
| 399 |
|
| 400 |
trap_UnlinkEntity (ent); |
| 401 |
|
| 402 |
// if client is in a nodrop area, don't leave the body |
| 403 |
contents = trap_PointContents( ent->s.origin, -1 ); |
| 404 |
if ( (contents & CONTENTS_NODROP) && !(ent->s.eFlags & EF_KAMIKAZE) ) { //the check for kamikaze is a workaround for ctf4ish |
| 405 |
return; |
| 406 |
} |
| 407 |
|
| 408 |
// grab a body que and cycle to the next one |
| 409 |
body = level.bodyQue[ level.bodyQueIndex ]; |
| 410 |
level.bodyQueIndex = (level.bodyQueIndex + 1) % BODY_QUEUE_SIZE; |
| 411 |
|
| 412 |
//Check if the next body has the kamikaze, in that case skip it. |
| 413 |
for(i=0;(level.bodyQue[ level.bodyQueIndex ]->s.eFlags & EF_KAMIKAZE) && (i<10);i++) { |
| 414 |
level.bodyQueIndex = (level.bodyQueIndex + 1) % BODY_QUEUE_SIZE; |
| 415 |
} |
| 416 |
|
| 417 |
body->s = ent->s; |
| 418 |
body->s.eFlags = EF_DEAD; // clear EF_TALK, etc |
| 419 |
if ( ent->s.eFlags & EF_KAMIKAZE ) { |
| 420 |
ent->s.eFlags &= ~EF_KAMIKAZE; |
| 421 |
body->s.eFlags |= EF_KAMIKAZE; |
| 422 |
|
| 423 |
// check if there is a kamikaze timer around for this owner |
| 424 |
for (i = 0; i < MAX_GENTITIES; i++) { |
| 425 |
e = &g_entities[i]; |
| 426 |
if (!e->inuse) |
| 427 |
continue; |
| 428 |
if (e->activator != ent) |
| 429 |
continue; |
| 430 |
if (strcmp(e->classname, "kamikaze timer")) |
| 431 |
continue; |
| 432 |
e->activator = body; |
| 433 |
break; |
| 434 |
} |
| 435 |
} |
| 436 |
body->s.powerups = 0; // clear powerups |
| 437 |
body->s.loopSound = 0; // clear lava burning |
| 438 |
body->s.number = body - g_entities; |
| 439 |
body->timestamp = level.time; |
| 440 |
body->physicsObject = qtrue; |
| 441 |
body->physicsBounce = 0; // don't bounce |
| 442 |
if ( body->s.groundEntityNum == ENTITYNUM_NONE ) { |
| 443 |
body->s.pos.trType = TR_GRAVITY; |
| 444 |
body->s.pos.trTime = level.time; |
| 445 |
VectorCopy( ent->client->ps.velocity, body->s.pos.trDelta ); |
| 446 |
} else { |
| 447 |
body->s.pos.trType = TR_STATIONARY; |
| 448 |
} |
| 449 |
body->s.event = 0; |
| 450 |
|
| 451 |
// change the animation to the last-frame only, so the sequence |
| 452 |
// doesn't repeat anew for the body |
| 453 |
switch ( body->s.legsAnim & ~ANIM_TOGGLEBIT ) { |
| 454 |
case BOTH_DEATH1: |
| 455 |
case BOTH_DEAD1: |
| 456 |
body->s.torsoAnim = body->s.legsAnim = BOTH_DEAD1; |
| 457 |
break; |
| 458 |
case BOTH_DEATH2: |
| 459 |
case BOTH_DEAD2: |
| 460 |
body->s.torsoAnim = body->s.legsAnim = BOTH_DEAD2; |
| 461 |
break; |
| 462 |
case BOTH_DEATH3: |
| 463 |
case BOTH_DEAD3: |
| 464 |
default: |
| 465 |
body->s.torsoAnim = body->s.legsAnim = BOTH_DEAD3; |
| 466 |
break; |
| 467 |
} |
| 468 |
|
| 469 |
body->r.svFlags = ent->r.svFlags; |
| 470 |
VectorCopy (ent->r.mins, body->r.mins); |
| 471 |
VectorCopy (ent->r.maxs, body->r.maxs); |
| 472 |
VectorCopy (ent->r.absmin, body->r.absmin); |
| 473 |
VectorCopy (ent->r.absmax, body->r.absmax); |
| 474 |
|
| 475 |
body->clipmask = CONTENTS_SOLID | CONTENTS_PLAYERCLIP; |
| 476 |
body->r.contents = CONTENTS_CORPSE; |
| 477 |
body->r.ownerNum = ent->s.number; |
| 478 |
|
| 479 |
body->nextthink = level.time + 5000; |
| 480 |
body->think = BodySink; |
| 481 |
|
| 482 |
body->die = body_die; |
| 483 |
|
| 484 |
// don't take more damage if already gibbed |
| 485 |
if ( ent->health <= GIB_HEALTH ) { |
| 486 |
body->takedamage = qfalse; |
| 487 |
} else { |
| 488 |
body->takedamage = qtrue; |
| 489 |
} |
| 490 |
|
| 491 |
|
| 492 |
VectorCopy ( body->s.pos.trBase, body->r.currentOrigin ); |
| 493 |
trap_LinkEntity (body); |
| 494 |
} |
| 495 |
|
| 496 |
//====================================================================== |
| 497 |
|
| 498 |
|
| 499 |
/* |
| 500 |
================== |
| 501 |
SetClientViewAngle |
| 502 |
|
| 503 |
================== |
| 504 |
*/ |
| 505 |
void SetClientViewAngle( gentity_t *ent, vec3_t angle ) { |
| 506 |
int i; |
| 507 |
|
| 508 |
// set the delta angle |
| 509 |
for (i=0 ; i<3 ; i++) { |
| 510 |
int cmdAngle; |
| 511 |
|
| 512 |
cmdAngle = ANGLE2SHORT(angle[i]); |
| 513 |
ent->client->ps.delta_angles[i] = cmdAngle - ent->client->pers.cmd.angles[i]; |
| 514 |
} |
| 515 |
VectorCopy( angle, ent->s.angles ); |
| 516 |
VectorCopy (ent->s.angles, ent->client->ps.viewangles); |
| 517 |
} |
| 518 |
|
| 519 |
/* |
| 520 |
================ |
| 521 |
respawn |
| 522 |
================ |
| 523 |
*/ |
| 524 |
void ClientRespawn( gentity_t *ent ) { |
| 525 |
gentity_t *tent; |
| 526 |
|
| 527 |
if((g_gametype.integer!=GT_ELIMINATION && g_gametype.integer!=GT_CTF_ELIMINATION && g_gametype.integer !=GT_LMS) && !ent->client->isEliminated) |
| 528 |
{ |
| 529 |
ent->client->isEliminated = qtrue; //must not be true in warmup |
| 530 |
//Tried moving CopyToBodyQue |
| 531 |
} else { |
| 532 |
//Must always be false in other gametypes |
| 533 |
ent->client->isEliminated = qfalse; |
| 534 |
} |
| 535 |
CopyToBodyQue (ent); //Unlinks ent |
| 536 |
|
| 537 |
if(g_gametype.integer==GT_LMS) { |
| 538 |
if(ent->client->pers.livesLeft>0) |
| 539 |
{ |
| 540 |
//ent->client->pers.livesLeft--; Coutned down somewhere else |
| 541 |
ent->client->isEliminated = qfalse; |
| 542 |
} |
| 543 |
else //We have used all our lives |
| 544 |
{ |
| 545 |
if( ent->client->isEliminated!=qtrue) { |
| 546 |
ent->client->isEliminated = qtrue; |
| 547 |
if((g_lms_mode.integer == 2 || g_lms_mode.integer == 3) && level.roundNumber == level.roundNumberStarted) |
| 548 |
LMSpoint(); |
| 549 |
//Sago: This is really bad |
| 550 |
//TODO: Try not to make people spectators here |
| 551 |
ent->client->sess.spectatorState = PM_SPECTATOR; |
| 552 |
//We have to force spawn imidiantly to prevent lag. |
| 553 |
ClientSpawn(ent); |
| 554 |
} |
| 555 |
return; |
| 556 |
} |
| 557 |
} |
| 558 |
|
| 559 |
if((g_gametype.integer==GT_ELIMINATION || g_gametype.integer==GT_CTF_ELIMINATION || g_gametype.integer==GT_LMS) |
| 560 |
&& ent->client->ps.pm_type == PM_SPECTATOR && ent->client->ps.stats[STAT_HEALTH] > 0) |
| 561 |
return; |
| 562 |
ClientSpawn(ent); |
| 563 |
|
| 564 |
// add a teleportation effect |
| 565 |
if(g_gametype.integer!=GT_ELIMINATION && g_gametype.integer!=GT_CTF_ELIMINATION && g_gametype.integer!=GT_LMS) |
| 566 |
{ |
| 567 |
tent = G_TempEntity( ent->client->ps.origin, EV_PLAYER_TELEPORT_IN ); |
| 568 |
tent->s.clientNum = ent->s.clientNum; |
| 569 |
} |
| 570 |
} |
| 571 |
|
| 572 |
/* |
| 573 |
================ |
| 574 |
respawnRound |
| 575 |
================ |
| 576 |
*/ |
| 577 |
void respawnRound( gentity_t *ent ) { |
| 578 |
gentity_t *tent; |
| 579 |
|
| 580 |
//if(g_gametype.integer!=GT_ELIMINATION || !ent->client->isEliminated) |
| 581 |
//{ |
| 582 |
// ent->client->isEliminated = qtrue; |
| 583 |
//CopyToBodyQue (ent); |
| 584 |
//} |
| 585 |
|
| 586 |
|
| 587 |
//if(g_gametype.integer==GT_ELIMINATION && ent->client->ps.pm_type == PM_SPECTATOR && ent->client->ps.stats[STAT_HEALTH] > 0) |
| 588 |
// return; |
| 589 |
if(ent->client->hook) |
| 590 |
Weapon_HookFree(ent->client->hook); |
| 591 |
|
| 592 |
trap_UnlinkEntity (ent); |
| 593 |
|
| 594 |
ClientSpawn(ent); |
| 595 |
|
| 596 |
// add a teleportation effect |
| 597 |
if(g_gametype.integer!=GT_ELIMINATION && g_gametype.integer!=GT_CTF_ELIMINATION && g_gametype.integer!=GT_LMS) |
| 598 |
{ |
| 599 |
tent = G_TempEntity( ent->client->ps.origin, EV_PLAYER_TELEPORT_IN ); |
| 600 |
tent->s.clientNum = ent->s.clientNum; |
| 601 |
} |
| 602 |
} |
| 603 |
|
| 604 |
/* |
| 605 |
================ |
| 606 |
TeamCvarSet |
| 607 |
|
| 608 |
Sets the red and blue team client number cvars. |
| 609 |
================ |
| 610 |
*/ |
| 611 |
void TeamCvarSet( void ) |
| 612 |
{ |
| 613 |
int i; |
| 614 |
qboolean redChanged = qfalse; |
| 615 |
qboolean blueChanged = qfalse; |
| 616 |
qboolean first = qtrue; |
| 617 |
char* temp = NULL; |
| 618 |
|
| 619 |
for ( i = 0 ; i < level.maxclients ; i++ ) { |
| 620 |
if ( level.clients[i].pers.connected == CON_DISCONNECTED ) { |
| 621 |
continue; |
| 622 |
} |
| 623 |
if ( level.clients[i].sess.sessionTeam == TEAM_RED ) { |
| 624 |
if(first) { |
| 625 |
temp = va("%i",i); |
| 626 |
first = qfalse; |
| 627 |
} |
| 628 |
else |
| 629 |
temp = va("%s,%i",temp,i); |
| 630 |
} |
| 631 |
} |
| 632 |
|
| 633 |
if(Q_stricmp(g_redTeamClientNumbers.string,temp)) |
| 634 |
redChanged = qtrue; |
| 635 |
trap_Cvar_Set("g_redTeamClientNumbers",temp); //Set it right |
| 636 |
first= qtrue; |
| 637 |
|
| 638 |
for ( i = 0 ; i < level.maxclients ; i++ ) { |
| 639 |
if ( level.clients[i].pers.connected == CON_DISCONNECTED ) { |
| 640 |
continue; |
| 641 |
} |
| 642 |
if ( level.clients[i].sess.sessionTeam == TEAM_BLUE ) { |
| 643 |
if(first) { |
| 644 |
temp = va("%i",i); |
| 645 |
first = qfalse; |
| 646 |
} |
| 647 |
else |
| 648 |
temp = va("%s,%i",temp,i); |
| 649 |
} |
| 650 |
} |
| 651 |
if(Q_stricmp(g_blueTeamClientNumbers.string,temp)) |
| 652 |
blueChanged = qtrue; |
| 653 |
trap_Cvar_Set("g_blueTeamClientNumbers",temp); |
| 654 |
|
| 655 |
//Note: We need to force update of the cvar or SendYourTeamMessage will send the old cvar value! |
| 656 |
if(redChanged) { |
| 657 |
trap_Cvar_Update(&g_redTeamClientNumbers); //Force update of CVAR |
| 658 |
SendYourTeamMessageToTeam(TEAM_RED); |
| 659 |
} |
| 660 |
if(blueChanged) { |
| 661 |
trap_Cvar_Update(&g_blueTeamClientNumbers); |
| 662 |
SendYourTeamMessageToTeam(TEAM_BLUE); //Force update of CVAR |
| 663 |
} |
| 664 |
} |
| 665 |
|
| 666 |
/* |
| 667 |
================ |
| 668 |
TeamCount |
| 669 |
|
| 670 |
Returns number of players on a team |
| 671 |
================ |
| 672 |
*/ |
| 673 |
team_t TeamCount( int ignoreClientNum, int team ) { |
| 674 |
int i; |
| 675 |
int count = 0; |
| 676 |
|
| 677 |
for ( i = 0 ; i < level.maxclients ; i++ ) { |
| 678 |
if ( i == ignoreClientNum ) { |
| 679 |
continue; |
| 680 |
} |
| 681 |
if ( level.clients[i].pers.connected == CON_DISCONNECTED ) { |
| 682 |
continue; |
| 683 |
} |
| 684 |
|
| 685 |
if ( level.clients[i].pers.connected == CON_CONNECTING) { |
| 686 |
continue; |
| 687 |
} |
| 688 |
|
| 689 |
if ( level.clients[i].sess.sessionTeam == team ) { |
| 690 |
count++; |
| 691 |
} |
| 692 |
} |
| 693 |
|
| 694 |
return count; |
| 695 |
} |
| 696 |
|
| 697 |
/* |
| 698 |
================ |
| 699 |
TeamLivingCount |
| 700 |
|
| 701 |
Returns number of living players on a team |
| 702 |
================ |
| 703 |
*/ |
| 704 |
team_t TeamLivingCount( int ignoreClientNum, int team ) { |
| 705 |
int i; |
| 706 |
int count = 0; |
| 707 |
qboolean LMS = (g_gametype.integer==GT_LMS); |
| 708 |
|
| 709 |
for ( i = 0 ; i < level.maxclients ; i++ ) { |
| 710 |
if ( i == ignoreClientNum ) { |
| 711 |
continue; |
| 712 |
} |
| 713 |
if ( level.clients[i].pers.connected == CON_DISCONNECTED ) { |
| 714 |
continue; |
| 715 |
} |
| 716 |
|
| 717 |
if ( level.clients[i].pers.connected == CON_CONNECTING) { |
| 718 |
continue; |
| 719 |
} |
| 720 |
//crash if g_gametype.integer is used here, why? |
| 721 |
if ( level.clients[i].sess.sessionTeam == team && (level.clients[i].ps.stats[STAT_HEALTH]>0 || LMS) && !(level.clients[i].isEliminated)) { |
| 722 |
count++; |
| 723 |
} |
| 724 |
} |
| 725 |
|
| 726 |
return count; |
| 727 |
} |
| 728 |
|
| 729 |
/* |
| 730 |
================ |
| 731 |
TeamHealthCount |
| 732 |
|
| 733 |
Count total number of healthpoints on teh teams used for draws in Elimination |
| 734 |
================ |
| 735 |
*/ |
| 736 |
|
| 737 |
team_t TeamHealthCount(int ignoreClientNum, int team ) { |
| 738 |
int i; |
| 739 |
int count = 0; |
| 740 |
|
| 741 |
for ( i = 0 ; i < level.maxclients ; i++ ) { |
| 742 |
if ( i == ignoreClientNum ) { |
| 743 |
continue; |
| 744 |
} |
| 745 |
if ( level.clients[i].pers.connected == CON_DISCONNECTED ) { |
| 746 |
continue; |
| 747 |
} |
| 748 |
|
| 749 |
if ( level.clients[i].pers.connected == CON_CONNECTING) { |
| 750 |
continue; |
| 751 |
} |
| 752 |
|
| 753 |
//only count clients with positive health |
| 754 |
if ( level.clients[i].sess.sessionTeam == team && (level.clients[i].ps.stats[STAT_HEALTH]>0)&& !(level.clients[i].isEliminated)) { |
| 755 |
count+=level.clients[i].ps.stats[STAT_HEALTH]; |
| 756 |
} |
| 757 |
} |
| 758 |
|
| 759 |
return count; |
| 760 |
} |
| 761 |
|
| 762 |
|
| 763 |
/* |
| 764 |
================ |
| 765 |
RespawnAll |
| 766 |
|
| 767 |
Forces all clients to respawn. |
| 768 |
================ |
| 769 |
*/ |
| 770 |
|
| 771 |
void RespawnAll(void) |
| 772 |
{ |
| 773 |
int i; |
| 774 |
gentity_t *client; |
| 775 |
for(i=0;i<level.maxclients;i++) |
| 776 |
{ |
| 777 |
if ( level.clients[i].pers.connected == CON_DISCONNECTED ) { |
| 778 |
continue; |
| 779 |
} |
| 780 |
|
| 781 |
if ( level.clients[i].pers.connected == CON_CONNECTING) { |
| 782 |
continue; |
| 783 |
} |
| 784 |
|
| 785 |
if ( level.clients[i].sess.sessionTeam == TEAM_SPECTATOR ) { |
| 786 |
continue; |
| 787 |
} |
| 788 |
client = g_entities + i; |
| 789 |
client->client->ps.pm_type = PM_NORMAL; |
| 790 |
client->client->pers.livesLeft = g_lms_lives.integer; |
| 791 |
respawnRound(client); |
| 792 |
} |
| 793 |
return; |
| 794 |
} |
| 795 |
|
| 796 |
/* |
| 797 |
================ |
| 798 |
RespawnDead |
| 799 |
|
| 800 |
Forces all *DEAD* clients to respawn. |
| 801 |
================ |
| 802 |
*/ |
| 803 |
|
| 804 |
void RespawnDead(void) |
| 805 |
{ |
| 806 |
int i; |
| 807 |
gentity_t *client; |
| 808 |
for(i=0;i<level.maxclients;i++) |
| 809 |
{ |
| 810 |
|
| 811 |
if ( level.clients[i].pers.connected == CON_DISCONNECTED ) { |
| 812 |
continue; |
| 813 |
} |
| 814 |
if ( level.clients[i].pers.connected == CON_CONNECTING) { |
| 815 |
continue; |
| 816 |
} |
| 817 |
client = g_entities + i; |
| 818 |
client->client->pers.livesLeft = g_lms_lives.integer-1; |
| 819 |
if ( level.clients[i].isEliminated == qfalse ){ |
| 820 |
continue; |
| 821 |
} |
| 822 |
if ( level.clients[i].sess.sessionTeam == TEAM_SPECTATOR ) { |
| 823 |
continue; |
| 824 |
} |
| 825 |
|
| 826 |
client->client->pers.livesLeft = g_lms_lives.integer; |
| 827 |
|
| 828 |
respawnRound(client); |
| 829 |
} |
| 830 |
return; |
| 831 |
} |
| 832 |
|
| 833 |
/* |
| 834 |
================ |
| 835 |
DisableWeapons |
| 836 |
|
| 837 |
disables all weapons |
| 838 |
================ |
| 839 |
*/ |
| 840 |
|
| 841 |
void DisableWeapons(void) |
| 842 |
{ |
| 843 |
int i; |
| 844 |
gentity_t *client; |
| 845 |
for(i=0;i<level.maxclients;i++) |
| 846 |
{ |
| 847 |
if ( level.clients[i].pers.connected == CON_DISCONNECTED ) { |
| 848 |
continue; |
| 849 |
} |
| 850 |
if ( level.clients[i].pers.connected == CON_CONNECTING) { |
| 851 |
continue; |
| 852 |
} |
| 853 |
|
| 854 |
if ( level.clients[i].sess.sessionTeam == TEAM_SPECTATOR ) { |
| 855 |
continue; |
| 856 |
} |
| 857 |
client = g_entities + i; |
| 858 |
client->client->ps.pm_flags |= PMF_ELIMWARMUP; |
| 859 |
} |
| 860 |
ProximityMine_RemoveAll(); //Remove all the prox mines |
| 861 |
return; |
| 862 |
} |
| 863 |
|
| 864 |
/* |
| 865 |
================ |
| 866 |
EnableWeapons |
| 867 |
|
| 868 |
enables all weapons |
| 869 |
================ |
| 870 |
*/ |
| 871 |
|
| 872 |
void EnableWeapons(void) |
| 873 |
{ |
| 874 |
int i; |
| 875 |
gentity_t *client; |
| 876 |
for(i=0;i<level.maxclients;i++) |
| 877 |
{ |
| 878 |
if ( level.clients[i].pers.connected == CON_DISCONNECTED ) { |
| 879 |
continue; |
| 880 |
} |
| 881 |
|
| 882 |
if ( level.clients[i].sess.sessionTeam == TEAM_SPECTATOR ) { |
| 883 |
continue; |
| 884 |
} |
| 885 |
|
| 886 |
/*if ( level.clients[i].isEliminated == qtrue ){ |
| 887 |
continue; |
| 888 |
}*/ |
| 889 |
|
| 890 |
client = g_entities + i; |
| 891 |
client->client->ps.pm_flags &= ~PMF_ELIMWARMUP; |
| 892 |
} |
| 893 |
return; |
| 894 |
} |
| 895 |
|
| 896 |
/* |
| 897 |
================ |
| 898 |
LMSpoint |
| 899 |
|
| 900 |
Gives a point to the lucky survivor |
| 901 |
================ |
| 902 |
*/ |
| 903 |
|
| 904 |
void LMSpoint(void) |
| 905 |
{ |
| 906 |
int i; |
| 907 |
gentity_t *client; |
| 908 |
for(i=0;i<level.maxclients;i++) |
| 909 |
{ |
| 910 |
if ( level.clients[i].pers.connected == CON_DISCONNECTED ) { |
| 911 |
continue; |
| 912 |
} |
| 913 |
|
| 914 |
if ( level.clients[i].sess.sessionTeam == TEAM_SPECTATOR ) { |
| 915 |
continue; |
| 916 |
} |
| 917 |
|
| 918 |
if ( level.clients[i].isEliminated ){ |
| 919 |
continue; |
| 920 |
} |
| 921 |
|
| 922 |
client = g_entities + i; |
| 923 |
/* |
| 924 |
Not good in mode 2 & 3 |
| 925 |
if ( client->health <= 0 ){ |
| 926 |
continue; |
| 927 |
} |
| 928 |
*/ |
| 929 |
|
| 930 |
client->client->ps.persistant[PERS_SCORE] += 1; |
| 931 |
G_LogPrintf("PlayerScore: %i %i: %s now has %d points\n", |
| 932 |
i, client->client->ps.persistant[PERS_SCORE], client->client->pers.netname, client->client->ps.persistant[PERS_SCORE] ); |
| 933 |
} |
| 934 |
|
| 935 |
CalculateRanks(); |
| 936 |
return; |
| 937 |
} |
| 938 |
|
| 939 |
/* |
| 940 |
================ |
| 941 |
TeamLeader |
| 942 |
|
| 943 |
Returns the client number of the team leader |
| 944 |
================ |
| 945 |
*/ |
| 946 |
int TeamLeader( int team ) { |
| 947 |
int i; |
| 948 |
|
| 949 |
for ( i = 0 ; i < level.maxclients ; i++ ) { |
| 950 |
if ( level.clients[i].pers.connected == CON_DISCONNECTED ) { |
| 951 |
continue; |
| 952 |
} |
| 953 |
if ( level.clients[i].sess.sessionTeam == team ) { |
| 954 |
if ( level.clients[i].sess.teamLeader ) |
| 955 |
return i; |
| 956 |
} |
| 957 |
} |
| 958 |
|
| 959 |
return -1; |
| 960 |
} |
| 961 |
|
| 962 |
|
| 963 |
/* |
| 964 |
================ |
| 965 |
PickTeam |
| 966 |
|
| 967 |
================ |
| 968 |
*/ |
| 969 |
team_t PickTeam( int ignoreClientNum ) { |
| 970 |
int counts[TEAM_NUM_TEAMS]; |
| 971 |
|
| 972 |
counts[TEAM_BLUE] = TeamCount( ignoreClientNum, TEAM_BLUE ); |
| 973 |
counts[TEAM_RED] = TeamCount( ignoreClientNum, TEAM_RED ); |
| 974 |
|
| 975 |
//KK-OAX Both Teams locked...forget about it, print an error message, keep as spec |
| 976 |
if ( level.RedTeamLocked && level.BlueTeamLocked ) { |
| 977 |
G_Printf( "Both teams have been locked by the Admin! \n" ); |
| 978 |
return TEAM_NONE; |
| 979 |
} |
| 980 |
if ( ( counts[TEAM_BLUE] > counts[TEAM_RED] ) && ( !level.RedTeamLocked ) ) { |
| 981 |
return TEAM_RED; |
| 982 |
} |
| 983 |
if ( ( counts[TEAM_RED] > counts[TEAM_BLUE] ) && ( !level.BlueTeamLocked ) ) { |
| 984 |
return TEAM_BLUE; |
| 985 |
} |
| 986 |
// equal team count, so join the team with the lowest score |
| 987 |
if ( ( level.teamScores[TEAM_BLUE] > level.teamScores[TEAM_RED] ) && ( !level.RedTeamLocked ) ) { |
| 988 |
return TEAM_RED; |
| 989 |
} |
| 990 |
if ( ( level.teamScores[TEAM_RED] > level.teamScores[TEAM_BLUE] ) && ( !level.BlueTeamLocked ) ) { |
| 991 |
return TEAM_BLUE; |
| 992 |
} |
| 993 |
//KK-OAX Force Team Blue? |
| 994 |
return TEAM_BLUE; |
| 995 |
} |
| 996 |
|
| 997 |
/* |
| 998 |
=========== |
| 999 |
ForceClientSkin |
| 1000 |
|
| 1001 |
Forces a client's skin (for teamplay) |
| 1002 |
=========== |
| 1003 |
*/ |
| 1004 |
/* |
| 1005 |
static void ForceClientSkin( gclient_t *client, char *model, const char *skin ) { |
| 1006 |
char *p; |
| 1007 |
|
| 1008 |
if ((p = strrchr(model, '/')) != 0) { |
| 1009 |
*p = 0; |
| 1010 |
} |
| 1011 |
|
| 1012 |
Q_strcat(model, MAX_QPATH, "/"); |
| 1013 |
Q_strcat(model, MAX_QPATH, skin); |
| 1014 |
} |
| 1015 |
*/ |
| 1016 |
|
| 1017 |
/* |
| 1018 |
=========== |
| 1019 |
ClientCheckName |
| 1020 |
============ |
| 1021 |
*/ |
| 1022 |
static void ClientCleanName(const char *in, char *out, int outSize, int clientNum) |
| 1023 |
{ |
| 1024 |
int outpos = 0, colorlessLen = 0, spaces = 0, notblack=0; |
| 1025 |
qboolean black = qfalse; |
| 1026 |
|
| 1027 |
// discard leading spaces |
| 1028 |
for(; *in == ' '; in++); |
| 1029 |
|
| 1030 |
for(; *in && outpos < outSize - 1; in++) |
| 1031 |
{ |
| 1032 |
out[outpos] = *in; |
| 1033 |
|
| 1034 |
if(*in == ' ') |
| 1035 |
{ |
| 1036 |
// don't allow too many consecutive spaces |
| 1037 |
if(spaces > 2) |
| 1038 |
continue; |
| 1039 |
|
| 1040 |
spaces++; |
| 1041 |
} |
| 1042 |
else if(outpos > 0 && out[outpos - 1] == Q_COLOR_ESCAPE) |
| 1043 |
{ |
| 1044 |
if(Q_IsColorString(&out[outpos - 1])) |
| 1045 |
{ |
| 1046 |
colorlessLen--; |
| 1047 |
|
| 1048 |
if(ColorIndex(*in) == 0) |
| 1049 |
{ |
| 1050 |
// Disallow color black in names to prevent players |
| 1051 |
// from getting advantage playing in front of black backgrounds |
| 1052 |
//outpos--; |
| 1053 |
//continue; |
| 1054 |
black = qtrue; |
| 1055 |
} |
| 1056 |
else |
| 1057 |
black = qfalse; |
| 1058 |
} |
| 1059 |
else |
| 1060 |
{ |
| 1061 |
spaces = 0; |
| 1062 |
colorlessLen++; |
| 1063 |
} |
| 1064 |
} |
| 1065 |
else |
| 1066 |
{ |
| 1067 |
spaces = 0; |
| 1068 |
colorlessLen++; |
| 1069 |
if(!black && (Q_isalpha(*in) || (*in>='0' && *in<='9') ) ) |
| 1070 |
notblack++; |
| 1071 |
} |
| 1072 |
|
| 1073 |
outpos++; |
| 1074 |
} |
| 1075 |
|
| 1076 |
out[outpos] = '\0'; |
| 1077 |
|
| 1078 |
//There was none not-black alphanum chars. Remove all colors |
| 1079 |
if(notblack<1) |
| 1080 |
Q_CleanStr(out); |
| 1081 |
|
| 1082 |
// don't allow empty names |
| 1083 |
if( *out == '\0' || colorlessLen == 0) |
| 1084 |
Q_strncpyz(out, va("Nameless%i",clientNum), outSize ); |
| 1085 |
} |
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
/* |
| 1090 |
=========== |
| 1091 |
ClientUserInfoChanged |
| 1092 |
|
| 1093 |
Called from ClientConnect when the player first connects and |
| 1094 |
directly by the server system when the player updates a userinfo variable. |
| 1095 |
|
| 1096 |
The game can override any of the settings and call trap_SetUserinfo |
| 1097 |
if desired. |
| 1098 |
============ |
| 1099 |
*/ |
| 1100 |
void ClientUserinfoChanged( int clientNum ) { |
| 1101 |
gentity_t *ent; |
| 1102 |
int teamTask, teamLeader, team, health; |
| 1103 |
char *s; |
| 1104 |
char model[MAX_QPATH]; |
| 1105 |
char headModel[MAX_QPATH]; |
| 1106 |
char oldname[MAX_STRING_CHARS]; |
| 1107 |
//KK-OAX |
| 1108 |
char err[MAX_STRING_CHARS]; |
| 1109 |
qboolean revertName = qfalse; |
| 1110 |
|
| 1111 |
gclient_t *client; |
| 1112 |
char c1[MAX_INFO_STRING]; |
| 1113 |
char c2[MAX_INFO_STRING]; |
| 1114 |
char redTeam[MAX_INFO_STRING]; |
| 1115 |
char blueTeam[MAX_INFO_STRING]; |
| 1116 |
char userinfo[MAX_INFO_STRING]; |
| 1117 |
|
| 1118 |
ent = g_entities + clientNum; |
| 1119 |
client = ent->client; |
| 1120 |
|
| 1121 |
trap_GetUserinfo( clientNum, userinfo, sizeof( userinfo ) ); |
| 1122 |
|
| 1123 |
// check for malformed or illegal info strings |
| 1124 |
if ( !Info_Validate(userinfo) ) { |
| 1125 |
strcpy (userinfo, "\\name\\badinfo"); |
| 1126 |
} |
| 1127 |
|
| 1128 |
// check for local client |
| 1129 |
s = Info_ValueForKey( userinfo, "ip" ); |
| 1130 |
if ( !strcmp( s, "localhost" ) ) { |
| 1131 |
client->pers.localClient = qtrue; |
| 1132 |
} |
| 1133 |
|
| 1134 |
// check the item prediction |
| 1135 |
s = Info_ValueForKey( userinfo, "cg_predictItems" ); |
| 1136 |
if ( !atoi( s ) ) { |
| 1137 |
client->pers.predictItemPickup = qfalse; |
| 1138 |
} else { |
| 1139 |
client->pers.predictItemPickup = qtrue; |
| 1140 |
} |
| 1141 |
|
| 1142 |
//unlagged - client options |
| 1143 |
// see if the player has opted out |
| 1144 |
s = Info_ValueForKey( userinfo, "cg_delag" ); |
| 1145 |
if ( !atoi( s ) ) { |
| 1146 |
client->pers.delag = 0; |
| 1147 |
} else { |
| 1148 |
client->pers.delag = atoi( s ); |
| 1149 |
} |
| 1150 |
|
| 1151 |
// see if the player is nudging his shots |
| 1152 |
s = Info_ValueForKey( userinfo, "cg_cmdTimeNudge" ); |
| 1153 |
client->pers.cmdTimeNudge = atoi( s ); |
| 1154 |
|
| 1155 |
// see if the player wants to debug the backward reconciliation |
| 1156 |
/*s = Info_ValueForKey( userinfo, "cg_debugDelag" ); |
| 1157 |
if ( !atoi( s ) ) { |
| 1158 |
client->pers.debugDelag = qfalse; |
| 1159 |
} |
| 1160 |
else { |
| 1161 |
client->pers.debugDelag = qtrue; |
| 1162 |
}*/ |
| 1163 |
|
| 1164 |
// see if the player is simulating incoming latency |
| 1165 |
//s = Info_ValueForKey( userinfo, "cg_latentSnaps" ); |
| 1166 |
//client->pers.latentSnaps = atoi( s ); |
| 1167 |
|
| 1168 |
// see if the player is simulating outgoing latency |
| 1169 |
//s = Info_ValueForKey( userinfo, "cg_latentCmds" ); |
| 1170 |
//client->pers.latentCmds = atoi( s ); |
| 1171 |
|
| 1172 |
// see if the player is simulating outgoing packet loss |
| 1173 |
//s = Info_ValueForKey( userinfo, "cg_plOut" ); |
| 1174 |
//client->pers.plOut = atoi( s ); |
| 1175 |
//unlagged - client options |
| 1176 |
|
| 1177 |
// set name |
| 1178 |
Q_strncpyz ( oldname, client->pers.netname, sizeof( oldname ) ); |
| 1179 |
s = Info_ValueForKey (userinfo, "name"); |
| 1180 |
ClientCleanName( s, client->pers.netname, sizeof(client->pers.netname), clientNum ); |
| 1181 |
|
| 1182 |
//KK-OAPub Added From Tremulous-Control Name Changes |
| 1183 |
if( strcmp( oldname, client->pers.netname ) ) |
| 1184 |
{ |
| 1185 |
if( client->pers.nameChangeTime && |
| 1186 |
( level.time - client->pers.nameChangeTime ) |
| 1187 |
<= ( g_minNameChangePeriod.value * 1000 ) ) |
| 1188 |
{ |
| 1189 |
trap_SendServerCommand( ent - g_entities, va( |
| 1190 |
"print \"Name change spam protection (g_minNameChangePeriod = %d)\n\"", |
| 1191 |
g_minNameChangePeriod.integer ) ); |
| 1192 |
revertName = qtrue; |
| 1193 |
} |
| 1194 |
else if( g_maxNameChanges.integer > 0 |
| 1195 |
&& client->pers.nameChanges >= g_maxNameChanges.integer ) |
| 1196 |
{ |
| 1197 |
trap_SendServerCommand( ent - g_entities, va( |
| 1198 |
"print \"Maximum name changes reached (g_maxNameChanges = %d)\n\"", |
| 1199 |
g_maxNameChanges.integer ) ); |
| 1200 |
revertName = qtrue; |
| 1201 |
} |
| 1202 |
else if( client->pers.muted ) |
| 1203 |
{ |
| 1204 |
trap_SendServerCommand( ent - g_entities, |
| 1205 |
"print \"You cannot change your name while you are muted\n\"" ); |
| 1206 |
revertName = qtrue; |
| 1207 |
} |
| 1208 |
else if( !G_admin_name_check( ent, client->pers.netname, err, sizeof( err ) ) ) |
| 1209 |
{ |
| 1210 |
trap_SendServerCommand( ent - g_entities, va( "print \"%s\n\"", err ) ); |
| 1211 |
revertName = qtrue; |
| 1212 |
} |
| 1213 |
|
| 1214 |
//Never revert a bots name... just to bad if it hapens... but the bot will always be expendeble :-) |
| 1215 |
if (ent->r.svFlags & SVF_BOT) |
| 1216 |
revertName = qfalse; |
| 1217 |
|
| 1218 |
if( revertName ) |
| 1219 |
{ |
| 1220 |
Q_strncpyz( client->pers.netname, *oldname ? oldname : "UnnamedPlayer", |
| 1221 |
sizeof( client->pers.netname ) ); |
| 1222 |
Info_SetValueForKey( userinfo, "name", oldname ); |
| 1223 |
trap_SetUserinfo( clientNum, userinfo ); |
| 1224 |
} |
| 1225 |
else |
| 1226 |
{ |
| 1227 |
if( client->pers.connected == CON_CONNECTED ) |
| 1228 |
{ |
| 1229 |
client->pers.nameChangeTime = level.time; |
| 1230 |
client->pers.nameChanges++; |
| 1231 |
} |
| 1232 |
} |
| 1233 |
} |
| 1234 |
// N_G: this condition makes no sense to me and I'm not going to |
| 1235 |
// try finding out what it means, I've added parentheses according to |
| 1236 |
// evaluation rules of the original code so grab a |
| 1237 |
// parentheses pairing highlighting text editor and see for yourself |
| 1238 |
// if you got it right |
| 1239 |
//Sago: One redundant check and CTF Elim and LMS was missing. Not an important function and I might never have noticed, should properly be || |
| 1240 |
if ( ( ( client->sess.sessionTeam == TEAM_SPECTATOR ) || |
| 1241 |
( ( ( client->isEliminated ) /*|| |
| 1242 |
( client->ps.pm_type == PM_SPECTATOR )*/ ) && //Sago: If this is true client.isEliminated or TEAM_SPECTATOR is true to and this is redundant |
| 1243 |
( g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_CTF_ELIMINATION || g_gametype.integer == GT_LMS) ) ) && |
| 1244 |
( client->sess.spectatorState == SPECTATOR_SCOREBOARD ) ) { |
| 1245 |
|
| 1246 |
Q_strncpyz( client->pers.netname, "scoreboard", sizeof(client->pers.netname) ); |
| 1247 |
} |
| 1248 |
|
| 1249 |
if ( client->pers.connected == CON_CONNECTED ) { |
| 1250 |
if ( strcmp( oldname, client->pers.netname ) ) { |
| 1251 |
trap_SendServerCommand( -1, va("print \"%s" S_COLOR_WHITE " renamed to %s\n\"", oldname, |
| 1252 |
client->pers.netname) ); |
| 1253 |
} |
| 1254 |
} |
| 1255 |
|
| 1256 |
// set max health |
| 1257 |
if (client->ps.powerups[PW_GUARD]) { |
| 1258 |
client->pers.maxHealth = 200; |
| 1259 |
} else { |
| 1260 |
health = atoi( Info_ValueForKey( userinfo, "handicap" ) ); |
| 1261 |
client->pers.maxHealth = health; |
| 1262 |
if ( client->pers.maxHealth < 1 || client->pers.maxHealth > 100 ) { |
| 1263 |
client->pers.maxHealth = 100; |
| 1264 |
} |
| 1265 |
} |
| 1266 |
client->ps.stats[STAT_MAX_HEALTH] = client->pers.maxHealth; |
| 1267 |
|
| 1268 |
// set model |
| 1269 |
if( g_gametype.integer >= GT_TEAM && g_ffa_gt==0) { |
| 1270 |
Q_strncpyz( model, Info_ValueForKey (userinfo, "team_model"), sizeof( model ) ); |
| 1271 |
Q_strncpyz( headModel, Info_ValueForKey (userinfo, "team_headmodel"), sizeof( headModel ) ); |
| 1272 |
} else { |
| 1273 |
Q_strncpyz( model, Info_ValueForKey (userinfo, "model"), sizeof( model ) ); |
| 1274 |
Q_strncpyz( headModel, Info_ValueForKey (userinfo, "headmodel"), sizeof( headModel ) ); |
| 1275 |
} |
| 1276 |
|
| 1277 |
// bots set their team a few frames later |
| 1278 |
if (g_gametype.integer >= GT_TEAM && g_ffa_gt==0 && g_entities[clientNum].r.svFlags & SVF_BOT) { |
| 1279 |
s = Info_ValueForKey( userinfo, "team" ); |
| 1280 |
if ( !Q_stricmp( s, "red" ) || !Q_stricmp( s, "r" ) ) { |
| 1281 |
team = TEAM_RED; |
| 1282 |
} else if ( !Q_stricmp( s, "blue" ) || !Q_stricmp( s, "b" ) ) { |
| 1283 |
team = TEAM_BLUE; |
| 1284 |
} else { |
| 1285 |
// pick the team with the least number of players |
| 1286 |
team = PickTeam( clientNum ); |
| 1287 |
} |
| 1288 |
client->sess.sessionTeam = team; |
| 1289 |
} |
| 1290 |
else { |
| 1291 |
team = client->sess.sessionTeam; |
| 1292 |
} |
| 1293 |
|
| 1294 |
/* NOTE: all client side now |
| 1295 |
Sago: I am not happy with this exception |
| 1296 |
|
| 1297 |
// team |
| 1298 |
switch( team ) { |
| 1299 |
case TEAM_RED: |
| 1300 |
ForceClientSkin(client, model, "red"); |
| 1301 |
// ForceClientSkin(client, headModel, "red"); |
| 1302 |
break; |
| 1303 |
case TEAM_BLUE: |
| 1304 |
ForceClientSkin(client, model, "blue"); |
| 1305 |
// ForceClientSkin(client, headModel, "blue"); |
| 1306 |
break; |
| 1307 |
} |
| 1308 |
// don't ever use a default skin in teamplay, it would just waste memory |
| 1309 |
// however bots will always join a team but they spawn in as spectator |
| 1310 |
if ( g_gametype.integer >= GT_TEAM && team == TEAM_SPECTATOR) { |
| 1311 |
ForceClientSkin(client, model, "red"); |
| 1312 |
// ForceClientSkin(client, headModel, "red"); |
| 1313 |
} |
| 1314 |
*/ |
| 1315 |
|
| 1316 |
if (g_gametype.integer >= GT_TEAM && g_ffa_gt!=1) { |
| 1317 |
client->pers.teamInfo = qtrue; |
| 1318 |
} else { |
| 1319 |
s = Info_ValueForKey( userinfo, "teamoverlay" ); |
| 1320 |
if ( ! *s || atoi( s ) != 0 ) { |
| 1321 |
client->pers.teamInfo = qtrue; |
| 1322 |
} else { |
| 1323 |
client->pers.teamInfo = qfalse; |
| 1324 |
} |
| 1325 |
} |
| 1326 |
/* |
| 1327 |
s = Info_ValueForKey( userinfo, "cg_pmove_fixed" ); |
| 1328 |
if ( !*s || atoi( s ) == 0 ) { |
| 1329 |
client->pers.pmoveFixed = qfalse; |
| 1330 |
} |
| 1331 |
else { |
| 1332 |
client->pers.pmoveFixed = qtrue; |
| 1333 |
} |
| 1334 |
*/ |
| 1335 |
|
| 1336 |
// team task (0 = none, 1 = offence, 2 = defence) |
| 1337 |
teamTask = atoi(Info_ValueForKey(userinfo, "teamtask")); |
| 1338 |
// team Leader (1 = leader, 0 is normal player) |
| 1339 |
teamLeader = client->sess.teamLeader; |
| 1340 |
|
| 1341 |
// colors |
| 1342 |
if( g_gametype.integer >= GT_TEAM && g_ffa_gt==0 && g_instantgib.integer) { |
| 1343 |
switch(team) { |
| 1344 |
case TEAM_RED: |
| 1345 |
c1[0] = COLOR_BLUE; |
| 1346 |
c2[0] = COLOR_BLUE; |
| 1347 |
c1[1] = 0; |
| 1348 |
c2[1] = 0; |
| 1349 |
break; |
| 1350 |
case TEAM_BLUE: |
| 1351 |
c1[0] = COLOR_RED; |
| 1352 |
c2[0] = COLOR_RED; |
| 1353 |
c1[1] = 0; |
| 1354 |
c2[1] = 0; |
| 1355 |
break; |
| 1356 |
default: |
| 1357 |
break; |
| 1358 |
} |
| 1359 |
} else { |
| 1360 |
strcpy(c1, Info_ValueForKey( userinfo, "color1" )); |
| 1361 |
strcpy(c2, Info_ValueForKey( userinfo, "color2" )); |
| 1362 |
} |
| 1363 |
|
| 1364 |
strcpy(redTeam, Info_ValueForKey( userinfo, "g_redteam" )); |
| 1365 |
strcpy(blueTeam, Info_ValueForKey( userinfo, "g_blueteam" )); |
| 1366 |
|
| 1367 |
// send over a subset of the userinfo keys so other clients can |
| 1368 |
// print scoreboards, display models, and play custom sounds |
| 1369 |
if ( ent->r.svFlags & SVF_BOT ) { |
| 1370 |
s = va("n\\%s\\t\\%i\\model\\%s\\hmodel\\%s\\c1\\%s\\c2\\%s\\hc\\%i\\w\\%i\\l\\%i\\skill\\%s\\tt\\%d\\tl\\%d", |
| 1371 |
client->pers.netname, team, model, headModel, c1, c2, |
| 1372 |
client->pers.maxHealth, client->sess.wins, client->sess.losses, |
| 1373 |
Info_ValueForKey( userinfo, "skill" ), teamTask, teamLeader ); |
| 1374 |
} else { |
| 1375 |
s = va("n\\%s\\t\\%i\\model\\%s\\hmodel\\%s\\g_redteam\\%s\\g_blueteam\\%s\\c1\\%s\\c2\\%s\\hc\\%i\\w\\%i\\l\\%i\\tt\\%d\\tl\\%d", |
| 1376 |
client->pers.netname, client->sess.sessionTeam, model, headModel, redTeam, blueTeam, c1, c2, |
| 1377 |
client->pers.maxHealth, client->sess.wins, client->sess.losses, teamTask, teamLeader); |
| 1378 |
} |
| 1379 |
|
| 1380 |
trap_SetConfigstring( CS_PLAYERS+clientNum, s ); |
| 1381 |
|
| 1382 |
// this is not the userinfo, more like the configstring actually |
| 1383 |
G_LogPrintf( "ClientUserinfoChanged: %i %s\\id\\%s\n", clientNum, s, Info_ValueForKey(userinfo, "cl_guid") ); |
| 1384 |
} |
| 1385 |
|
| 1386 |
|
| 1387 |
/* |
| 1388 |
=========== |
| 1389 |
ClientConnect |
| 1390 |
|
| 1391 |
Called when a player begins connecting to the server. |
| 1392 |
Called again for every map change or tournement restart. |
| 1393 |
|
| 1394 |
The session information will be valid after exit. |
| 1395 |
|
| 1396 |
Return NULL if the client should be allowed, otherwise return |
| 1397 |
a string with the reason for denial. |
| 1398 |
|
| 1399 |
Otherwise, the client will be sent the current gamestate |
| 1400 |
and will eventually get to ClientBegin. |
| 1401 |
|
| 1402 |
firstTime will be qtrue the very first time a client connects |
| 1403 |
to the server machine, but qfalse on map changes and tournement |
| 1404 |
restarts. |
| 1405 |
============ |
| 1406 |
*/ |
| 1407 |
char *ClientConnect( int clientNum, qboolean firstTime, qboolean isBot ) { |
| 1408 |
char *value; |
| 1409 |
// char *areabits; |
| 1410 |
gclient_t *client; |
| 1411 |
char userinfo[MAX_INFO_STRING]; |
| 1412 |
gentity_t *ent; |
| 1413 |
char reason[ MAX_STRING_CHARS ] = {""}; |
| 1414 |
int i; |
| 1415 |
|
| 1416 |
//KK-OAX I moved these up so userinfo could be assigned/used. |
| 1417 |
ent = &g_entities[ clientNum ]; |
| 1418 |
client = &level.clients[ clientNum ]; |
| 1419 |
ent->client = client; |
| 1420 |
memset( client, 0, sizeof(*client) ); |
| 1421 |
|
| 1422 |
trap_GetUserinfo( clientNum, userinfo, sizeof( userinfo ) ); |
| 1423 |
|
| 1424 |
value = Info_ValueForKey( userinfo, "cl_guid" ); |
| 1425 |
Q_strncpyz( client->pers.guid, value, sizeof( client->pers.guid ) ); |
| 1426 |
|
| 1427 |
|
| 1428 |
// IP filtering //KK-OAX Has this been obsoleted? |
| 1429 |
// https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=500 |
| 1430 |
// recommanding PB based IP / GUID banning, the builtin system is pretty limited |
| 1431 |
// check to see if they are on the banned IP list |
| 1432 |
value = Info_ValueForKey (userinfo, "ip"); |
| 1433 |
Q_strncpyz( client->pers.ip, value, sizeof( client->pers.ip ) ); |
| 1434 |
|
| 1435 |
if ( G_FilterPacket( value ) && !Q_stricmp(value,"localhost") ) { |
| 1436 |
G_Printf("Player with IP: %s is banned\n",value); |
| 1437 |
return "You are banned from this server."; |
| 1438 |
} |
| 1439 |
|
| 1440 |
if( G_admin_ban_check( userinfo, reason, sizeof( reason ) ) ) { |
| 1441 |
return va( "%s", reason ); |
| 1442 |
} |
| 1443 |
|
| 1444 |
//KK-OAX |
| 1445 |
// we don't check GUID or password for bots and local client |
| 1446 |
// NOTE: local client <-> "ip" "localhost" |
| 1447 |
// this means this client is not running in our current process |
| 1448 |
if ( !isBot && (strcmp(value, "localhost") != 0)) { |
| 1449 |
// check for a password |
| 1450 |
value = Info_ValueForKey (userinfo, "password"); |
| 1451 |
if ( g_password.string[0] && Q_stricmp( g_password.string, "none" ) && |
| 1452 |
strcmp( g_password.string, value) != 0) { |
| 1453 |
return "Invalid password"; |
| 1454 |
} |
| 1455 |
for( i = 0; i < sizeof( client->pers.guid ) - 1 && |
| 1456 |
isxdigit( client->pers.guid[ i ] ); i++ ); |
| 1457 |
if( i < sizeof( client->pers.guid ) - 1 ) |
| 1458 |
return "Invalid GUID"; |
| 1459 |
|
| 1460 |
for( i = 0; i < level.maxclients; i++ ) { |
| 1461 |
|
| 1462 |
if( level.clients[ i ].pers.connected == CON_DISCONNECTED ) |
| 1463 |
continue; |
| 1464 |
|
| 1465 |
if( !Q_stricmp( client->pers.guid, level.clients[ i ].pers.guid ) ) { |
| 1466 |
if( !G_ClientIsLagging( level.clients + i ) ) { |
| 1467 |
trap_SendServerCommand( i, "cp \"Your GUID is not secure\"" ); |
| 1468 |
return "Duplicate GUID"; |
| 1469 |
} |
| 1470 |
trap_DropClient( i, "Ghost" ); |
| 1471 |
} |
| 1472 |
} |
| 1473 |
|
| 1474 |
} |
| 1475 |
|
| 1476 |
//Check for local client |
| 1477 |
if( !strcmp( client->pers.ip, "localhost" ) ) |
| 1478 |
client->pers.localClient = qtrue; |
| 1479 |
client->pers.adminLevel = G_admin_level( ent ); |
| 1480 |
|
| 1481 |
client->pers.connected = CON_CONNECTING; |
| 1482 |
|
| 1483 |
// read or initialize the session data |
| 1484 |
if ( firstTime || level.newSession ) { |
| 1485 |
G_InitSessionData( client, userinfo ); |
| 1486 |
} |
| 1487 |
G_ReadSessionData( client ); |
| 1488 |
|
| 1489 |
if( isBot ) { |
| 1490 |
ent->r.svFlags |= SVF_BOT; |
| 1491 |
ent->inuse = qtrue; |
| 1492 |
if( !G_BotConnect( clientNum, !firstTime ) ) { |
| 1493 |
return "BotConnectfailed"; |
| 1494 |
} |
| 1495 |
} |
| 1496 |
|
| 1497 |
//KK-OAX Swapped these in order...seemed to help the connection process. |
| 1498 |
// get and distribute relevent paramters |
| 1499 |
ClientUserinfoChanged( clientNum ); |
| 1500 |
G_LogPrintf( "ClientConnect: %i\n", clientNum ); |
| 1501 |
|
| 1502 |
|
| 1503 |
// don't do the "xxx connected" messages if they were caried over from previous level |
| 1504 |
if ( firstTime ) { |
| 1505 |
trap_SendServerCommand( -1, va("print \"%s" S_COLOR_WHITE " connected\n\"", client->pers.netname) ); |
| 1506 |
} |
| 1507 |
|
| 1508 |
if ( g_gametype.integer >= GT_TEAM && |
| 1509 |
client->sess.sessionTeam != TEAM_SPECTATOR ) { |
| 1510 |
BroadcastTeamChange( client, -1 ); |
| 1511 |
} |
| 1512 |
|
| 1513 |
// count current clients and rank for scoreboard |
| 1514 |
CalculateRanks(); |
| 1515 |
|
| 1516 |
// for statistics |
| 1517 |
// client->areabits = areabits; |
| 1518 |
// if ( !client->areabits ) |
| 1519 |
// client->areabits = G_Alloc( (trap_AAS_PointReachabilityAreaIndex( NULL ) + 7) / 8 ); |
| 1520 |
|
| 1521 |
//Sago: Changed the message |
| 1522 |
//unlagged - backward reconciliation #5 |
| 1523 |
// announce it |
| 1524 |
if ( g_delagHitscan.integer ) { |
| 1525 |
trap_SendServerCommand( clientNum, "print \"Full lag compensation is ON!\n\"" ); |
| 1526 |
} |
| 1527 |
else { |
| 1528 |
trap_SendServerCommand( clientNum, "print \"Full lag compensation is OFF!\n\"" ); |
| 1529 |
} |
| 1530 |
|
| 1531 |
//unlagged - backward reconciliation #5 |
| 1532 |
G_admin_namelog_update( client, qfalse ); |
| 1533 |
return NULL; |
| 1534 |
} |
| 1535 |
|
| 1536 |
void motd (gentity_t *ent) |
| 1537 |
{ |
| 1538 |
char motd[1024]; |
| 1539 |
fileHandle_t motdFile; |
| 1540 |
int motdLen; |
| 1541 |
int fileLen; |
| 1542 |
|
| 1543 |
strcpy (motd, "cp \""); |
| 1544 |
fileLen = trap_FS_FOpenFile(g_motdfile.string, &motdFile, FS_READ); |
| 1545 |
if(motdFile) |
| 1546 |
{ |
| 1547 |
char * p; |
| 1548 |
|
| 1549 |
motdLen = strlen(motd); |
| 1550 |
if((motdLen + fileLen) > (sizeof(motd) - 2)) |
| 1551 |
fileLen = (sizeof(motd) - 2 - motdLen); |
| 1552 |
trap_FS_Read(motd + motdLen, fileLen, motdFile); |
| 1553 |
motd[motdLen + fileLen] = '"'; |
| 1554 |
motd[motdLen + fileLen + 1] = 0; |
| 1555 |
trap_FS_FCloseFile(motdFile); |
| 1556 |
|
| 1557 |
while((p = strchr(motd, '\r'))) //Remove carrier return. 0x0D |
| 1558 |
memmove(p, p + 1, motdLen + fileLen - (p - motd)); |
| 1559 |
} |
| 1560 |
trap_SendServerCommand(ent - g_entities, motd); |
| 1561 |
} |
| 1562 |
|
| 1563 |
/* |
| 1564 |
=========== |
| 1565 |
ClientBegin |
| 1566 |
|
| 1567 |
called when a client has finished connecting, and is ready |
| 1568 |
to be placed into the level. This will happen every level load, |
| 1569 |
and on transition between teams, but doesn't happen on respawns |
| 1570 |
============ |
| 1571 |
*/ |
| 1572 |
void ClientBegin( int clientNum ) { |
| 1573 |
gentity_t *ent; |
| 1574 |
gclient_t *client; |
| 1575 |
gentity_t *tent; |
| 1576 |
int flags; |
| 1577 |
int countRed, countBlue, countFree; |
| 1578 |
char userinfo[MAX_INFO_STRING]; |
| 1579 |
|
| 1580 |
trap_GetUserinfo( clientNum, userinfo, sizeof( userinfo ) ); |
| 1581 |
|
| 1582 |
ent = g_entities + clientNum; |
| 1583 |
|
| 1584 |
client = level.clients + clientNum; |
| 1585 |
|
| 1586 |
if ( ent->r.linked ) { |
| 1587 |
trap_UnlinkEntity( ent ); |
| 1588 |
} |
| 1589 |
G_InitGentity( ent ); |
| 1590 |
ent->touch = 0; |
| 1591 |
ent->pain = 0; |
| 1592 |
ent->client = client; |
| 1593 |
|
| 1594 |
client->pers.connected = CON_CONNECTED; |
| 1595 |
client->pers.enterTime = level.time; |
| 1596 |
client->pers.teamState.state = TEAM_BEGIN; |
| 1597 |
|
| 1598 |
//Elimination: |
| 1599 |
client->pers.roundReached = 0; //We will spawn in next round |
| 1600 |
if(g_gametype.integer == GT_LMS) { |
| 1601 |
client->isEliminated = qtrue; //So player does not give a point in gamemode 2 and 3 |
| 1602 |
//trap_SendServerCommand( -1, va("print \"%s" S_COLOR_WHITE " will start dead\n\"", client->pers.netname) ); |
| 1603 |
} |
| 1604 |
|
| 1605 |
//player is a bot: |
| 1606 |
if( ent->r.svFlags & SVF_BOT ) |
| 1607 |
{ |
| 1608 |
if(!level.hadBots) |
| 1609 |
{ |
| 1610 |
G_LogPrintf( "Info: There has been at least 1 bot now\n" ); |
| 1611 |
level.hadBots = qtrue; |
| 1612 |
} |
| 1613 |
} |
| 1614 |
|
| 1615 |
//Count smallest team |
| 1616 |
countFree = TeamCount(-1,TEAM_FREE); |
| 1617 |
countRed = TeamCount(-1,TEAM_RED); |
| 1618 |
countBlue = TeamCount(-1,TEAM_BLUE); |
| 1619 |
if(g_gametype.integer < GT_TEAM || g_ffa_gt) |
| 1620 |
{ |
| 1621 |
if(countFree>level.teamSize) |
| 1622 |
level.teamSize=countFree; |
| 1623 |
} |
| 1624 |
else |
| 1625 |
if(countRed>countBlue) |
| 1626 |
{ |
| 1627 |
if(countBlue>level.teamSize) |
| 1628 |
level.teamSize=countBlue; |
| 1629 |
} |
| 1630 |
else |
| 1631 |
{ |
| 1632 |
if(countRed>level.teamSize) |
| 1633 |
level.teamSize=countRed; |
| 1634 |
} |
| 1635 |
|
| 1636 |
// save eflags around this, because changing teams will |
| 1637 |
// cause this to happen with a valid entity, and we |
| 1638 |
// want to make sure the teleport bit is set right |
| 1639 |
// so the viewpoint doesn't interpolate through the |
| 1640 |
// world to the new position |
| 1641 |
flags = client->ps.eFlags; |
| 1642 |
memset( &client->ps, 0, sizeof( client->ps ) ); |
| 1643 |
if( client->sess.sessionTeam != TEAM_SPECTATOR ) |
| 1644 |
PlayerStore_restore(Info_ValueForKey(userinfo,"cl_guid"),&(client->ps)); |
| 1645 |
client->ps.eFlags = flags; |
| 1646 |
|
| 1647 |
// locate ent at a spawn point |
| 1648 |
ClientSpawn( ent ); |
| 1649 |
|
| 1650 |
if( ( client->sess.sessionTeam != TEAM_SPECTATOR ) && |
| 1651 |
( ( !( client->isEliminated ) /*&& |
| 1652 |
( ( !client->ps.pm_type ) == PM_SPECTATOR ) */ ) || //Sago: Yes, it made no sense |
| 1653 |
( ( g_gametype.integer != GT_ELIMINATION || level.intermissiontime) && |
| 1654 |
( g_gametype.integer != GT_CTF_ELIMINATION || level.intermissiontime) && |
| 1655 |
( g_gametype.integer != GT_LMS || level.intermissiontime ) ) ) ) { |
| 1656 |
// send event |
| 1657 |
tent = G_TempEntity( ent->client->ps.origin, EV_PLAYER_TELEPORT_IN ); |
| 1658 |
tent->s.clientNum = ent->s.clientNum; |
| 1659 |
|
| 1660 |
if ( g_gametype.integer != GT_TOURNAMENT ) { |
| 1661 |
trap_SendServerCommand( -1, va("print \"%s" S_COLOR_WHITE " entered the game\n\"", client->pers.netname) ); |
| 1662 |
} |
| 1663 |
} |
| 1664 |
|
| 1665 |
motd ( ent ); |
| 1666 |
|
| 1667 |
G_LogPrintf( "ClientBegin: %i\n", clientNum ); |
| 1668 |
|
| 1669 |
//Send domination point names: |
| 1670 |
if(g_gametype.integer == GT_DOMINATION) { |
| 1671 |
DominationPointNamesMessage(ent); |
| 1672 |
DominationPointStatusMessage(ent); |
| 1673 |
} |
| 1674 |
|
| 1675 |
TeamCvarSet(); |
| 1676 |
|
| 1677 |
// count current clients and rank for scoreboard |
| 1678 |
CalculateRanks(); |
| 1679 |
|
| 1680 |
//Send the list of custom vote options: |
| 1681 |
if(strlen(custom_vote_info)) |
| 1682 |
SendCustomVoteCommands(clientNum); |
| 1683 |
} |
| 1684 |
|
| 1685 |
/* |
| 1686 |
=========== |
| 1687 |
ClientSpawn |
| 1688 |
|
| 1689 |
Called every time a client is placed fresh in the world: |
| 1690 |
after the first ClientBegin, and after each respawn |
| 1691 |
Initializes all non-persistant parts of playerState |
| 1692 |
============ |
| 1693 |
*/ |
| 1694 |
void ClientSpawn(gentity_t *ent) { |
| 1695 |
int index; |
| 1696 |
vec3_t spawn_origin, spawn_angles; |
| 1697 |
gclient_t *client; |
| 1698 |
int i; |
| 1699 |
clientPersistant_t saved; |
| 1700 |
clientSession_t savedSess; |
| 1701 |
int persistant[MAX_PERSISTANT]; |
| 1702 |
gentity_t *spawnPoint; |
| 1703 |
//gentity_t *tent; |
| 1704 |
int flags; |
| 1705 |
int savedPing; |
| 1706 |
// char *savedAreaBits; |
| 1707 |
int accuracy_hits, accuracy_shots,vote; |
| 1708 |
int accuracy[WP_NUM_WEAPONS][2]; |
| 1709 |
int eventSequence; |
| 1710 |
char userinfo[MAX_INFO_STRING]; |
| 1711 |
|
| 1712 |
index = ent - g_entities; |
| 1713 |
client = ent->client; |
| 1714 |
|
| 1715 |
//In Elimination the player should not spawn if he have already spawned in the round (but not for spectators) |
| 1716 |
// N_G: You've obviously wanted something ELSE |
| 1717 |
//Sago: Yes, the !level.intermissiontime is currently redundant but it might still be the bast place to make the test, CheckElimination in g_main makes sure the next if will fail and the rest of the things this block does might not affect if in Intermission (I'll just test that) |
| 1718 |
if( |
| 1719 |
( |
| 1720 |
( |
| 1721 |
g_gametype.integer == GT_ELIMINATION || |
| 1722 |
g_gametype.integer == GT_CTF_ELIMINATION || (g_gametype.integer == GT_LMS && client->isEliminated)) && |
| 1723 |
(!level.intermissiontime || level.warmupTime != 0) |
| 1724 |
) && |
| 1725 |
( client->sess.sessionTeam != TEAM_SPECTATOR ) |
| 1726 |
) |
| 1727 |
{ |
| 1728 |
// N_G: Another condition that makes no sense to me, see for |
| 1729 |
// yourself if you really meant this |
| 1730 |
// Sago: I beleive the TeamCount is to make sure people can join even if the game can't start |
| 1731 |
if( ( level.roundNumber == level.roundNumberStarted ) || |
| 1732 |
( (level.time < level.roundStartTime - g_elimination_activewarmup.integer*1000 ) && |
| 1733 |
TeamCount( -1, TEAM_BLUE ) && |
| 1734 |
TeamCount( -1, TEAM_RED ) ) ) |
| 1735 |
{ |
| 1736 |
client->sess.spectatorState = SPECTATOR_FREE; |
| 1737 |
client->isEliminated = qtrue; |
| 1738 |
if(g_gametype.integer == GT_LMS) |
| 1739 |
G_LogPrintf( "LMS: %i %i %i: Player \"%s^7\" eliminated!\n", level.roundNumber, index, 1, client->pers.netname ); |
| 1740 |
client->ps.pm_type = PM_SPECTATOR; |
| 1741 |
CalculateRanks(); |
| 1742 |
return; |
| 1743 |
} |
| 1744 |
else |
| 1745 |
{ |
| 1746 |
client->pers.roundReached = level.roundNumber+1; |
| 1747 |
client->sess.spectatorState = SPECTATOR_NOT; |
| 1748 |
client->ps.pm_type = PM_NORMAL; |
| 1749 |
client->isEliminated = qfalse; |
| 1750 |
CalculateRanks(); |
| 1751 |
} |
| 1752 |
} else { |
| 1753 |
//Force false. |
| 1754 |
if(client->isEliminated) { |
| 1755 |
client->isEliminated = qfalse; |
| 1756 |
CalculateRanks(); |
| 1757 |
} |
| 1758 |
} |
| 1759 |
|
| 1760 |
if(g_gametype.integer == GT_LMS && client->sess.sessionTeam != TEAM_SPECTATOR && (!level.intermissiontime || level.warmupTime != 0)) |
| 1761 |
{ |
| 1762 |
if(level.roundNumber==level.roundNumberStarted /*|| level.time<level.roundStartTime-g_elimination_activewarmup.integer*1000*/ && 1>client->pers.livesLeft) |
| 1763 |
{ |
| 1764 |
client->sess.spectatorState = SPECTATOR_FREE; |
| 1765 |
if( ent->client->isEliminated!=qtrue) { |
| 1766 |
client->isEliminated = qtrue; |
| 1767 |
if((g_lms_mode.integer == 2 || g_lms_mode.integer == 3) && level.roundNumber == level.roundNumberStarted) |
| 1768 |
LMSpoint(); |
| 1769 |
G_LogPrintf( "LMS: %i %i %i: Player \"%s^7\" eliminated!\n", level.roundNumber, index, 1, client->pers.netname ); |
| 1770 |
} |
| 1771 |
client->ps.pm_type = PM_SPECTATOR; |
| 1772 |
return; |
| 1773 |
} |
| 1774 |
|
| 1775 |
client->sess.spectatorState = SPECTATOR_NOT; |
| 1776 |
client->ps.pm_type = PM_NORMAL; |
| 1777 |
client->isEliminated = qfalse; |
| 1778 |
if(client->pers.livesLeft>0) |
| 1779 |
client->pers.livesLeft--; |
| 1780 |
} |
| 1781 |
|
| 1782 |
// find a spawn point |
| 1783 |
// do it before setting health back up, so farthest |
| 1784 |
// ranging doesn't count this client |
| 1785 |
if ((client->sess.sessionTeam == TEAM_SPECTATOR) |
| 1786 |
|| ( (client->ps.pm_type == PM_SPECTATOR || client->isEliminated ) && (g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_CTF_ELIMINATION) ) ) { |
| 1787 |
spawnPoint = SelectSpectatorSpawnPoint ( spawn_origin, spawn_angles); |
| 1788 |
} else if (g_gametype.integer == GT_DOUBLE_D) { |
| 1789 |
//Double Domination uses special spawn points: |
| 1790 |
spawnPoint = SelectDoubleDominationSpawnPoint (client->sess.sessionTeam, spawn_origin, spawn_angles); |
| 1791 |
} else if (g_gametype.integer >= GT_CTF && g_ffa_gt==0 && g_gametype.integer!= GT_DOMINATION) { |
| 1792 |
// all base oriented team games use the CTF spawn points |
| 1793 |
spawnPoint = SelectCTFSpawnPoint ( |
| 1794 |
client->sess.sessionTeam, |
| 1795 |
client->pers.teamState.state, |
| 1796 |
spawn_origin, spawn_angles); |
| 1797 |
} else { |
| 1798 |
do { |
| 1799 |
// the first spawn should be at a good looking spot |
| 1800 |
if ( !client->pers.initialSpawn && client->pers.localClient ) { |
| 1801 |
client->pers.initialSpawn = qtrue; |
| 1802 |
spawnPoint = SelectInitialSpawnPoint( spawn_origin, spawn_angles ); |
| 1803 |
} else { |
| 1804 |
// don't spawn near existing origin if possible |
| 1805 |
spawnPoint = SelectSpawnPoint ( |
| 1806 |
client->ps.origin, |
| 1807 |
spawn_origin, spawn_angles); |
| 1808 |
} |
| 1809 |
|
| 1810 |
// Tim needs to prevent bots from spawning at the initial point |
| 1811 |
// on q3dm0... |
| 1812 |
if ( ( spawnPoint->flags & FL_NO_BOTS ) && ( ent->r.svFlags & SVF_BOT ) ) { |
| 1813 |
//Sago: The game has a tendency to select the furtest spawn point |
| 1814 |
//This is a problem if the fursest spawnpoint keeps being NO_BOTS and it does! |
| 1815 |
//This is a hot fix that seeks a spawn point faraway from the the currently found one |
| 1816 |
vec3_t old_origin; |
| 1817 |
VectorCopy(spawn_origin,old_origin); |
| 1818 |
spawnPoint = SelectSpawnPoint (old_origin, spawn_origin, spawn_angles); |
| 1819 |
if ( ( spawnPoint->flags & FL_NO_BOTS ) && ( ent->r.svFlags & SVF_BOT ) ) { |
| 1820 |
continue; // try again |
| 1821 |
} |
| 1822 |
} |
| 1823 |
// just to be symetric, we have a nohumans option... |
| 1824 |
if ( ( spawnPoint->flags & FL_NO_HUMANS ) && !( ent->r.svFlags & SVF_BOT ) ) { |
| 1825 |
continue; // try again |
| 1826 |
} |
| 1827 |
|
| 1828 |
break; |
| 1829 |
|
| 1830 |
} while ( 1 ); |
| 1831 |
} |
| 1832 |
client->pers.teamState.state = TEAM_ACTIVE; |
| 1833 |
|
| 1834 |
// always clear the kamikaze flag |
| 1835 |
ent->s.eFlags &= ~EF_KAMIKAZE; |
| 1836 |
|
| 1837 |
// toggle the teleport bit so the client knows to not lerp |
| 1838 |
// and never clear the voted flag |
| 1839 |
flags = ent->client->ps.eFlags & (EF_TELEPORT_BIT | EF_VOTED | EF_TEAMVOTED); |
| 1840 |
flags ^= EF_TELEPORT_BIT; |
| 1841 |
|
| 1842 |
//unlagged - backward reconciliation #3 |
| 1843 |
// we don't want players being backward-reconciled to the place they died |
| 1844 |
G_ResetHistory( ent ); |
| 1845 |
// and this is as good a time as any to clear the saved state |
| 1846 |
ent->client->saved.leveltime = 0; |
| 1847 |
//unlagged - backward reconciliation #3 |
| 1848 |
|
| 1849 |
// clear everything but the persistant data |
| 1850 |
|
| 1851 |
saved = client->pers; |
| 1852 |
savedSess = client->sess; |
| 1853 |
savedPing = client->ps.ping; |
| 1854 |
vote = client->vote; |
| 1855 |
// savedAreaBits = client->areabits; |
| 1856 |
accuracy_hits = client->accuracy_hits; |
| 1857 |
accuracy_shots = client->accuracy_shots; |
| 1858 |
memcpy(accuracy,client->accuracy,sizeof(accuracy)); |
| 1859 |
|
| 1860 |
memcpy(persistant,client->ps.persistant,MAX_PERSISTANT*sizeof(int)); |
| 1861 |
eventSequence = client->ps.eventSequence; |
| 1862 |
|
| 1863 |
Com_Memset (client, 0, sizeof(*client)); |
| 1864 |
|
| 1865 |
client->pers = saved; |
| 1866 |
client->sess = savedSess; |
| 1867 |
client->ps.ping = savedPing; |
| 1868 |
client->vote = vote; |
| 1869 |
// client->areabits = savedAreaBits; |
| 1870 |
client->accuracy_hits = accuracy_hits; |
| 1871 |
client->accuracy_shots = accuracy_shots; |
| 1872 |
for( i = 0 ; i < WP_NUM_WEAPONS ; i++ ){ |
| 1873 |
client->accuracy[i][0] = accuracy[i][0]; |
| 1874 |
client->accuracy[i][1] = accuracy[i][1]; |
| 1875 |
} |
| 1876 |
|
| 1877 |
client->lastkilled_client = -1; |
| 1878 |
|
| 1879 |
for ( i = 0 ; i < MAX_PERSISTANT ; i++ ) { |
| 1880 |
client->ps.persistant[i] = persistant[i]; |
| 1881 |
} |
| 1882 |
client->ps.eventSequence = eventSequence; |
| 1883 |
// increment the spawncount so the client will detect the respawn |
| 1884 |
client->ps.persistant[PERS_SPAWN_COUNT]++; |
| 1885 |
client->ps.persistant[PERS_TEAM] = client->sess.sessionTeam; |
| 1886 |
|
| 1887 |
client->airOutTime = level.time + 12000; |
| 1888 |
|
| 1889 |
trap_GetUserinfo( index, userinfo, sizeof(userinfo) ); |
| 1890 |
// set max health |
| 1891 |
client->pers.maxHealth = atoi( Info_ValueForKey( userinfo, "handicap" ) ); |
| 1892 |
if ( client->pers.maxHealth < 1 || client->pers.maxHealth > 100 ) { |
| 1893 |
client->pers.maxHealth = 100; |
| 1894 |
} |
| 1895 |
// clear entity values |
| 1896 |
client->ps.stats[STAT_MAX_HEALTH] = client->pers.maxHealth; |
| 1897 |
client->ps.eFlags = flags; |
| 1898 |
|
| 1899 |
ent->s.groundEntityNum = ENTITYNUM_NONE; |
| 1900 |
ent->client = &level.clients[index]; |
| 1901 |
ent->takedamage = qtrue; |
| 1902 |
ent->inuse = qtrue; |
| 1903 |
ent->classname = "player"; |
| 1904 |
ent->r.contents = CONTENTS_BODY; |
| 1905 |
ent->clipmask = MASK_PLAYERSOLID; |
| 1906 |
ent->die = player_die; |
| 1907 |
ent->waterlevel = 0; |
| 1908 |
ent->watertype = 0; |
| 1909 |
ent->flags = 0; |
| 1910 |
|
| 1911 |
//Sago: No one has hit the client yet! |
| 1912 |
client->lastSentFlying = -1; |
| 1913 |
|
| 1914 |
VectorCopy (playerMins, ent->r.mins); |
| 1915 |
VectorCopy (playerMaxs, ent->r.maxs); |
| 1916 |
|
| 1917 |
client->ps.clientNum = index; |
| 1918 |
|
| 1919 |
if(g_gametype.integer != GT_ELIMINATION && g_gametype.integer != GT_CTF_ELIMINATION && g_gametype.integer != GT_LMS && !g_elimination_allgametypes.integer) |
| 1920 |
{ |
| 1921 |
client->ps.stats[STAT_WEAPONS] = ( 1 << WP_MACHINEGUN ); |
| 1922 |
if ( g_gametype.integer == GT_TEAM ) { |
| 1923 |
client->ps.ammo[WP_MACHINEGUN] = 50; |
| 1924 |
} else { |
| 1925 |
client->ps.ammo[WP_MACHINEGUN] = 100; |
| 1926 |
} |
| 1927 |
|
| 1928 |
client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_GAUNTLET ); |
| 1929 |
client->ps.ammo[WP_GAUNTLET] = -1; |
| 1930 |
client->ps.ammo[WP_GRAPPLING_HOOK] = -1; |
| 1931 |
|
| 1932 |
// health will count down towards max_health |
| 1933 |
ent->health = client->ps.stats[STAT_HEALTH] = client->ps.stats[STAT_MAX_HEALTH] + 25; |
| 1934 |
} |
| 1935 |
else |
| 1936 |
{ |
| 1937 |
client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_GAUNTLET ); |
| 1938 |
client->ps.ammo[WP_GAUNTLET] = -1; |
| 1939 |
client->ps.ammo[WP_GRAPPLING_HOOK] = -1; |
| 1940 |
if (g_elimination_machinegun.integer > 0) { |
| 1941 |
client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_MACHINEGUN ); |
| 1942 |
client->ps.ammo[WP_MACHINEGUN] = g_elimination_machinegun.integer; |
| 1943 |
} |
| 1944 |
if (g_elimination_shotgun.integer > 0) { |
| 1945 |
client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_SHOTGUN ); |
| 1946 |
client->ps.ammo[WP_SHOTGUN] = g_elimination_shotgun.integer; |
| 1947 |
} |
| 1948 |
if (g_elimination_grenade.integer > 0) { |
| 1949 |
client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_GRENADE_LAUNCHER ); |
| 1950 |
client->ps.ammo[WP_GRENADE_LAUNCHER] = g_elimination_grenade.integer; |
| 1951 |
} |
| 1952 |
if (g_elimination_rocket.integer > 0) { |
| 1953 |
client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_ROCKET_LAUNCHER ); |
| 1954 |
client->ps.ammo[WP_ROCKET_LAUNCHER] = g_elimination_rocket.integer; |
| 1955 |
} |
| 1956 |
if (g_elimination_lightning.integer > 0) { |
| 1957 |
client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_LIGHTNING ); |
| 1958 |
client->ps.ammo[WP_LIGHTNING] = g_elimination_lightning.integer; |
| 1959 |
} |
| 1960 |
if (g_elimination_railgun.integer > 0) { |
| 1961 |
client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_RAILGUN ); |
| 1962 |
client->ps.ammo[WP_RAILGUN] = g_elimination_railgun.integer; |
| 1963 |
} |
| 1964 |
if (g_elimination_plasmagun.integer > 0) { |
| 1965 |
client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_PLASMAGUN ); |
| 1966 |
client->ps.ammo[WP_PLASMAGUN] = g_elimination_plasmagun.integer; |
| 1967 |
} |
| 1968 |
if (g_elimination_bfg.integer > 0) { |
| 1969 |
client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_BFG ); |
| 1970 |
client->ps.ammo[WP_BFG] = g_elimination_bfg.integer; |
| 1971 |
} |
| 1972 |
if (g_elimination_grapple.integer) { |
| 1973 |
client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_GRAPPLING_HOOK ); |
| 1974 |
} |
| 1975 |
if (g_elimination_nail.integer > 0) { |
| 1976 |
client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_NAILGUN ); |
| 1977 |
client->ps.ammo[WP_NAILGUN] = g_elimination_nail.integer; |
| 1978 |
} |
| 1979 |
if (g_elimination_mine.integer > 0) { |
| 1980 |
client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_PROX_LAUNCHER ); |
| 1981 |
client->ps.ammo[WP_PROX_LAUNCHER] = g_elimination_mine.integer; |
| 1982 |
} |
| 1983 |
if (g_elimination_chain.integer > 0) { |
| 1984 |
client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_CHAINGUN ); |
| 1985 |
client->ps.ammo[WP_CHAINGUN] = g_elimination_chain.integer; |
| 1986 |
} |
| 1987 |
|
| 1988 |
ent->health = client->ps.stats[STAT_ARMOR] = g_elimination_startArmor.integer; //client->ps.stats[STAT_MAX_HEALTH]*2; |
| 1989 |
ent->health = client->ps.stats[STAT_HEALTH] = g_elimination_startHealth.integer; //client->ps.stats[STAT_MAX_HEALTH]*2; |
| 1990 |
|
| 1991 |
|
| 1992 |
// ent->health = client->ps.stats[STAT_HEALTH] = 0; |
| 1993 |
} |
| 1994 |
//Instantgib mode, replace weapons with rail (and maybe gauntlet) |
| 1995 |
if(g_instantgib.integer) |
| 1996 |
{ |
| 1997 |
client->ps.stats[STAT_WEAPONS] = ( 1 << WP_RAILGUN ); |
| 1998 |
client->ps.ammo[WP_RAILGUN] = 999; //Don't display any ammo |
| 1999 |
if(g_instantgib.integer>1) |
| 2000 |
{ |
| 2001 |
client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_GAUNTLET ); |
| 2002 |
client->ps.ammo[WP_GAUNTLET] = -1; |
| 2003 |
} |
| 2004 |
} |
| 2005 |
|
| 2006 |
//nexuiz style rocket arena (rocket launcher only) |
| 2007 |
if(g_rockets.integer) |
| 2008 |
{ |
| 2009 |
client->ps.stats[STAT_WEAPONS] = ( 1 << WP_ROCKET_LAUNCHER ); |
| 2010 |
client->ps.ammo[WP_ROCKET_LAUNCHER] = 999; |
| 2011 |
} |
| 2012 |
|
| 2013 |
G_SetOrigin( ent, spawn_origin ); |
| 2014 |
VectorCopy( spawn_origin, client->ps.origin ); |
| 2015 |
|
| 2016 |
// the respawned flag will be cleared after the attack and jump keys come up |
| 2017 |
client->ps.pm_flags |= PMF_RESPAWNED; |
| 2018 |
if(g_gametype.integer==GT_ELIMINATION || g_gametype.integer==GT_CTF_ELIMINATION || g_gametype.integer==GT_LMS) |
| 2019 |
client->ps.pm_flags |= PMF_ELIMWARMUP; |
| 2020 |
|
| 2021 |
trap_GetUsercmd( client - level.clients, &ent->client->pers.cmd ); |
| 2022 |
SetClientViewAngle( ent, spawn_angles ); |
| 2023 |
|
| 2024 |
if ( (ent->client->sess.sessionTeam == TEAM_SPECTATOR) || ((client->ps.pm_type == PM_SPECTATOR || client->isEliminated) && |
| 2025 |
(g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_CTF_ELIMINATION || g_gametype.integer == GT_LMS) ) ) { |
| 2026 |
//Sago: Lets see if this fixes the bots only bug - loose all point on dead bug. (It didn't) |
| 2027 |
/*if(g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_CTF_ELIMINATION || g_gametype.integer == GT_LMS) { |
| 2028 |
G_KillBox( ent ); |
| 2029 |
trap_LinkEntity (ent); |
| 2030 |
}*/ |
| 2031 |
} else { |
| 2032 |
G_KillBox( ent ); |
| 2033 |
trap_LinkEntity (ent); |
| 2034 |
|
| 2035 |
// force the base weapon up |
| 2036 |
client->ps.weapon = WP_MACHINEGUN; |
| 2037 |
client->ps.weaponstate = WEAPON_READY; |
| 2038 |
|
| 2039 |
} |
| 2040 |
|
| 2041 |
// don't allow full run speed for a bit |
| 2042 |
client->ps.pm_flags |= PMF_TIME_KNOCKBACK; |
| 2043 |
client->ps.pm_time = 100; |
| 2044 |
|
| 2045 |
client->respawnTime = level.time; |
| 2046 |
client->inactivityTime = level.time + g_inactivity.integer * 1000; |
| 2047 |
client->latched_buttons = 0; |
| 2048 |
|
| 2049 |
// set default animations |
| 2050 |
client->ps.torsoAnim = TORSO_STAND; |
| 2051 |
client->ps.legsAnim = LEGS_IDLE; |
| 2052 |
|
| 2053 |
if ( level.intermissiontime ) { |
| 2054 |
MoveClientToIntermission( ent ); |
| 2055 |
} else { |
| 2056 |
// fire the targets of the spawn point |
| 2057 |
G_UseTargets( spawnPoint, ent ); |
| 2058 |
|
| 2059 |
// select the highest weapon number available, after any |
| 2060 |
// spawn given items have fired |
| 2061 |
client->ps.weapon = 1; |
| 2062 |
for ( i = WP_NUM_WEAPONS - 1 ; i > 0 ; i-- ) { |
| 2063 |
if ( client->ps.stats[STAT_WEAPONS] & ( 1 << i ) && i !=WP_GRAPPLING_HOOK ) { |
| 2064 |
client->ps.weapon = i; |
| 2065 |
break; |
| 2066 |
} |
| 2067 |
} |
| 2068 |
} |
| 2069 |
|
| 2070 |
// run a client frame to drop exactly to the floor, |
| 2071 |
// initialize animations and other things |
| 2072 |
client->ps.commandTime = level.time - 100; |
| 2073 |
ent->client->pers.cmd.serverTime = level.time; |
| 2074 |
ClientThink( ent-g_entities ); |
| 2075 |
|
| 2076 |
// positively link the client, even if the command times are weird |
| 2077 |
if ( (ent->client->sess.sessionTeam != TEAM_SPECTATOR) || ( (!client->isEliminated || client->ps.pm_type != PM_SPECTATOR)&& |
| 2078 |
(g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_CTF_ELIMINATION || g_gametype.integer == GT_LMS) ) ) { |
| 2079 |
BG_PlayerStateToEntityState( &client->ps, &ent->s, qtrue ); |
| 2080 |
VectorCopy( ent->client->ps.origin, ent->r.currentOrigin ); |
| 2081 |
trap_LinkEntity( ent ); |
| 2082 |
} |
| 2083 |
|
| 2084 |
// run the presend to set anything else |
| 2085 |
ClientEndFrame( ent ); |
| 2086 |
|
| 2087 |
// clear entity state values |
| 2088 |
BG_PlayerStateToEntityState( &client->ps, &ent->s, qtrue ); |
| 2089 |
|
| 2090 |
if(g_spawnprotect.integer) |
| 2091 |
client->spawnprotected = qtrue; |
| 2092 |
|
| 2093 |
RespawnTimeMessage(ent,0); |
| 2094 |
} |
| 2095 |
|
| 2096 |
|
| 2097 |
/* |
| 2098 |
=========== |
| 2099 |
ClientDisconnect |
| 2100 |
|
| 2101 |
Called when a player drops from the server. |
| 2102 |
Will not be called between levels. |
| 2103 |
|
| 2104 |
This should NOT be called directly by any game logic, |
| 2105 |
call trap_DropClient(), which will call this and do |
| 2106 |
server system housekeeping. |
| 2107 |
============ |
| 2108 |
*/ |
| 2109 |
void ClientDisconnect( int clientNum ) { |
| 2110 |
gentity_t *ent; |
| 2111 |
int i; |
| 2112 |
char userinfo[MAX_INFO_STRING]; |
| 2113 |
|
| 2114 |
// cleanup if we are kicking a bot that |
| 2115 |
// hasn't spawned yet |
| 2116 |
G_RemoveQueuedBotBegin( clientNum ); |
| 2117 |
|
| 2118 |
ent = g_entities + clientNum; |
| 2119 |
if ( !ent->client ) { |
| 2120 |
return; |
| 2121 |
} |
| 2122 |
|
| 2123 |
ClientLeaving( clientNum); |
| 2124 |
//KK-OAX Admin |
| 2125 |
G_admin_namelog_update( ent->client, qtrue ); |
| 2126 |
|
| 2127 |
trap_GetUserinfo( clientNum, userinfo, sizeof( userinfo ) ); |
| 2128 |
|
| 2129 |
// stop any following clients |
| 2130 |
for ( i = 0 ; i < level.maxclients ; i++ ) { |
| 2131 |
if ( (level.clients[i].sess.sessionTeam == TEAM_SPECTATOR || level.clients[i].ps.pm_type == PM_SPECTATOR) |
| 2132 |
&& level.clients[i].sess.spectatorState == SPECTATOR_FOLLOW |
| 2133 |
&& level.clients[i].sess.spectatorClient == clientNum ) { |
| 2134 |
StopFollowing( &g_entities[i] ); |
| 2135 |
} |
| 2136 |
} |
| 2137 |
|
| 2138 |
// send effect if they were completely connected |
| 2139 |
/* |
| 2140 |
*Sago: I have removed this. A little dangerous but I make him suicide in a moment. |
| 2141 |
*/ |
| 2142 |
/*if ( ent->client->pers.connected == CON_CONNECTED |
| 2143 |
&& ent->client->sess.sessionTeam != TEAM_SPECTATOR ) { |
| 2144 |
tent = G_TempEntity( ent->client->ps.origin, EV_PLAYER_TELEPORT_OUT ); |
| 2145 |
tent->s.clientNum = ent->s.clientNum; |
| 2146 |
|
| 2147 |
// They don't get to take powerups with them! |
| 2148 |
// Especially important for stuff like CTF flags |
| 2149 |
TossClientItems( ent ); |
| 2150 |
TossClientPersistantPowerups( ent ); |
| 2151 |
if( g_gametype.integer == GT_HARVESTER ) { |
| 2152 |
TossClientCubes( ent ); |
| 2153 |
} |
| 2154 |
//#endif |
| 2155 |
|
| 2156 |
}*/ |
| 2157 |
|
| 2158 |
//Is the player alive? |
| 2159 |
i = (ent->client->ps.stats[STAT_HEALTH]>0); |
| 2160 |
//Commit suicide! |
| 2161 |
if ( ent->client->pers.connected == CON_CONNECTED |
| 2162 |
&& ent->client->sess.sessionTeam != TEAM_SPECTATOR && i ) { |
| 2163 |
//Prevent a team from loosing point because of player leaving |
| 2164 |
int teamscore = 0; |
| 2165 |
if(g_gametype.integer == GT_TEAM) |
| 2166 |
teamscore = level.teamScores[ ent->client->sess.sessionTeam ]; |
| 2167 |
// Kill him (makes sure he loses flags, etc) |
| 2168 |
ent->flags &= ~FL_GODMODE; |
| 2169 |
ent->client->ps.stats[STAT_HEALTH] = ent->health = 0; |
| 2170 |
player_die (ent, ent, g_entities + ENTITYNUM_WORLD, 100000, MOD_SUICIDE); |
| 2171 |
if(g_gametype.integer == GT_TEAM) |
| 2172 |
level.teamScores[ ent->client->sess.sessionTeam ] = teamscore; |
| 2173 |
} |
| 2174 |
|
| 2175 |
|
| 2176 |
|
| 2177 |
if ( ent->client->pers.connected == CON_CONNECTED && ent->client->sess.sessionTeam != TEAM_SPECTATOR) |
| 2178 |
PlayerStore_store(Info_ValueForKey(userinfo,"cl_guid"),ent->client->ps); |
| 2179 |
|
| 2180 |
G_LogPrintf( "ClientDisconnect: %i\n", clientNum ); |
| 2181 |
|
| 2182 |
// if we are playing in tourney mode and losing, give a win to the other player |
| 2183 |
if ( (g_gametype.integer == GT_TOURNAMENT ) |
| 2184 |
&& !level.intermissiontime |
| 2185 |
&& !level.warmupTime && level.sortedClients[1] == clientNum ) { |
| 2186 |
level.clients[ level.sortedClients[0] ].sess.wins++; |
| 2187 |
ClientUserinfoChanged( level.sortedClients[0] ); |
| 2188 |
} |
| 2189 |
|
| 2190 |
if( g_gametype.integer == GT_TOURNAMENT && |
| 2191 |
ent->client->sess.sessionTeam == TEAM_FREE && |
| 2192 |
level.intermissiontime ) { |
| 2193 |
|
| 2194 |
trap_SendConsoleCommand( EXEC_APPEND, "map_restart 0\n" ); |
| 2195 |
level.restarted = qtrue; |
| 2196 |
level.changemap = NULL; |
| 2197 |
level.intermissiontime = 0; |
| 2198 |
} |
| 2199 |
|
| 2200 |
trap_UnlinkEntity (ent); |
| 2201 |
ent->s.modelindex = 0; |
| 2202 |
ent->inuse = qfalse; |
| 2203 |
ent->classname = "disconnected"; |
| 2204 |
ent->client->pers.connected = CON_DISCONNECTED; |
| 2205 |
ent->client->ps.persistant[PERS_TEAM] = TEAM_FREE; |
| 2206 |
ent->client->sess.sessionTeam = TEAM_FREE; |
| 2207 |
|
| 2208 |
trap_SetConfigstring( CS_PLAYERS + clientNum, ""); |
| 2209 |
|
| 2210 |
CalculateRanks(); |
| 2211 |
CountVotes(); |
| 2212 |
|
| 2213 |
if ( ent->r.svFlags & SVF_BOT ) { |
| 2214 |
BotAIShutdownClient( clientNum, qfalse ); |
| 2215 |
} |
| 2216 |
} |
| 2217 |
|
| 2218 |
|