/* =============== Touch_Item =============== */ void Touch_Item( gentity_t *ent, gentity_t *other, trace_t *trace ) { int respawn; int makenoise = EV_ITEM_PICKUP; // only activated items can be picked up if ( !ent->active ) { return; } else { // need to set active to false if player is maxed out ent->active = qfalse; } if ( !other->client ) { return; } if ( other->health < 1 ) { return; // dead people can't pickup } // the same pickup rules are used for client side and server side if ( !BG_CanItemBeGrabbed( &ent->s, &other->client->ps ) ) { return; } G_LogPrintf( "Item: %i %s\n", other->s.number, ent->item->classname ); // call the item-specific pickup function switch ( ent->item->giType ) { case IT_WEAPON: respawn = Pickup_Weapon( ent, other ); break; case IT_AMMO: respawn = Pickup_Ammo( ent, other ); break; case IT_ARMOR: respawn = Pickup_Armor( ent, other ); break; case IT_HEALTH: respawn = Pickup_Health( ent, other ); break; case IT_POWERUP: respawn = Pickup_Powerup( ent, other ); break; case IT_TEAM: respawn = Pickup_Team( ent, other ); break; case IT_HOLDABLE: respawn = Pickup_Holdable( ent, other ); break; case IT_KEY: respawn = Pickup_Key( ent, other ); break; case IT_TREASURE: respawn = Pickup_Treasure( ent, other ); break; case IT_CLIPBOARD: respawn = Pickup_Clipboard( ent, other ); // send the event to the client to request that the UI draw a popup // (specified by the configstring in ent->s.density). //G_AddEvent( other, EV_POPUP, ent->s.density); //if(ent->key) //G_AddEvent( other, EV_GIVEPAGE, ent->key ); break; default: return; } if ( !respawn ) { return; } // play sounds if ( ent->noise_index ) { // (SA) a sound was specified in the entity, so play that sound // (this G_AddEvent) and send the pickup as "EV_ITEM_PICKUP_QUIET" // so it doesn't make the default pickup sound when the pickup event is recieved makenoise = EV_ITEM_PICKUP_QUIET; G_AddEvent( other, EV_GENERAL_SOUND, ent->noise_index ); } // send the pickup event if ( other->client->pers.predictItemPickup ) { G_AddPredictableEvent( other, makenoise, ent->s.modelindex ); } else { G_AddEvent( other, makenoise, ent->s.modelindex ); } // powerup pickups are global broadcasts if ( ent->item->giType == IT_POWERUP || ent->item->giType == IT_TEAM ) { // (SA) probably need to check for IT_KEY here too... (coop?) gentity_t *te; te = G_TempEntity( ent->s.pos.trBase, EV_GLOBAL_ITEM_PICKUP ); te->s.eventParm = ent->s.modelindex; te->r.svFlags |= SVF_BROADCAST; // (SA) set if we want this to only go to the pickup client // te->r.svFlags |= SVF_SINGLECLIENT; // te->r.singleClient = other->s.number; } // fire item targets G_UseTargets( ent, other ); // wait of -1 will not respawn if ( ent->wait == -1 ) { ent->flags |= FL_NODRAW; //ent->r.svFlags |= SVF_NOCLIENT; ent->s.eFlags |= EF_NODRAW; ent->r.contents = 0; ent->unlinkAfterEvent = qtrue; return; } // wait of -2 will respawn but not be available for pickup anymore // (partial use things that leave a spent modle (ex. plate for turkey) if ( respawn == RESPAWN_PARTIAL_DONE ) { ent->s.density = ( 1 << 9 ); // (10 bits of data transmission for density) ent->active = qtrue; // re-activate trap_LinkEntity( ent ); return; } if ( respawn == RESPAWN_PARTIAL ) { // multi-stage health ent->s.density--; if ( ent->s.density ) { // still not completely used up ( (SA) this will change to == 0 and stage 1 will be a destroyable item (plate/etc.) ) ent->active = qtrue; // re-activate trap_LinkEntity( ent ); return; } } // non zero wait overrides respawn time if ( ent->wait ) { respawn = ent->wait; } // random can be used to vary the respawn time if ( ent->random ) { respawn += crandom() * ent->random; if ( respawn < 1 ) { respawn = 1; } } // dropped items will not respawn if ( ent->flags & FL_DROPPED_ITEM ) { ent->freeAfterEvent = qtrue; } // picked up items still stay around, they just don't // draw anything. This allows respawnable items // to be placed on movers. ent->r.svFlags |= SVF_NOCLIENT; ent->flags |= FL_NODRAW; //ent->s.eFlags |= EF_NODRAW; ent->r.contents = 0; // ZOID // A negative respawn times means to never respawn this item (but don't // delete it). This is used by items that are respawned by third party // events such as ctf flags if ( respawn <= 0 ) { ent->nextthink = 0; ent->think = 0; } else { ent->nextthink = level.time + respawn * 1000; ent->think = RespawnItem; } trap_LinkEntity( ent ); }
/* ============= CheckTournament Once a frame, check for changes in tournement player state ============= */ void CheckTournament( void ) { // check because we run 3 game frames before calling Connect and/or ClientBegin // for clients on a map_restart if ( level.numPlayingClients == 0 ) { return; } if ( g_gametype.integer == GT_TOURNAMENT ) { // pull in a spectator if needed if ( level.numPlayingClients < 2 ) { AddTournamentPlayer(); } // if we don't have two players, go back to "waiting for players" if ( level.numPlayingClients != 2 ) { if ( level.warmupTime != -1 ) { level.warmupTime = -1; trap_SetConfigstring( CS_WARMUP, va("%i", level.warmupTime) ); G_LogPrintf( "Warmup:\n" ); } return; } if ( level.warmupTime == 0 ) { return; } // if the warmup is changed at the console, restart it if ( g_warmup.modificationCount != level.warmupModificationCount ) { level.warmupModificationCount = g_warmup.modificationCount; level.warmupTime = -1; } // if all players have arrived, start the countdown if ( level.warmupTime < 0 ) { if ( level.numPlayingClients == 2 ) { // fudge by -1 to account for extra delays if ( g_warmup.integer > 1 ) { level.warmupTime = level.time + ( g_warmup.integer - 1 ) * 1000; } else { level.warmupTime = 0; } trap_SetConfigstring( CS_WARMUP, va("%i", level.warmupTime) ); } return; } // if the warmup time has counted down, restart if ( level.time > level.warmupTime ) { level.warmupTime += 10000; trap_Cvar_Set( "g_restarted", "1" ); trap_SendConsoleCommand( EXEC_APPEND, "map_restart 0\n" ); level.restarted = qtrue; return; } } else if ( g_gametype.integer != GT_SINGLE_PLAYER && level.warmupTime != 0 ) { int counts[TEAM_NUM_TEAMS]; qboolean notEnough = qfalse; if ( g_gametype.integer > GT_TEAM ) { counts[TEAM_BLUE] = TeamCount( -1, TEAM_BLUE ); counts[TEAM_RED] = TeamCount( -1, TEAM_RED ); if (counts[TEAM_RED] < 1 || counts[TEAM_BLUE] < 1) { notEnough = qtrue; } } else if ( level.numPlayingClients < 2 ) { notEnough = qtrue; } if ( notEnough ) { if ( level.warmupTime != -1 ) { level.warmupTime = -1; trap_SetConfigstring( CS_WARMUP, va("%i", level.warmupTime) ); G_LogPrintf( "Warmup:\n" ); } return; // still waiting for team members } if ( level.warmupTime == 0 ) { return; } // if the warmup is changed at the console, restart it if ( g_warmup.modificationCount != level.warmupModificationCount ) { level.warmupModificationCount = g_warmup.modificationCount; level.warmupTime = -1; } // if all players have arrived, start the countdown if ( level.warmupTime < 0 ) { // fudge by -1 to account for extra delays level.warmupTime = level.time + ( g_warmup.integer - 1 ) * 1000; trap_SetConfigstring( CS_WARMUP, va("%i", level.warmupTime) ); return; } // if the warmup time has counted down, restart if ( level.time > level.warmupTime ) { level.warmupTime += 10000; trap_Cvar_Set( "g_restarted", "1" ); trap_SendConsoleCommand( EXEC_APPEND, "map_restart 0\n" ); level.restarted = qtrue; return; } } }
// Dumps end-of-match info void G_matchInfoDump(unsigned int dwDumpType) { int i, ref; gentity_t *ent; gclient_t *cl; for(i=0; i<level.numConnectedClients; i++ ) { ref = level.sortedClients[i]; ent = &g_entities[ref]; cl = ent->client; if(cl->pers.connected != CON_CONNECTED) continue; if(dwDumpType == EOM_WEAPONSTATS) { // forty - #607 - Merge in Density's damage received display code // If client wants to write stats to a file, don't auto send this stuff if(!(cl->pers.clientFlags & CGF_STATSDUMP)) { if((cl->pers.autoaction & AA_STATSALL) || cl->pers.mvCount > 0) { G_statsall_cmd(ent, 0, qfalse); } else if(cl->sess.sessionTeam != TEAM_SPECTATOR) { if(cl->pers.autoaction & AA_STATSTEAM) G_statsall_cmd(ent, cl->sess.sessionTeam, qfalse); // Currently broken.. need to support the overloading of dwCommandID else CP(va("ws %s\n", G_createStats(ent, ent))); } else if(cl->sess.spectatorState != SPECTATOR_FREE) { int pid = cl->sess.spectatorClient; if((cl->pers.autoaction & AA_STATSTEAM)) G_statsall_cmd(ent, level.clients[pid].sess.sessionTeam, qfalse); // Currently broken.. need to support the overloading of dwCommandID else CP(va("ws %s\n", G_createStats(g_entities + pid, ent))); } } // Log it if(cl->sess.sessionTeam != TEAM_SPECTATOR) { G_LogPrintf("WeaponStats: %s\n", G_createStats(ent, NULL)); } } else if(dwDumpType == EOM_MATCHINFO) { if(!(cl->pers.clientFlags & CGF_STATSDUMP)) G_printMatchInfo(ent); if(g_gametype.integer == GT_WOLF_STOPWATCH) { if(g_currentRound.integer == 1) { // We've already missed the switch CP(va("print \">>> ^3Clock set to: %d:%02d\n\n\n\"", g_nextTimeLimit.integer, (int)(60.0 * (float)(g_nextTimeLimit.value - g_nextTimeLimit.integer)))); } else { float val = (float)((level.timeCurrent - (level.startTime + level.time - level.intermissiontime)) / 60000.0); if(val < g_timelimit.value) { CP(va("print \">>> ^3Objective reached at %d:%02d (original: %d:%02d)\n\n\n\"", (int)val, (int)(60.0 * (val - (int)val)), g_timelimit.integer, (int)(60.0 * (float)(g_timelimit.value - g_timelimit.integer)))); } else { CP(va("print \">>> ^3Objective NOT reached in time (%d:%02d)\n\n\n\"", g_timelimit.integer, (int)(60.0 * (float)(g_timelimit.value - g_timelimit.integer)))); } } } } } }
/* =========== ClientConnect Called when a player begins connecting to the server. Called again for every map change or tournement restart. The session information will be valid after exit. Return NULL if the client should be allowed, otherwise return a string with the reason for denial. Otherwise, the client will be sent the current gamestate and will eventually get to ClientBegin. firstTime will be qtrue the very first time a client connects to the server machine, but qfalse on map changes and tournement restarts. ============ */ char *ClientConnect( int clientNum, qboolean firstTime ) { char *value; char *userInfoError; gclient_t *client; char userinfo[ MAX_INFO_STRING ]; char pubkey[ RSA_STRING_LENGTH ]; gentity_t *ent; char reason[ MAX_STRING_CHARS ] = { "" }; int i; ent = &g_entities[ clientNum ]; client = &level.clients[ clientNum ]; // ignore if client already connected if ( client->pers.connected != CON_DISCONNECTED ) { return NULL; } ent->client = client; memset( client, 0, sizeof( *client ) ); trap_GetUserinfo( clientNum, userinfo, sizeof( userinfo ) ); value = Info_ValueForKey( userinfo, "ip" ); // check for local client if ( !strcmp( value, "localhost" ) ) { client->pers.localClient = qtrue; } G_AddressParse( value, &client->pers.ip ); trap_GetPlayerPubkey( clientNum, pubkey, sizeof( pubkey ) ); if ( strlen( pubkey ) != RSA_STRING_LENGTH - 1 ) { return "Invalid pubkey key"; } trap_GenFingerprint( pubkey, sizeof( pubkey ), client->pers.guid, sizeof( client->pers.guid ) ); client->pers.admin = G_admin_admin( client->pers.guid ); client->pers.pubkey_authenticated = 0; if ( client->pers.admin ) { trap_RealTime( &client->pers.admin->lastSeen ); } // check for admin ban if ( G_admin_ban_check( ent, reason, sizeof( reason ) ) ) { return va( "%s", reason ); // reason is local } // check for a password value = Info_ValueForKey( userinfo, "password" ); if ( g_password.string[ 0 ] && Q_stricmp( g_password.string, "none" ) && strcmp( g_password.string, value ) != 0 ) { return "Invalid password"; } // if a player reconnects quickly after a disconnect, the client disconnect may never be called, thus flag can get lost in the ether if ( ent->inuse ) { G_LogPrintf( "Forcing disconnect on active client: %i\n", (int)( ent - g_entities ) ); // so lets just fix up anything that should happen on a disconnect ClientDisconnect( ent-g_entities ); } for ( i = 0; i < level.maxclients; i++ ) { if ( level.clients[ i ].pers.connected == CON_DISCONNECTED ) { continue; } if ( !Q_stricmp( client->pers.guid, level.clients[ i ].pers.guid ) ) { if ( !G_ClientIsLagging( level.clients + i ) ) { trap_SendServerCommand( i, "cp \"Your GUID is not secure\"" ); return "Duplicate GUID"; } trap_DropClient( i, "Ghost" ); } } client->pers.connected = CON_CONNECTING; // read or initialize the session data if ( firstTime ) { G_InitSessionData( client, userinfo ); } G_ReadSessionData( client ); // get and distribute relevent paramters G_namelog_connect( client ); userInfoError = ClientUserinfoChanged( clientNum, qfalse ); if ( userInfoError != NULL ) { return userInfoError; } G_LogPrintf( "ClientConnect: %i [%s] (%s) \"%s^7\" \"%c%s%c^7\"\n", clientNum, client->pers.ip.str, client->pers.guid, client->pers.netname, DECOLOR_OFF, client->pers.netname, DECOLOR_ON ); // don't do the "xxx connected" messages if they were caried over from previous level if ( firstTime ) { trap_SendServerCommand( -1, va( "print_tr %s %s", QQ( N_("$1$^7 connected\n") ), Quote( client->pers.netname ) ) ); } // count current clients and rank for scoreboard CalculateRanks(); // if this is after !restart keepteams or !restart switchteams, apply said selection if ( client->sess.restartTeam != TEAM_NONE ) { G_ChangeTeam( ent, client->sess.restartTeam ); client->sess.restartTeam = TEAM_NONE; } return NULL; }
/* =========== ClientUserInfoChanged Called from ClientConnect when the player first connects and directly by the server system when the player updates a userinfo variable. The game can override any of the settings and call trap_SetUserinfo if desired. ============ */ char *ClientUserinfoChanged( int clientNum, qboolean forceName ) { gentity_t *ent; char *s; char model[ MAX_QPATH ]; char buffer[ MAX_QPATH ]; char filename[ MAX_QPATH ]; char oldname[ MAX_NAME_LENGTH ]; char newname[ MAX_NAME_LENGTH ]; char err[ MAX_STRING_CHARS ]; qboolean revertName = qfalse; gclient_t *client; char userinfo[ MAX_INFO_STRING ]; ent = g_entities + clientNum; client = ent->client; trap_GetUserinfo( clientNum, userinfo, sizeof( userinfo ) ); // check for malformed or illegal info strings if ( !Info_Validate( userinfo ) ) { trap_SendServerCommand( ent - g_entities, "disconnect \"illegal or malformed userinfo\n\"" ); trap_DropClient( ent - g_entities, "dropped: illegal or malformed userinfo" ); return "Illegal or malformed userinfo"; } // If their userinfo overflowed, tremded is in the process of disconnecting them. // If we send our own disconnect, it won't work, so just return to prevent crashes later // in this function. This check must come after the Info_Validate call. else if ( !userinfo[ 0 ] ) { return "Empty (overflowed) userinfo"; } // stickyspec toggle s = Info_ValueForKey( userinfo, "cg_stickySpec" ); client->pers.stickySpec = atoi( s ) != 0; // set name Q_strncpyz( oldname, client->pers.netname, sizeof( oldname ) ); s = Info_ValueForKey( userinfo, "name" ); G_ClientCleanName( s, newname, sizeof( newname ), client ); if ( strcmp( oldname, newname ) ) { if ( !forceName && client->pers.namelog->nameChangeTime && level.time - client->pers.namelog->nameChangeTime <= g_minNameChangePeriod.value * 1000 ) { trap_SendServerCommand( ent - g_entities, va( "print_tr %s %d", QQ( N_("Name change spam protection (g_minNameChangePeriod = $1$)\n") ), g_minNameChangePeriod.integer ) ); revertName = qtrue; } else if ( !forceName && g_maxNameChanges.integer > 0 && client->pers.namelog->nameChanges >= g_maxNameChanges.integer ) { trap_SendServerCommand( ent - g_entities, va( "print_tr %s %d", QQ( N_("Maximum name changes reached (g_maxNameChanges = $1$)\n") ), g_maxNameChanges.integer ) ); revertName = qtrue; } else if ( !forceName && client->pers.namelog->muted ) { trap_SendServerCommand( ent - g_entities, va( "print_tr %s", QQ( N_("You cannot change your name while you are muted\n") ) ) ); revertName = qtrue; } else if ( !G_admin_name_check( ent, newname, err, sizeof( err ) ) ) { trap_SendServerCommand( ent - g_entities, va( "print_tr %s %s %s", QQ( "$1t$ $2$\n" ), Quote( err ), Quote( newname ) ) ); revertName = qtrue; } if ( revertName ) { Q_strncpyz( client->pers.netname, *oldname ? oldname : G_UnnamedClientName( client ), sizeof( client->pers.netname ) ); Info_SetValueForKey( userinfo, "name", oldname ); trap_SetUserinfo( clientNum, userinfo ); } else { if( G_IsUnnamed( newname ) ) { Q_strncpyz( newname, G_UnnamedClientName( client ), sizeof( newname ) ); } G_CensorString( client->pers.netname, newname, sizeof( client->pers.netname ), ent ); if ( !forceName && client->pers.connected == CON_CONNECTED ) { client->pers.namelog->nameChangeTime = level.time; client->pers.namelog->nameChanges++; } if ( *oldname ) { G_LogPrintf( "ClientRename: %i [%s] (%s) \"%s^7\" -> \"%s^7\" \"%c%s%c^7\"\n", clientNum, client->pers.ip.str, client->pers.guid, oldname, client->pers.netname, DECOLOR_OFF, client->pers.netname, DECOLOR_ON ); } } G_namelog_update_name( client ); } if ( client->pers.classSelection == PCL_NONE ) { //This looks hacky and frankly it is. The clientInfo string needs to hold different //model details to that of the spawning class or the info change will not be //registered and an axis appears instead of the player model. There is zero chance //the player can spawn with the battlesuit, hence this choice. Com_sprintf( buffer, MAX_QPATH, "%s/%s", BG_ClassConfig( PCL_HUMAN_BSUIT )->modelName, BG_ClassConfig( PCL_HUMAN_BSUIT )->skinName ); } else { Com_sprintf( buffer, MAX_QPATH, "%s/%s", BG_ClassConfig( client->pers.classSelection )->modelName, BG_ClassConfig( client->pers.classSelection )->skinName ); //model segmentation Com_sprintf( filename, sizeof( filename ), "models/players/%s/animation.cfg", BG_ClassConfig( client->pers.classSelection )->modelName ); if ( G_NonSegModel( filename ) ) { client->ps.persistant[ PERS_STATE ] |= PS_NONSEGMODEL; } else { client->ps.persistant[ PERS_STATE ] &= ~PS_NONSEGMODEL; } } Q_strncpyz( model, buffer, sizeof( model ) ); // wallwalk follow s = Info_ValueForKey( userinfo, "cg_wwFollow" ); if ( atoi( s ) ) { client->ps.persistant[ PERS_STATE ] |= PS_WALLCLIMBINGFOLLOW; } else { client->ps.persistant[ PERS_STATE ] &= ~PS_WALLCLIMBINGFOLLOW; } // wallwalk toggle s = Info_ValueForKey( userinfo, "cg_wwToggle" ); if ( atoi( s ) ) { client->ps.persistant[ PERS_STATE ] |= PS_WALLCLIMBINGTOGGLE; } else { client->ps.persistant[ PERS_STATE ] &= ~PS_WALLCLIMBINGTOGGLE; } // always sprint s = Info_ValueForKey( userinfo, "cg_sprintToggle" ); if ( atoi( s ) ) { client->ps.persistant[ PERS_STATE ] |= PS_SPRINTTOGGLE; } else { client->ps.persistant[ PERS_STATE ] &= ~PS_SPRINTTOGGLE; } // fly speed s = Info_ValueForKey( userinfo, "cg_flySpeed" ); if ( *s ) { client->pers.flySpeed = atoi( s ); } else { client->pers.flySpeed = BG_Class( PCL_NONE )->speed; } // disable blueprint errors s = Info_ValueForKey( userinfo, "cg_disableBlueprintErrors" ); if ( atoi( s ) ) { client->pers.disableBlueprintErrors = qtrue; } else { client->pers.disableBlueprintErrors = qfalse; } client->pers.buildableRangeMarkerMask = atoi( Info_ValueForKey( userinfo, "cg_buildableRangeMarkerMask" ) ); // teamInfo s = Info_ValueForKey( userinfo, "teamoverlay" ); if ( atoi( s ) != 0 ) { client->pers.teamInfo = qtrue; } else { client->pers.teamInfo = qfalse; } s = Info_ValueForKey( userinfo, "cg_unlagged" ); if ( !s[ 0 ] || atoi( s ) != 0 ) { client->pers.useUnlagged = qtrue; } else { client->pers.useUnlagged = qfalse; } Q_strncpyz( client->pers.voice, Info_ValueForKey( userinfo, "voice" ), sizeof( client->pers.voice ) ); // send over a subset of the userinfo keys so other clients can // print scoreboards, display models, and play custom sounds Com_sprintf( userinfo, sizeof( userinfo ), "n\\%s\\t\\%i\\model\\%s\\ig\\%16s\\v\\%s", client->pers.netname, client->pers.teamSelection, model, Com_ClientListString( &client->sess.ignoreList ), client->pers.voice ); trap_SetConfigstring( CS_PLAYERS + clientNum, userinfo ); /*G_LogPrintf( "ClientUserinfoChanged: %i %s\n", clientNum, userinfo );*/ return NULL; }
void G_Say( gentity_t *ent, gentity_t *target, int mode, const char *chatText ) { int j; gentity_t *other; int color; char name[64]; // don't let text be too long for malicious reasons char text[MAX_SAY_TEXT]; char location[64]; if ( g_gametype.integer < GT_TEAM && mode == SAY_TEAM ) { mode = SAY_ALL; } switch ( mode ) { default: case SAY_ALL: G_LogPrintf( "say: %s: %s\n", ent->client->pers.netname, chatText ); // >>> FIX: For Nintendo Wii using devkitPPC / libogc // Using renamed color constants: //Com_sprintf (name, sizeof(name), "%s%c%c"EC": ", ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE ); //color = COLOR_GREEN; Com_sprintf (name, sizeof(name), "%s%c%c"EC": ", ent->client->pers.netname, Q_COLOR_ESCAPE, Q_COLOR_WHITE ); color = Q_COLOR_GREEN; // <<< FIX break; case SAY_TEAM: G_LogPrintf( "sayteam: %s: %s\n", ent->client->pers.netname, chatText ); if (Team_GetLocationMsg(ent, location, sizeof(location))) Com_sprintf (name, sizeof(name), EC"(%s%c%c"EC") (%s)"EC": ", // >>> FIX: For Nintendo Wii using devkitPPC / libogc // Using renamed color constants: //ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE, location); ent->client->pers.netname, Q_COLOR_ESCAPE, Q_COLOR_WHITE, location); // <<< FIX else Com_sprintf (name, sizeof(name), EC"(%s%c%c"EC")"EC": ", // >>> FIX: For Nintendo Wii using devkitPPC / libogc // Using renamed color constants: // ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE ); //color = COLOR_CYAN; ent->client->pers.netname, Q_COLOR_ESCAPE, Q_COLOR_WHITE ); color = Q_COLOR_CYAN; // <<< FIX break; case SAY_TELL: if (target && g_gametype.integer >= GT_TEAM && target->client->sess.sessionTeam == ent->client->sess.sessionTeam && Team_GetLocationMsg(ent, location, sizeof(location))) // >>> FIX: For Nintendo Wii using devkitPPC / libogc // Using renamed color constants: // Com_sprintf (name, sizeof(name), EC"[%s%c%c"EC"] (%s)"EC": ", ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE, location ); //else // Com_sprintf (name, sizeof(name), EC"[%s%c%c"EC"]"EC": ", ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE ); //color = COLOR_MAGENTA; Com_sprintf (name, sizeof(name), EC"[%s%c%c"EC"] (%s)"EC": ", ent->client->pers.netname, Q_COLOR_ESCAPE, Q_COLOR_WHITE, location ); else Com_sprintf (name, sizeof(name), EC"[%s%c%c"EC"]"EC": ", ent->client->pers.netname, Q_COLOR_ESCAPE, Q_COLOR_WHITE ); color = Q_COLOR_MAGENTA; // <<< FIX break; } Q_strncpyz( text, chatText, sizeof(text) ); if ( target ) { G_SayTo( ent, target, mode, color, name, text ); return; } // echo the text to the console if ( g_dedicated.integer ) { G_Printf( "%s%s\n", name, text); } // send it to all the apropriate clients for (j = 0; j < level.maxclients; j++) { other = &g_entities[j]; G_SayTo( ent, other, mode, color, name, text ); } }
/* =========== ClientUserInfoChanged Called from ClientConnect when the player first connects and directly by the server system when the player updates a userinfo variable. The game can override any of the settings and call trap_SetUserinfo if desired. ============ */ void ClientUserinfoChanged( int clientNum ) { gentity_t *ent; int teamTask, teamLeader; char *s; char model[MAX_QPATH]; char headModel[MAX_QPATH]; char oldname[MAX_STRING_CHARS]; gclient_t *client; char c1[MAX_INFO_STRING]; char c2[MAX_INFO_STRING]; char userinfo[MAX_INFO_STRING]; ent = g_entities + clientNum; client = ent->client; trap_GetUserinfo( clientNum, userinfo, sizeof( userinfo ) ); // check for malformed or illegal info strings if ( !Info_Validate(userinfo) ) { strcpy (userinfo, "\\name\\badinfo"); // don't keep those clients and userinfo trap_DropClient(clientNum, "Invalid userinfo"); } // check for local client s = Info_ValueForKey( userinfo, "ip" ); if ( !strcmp( s, "localhost" ) ) { client->pers.localClient = qtrue; } // check the item prediction s = Info_ValueForKey( userinfo, "cg_predictItems" ); if ( !atoi( s ) ) { client->pers.predictItemPickup = qfalse; } else { client->pers.predictItemPickup = qtrue; } // set name Q_strncpyz ( oldname, client->pers.netname, sizeof( oldname ) ); s = Info_ValueForKey (userinfo, "name"); ClientCleanName( s, client->pers.netname, sizeof(client->pers.netname) ); if ( client->sess.sessionTeam == TEAM_SPECTATOR ) { if ( client->sess.spectatorState == SPECTATOR_SCOREBOARD ) { Q_strncpyz( client->pers.netname, "scoreboard", sizeof(client->pers.netname) ); } } if ( client->pers.connected == CON_CONNECTED ) { if ( strcmp( oldname, client->pers.netname ) ) { trap_SendServerCommand( -1, va("print \"%s" S_COLOR_WHITE " renamed to %s\n\"", oldname, client->pers.netname) ); } } // set max health #ifdef MISSIONPACK if (client->ps.powerups[PW_GUARD]) { client->pers.maxHealth = 200; } else { client->pers.maxHealth = ClientHandicap( client ); } #else client->pers.maxHealth = ClientHandicap( client ); #endif client->ps.stats[STAT_MAX_HEALTH] = client->pers.maxHealth; // set model if( g_gametype.integer >= GT_TEAM ) { Q_strncpyz( model, Info_ValueForKey (userinfo, "team_model"), sizeof( model ) ); Q_strncpyz( headModel, Info_ValueForKey (userinfo, "team_headmodel"), sizeof( headModel ) ); } else { Q_strncpyz( model, Info_ValueForKey (userinfo, "model"), sizeof( model ) ); Q_strncpyz( headModel, Info_ValueForKey (userinfo, "headmodel"), sizeof( headModel ) ); } /* NOTE: all client side now // team switch( team ) { case TEAM_RED: ForceClientSkin(client, model, "red"); // ForceClientSkin(client, headModel, "red"); break; case TEAM_BLUE: ForceClientSkin(client, model, "blue"); // ForceClientSkin(client, headModel, "blue"); break; } // don't ever use a default skin in teamplay, it would just waste memory // however bots will always join a team but they spawn in as spectator if ( g_gametype.integer >= GT_TEAM && team == TEAM_SPECTATOR) { ForceClientSkin(client, model, "red"); // ForceClientSkin(client, headModel, "red"); } */ #ifdef MISSIONPACK if (g_gametype.integer >= GT_TEAM) { client->pers.teamInfo = qtrue; } else { s = Info_ValueForKey( userinfo, "teamoverlay" ); if ( ! *s || atoi( s ) != 0 ) { client->pers.teamInfo = qtrue; } else { client->pers.teamInfo = qfalse; } } #else // teamInfo s = Info_ValueForKey( userinfo, "teamoverlay" ); if ( ! *s || atoi( s ) != 0 ) { client->pers.teamInfo = qtrue; } else { client->pers.teamInfo = qfalse; } #endif /* s = Info_ValueForKey( userinfo, "cg_pmove_fixed" ); if ( !*s || atoi( s ) == 0 ) { client->pers.pmoveFixed = qfalse; } else { client->pers.pmoveFixed = qtrue; } */ // team task (0 = none, 1 = offence, 2 = defence) teamTask = atoi(Info_ValueForKey(userinfo, "teamtask")); // team Leader (1 = leader, 0 is normal player) teamLeader = client->sess.teamLeader; // colors strcpy(c1, Info_ValueForKey( userinfo, "color1" )); strcpy(c2, Info_ValueForKey( userinfo, "color2" )); // send over a subset of the userinfo keys so other clients can // print scoreboards, display models, and play custom sounds if (ent->r.svFlags & SVF_BOT) { 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", client->pers.netname, client->sess.sessionTeam, model, headModel, c1, c2, client->pers.maxHealth, client->sess.wins, client->sess.losses, Info_ValueForKey( userinfo, "skill" ), teamTask, teamLeader ); } else { s = va("n\\%s\\t\\%i\\model\\%s\\hmodel\\%s\\c1\\%s\\c2\\%s\\hc\\%i\\w\\%i\\l\\%i\\tt\\%d\\tl\\%d", client->pers.netname, client->sess.sessionTeam, model, headModel, c1, c2, client->pers.maxHealth, client->sess.wins, client->sess.losses, teamTask, teamLeader); } trap_SetConfigstring( CS_PLAYERS+clientNum, s ); // this is not the userinfo, more like the configstring actually G_LogPrintf( "ClientUserinfoChanged: %i %s\n", clientNum, s ); }
void player_die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int meansOfDeath ) { gentity_t *ent; // TTimo might be used uninitialized int contents = 0; int killer; int i; char *killerName, *obit; qboolean nogib = qtrue; gitem_t *item = NULL; // JPW NERVE for flag drop vec3_t launchvel,launchspot; // JPW NERVE gentity_t *flag; // JPW NERVE if ( self->client->ps.pm_type == PM_DEAD ) { return; } if ( level.intermissiontime ) { return; } self->client->ps.pm_type = PM_DEAD; G_AddEvent( self, EV_STOPSTREAMINGSOUND, 0 ); if ( attacker ) { killer = attacker->s.number; if ( attacker->client ) { killerName = attacker->client->pers.netname; } else { killerName = "<non-client>"; } } else { killer = ENTITYNUM_WORLD; killerName = "<world>"; } if ( killer < 0 || killer >= MAX_CLIENTS ) { killer = ENTITYNUM_WORLD; killerName = "<world>"; } if ( meansOfDeath < 0 || meansOfDeath >= sizeof( modNames ) / sizeof( modNames[0] ) ) { obit = "<bad obituary>"; } else { obit = modNames[ meansOfDeath ]; } G_LogPrintf( "Kill: %i %i %i: %s killed %s by %s\n", killer, self->s.number, meansOfDeath, killerName, self->client->pers.netname, obit ); // broadcast the death event to everyone ent = G_TempEntity( self->r.currentOrigin, EV_OBITUARY ); ent->s.eventParm = meansOfDeath; ent->s.otherEntityNum = self->s.number; ent->s.otherEntityNum2 = killer; ent->r.svFlags = SVF_BROADCAST; // send to everyone self->enemy = attacker; self->client->ps.persistant[PERS_KILLED]++; // JPW NERVE -- if player is holding ticking grenade, drop it if ( g_gametype.integer != GT_SINGLE_PLAYER ) { if ( ( self->client->ps.grenadeTimeLeft ) && ( self->s.weapon != WP_DYNAMITE ) ) { launchvel[0] = crandom(); launchvel[1] = crandom(); launchvel[2] = random(); VectorScale( launchvel, 160, launchvel ); VectorCopy( self->r.currentOrigin, launchspot ); launchspot[2] += 40; fire_grenade( self, launchspot, launchvel, self->s.weapon ); } } // jpw if ( attacker && attacker->client ) { if ( attacker == self || OnSameTeam( self, attacker ) ) { // DHM - Nerve :: Complaint lodging if ( attacker != self && level.warmupTime <= 0 ) { if ( attacker->client->pers.localClient ) { trap_SendServerCommand( self - g_entities, "complaint -4" ); } else { trap_SendServerCommand( self - g_entities, va( "complaint %i", attacker->s.number ) ); self->client->pers.complaintClient = attacker->s.clientNum; self->client->pers.complaintEndTime = level.time + 20500; } } // dhm // JPW NERVE if ( g_gametype.integer >= GT_WOLF ) { // high penalty to offset medic heal AddScore( attacker, WOLF_FRIENDLY_PENALTY ); } else { // jpw AddScore( attacker, -1 ); } } else { // JPW NERVE -- mostly added as conveneience so we can tweak from the #defines all in one place if ( g_gametype.integer >= GT_WOLF ) { AddScore( attacker, WOLF_FRAG_BONUS ); } else { // jpw AddScore( attacker, 1 ); } attacker->client->lastKillTime = level.time; } } else { AddScore( self, -1 ); } // Add team bonuses Team_FragBonuses( self, inflictor, attacker ); // if client is in a nodrop area, don't drop anything // JPW NERVE new drop behavior if ( g_gametype.integer == GT_SINGLE_PLAYER ) { // only drop here in single player; in multiplayer, drop @ limbo contents = trap_PointContents( self->r.currentOrigin, -1 ); if ( !( contents & CONTENTS_NODROP ) ) { TossClientItems( self ); } } // drop flag regardless if ( g_gametype.integer != GT_SINGLE_PLAYER ) { if ( self->client->ps.powerups[PW_REDFLAG] ) { item = BG_FindItem( "Red Flag" ); if ( !item ) { item = BG_FindItem( "Objective" ); } self->client->ps.powerups[PW_REDFLAG] = 0; } if ( self->client->ps.powerups[PW_BLUEFLAG] ) { item = BG_FindItem( "Blue Flag" ); if ( !item ) { item = BG_FindItem( "Objective" ); } self->client->ps.powerups[PW_BLUEFLAG] = 0; } if ( item ) { launchvel[0] = crandom() * 20; launchvel[1] = crandom() * 20; launchvel[2] = 10 + random() * 10; flag = LaunchItem( item,self->r.currentOrigin,launchvel,self->s.number ); flag->s.modelindex2 = self->s.otherEntityNum2; // JPW NERVE FIXME set player->otherentitynum2 with old modelindex2 from flag and restore here flag->message = self->message; // DHM - Nerve :: also restore item name // Clear out player's temp copies self->s.otherEntityNum2 = 0; self->message = NULL; } // send a fancy "MEDIC!" scream. Sissies, ain' they? if ( self->client != NULL ) { if ( self->health > GIB_HEALTH && meansOfDeath != MOD_SUICIDE ) { if ( self->client->sess.sessionTeam == TEAM_RED ) { if ( random() > 0.5 ) { G_AddEvent( self, EV_GENERAL_SOUND, G_SoundIndex( "sound/multiplayer/axis/g-medic2.wav" ) ); } else { G_AddEvent( self, EV_GENERAL_SOUND, G_SoundIndex( "sound/multiplayer/axis/g-medic3.wav" ) ); } } else { if ( random() > 0.5 ) { G_AddEvent( self, EV_GENERAL_SOUND, G_SoundIndex( "sound/multiplayer/allies/a-medic3.wav" ) ); } else { G_AddEvent( self, EV_GENERAL_SOUND, G_SoundIndex( "sound/multiplayer/allies/a-medic2.wav" ) ); } } } } } // jpw Cmd_Score_f( self ); // show scores // send updated scores to any clients that are following this one, // or they would get stale scoreboards for ( i = 0 ; i < level.maxclients ; i++ ) { gclient_t *client; client = &level.clients[i]; if ( client->pers.connected != CON_CONNECTED ) { continue; } if ( client->sess.sessionTeam != TEAM_SPECTATOR ) { continue; } if ( client->sess.spectatorClient == self->s.number ) { Cmd_Score_f( g_entities + i ); } } self->takedamage = qtrue; // can still be gibbed self->r.contents = CONTENTS_CORPSE; self->s.powerups = 0; // JPW NERVE -- only corpse in SP; in MP, need CONTENTS_BODY so medic can operate if ( g_gametype.integer == GT_SINGLE_PLAYER ) { self->s.weapon = WP_NONE; self->s.angles[0] = 0; } else { self->client->limboDropWeapon = self->s.weapon; // store this so it can be dropped in limbo } // jpw self->s.angles[2] = 0; LookAtKiller( self, inflictor, attacker ); VectorCopy( self->s.angles, self->client->ps.viewangles ); self->s.loopSound = 0; trap_UnlinkEntity( self ); self->r.maxs[2] = 0; self->client->ps.maxs[2] = 0; trap_LinkEntity( self ); // don't allow respawn until the death anim is done // g_forcerespawn may force spawning at some later time self->client->respawnTime = level.time + 800; // remove powerups memset( self->client->ps.powerups, 0, sizeof( self->client->ps.powerups ) ); // never gib in a nodrop if ( self->health <= GIB_HEALTH && !( contents & CONTENTS_NODROP ) ) { GibEntity( self, killer ); nogib = qfalse; } if ( nogib ) { // normal death // for the no-blood option, we need to prevent the health // from going to gib level if ( self->health <= GIB_HEALTH ) { self->health = GIB_HEALTH + 1; } // JPW NERVE for medic self->client->medicHealAmt = 0; // jpw // DHM - Play death animation, and set pm_time to delay 'fallen' animation self->client->ps.pm_time = BG_AnimScriptEvent( &self->client->ps, ANIM_ET_DEATH, qfalse, qtrue ); G_AddEvent( self, EV_DEATH1 + 1, killer ); // the body can still be gibbed self->die = body_die; } trap_LinkEntity( self ); if ( g_gametype.integer >= GT_WOLF && meansOfDeath == MOD_SUICIDE ) { limbo( self, qtrue ); } }
/* ================== player_die ================== */ void player_die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int meansOfDeath ) { gentity_t *ent; int anim; int contents; int killer; int i; const char *killerName, *obit; if ( self->client->ps.pm_type == PM_DEAD ) { return; } if ( level.intermissiontime ) { return; } // check for an almost capture CheckAlmostCapture( self, attacker ); // check for a player that almost brought in cubes CheckAlmostScored( self, attacker ); if (self->client && self->client->hook) { Weapon_HookFree(self->client->hook); } #ifdef MISSIONPACK if ((self->client->ps.eFlags & EF_TICKING) && self->activator) { self->client->ps.eFlags &= ~EF_TICKING; self->activator->think = G_FreeEntity; self->activator->nextthink = level.time; } #endif self->client->ps.pm_type = PM_DEAD; if ( attacker ) { killer = attacker->s.number; if ( attacker->client ) { killerName = attacker->client->pers.netname; } else { killerName = "<non-client>"; } } else { killer = ENTITYNUM_WORLD; killerName = "<world>"; } if ( killer < 0 || killer >= MAX_CLIENTS ) { killer = ENTITYNUM_WORLD; killerName = "<world>"; } if ( meansOfDeath < 0 || meansOfDeath >= sizeof( modNames ) / sizeof( modNames[0] ) ) { obit = "<bad obituary>"; } else { obit = modNames[ meansOfDeath ]; } G_LogPrintf("Kill: %i %i %i: %s killed %s by %s\n", killer, self->s.number, meansOfDeath, killerName, self->client->pers.netname, obit ); // broadcast the death event to everyone ent = G_TempEntity( self->r.currentOrigin, EV_OBITUARY ); ent->s.eventParm = meansOfDeath; ent->s.otherEntityNum = self->s.number; ent->s.otherEntityNum2 = killer; ent->r.svFlags = SVF_BROADCAST; // send to everyone self->enemy = attacker; self->client->ps.persistant[PERS_KILLED]++; if (attacker && attacker->client) { attacker->client->lastkilled_client = self->s.number; if ( attacker == self || OnSameTeam (self, attacker ) ) { AddScore( attacker, self->r.currentOrigin, -1 ); } else { AddScore( attacker, self->r.currentOrigin, 1 ); if( meansOfDeath == MOD_GAUNTLET ) { // play humiliation on player attacker->client->ps.persistant[PERS_GAUNTLET_FRAG_COUNT]++; // add the sprite over the player's head attacker->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP ); attacker->client->ps.eFlags |= EF_AWARD_GAUNTLET; attacker->client->rewardTime = level.time + REWARD_SPRITE_TIME; // also play humiliation on target self->client->ps.persistant[PERS_PLAYEREVENTS] ^= PLAYEREVENT_GAUNTLETREWARD; } // check for two kills in a short amount of time // if this is close enough to the last kill, give a reward sound if ( level.time - attacker->client->lastKillTime < CARNAGE_REWARD_TIME ) { // play excellent on player attacker->client->ps.persistant[PERS_EXCELLENT_COUNT]++; // add the sprite over the player's head attacker->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP ); attacker->client->ps.eFlags |= EF_AWARD_EXCELLENT; attacker->client->rewardTime = level.time + REWARD_SPRITE_TIME; } attacker->client->lastKillTime = level.time; } } else { AddScore( self, self->r.currentOrigin, -1 ); } // Add team bonuses Team_FragBonuses(self, inflictor, attacker); // if I committed suicide, the flag does not fall, it returns. if (meansOfDeath == MOD_SUICIDE) { if ( self->client->ps.powerups[PW_NEUTRALFLAG] ) { // only happens in One Flag CTF Team_ReturnFlag( TEAM_FREE ); self->client->ps.powerups[PW_NEUTRALFLAG] = 0; } else if ( self->client->ps.powerups[PW_REDFLAG] ) { // only happens in standard CTF Team_ReturnFlag( TEAM_RED ); self->client->ps.powerups[PW_REDFLAG] = 0; } else if ( self->client->ps.powerups[PW_BLUEFLAG] ) { // only happens in standard CTF Team_ReturnFlag( TEAM_BLUE ); self->client->ps.powerups[PW_BLUEFLAG] = 0; } } // if client is in a nodrop area, don't drop anything (but return CTF flags!) contents = _G_trap_PointContents( self->r.currentOrigin, -1 ); if ( !( contents & CONTENTS_NODROP )) { TossClientItems( self ); } else { if ( self->client->ps.powerups[PW_NEUTRALFLAG] ) { // only happens in One Flag CTF Team_ReturnFlag( TEAM_FREE ); } else if ( self->client->ps.powerups[PW_REDFLAG] ) { // only happens in standard CTF Team_ReturnFlag( TEAM_RED ); } else if ( self->client->ps.powerups[PW_BLUEFLAG] ) { // only happens in standard CTF Team_ReturnFlag( TEAM_BLUE ); } } #ifdef MISSIONPACK TossClientPersistantPowerups( self ); if( g_gametype.integer == GT_HARVESTER ) { TossClientCubes( self ); } #endif Cmd_Score_f( self ); // show scores // send updated scores to any clients that are following this one, // or they would get stale scoreboards for ( i = 0 ; i < level.maxclients ; i++ ) { gclient_t *client; client = &level.clients[i]; if ( client->pers.connected != CON_CONNECTED ) { continue; } if ( client->sess.sessionTeam != TEAM_SPECTATOR ) { continue; } if ( client->sess.spectatorClient == self->s.number ) { Cmd_Score_f( g_entities + i ); } } self->takedamage = qtrue; // can still be gibbed self->s.weapon = WP_NONE; self->s.powerups = 0; self->r.contents = CONTENTS_CORPSE; self->s.angles[0] = AFIXED_0; self->s.angles[2] = AFIXED_0; LookAtKiller (self, inflictor, attacker); VectorCopy( self->s.angles, self->client->ps.viewangles ); self->s.loopSound = 0; self->r.maxs[2] = -BFIXED(8,0); // don't allow respawn until the death anim is done // g_forcerespawn may force spawning at some later time self->client->respawnTime = level.time + 1700; // remove powerups memset( self->client->ps.powerups, 0, sizeof(self->client->ps.powerups) ); // never gib in a nodrop if ( (self->health <= GIB_HEALTH && !(contents & CONTENTS_NODROP) && g_blood.integer) || meansOfDeath == MOD_SUICIDE) { // gib death GibEntity( self, killer ); } else { // normal death static int i; switch ( i ) { case 0: anim = BOTH_DEATH1; break; case 1: anim = BOTH_DEATH2; break; case 2: default: anim = BOTH_DEATH3; break; } // for the no-blood option, we need to prevent the health // from going to gib level if ( self->health <= GIB_HEALTH ) { self->health = GIB_HEALTH+1; } self->client->ps.legsAnim = ( ( self->client->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | anim; self->client->ps.torsoAnim = ( ( self->client->ps.torsoAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | anim; G_AddEvent( self, EV_DEATH1 + i, killer ); // the body can still be gibbed self->die = body_die; // globally cycle through the different death animations i = ( i + 1 ) % 3; #ifdef MISSIONPACK if (self->s.eFlags & EF_KAMIKAZE) { Kamikaze_DeathTimer( self ); } #endif } _G_trap_LinkEntity (self); }
/* ================== player_die ================== */ void player_die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int meansOfDeath ) { gentity_t *ent; int anim; int killer; int i, j; char *killerName, *obit; float totalTK = 0; float totalDamage = 0.0f; float percentDamage = 0.0f; gentity_t *player; qboolean tk = qfalse; if( self->client->ps.pm_type == PM_DEAD ) return; if( level.intermissiontime ) return; self->client->ps.pm_type = PM_DEAD; self->suicideTime = 0; if( attacker ) { killer = attacker->s.number; if( attacker->client ) { killerName = attacker->client->pers.netname; tk = ( attacker != self && attacker->client->ps.stats[ STAT_PTEAM ] == self->client->ps.stats[ STAT_PTEAM ] ); if( attacker != self && attacker->client->ps.stats[ STAT_PTEAM ] == self->client->ps.stats[ STAT_PTEAM ] ) { attacker->client->pers.statscounters.teamkills++; if( attacker->client->pers.teamSelection == PTE_ALIENS ) { level.alienStatsCounters.teamkills++; } else if( attacker->client->pers.teamSelection == PTE_HUMANS ) { level.humanStatsCounters.teamkills++; } } } else killerName = "<non-client>"; } else { killer = ENTITYNUM_WORLD; killerName = "<world>"; } if( killer < 0 || killer >= MAX_CLIENTS ) { killer = ENTITYNUM_WORLD; killerName = "<world>"; } if( meansOfDeath < 0 || meansOfDeath >= sizeof( modNames ) / sizeof( modNames[0] ) ) obit = "<bad obituary>"; else obit = modNames[ meansOfDeath ]; G_LogPrintf("Kill: %i %i %i: %s^7 killed %s^7 by %s\n", killer, self->s.number, meansOfDeath, killerName, self->client->pers.netname, obit ); //TA: close any menus the client has open G_CloseMenus( self->client->ps.clientNum ); //TA: deactivate all upgrades for( i = UP_NONE + 1; i < UP_NUM_UPGRADES; i++ ) BG_DeactivateUpgrade( i, self->client->ps.stats ); if( meansOfDeath == MOD_SLAP ) { trap_SendServerCommand( -1, va( "print \"%s^7 felt %s^7's authority\n\"", self->client->pers.netname, killerName ) ); goto finish_dying; } // broadcast the death event to everyone if( !tk ) { ent = G_TempEntity( self->r.currentOrigin, EV_OBITUARY ); ent->s.eventParm = meansOfDeath; ent->s.otherEntityNum = self->s.number; ent->s.otherEntityNum2 = killer; ent->r.svFlags = SVF_BROADCAST; // send to everyone } else if( attacker && attacker->client ) { // tjw: obviously this is a hack and belongs in the client, but // this works as a temporary fix. trap_SendServerCommand( -1, va( "print \"%s^7 was killed by ^1TEAMMATE^7 %s^7 (Did %d damage to %d max)\n\"", self->client->pers.netname, attacker->client->pers.netname, self->client->tkcredits[ attacker->s.number ], self->client->ps.stats[ STAT_MAX_HEALTH ] ) ); trap_SendServerCommand( attacker - g_entities, va( "cp \"You killed ^1TEAMMATE^7 %s\"", self->client->pers.netname ) ); G_LogOnlyPrintf("%s^7 was killed by ^1TEAMMATE^7 %s^7 (Did %d damage to %d max)\n", self->client->pers.netname, attacker->client->pers.netname, self->client->tkcredits[ attacker->s.number ], self->client->ps.stats[ STAT_MAX_HEALTH ] ); G_TeamKill_Repent( attacker ); } self->enemy = attacker; self->client->ps.persistant[ PERS_KILLED ]++; self->client->pers.statscounters.deaths++; if( self->client->pers.teamSelection == PTE_ALIENS ) { level.alienStatsCounters.deaths++; } else if( self->client->pers.teamSelection == PTE_HUMANS ) { level.humanStatsCounters.deaths++; } if( attacker && attacker->client ) { attacker->client->lastkilled_client = self->s.number; if( g_killerHP.integer || ( g_devmapKillerHP.integer && g_cheats.integer ) ) { trap_SendServerCommand( self-g_entities, va( "print \"Your killer, %s^7, had %3i HP.\n\"", killerName, attacker->health ) ); } if( attacker == self || OnSameTeam( self, attacker ) ) { AddScore( attacker, -1 ); // Normal teamkill penalty if( !g_retribution.integer ) { if( attacker->client->ps.stats[ STAT_PTEAM ] == PTE_ALIENS ) G_AddCreditToClient( attacker->client, -FREEKILL_ALIEN, qtrue ); else if( attacker->client->ps.stats[ STAT_PTEAM ] == PTE_HUMANS ) G_AddCreditToClient( attacker->client, -FREEKILL_HUMAN, qtrue ); } } else { AddScore( attacker, 1 ); attacker->client->lastKillTime = level.time; attacker->client->pers.statscounters.kills++; if( attacker->client->pers.teamSelection == PTE_ALIENS ) { level.alienStatsCounters.kills++; } else if( attacker->client->pers.teamSelection == PTE_HUMANS ) { level.humanStatsCounters.kills++; } } if( attacker == self ) { attacker->client->pers.statscounters.suicides++; if( attacker->client->pers.teamSelection == PTE_ALIENS ) { level.alienStatsCounters.suicides++; } else if( attacker->client->pers.teamSelection == PTE_HUMANS ) { level.humanStatsCounters.suicides++; } } } else if( attacker->s.eType != ET_BUILDABLE ) AddScore( self, -1 ); //total up all the damage done by every client for( i = 0; i < MAX_CLIENTS; i++ ) { totalDamage += (float)self->credits[ i ]; totalTK += (float)self->client->tkcredits[ i ]; } // punish players for damaging teammates if ( g_retribution.integer && totalTK ) { int totalPrice; int max = HUMAN_MAX_CREDITS; if ( self->client->ps.stats[ STAT_PTEAM ] == PTE_ALIENS ) { totalPrice = BG_ClassCanEvolveFromTo( PCL_ALIEN_LEVEL0, self->client->ps.stats[ STAT_PCLASS ], ALIEN_MAX_KILLS, 0 ); max = ALIEN_MAX_KILLS; } else { totalPrice = BG_GetValueOfEquipment( &self->client->ps ); } if ( self->client->ps.persistant[ PERS_CREDIT ] + totalPrice > max ) totalPrice = max - self->client->ps.persistant[ PERS_CREDIT ]; if ( totalPrice > 0 ) { totalTK += totalDamage; if( totalTK < self->client->ps.stats[ STAT_MAX_HEALTH ] ) totalTK = self->client->ps.stats[ STAT_MAX_HEALTH ]; if ( self->client->ps.stats[ STAT_PTEAM ] == PTE_HUMANS ) { for ( i = 0; i < MAX_CLIENTS; i++ ) { int price; // no retribution if self damage or enemy damage or building damage or no damage from this client if ( i == self - g_entities || !g_entities[ i ].client || !OnSameTeam( &g_entities[ i ], self ) || !self->client->tkcredits[ i ] ) continue; // calculate retribution price (rounded up) price = ( totalPrice * self->client->tkcredits[ i ] ) / totalTK + 0.5f; self->client->tkcredits[ i ] = 0; // check for enough credits if ( g_entities[ i ].client->ps.persistant[ PERS_CREDIT ] < price ) price = g_entities[ i ].client->ps.persistant[ PERS_CREDIT ]; if ( price ) { G_AddCreditToClient( self->client, price, qtrue ); G_AddCreditToClient( g_entities[ i ].client, -price, qtrue ); trap_SendServerCommand( self->client->ps.clientNum, va( "print \"Received ^3%d credits ^7from %s ^7in retribution.\n\"", price, g_entities[ i ].client->pers.netname ) ); trap_SendServerCommand( g_entities[ i ].client->ps.clientNum, va( "print \"Transfered ^3%d credits ^7to %s ^7in retribution.\n\"", price, self->client->pers.netname ) ); } } } else { int toPay[ MAX_CLIENTS ] = { 0 }; int frags = totalPrice; int damageForEvo = totalTK / totalPrice; for ( i = 0; i < MAX_CLIENTS; i++ ) { // no retribution if self damage or enemy damage or building damage or no damage from this client if ( i == self - g_entities || !g_entities[ i ].client || !OnSameTeam( &g_entities[ i ], self ) || !self->client->tkcredits[ i ] ) continue; // find out how many full evos this client needs to pay toPay[ i ] = ( totalPrice * self->client->tkcredits[ i ] ) / totalTK; if ( toPay[ i ] > g_entities[ i ].client->ps.persistant[ PERS_CREDIT ] ) toPay[ i ] = g_entities[ i ].client->ps.persistant[ PERS_CREDIT ]; frags -= toPay[ i ]; self->client->tkcredits[ i ] -= damageForEvo * toPay[ i ]; } // if we have not met the evo count, continue stealing evos while ( 1 ) { int maximum = 0; int topClient = 0; for ( i = 0; i < MAX_CLIENTS; i++ ) { if ( self->client->tkcredits[ i ] > maximum && g_entities[ i ].client->ps.persistant[ PERS_CREDIT ] ) { maximum = self->client->tkcredits[ i ]; topClient = i; } } if ( !maximum ) break; toPay[ topClient ]++; self->client->tkcredits[ topClient ] = 0; frags--; if ( !frags ) break; } // now move the evos around for ( i = 0; i < MAX_CLIENTS; i++ ) { if ( !toPay[ i ] ) continue; G_AddCreditToClient( self->client, toPay[ i ], qtrue ); G_AddCreditToClient( g_entities[ i ].client, -toPay[ i ], qtrue ); trap_SendServerCommand( self->client->ps.clientNum, va( "print \"Received ^3%d ^7evos from %s ^7in retribution.\n\"", toPay[ i ], g_entities[ i ].client->pers.netname ) ); trap_SendServerCommand( g_entities[ i ].client->ps.clientNum, va( "print \"Transfered ^3%d ^7evos to %s ^7in retribution.\n\"", toPay[ i ], self->client->pers.netname ) ); } } } } // if players did more than DAMAGE_FRACTION_FOR_KILL increment the stage counters if( !OnSameTeam( self, attacker ) && totalDamage >= ( self->client->ps.stats[ STAT_MAX_HEALTH ] * DAMAGE_FRACTION_FOR_KILL ) ) { if( self->client->ps.stats[ STAT_PTEAM ] == PTE_HUMANS ) { trap_Cvar_Set( "g_alienKills", va( "%d", g_alienKills.integer + 1 ) ); if( g_alienStage.integer < 2 ) { self->client->pers.statscounters.feeds++; level.humanStatsCounters.feeds++; } } else if( self->client->ps.stats[ STAT_PTEAM ] == PTE_ALIENS ) { trap_Cvar_Set( "g_humanKills", va( "%d", g_humanKills.integer + 1 ) ); if( g_humanStage.integer < 2 ) { self->client->pers.statscounters.feeds++; level.alienStatsCounters.feeds++; } } } if( totalDamage > 0.0f ) { if( self->client->ps.stats[ STAT_PTEAM ] == PTE_ALIENS ) { //nice simple happy bouncy human land float classValue = BG_FindValueOfClass( self->client->ps.stats[ STAT_PCLASS ] ); for( i = 0; i < MAX_CLIENTS; i++ ) { player = g_entities + i; if( !player->client ) continue; if( player->client->ps.stats[ STAT_PTEAM ] != PTE_HUMANS ) continue; if( !self->credits[ i ] ) continue; percentDamage = (float)self->credits[ i ] / totalDamage; if( percentDamage > 0 && percentDamage < 1) { player->client->pers.statscounters.assists++; level.humanStatsCounters.assists++; } //add credit G_AddCreditToClient( player->client, (int)( classValue * percentDamage ), qtrue ); } } else if( self->client->ps.stats[ STAT_PTEAM ] == PTE_HUMANS ) { //horribly complex nasty alien land float humanValue = BG_GetValueOfHuman( &self->client->ps ); int frags; int unclaimedFrags = (int)humanValue; for( i = 0; i < MAX_CLIENTS; i++ ) { player = g_entities + i; if( !player->client ) continue; if( player->client->ps.stats[ STAT_PTEAM ] != PTE_ALIENS ) continue; //this client did no damage if( !self->credits[ i ] ) continue; //nothing left to claim if( !unclaimedFrags ) break; percentDamage = (float)self->credits[ i ] / totalDamage; if( percentDamage > 0 && percentDamage < 1) { player->client->pers.statscounters.assists++; level.alienStatsCounters.assists++; } frags = (int)floor( humanValue * percentDamage); if( frags > 0 ) { //add kills G_AddCreditToClient( player->client, frags, qtrue ); //can't revist this account later self->credits[ i ] = 0; //reduce frags left to be claimed unclaimedFrags -= frags; } } //there are frags still to be claimed if( unclaimedFrags ) { //the clients remaining at this point do not //have enough credit to claim even one frag //so simply give the top <unclaimedFrags> clients //a frag each for( i = 0; i < unclaimedFrags; i++ ) { int maximum = 0; int topClient = 0; for( j = 0; j < MAX_CLIENTS; j++ ) { //this client did no damage if( !self->credits[ j ] ) continue; if( self->credits[ j ] > maximum ) { maximum = self->credits[ j ]; topClient = j; } } if( maximum > 0 ) { player = g_entities + topClient; //add kills G_AddCreditToClient( player->client, 1, qtrue ); //can't revist this account again self->credits[ topClient ] = 0; } } } } } ScoreboardMessage( self ); // show scores // send updated scores to any clients that are following this one, // or they would get stale scoreboards for( i = 0 ; i < level.maxclients ; i++ ) { gclient_t *client; client = &level.clients[ i ]; if( client->pers.connected != CON_CONNECTED ) continue; if( client->sess.sessionTeam != TEAM_SPECTATOR ) continue; if( client->sess.spectatorClient == self->s.number ) ScoreboardMessage( g_entities + i ); } finish_dying: // from MOD_SLAP VectorCopy( self->s.origin, self->client->pers.lastDeathLocation ); self->takedamage = qfalse; // can still be gibbed self->s.weapon = WP_NONE; self->r.contents = CONTENTS_CORPSE; self->s.angles[ PITCH ] = 0; self->s.angles[ ROLL ] = 0; self->s.angles[ YAW ] = self->s.apos.trBase[ YAW ]; LookAtKiller( self, inflictor, attacker ); VectorCopy( self->s.angles, self->client->ps.viewangles ); self->s.loopSound = 0; self->r.maxs[ 2 ] = -8; // don't allow respawn until the death anim is done // g_forcerespawn may force spawning at some later time self->client->respawnTime = level.time + 1700; // remove powerups memset( self->client->ps.powerups, 0, sizeof( self->client->ps.powerups ) ); { // normal death static int i; if( !( self->client->ps.persistant[ PERS_STATE ] & PS_NONSEGMODEL ) ) { switch( i ) { case 0: anim = BOTH_DEATH1; break; case 1: anim = BOTH_DEATH2; break; case 2: default: anim = BOTH_DEATH3; break; } } else { switch( i ) { case 0: anim = NSPA_DEATH1; break; case 1: anim = NSPA_DEATH2; break; case 2: default: anim = NSPA_DEATH3; break; } } self->client->ps.legsAnim = ( ( self->client->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | anim; if( !( self->client->ps.persistant[ PERS_STATE ] & PS_NONSEGMODEL ) ) { self->client->ps.torsoAnim = ( ( self->client->ps.torsoAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | anim; } // use own entityid if killed by non-client to prevent uint8_t overflow G_AddEvent( self, EV_DEATH1 + i, ( killer < MAX_CLIENTS ) ? killer : self - g_entities ); // globally cycle through the different death animations i = ( i + 1 ) % 3; } trap_LinkEntity( self ); }
void G_LogWeaponOutput(void) { #ifdef LOGGING_WEAPONS int i,j,curwp; float pershot; fileHandle_t weaponfile; char string[1024]; int totalpickups[WP_NUM_WEAPONS]; int totaltime[WP_NUM_WEAPONS]; int totaldeaths[WP_NUM_WEAPONS]; int totaldamageMOD[MOD_MAX]; int totalkillsMOD[MOD_MAX]; int totaldamage[WP_NUM_WEAPONS]; int totalkills[WP_NUM_WEAPONS]; int totalshots[WP_NUM_WEAPONS]; int percharacter[WP_NUM_WEAPONS]; char info[1024]; char mapname[128]; char *nameptr, *unknownname="<Unknown>"; if (!g_statLog.integer) { return; } G_LogPrintf("*****************************Weapon Log:\n" ); memset(totalpickups, 0, sizeof(totalpickups)); memset(totaltime, 0, sizeof(totaltime)); memset(totaldeaths, 0, sizeof(totaldeaths)); memset(totaldamageMOD, 0, sizeof(totaldamageMOD)); memset(totalkillsMOD, 0, sizeof(totalkillsMOD)); memset(totaldamage, 0, sizeof(totaldamage)); memset(totalkills, 0, sizeof(totalkills)); memset(totalshots, 0, sizeof(totalshots)); for (i=0; i<MAX_CLIENTS; i++) { if (G_WeaponLogClientTouch[i]) { // Ignore any entity/clients we don't care about! for (j=0;j<WP_NUM_WEAPONS;j++) { totalpickups[j] += G_WeaponLogPickups[i][j]; totaltime[j] += G_WeaponLogTime[i][j]; totaldeaths[j] += G_WeaponLogDeaths[i][j]; totalshots[j] += G_WeaponLogFired[i][j]; } for (j=0;j<MOD_MAX;j++) { totaldamageMOD[j] += G_WeaponLogDamage[i][j]; totalkillsMOD[j] += G_WeaponLogKills[i][j]; } } } // Now total the weapon data from the MOD data. for (j=0; j<MOD_MAX; j++) { if (j <= MOD_SENTRY) { curwp = weaponFromMOD[j]; totaldamage[curwp] += totaldamageMOD[j]; totalkills[curwp] += totalkillsMOD[j]; } } G_LogPrintf( "\n****Data by Weapon:\n" ); for (j=0; j<WP_NUM_WEAPONS; j++) { G_LogPrintf("%15s: Pickups: %4d, Time: %5d, Deaths: %5d\n", weaponNameFromIndex[j], totalpickups[j], (int)(totaltime[j]/1000), totaldeaths[j]); } G_LogPrintf( "\n****Combat Data by Weapon:\n" ); for (j=0; j<WP_NUM_WEAPONS; j++) { if (totalshots[j] > 0) { pershot = (float)(totaldamage[j])/(float)(totalshots[j]); } else { pershot = 0; } G_LogPrintf("%15s: Damage: %6d, Kills: %5d, Dmg per Shot: %f\n", weaponNameFromIndex[j], totaldamage[j], totalkills[j], pershot); } G_LogPrintf( "\n****Combat Data By Damage Type:\n" ); for (j=0; j<MOD_MAX; j++) { G_LogPrintf("%25s: Damage: %6d, Kills: %5d\n", modNames[j], totaldamageMOD[j], totalkillsMOD[j]); } G_LogPrintf("\n"); // Write the whole weapon statistic log out to a file. trap_FS_FOpenFile( g_statLogFile.string, &weaponfile, FS_APPEND ); if (!weaponfile) { //failed to open file, let's not crash, shall we? return; } // Write out the level name trap_GetServerinfo(info, sizeof(info)); strncpy(mapname, Info_ValueForKey( info, "mapname" ), sizeof(mapname)-1); mapname[sizeof(mapname)-1] = '\0'; Com_sprintf(string, sizeof(string), "\n\n\nLevel:\t%s\n\n\n", mapname); trap_FS_Write( string, strlen( string ), weaponfile); // Combat data per character // Start with Pickups per character Com_sprintf(string, sizeof(string), "Weapon Pickups per Player:\n\n"); trap_FS_Write( string, strlen( string ), weaponfile); Com_sprintf(string, sizeof(string), "Player"); trap_FS_Write(string, strlen(string), weaponfile); for (j=0; j<WP_NUM_WEAPONS; j++) { Com_sprintf(string, sizeof(string), "\t%s", weaponNameFromIndex[j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n"); trap_FS_Write(string, strlen(string), weaponfile); // Cycle through each player, give their name and the number of times they picked up each weapon. for (i=0; i<MAX_CLIENTS; i++) { if (G_WeaponLogClientTouch[i]) { // Ignore any entity/clients we don't care about! if ( g_entities[i].client ) { nameptr = g_entities[i].client->pers.netname; } else { nameptr = unknownname; } trap_FS_Write(nameptr, strlen(nameptr), weaponfile); for (j=0;j<WP_NUM_WEAPONS;j++) { Com_sprintf(string, sizeof(string), "\t%d", G_WeaponLogPickups[i][j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n"); trap_FS_Write(string, strlen(string), weaponfile); } } // Sum up the totals. Com_sprintf(string, sizeof(string), "\n***TOTAL:"); trap_FS_Write(string, strlen(string), weaponfile); for (j=0;j<WP_NUM_WEAPONS;j++) { Com_sprintf(string, sizeof(string), "\t%d", totalpickups[j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n\n\n"); trap_FS_Write(string, strlen(string), weaponfile); // Weapon fires per character Com_sprintf(string, sizeof(string), "Weapon Shots per Player:\n\n"); trap_FS_Write( string, strlen( string ), weaponfile); Com_sprintf(string, sizeof(string), "Player"); trap_FS_Write(string, strlen(string), weaponfile); for (j=0; j<WP_NUM_WEAPONS; j++) { Com_sprintf(string, sizeof(string), "\t%s", weaponNameFromIndex[j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n"); trap_FS_Write(string, strlen(string), weaponfile); // Cycle through each player, give their name and the number of times they picked up each weapon. for (i=0; i<MAX_CLIENTS; i++) { if (G_WeaponLogClientTouch[i]) { // Ignore any entity/clients we don't care about! if ( g_entities[i].client ) { nameptr = g_entities[i].client->pers.netname; } else { nameptr = unknownname; } trap_FS_Write(nameptr, strlen(nameptr), weaponfile); for (j=0;j<WP_NUM_WEAPONS;j++) { Com_sprintf(string, sizeof(string), "\t%d", G_WeaponLogFired[i][j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n"); trap_FS_Write(string, strlen(string), weaponfile); } } // Sum up the totals. Com_sprintf(string, sizeof(string), "\n***TOTAL:"); trap_FS_Write(string, strlen(string), weaponfile); for (j=0;j<WP_NUM_WEAPONS;j++) { Com_sprintf(string, sizeof(string), "\t%d", totalshots[j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n\n\n"); trap_FS_Write(string, strlen(string), weaponfile); // Weapon time per character Com_sprintf(string, sizeof(string), "Weapon Use Time per Player:\n\n"); trap_FS_Write( string, strlen( string ), weaponfile); Com_sprintf(string, sizeof(string), "Player"); trap_FS_Write(string, strlen(string), weaponfile); for (j=0; j<WP_NUM_WEAPONS; j++) { Com_sprintf(string, sizeof(string), "\t%s", weaponNameFromIndex[j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n"); trap_FS_Write(string, strlen(string), weaponfile); // Cycle through each player, give their name and the number of times they picked up each weapon. for (i=0; i<MAX_CLIENTS; i++) { if (G_WeaponLogClientTouch[i]) { // Ignore any entity/clients we don't care about! if ( g_entities[i].client ) { nameptr = g_entities[i].client->pers.netname; } else { nameptr = unknownname; } trap_FS_Write(nameptr, strlen(nameptr), weaponfile); for (j=0;j<WP_NUM_WEAPONS;j++) { Com_sprintf(string, sizeof(string), "\t%d", G_WeaponLogTime[i][j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n"); trap_FS_Write(string, strlen(string), weaponfile); } } // Sum up the totals. Com_sprintf(string, sizeof(string), "\n***TOTAL:"); trap_FS_Write(string, strlen(string), weaponfile); for (j=0;j<WP_NUM_WEAPONS;j++) { Com_sprintf(string, sizeof(string), "\t%d", totaltime[j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n\n\n"); trap_FS_Write(string, strlen(string), weaponfile); // Weapon deaths per character Com_sprintf(string, sizeof(string), "Weapon Deaths per Player:\n\n"); trap_FS_Write( string, strlen( string ), weaponfile); Com_sprintf(string, sizeof(string), "Player"); trap_FS_Write(string, strlen(string), weaponfile); for (j=0; j<WP_NUM_WEAPONS; j++) { Com_sprintf(string, sizeof(string), "\t%s", weaponNameFromIndex[j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n"); trap_FS_Write(string, strlen(string), weaponfile); // Cycle through each player, give their name and the number of times they picked up each weapon. for (i=0; i<MAX_CLIENTS; i++) { if (G_WeaponLogClientTouch[i]) { // Ignore any entity/clients we don't care about! if ( g_entities[i].client ) { nameptr = g_entities[i].client->pers.netname; } else { nameptr = unknownname; } trap_FS_Write(nameptr, strlen(nameptr), weaponfile); for (j=0;j<WP_NUM_WEAPONS;j++) { Com_sprintf(string, sizeof(string), "\t%d", G_WeaponLogDeaths[i][j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n"); trap_FS_Write(string, strlen(string), weaponfile); } } // Sum up the totals. Com_sprintf(string, sizeof(string), "\n***TOTAL:"); trap_FS_Write(string, strlen(string), weaponfile); for (j=0;j<WP_NUM_WEAPONS;j++) { Com_sprintf(string, sizeof(string), "\t%d", totaldeaths[j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n\n\n"); trap_FS_Write(string, strlen(string), weaponfile); // Weapon damage per character Com_sprintf(string, sizeof(string), "Weapon Damage per Player:\n\n"); trap_FS_Write( string, strlen( string ), weaponfile); Com_sprintf(string, sizeof(string), "Player"); trap_FS_Write(string, strlen(string), weaponfile); for (j=0; j<WP_NUM_WEAPONS; j++) { Com_sprintf(string, sizeof(string), "\t%s", weaponNameFromIndex[j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n"); trap_FS_Write(string, strlen(string), weaponfile); // Cycle through each player, give their name and the number of times they picked up each weapon. for (i=0; i<MAX_CLIENTS; i++) { if (G_WeaponLogClientTouch[i]) { // Ignore any entity/clients we don't care about! // We must grab the totals from the damage types for the player and map them to the weapons. memset(percharacter, 0, sizeof(percharacter)); for (j=0; j<MOD_MAX; j++) { if (j <= MOD_SENTRY) { curwp = weaponFromMOD[j]; percharacter[curwp] += G_WeaponLogDamage[i][j]; } } if ( g_entities[i].client ) { nameptr = g_entities[i].client->pers.netname; } else { nameptr = unknownname; } trap_FS_Write(nameptr, strlen(nameptr), weaponfile); for (j=0;j<WP_NUM_WEAPONS;j++) { Com_sprintf(string, sizeof(string), "\t%d", percharacter[j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n"); trap_FS_Write(string, strlen(string), weaponfile); } } // Sum up the totals. Com_sprintf(string, sizeof(string), "\n***TOTAL:"); trap_FS_Write(string, strlen(string), weaponfile); for (j=0;j<WP_NUM_WEAPONS;j++) { Com_sprintf(string, sizeof(string), "\t%d", totaldamage[j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n\n\n"); trap_FS_Write(string, strlen(string), weaponfile); // Weapon kills per character Com_sprintf(string, sizeof(string), "Weapon Kills per Player:\n\n"); trap_FS_Write( string, strlen( string ), weaponfile); Com_sprintf(string, sizeof(string), "Player"); trap_FS_Write(string, strlen(string), weaponfile); for (j=0; j<WP_NUM_WEAPONS; j++) { Com_sprintf(string, sizeof(string), "\t%s", weaponNameFromIndex[j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n"); trap_FS_Write(string, strlen(string), weaponfile); // Cycle through each player, give their name and the number of times they picked up each weapon. for (i=0; i<MAX_CLIENTS; i++) { if (G_WeaponLogClientTouch[i]) { // Ignore any entity/clients we don't care about! // We must grab the totals from the damage types for the player and map them to the weapons. memset(percharacter, 0, sizeof(percharacter)); for (j=0; j<MOD_MAX; j++) { if (j <= MOD_SENTRY) { curwp = weaponFromMOD[j]; percharacter[curwp] += G_WeaponLogKills[i][j]; } } if ( g_entities[i].client ) { nameptr = g_entities[i].client->pers.netname; } else { nameptr = unknownname; } trap_FS_Write(nameptr, strlen(nameptr), weaponfile); for (j=0;j<WP_NUM_WEAPONS;j++) { Com_sprintf(string, sizeof(string), "\t%d", percharacter[j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n"); trap_FS_Write(string, strlen(string), weaponfile); } } // Sum up the totals. Com_sprintf(string, sizeof(string), "\n***TOTAL:"); trap_FS_Write(string, strlen(string), weaponfile); for (j=0;j<WP_NUM_WEAPONS;j++) { Com_sprintf(string, sizeof(string), "\t%d", totalkills[j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n\n\n"); trap_FS_Write(string, strlen(string), weaponfile); // Damage type damage per character Com_sprintf(string, sizeof(string), "Typed Damage per Player:\n\n"); trap_FS_Write( string, strlen( string ), weaponfile); Com_sprintf(string, sizeof(string), "Player"); trap_FS_Write(string, strlen(string), weaponfile); for (j=0; j<MOD_MAX; j++) { Com_sprintf(string, sizeof(string), "\t%s", modNames[j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n"); trap_FS_Write(string, strlen(string), weaponfile); // Cycle through each player, give their name and the number of times they picked up each weapon. for (i=0; i<MAX_CLIENTS; i++) { if (G_WeaponLogClientTouch[i]) { // Ignore any entity/clients we don't care about! if ( g_entities[i].client ) { nameptr = g_entities[i].client->pers.netname; } else { nameptr = unknownname; } trap_FS_Write(nameptr, strlen(nameptr), weaponfile); for (j=0;j<MOD_MAX;j++) { Com_sprintf(string, sizeof(string), "\t%d", G_WeaponLogDamage[i][j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n"); trap_FS_Write(string, strlen(string), weaponfile); } } // Sum up the totals. Com_sprintf(string, sizeof(string), "\n***TOTAL:"); trap_FS_Write(string, strlen(string), weaponfile); for (j=0;j<MOD_MAX;j++) { Com_sprintf(string, sizeof(string), "\t%d", totaldamageMOD[j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n\n\n"); trap_FS_Write(string, strlen(string), weaponfile); // Damage type kills per character Com_sprintf(string, sizeof(string), "Damage-Typed Kills per Player:\n\n"); trap_FS_Write( string, strlen( string ), weaponfile); Com_sprintf(string, sizeof(string), "Player"); trap_FS_Write(string, strlen(string), weaponfile); for (j=0; j<MOD_MAX; j++) { Com_sprintf(string, sizeof(string), "\t%s", modNames[j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n"); trap_FS_Write(string, strlen(string), weaponfile); // Cycle through each player, give their name and the number of times they picked up each weapon. for (i=0; i<MAX_CLIENTS; i++) { if (G_WeaponLogClientTouch[i]) { // Ignore any entity/clients we don't care about! if ( g_entities[i].client ) { nameptr = g_entities[i].client->pers.netname; } else { nameptr = unknownname; } trap_FS_Write(nameptr, strlen(nameptr), weaponfile); for (j=0;j<MOD_MAX;j++) { Com_sprintf(string, sizeof(string), "\t%d", G_WeaponLogKills[i][j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n"); trap_FS_Write(string, strlen(string), weaponfile); } } // Sum up the totals. Com_sprintf(string, sizeof(string), "\n***TOTAL:"); trap_FS_Write(string, strlen(string), weaponfile); for (j=0;j<MOD_MAX;j++) { Com_sprintf(string, sizeof(string), "\t%d", totalkillsMOD[j]); trap_FS_Write(string, strlen(string), weaponfile); } Com_sprintf(string, sizeof(string), "\n\n\n"); trap_FS_Write(string, strlen(string), weaponfile); trap_FS_FCloseFile(weaponfile); #endif //LOGGING_WEAPONS }
void SP_worldspawn( void ) { char *text, temp[32]; int i; int lengthRed, lengthBlue, lengthGreen; //I want to "cull" entities out of net sends to clients to reduce //net traffic on our larger open maps -rww G_SpawnFloat("distanceCull", "6000.0", &g_cullDistance); trap_SetServerCull(g_cullDistance); G_SpawnString( "classname", "", &text ); if ( Q_stricmp( text, "worldspawn" ) ) { G_Error( "SP_worldspawn: The first entity isn't 'worldspawn'" ); } for ( i = 0 ; i < level.numSpawnVars ; i++ ) { if ( Q_stricmp( "spawnscript", level.spawnVars[i][0] ) == 0 ) {//ONly let them set spawnscript, we don't want them setting an angle or something on the world. G_ParseField( level.spawnVars[i][0], level.spawnVars[i][1], &g_entities[ENTITYNUM_WORLD] ); } } //The server will precache the standard model and animations, so that there is no hit //when the first client connnects. if (!BGPAFtextLoaded) { BG_ParseAnimationFile("models/players/_humanoid/animation.cfg", bgHumanoidAnimations, qtrue); } if (!precachedKyle) { int defSkin; trap_G2API_InitGhoul2Model(&precachedKyle, "models/players/kyle/model.glm", 0, 0, -20, 0, 0); if (precachedKyle) { defSkin = trap_R_RegisterSkin("models/players/kyle/model_default.skin"); trap_G2API_SetSkin(precachedKyle, 0, defSkin, defSkin); } } if (!g2SaberInstance) { trap_G2API_InitGhoul2Model(&g2SaberInstance, "models/weapons2/saber/saber_w.glm", 0, 0, -20, 0, 0); if (g2SaberInstance) { // indicate we will be bolted to model 0 (ie the player) on bolt 0 (always the right hand) when we get copied trap_G2API_SetBoltInfo(g2SaberInstance, 0, 0); // now set up the gun bolt on it trap_G2API_AddBolt(g2SaberInstance, 0, "*blade1"); } } if (g_gametype.integer == GT_SIEGE) { //a tad bit of a hack, but.. EWebPrecache(); } // make some data visible to connecting client trap_SetConfigstring( CS_GAME_VERSION, GAME_VERSION ); trap_SetConfigstring( CS_LEVEL_START_TIME, va("%i", level.startTime ) ); G_SpawnString( "music", "", &text ); trap_SetConfigstring( CS_MUSIC, text ); G_SpawnString( "message", "", &text ); trap_SetConfigstring( CS_MESSAGE, text ); // map specific message trap_SetConfigstring( CS_MOTD, g_motd.string ); // message of the day G_SpawnString( "gravity", "800", &text ); trap_Cvar_Set( "g_gravity", text ); G_SpawnString( "enableBreath", "0", &text ); trap_Cvar_Set( "g_enableBreath", text ); G_SpawnString( "soundSet", "default", &text ); trap_SetConfigstring( CS_GLOBAL_AMBIENT_SET, text ); g_entities[ENTITYNUM_WORLD].s.number = ENTITYNUM_WORLD; g_entities[ENTITYNUM_WORLD].classname = "worldspawn"; // see if we want a warmup time trap_SetConfigstring( CS_WARMUP, "" ); if ( g_restarted.integer ) { trap_Cvar_Set( "g_restarted", "0" ); level.warmupTime = 0; } //Raz: Fix warmup #if 0 /* else if ( g_doWarmup.integer && g_gametype.integer != GT_DUEL && g_gametype.integer != GT_POWERDUEL ) { // Turn it on else if ( g_doWarmup.integer && level.gametype != GT_DUEL && level.gametype != GT_POWERDUEL ) { // Turn it on level.warmupTime = -1; trap_SetConfigstring( CS_WARMUP, va("%i", level.warmupTime) ); G_LogPrintf( "Warmup:\n" ); } */ #else else if ( g_doWarmup.integer && g_gametype.integer != GT_DUEL && g_gametype.integer != GT_POWERDUEL && g_gametype.integer != GT_SIEGE ) { // Turn it on level.warmupTime = -1; trap_SetConfigstring( CS_WARMUP, va("%i", level.warmupTime) ); G_LogPrintf( "Warmup:\n" ); } #endif trap_SetConfigstring(CS_LIGHT_STYLES+(LS_STYLES_START*3)+0, defaultStyles[0][0]); trap_SetConfigstring(CS_LIGHT_STYLES+(LS_STYLES_START*3)+1, defaultStyles[0][1]); trap_SetConfigstring(CS_LIGHT_STYLES+(LS_STYLES_START*3)+2, defaultStyles[0][2]); for(i=1;i<LS_NUM_STYLES;i++) { Com_sprintf(temp, sizeof(temp), "ls_%dr", i); G_SpawnString(temp, defaultStyles[i][0], &text); lengthRed = strlen(text); trap_SetConfigstring(CS_LIGHT_STYLES+((i+LS_STYLES_START)*3)+0, text); Com_sprintf(temp, sizeof(temp), "ls_%dg", i); G_SpawnString(temp, defaultStyles[i][1], &text); lengthGreen = strlen(text); trap_SetConfigstring(CS_LIGHT_STYLES+((i+LS_STYLES_START)*3)+1, text); Com_sprintf(temp, sizeof(temp), "ls_%db", i); G_SpawnString(temp, defaultStyles[i][2], &text); lengthBlue = strlen(text); trap_SetConfigstring(CS_LIGHT_STYLES+((i+LS_STYLES_START)*3)+2, text); if (lengthRed != lengthGreen || lengthGreen != lengthBlue) { Com_Error(ERR_DROP, "Style %d has inconsistent lengths: R %d, G %d, B %d", i, lengthRed, lengthGreen, lengthBlue); } } }
/* =========== ClientUserInfoChanged Called from ClientConnect when the player first connects and directly by the server system when the player updates a userinfo variable. The game can override any of the settings and call trap_SetUserinfo if desired. ============ */ void ClientUserinfoChanged(int clientNum) { gentity_t *ent; int teamTask, teamLeader, team, health; char *s; char model[MAX_QPATH]; char oldname[MAX_STRING_CHARS]; gclient_t *client; char c1[MAX_INFO_STRING]; char c2[MAX_INFO_STRING]; char redTeam[MAX_INFO_STRING]; char blueTeam[MAX_INFO_STRING]; char userinfo[MAX_INFO_STRING]; ent = g_entities + clientNum; client = ent->client; trap_GetUserinfo(clientNum, userinfo, sizeof(userinfo)); // check for malformed or illegal info strings if(!Info_Validate(userinfo)) { strcpy(userinfo, "\\name\\badinfo"); } // check for local client s = Info_ValueForKey(userinfo, "ip"); if(!strcmp(s, "localhost")) { client->pers.localClient = qtrue; } // check the item prediction s = Info_ValueForKey(userinfo, "cg_predictItems"); if(!atoi(s)) { client->pers.predictItemPickup = qfalse; } else { client->pers.predictItemPickup = qtrue; } // set name Q_strncpyz(oldname, client->pers.netname, sizeof(oldname)); s = Info_ValueForKey(userinfo, "name"); ClientCleanName(s, client->pers.netname, sizeof(client->pers.netname)); if(client->sess.sessionTeam == TEAM_SPECTATOR) { if(client->sess.spectatorState == SPECTATOR_SCOREBOARD) { Q_strncpyz(client->pers.netname, "scoreboard", sizeof(client->pers.netname)); } } if(client->pers.connected == CON_CONNECTED) { if(strcmp(oldname, client->pers.netname)) { trap_SendServerCommand(-1, va("print \"%s" S_COLOR_WHITE " renamed to %s\n\"", oldname, client->pers.netname)); } } // set max health #ifdef MISSIONPACK if(client->ps.powerups[PW_GUARD]) { client->pers.maxHealth = 200; } else { health = atoi(Info_ValueForKey(userinfo, "handicap")); client->pers.maxHealth = health; if(client->pers.maxHealth < 1 || client->pers.maxHealth > 100) { client->pers.maxHealth = 100; } } #else health = atoi(Info_ValueForKey(userinfo, "handicap")); client->pers.maxHealth = health; if(client->pers.maxHealth < 1 || client->pers.maxHealth > 100) { client->pers.maxHealth = 100; } #endif client->ps.stats[STAT_MAX_HEALTH] = client->pers.maxHealth; // set model Q_strncpyz(model, Info_ValueForKey(userinfo, "model"), sizeof(model)); // bots set their team a few frames later if(g_gametype.integer >= GT_TEAM && g_entities[clientNum].r.svFlags & SVF_BOT) { s = Info_ValueForKey(userinfo, "team"); if(!Q_stricmp(s, "red") || !Q_stricmp(s, "r")) { team = TEAM_RED; } else if(!Q_stricmp(s, "blue") || !Q_stricmp(s, "b")) { team = TEAM_BLUE; } else { // pick the team with the least number of players team = PickTeam(clientNum); } } else { team = client->sess.sessionTeam; } /* NOTE: all client side now // team switch( team ) { case TEAM_RED: ForceClientSkin(client, model, "red"); // ForceClientSkin(client, headModel, "red"); break; case TEAM_BLUE: ForceClientSkin(client, model, "blue"); // ForceClientSkin(client, headModel, "blue"); break; } // don't ever use a default skin in teamplay, it would just waste memory // however bots will always join a team but they spawn in as spectator if ( g_gametype.integer >= GT_TEAM && team == TEAM_SPECTATOR) { ForceClientSkin(client, model, "red"); // ForceClientSkin(client, headModel, "red"); } */ #ifdef MISSIONPACK if(g_gametype.integer >= GT_TEAM) { client->pers.teamInfo = qtrue; } else { s = Info_ValueForKey(userinfo, "teamoverlay"); if(!*s || atoi(s) != 0) { client->pers.teamInfo = qtrue; } else { client->pers.teamInfo = qfalse; } } #else // teamInfo s = Info_ValueForKey(userinfo, "teamoverlay"); if(!*s || atoi(s) != 0) { client->pers.teamInfo = qtrue; } else { client->pers.teamInfo = qfalse; } #endif /* s = Info_ValueForKey( userinfo, "cg_pmove_fixed" ); if ( !*s || atoi( s ) == 0 ) { client->pers.pmoveFixed = qfalse; } else { client->pers.pmoveFixed = qtrue; } */ // team task (0 = none, 1 = offence, 2 = defence) teamTask = atoi(Info_ValueForKey(userinfo, "teamtask")); // team Leader (1 = leader, 0 is normal player) teamLeader = client->sess.teamLeader; // colors strcpy(c1, Info_ValueForKey(userinfo, "color1")); strcpy(c2, Info_ValueForKey(userinfo, "color2")); strcpy(redTeam, Info_ValueForKey(userinfo, "g_redteam")); strcpy(blueTeam, Info_ValueForKey(userinfo, "g_blueteam")); // send over a subset of the userinfo keys so other clients can // print scoreboards, display models, and play custom sounds #if 0 if(ent->r.svFlags & SVF_BOT) { Com_sprintf(userinfo, sizeof(userinfo), "n\\%s\\t\\%i\\model\\%s\\hmodel\\%s\\g_redteam\\%s\\g_blueteam\\%s\\c1\\%s\\c2\\%s\\hc\\%i\\w\\%i\\l\\%i\\skill\\%s\\tt\\%d\\tl\\%d", client->pers.netname, team, model, headModel, redTeam, blueTeam, c1, c2, client->pers.maxHealth, client->sess.wins, client->sess.losses, Info_ValueForKey(userinfo, "skill"), teamTask, teamLeader); } else #endif { Com_sprintf(userinfo, sizeof(userinfo), "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", client->pers.netname, team, model, "", redTeam, blueTeam, c1, c2, client->pers.maxHealth, client->sess.wins, client->sess.losses, teamTask, teamLeader); } trap_SetConfigstring(CS_PLAYERS + clientNum, userinfo); #ifdef G_LUA // Lua API callbacks // This only gets called when the ClientUserinfo is changed, replicating // ETPro's behaviour. G_LuaHook_ClientUserinfoChanged(clientNum); #endif // this is not the userinfo, more like the configstring actually G_LogPrintf("ClientUserinfoChanged: %i %s\n", clientNum, s); }
/* =========== ClientConnect Called when a player begins connecting to the server. Called again for every map change or tournement restart. The session information will be valid after exit. Return NULL if the client should be allowed, otherwise return a string with the reason for denial. Otherwise, the client will be sent the current gamestate and will eventually get to ClientBegin. firstTime will be qtrue the very first time a client connects to the server machine, but qfalse on map changes and tournement restarts. ============ */ char *ClientConnect(int clientNum, qboolean firstTime, qboolean isBot) { char *value; // char *areabits; gclient_t *client; char userinfo[MAX_INFO_STRING]; char reason[MAX_STRING_CHARS] = ""; gentity_t *ent; ent = &g_entities[clientNum]; trap_GetUserinfo(clientNum, userinfo, sizeof(userinfo)); trap_LoadPlayerWeapons(clientNum, rr_weaponsAllowed.string); // IP filtering // https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=500 // recommanding PB based IP / GUID banning, the builtin system is pretty limited // check to see if they are on the banned IP list value = Info_ValueForKey(userinfo, "ip"); if(G_FilterPacket(value)) { return "You are banned from this server."; } // we don't check password for bots and local client // NOTE: local client <-> "ip" "localhost" // this means this client is not running in our current process if(!isBot && (strcmp(value, "localhost") != 0)) { // check for a password value = Info_ValueForKey(userinfo, "password"); if(g_password.string[0] && Q_stricmp(g_password.string, "none") && strcmp(g_password.string, value) != 0) { return "Invalid password"; } } #ifdef G_LUA // Lua API callbacks (check with Lua scripts) if(G_LuaHook_ClientConnect(clientNum, firstTime, isBot, reason)) { return "Connection Rejected by lua module."; } #endif // they can connect ent->client = level.clients + clientNum; client = ent->client; // areabits = client->areabits; memset(client, 0, sizeof(*client)); client->pers.connected = CON_CONNECTING; // read or initialize the session data if(firstTime || level.newSession) { G_InitSessionData(client, userinfo); } G_ReadSessionData(client); // Tr3B: add SVF_CAPSULE to players so we can trace against the rotated capsules // in the server entity tracing code SV_ClipToEntity // FIXME UPDATE: this seems to break the box traces against the player capsules by entities like rockets // it should be a bug in CM_TraceBoundingBoxThroughCapsule //ent->r.svFlags |= SVF_CAPSULE; if(isBot) { ent->r.svFlags |= SVF_BOT; ent->inuse = qtrue; #if defined(BRAINWORKS) if(!G_BotConnect(clientNum, !firstTime)) { return "BotConnectfailed"; } #elif defined(ACEBOT) if(!ACESP_BotConnect(clientNum, !firstTime)) { return "BotConnectfailed"; } #else return "BotConnectfailed"; #endif } // get and distribute relevent paramters G_LogPrintf("ClientConnect: %i\n", clientNum); ClientUserinfoChanged(clientNum); // don't do the "xxx connected" messages if they were caried over from previous level if(firstTime) { trap_SendServerCommand(-1, va("print \"%s" S_COLOR_WHITE " connected\n\"", client->pers.netname)); } if(g_gametype.integer >= GT_TEAM && client->sess.sessionTeam != TEAM_SPECTATOR) { BroadcastTeamChange(client, -1); } // count current clients and rank for scoreboard CalculateRanks(); // for statistics // client->areabits = areabits; // if ( !client->areabits ) // client->areabits = G_Alloc( (trap_AAS_PointReachabilityAreaIndex( NULL ) + 7) / 8 ); return NULL; }
/* =============== Touch_Item =============== */ void Touch_Item (gentity_t *ent, gentity_t *other, trace_t *trace) { int respawn; qboolean predict; if (!other->client) return; if (other->health < 1) return; // dead people can't pickup // the same pickup rules are used for client side and server side if (!BG_CanItemBeGrabbed(g_gametype.integer, &ent->s, &other->client->ps, &level.InvasionInfo)) { return; } G_LogPrintf("Item: %i %s\n", other->s.number, ent->item->classname); predict = other->client->pers.predictItemPickup; // call the item-specific pickup function switch (ent->item->giType) { case IT_WEAPON: respawn = Pickup_Weapon(ent, other); // predict = qfalse; break; case IT_AMMO: respawn = Pickup_Ammo(ent, other); // predict = qfalse; break; case IT_ARMOR: respawn = Pickup_Armor(ent, other); break; case IT_HEALTH: respawn = Pickup_Health(ent, other); break; case IT_POWERUP: respawn = Pickup_Powerup(ent, other); predict = qfalse; break; #ifdef MISSIONPACK case IT_PERSISTANT_POWERUP: respawn = Pickup_PersistantPowerup(ent, other); break; #endif case IT_TEAM: respawn = Pickup_Team(ent, other); break; case IT_HOLDABLE: respawn = Pickup_Holdable(ent, other); break; default: return; } if (!respawn) { return; } // play the normal pickup sound if (predict) { G_AddPredictableEvent(other, EV_ITEM_PICKUP, ent->s.modelindex); } else { G_AddEvent(other, EV_ITEM_PICKUP, ent->s.modelindex); } // powerup pickups are global broadcasts if (ent->item->giType == IT_POWERUP || ent->item->giType == IT_TEAM) { // if we want the global sound to play if (!ent->speed) { gentity_t *te; te = G_TempEntity(ent->s.pos.trBase, EV_GLOBAL_ITEM_PICKUP); te->s.eventParm = ent->s.modelindex; te->r.svFlags |= SVF_BROADCAST; } else { gentity_t *te; te = G_TempEntity(ent->s.pos.trBase, EV_GLOBAL_ITEM_PICKUP); te->s.eventParm = ent->s.modelindex; // only send this temp entity to a single client te->r.svFlags |= SVF_SINGLECLIENT; te->r.singleClient = other->s.number; } } // fire item targets G_UseTargets (ent, other); // wait of -1 will not respawn if (ent->wait == -1) { ent->r.svFlags |= SVF_NOCLIENT; ent->s.eFlags |= EF_NODRAW; ent->r.contents = 0; ent->unlinkAfterEvent = qtrue; return; } // non zero wait overrides respawn time if (ent->wait) { respawn = ent->wait; } // random can be used to vary the respawn time if (ent->random) { respawn += crandom() * ent->random; if (respawn < 1) { respawn = 1; } } // dropped items will not respawn if (ent->flags & FL_DROPPED_ITEM) { ent->freeAfterEvent = qtrue; } // picked up items still stay around, they just don't // draw anything. This allows respawnable items // to be placed on movers. ent->r.svFlags |= SVF_NOCLIENT; ent->s.eFlags |= EF_NODRAW; ent->r.contents = 0; // ZOID // A negative respawn times means to never respawn this item (but don't // delete it). This is used by items that are respawned by third party // events such as ctf flags if (respawn <= 0) { ent->nextthink = 0; ent->think = 0; } else { ent->nextthink = level.time + respawn * 1000; ent->think = RespawnItem; } trap_LinkEntity(ent); }
/* ================== player_die ================== */ void player_die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int meansOfDeath ) { static int rndAnim; gentity_t *ent; int anim; int contents; int killer; int i; char *killerName, *obit; qboolean gibPlayer; qboolean headshot = qfalse; if ( self->player->ps.pm_type == PM_DEAD ) { return; } if ( level.intermissiontime ) { return; } // make sure the body shows up in the player's current position G_UnTimeShiftClient( self ); // check for an almost capture CheckAlmostCapture( self, attacker ); // check for a player that almost brought in cubes CheckAlmostScored( self, attacker ); if (self->player && self->player->hook) { Weapon_HookFree(self->player->hook); } #ifdef MISSIONPACK if ((self->player->ps.eFlags & EF_TICKING) && self->activator) { self->player->ps.eFlags &= ~EF_TICKING; self->activator->think = G_FreeEntity; self->activator->nextthink = level.time; } #endif self->player->ps.pm_type = PM_DEAD; if ( attacker ) { killer = attacker->s.number; if ( attacker->player ) { killerName = attacker->player->pers.netname; } else { killerName = "<non-player>"; } } else { killer = ENTITYNUM_WORLD; killerName = "<world>"; } if ( killer < 0 || killer >= MAX_CLIENTS ) { killer = ENTITYNUM_WORLD; killerName = "<world>"; } if ( meansOfDeath < 0 || meansOfDeath >= ARRAY_LEN( modNames ) ) { obit = "<bad obituary>"; } else { obit = modNames[meansOfDeath]; } G_LogPrintf("Kill: %i %i %i: %s killed %s by %s\n", killer, self->s.number, meansOfDeath, killerName, self->player->pers.netname, obit ); self->enemy = attacker; self->player->ps.persistant[PERS_KILLED]++; if (attacker && attacker->player) { attacker->player->lastkilled_player = self->s.number; if ( attacker == self || OnSameTeam (self, attacker ) ) { if ( ((level.time - self->player->lasthurt_time) <= ASSISTED_SUICIDE_TIME) && g_entities[self->player->lasthurt_player2].player && (self->player->lasthurt_player2 != self->s.number) ) { AddScore( &g_entities[self->player->lasthurt_player2], self->r.currentOrigin, 1 ); meansOfDeath = MOD_ASSISTED_SUICIDE; } else AddScore( attacker, self->r.currentOrigin, -1 ); } else { AddScore( attacker, self->r.currentOrigin, 1 ); if( meansOfDeath == MOD_GAUNTLET ) { // play humiliation on player attacker->player->ps.persistant[PERS_GAUNTLET_FRAG_COUNT]++; // add the sprite over the player's head attacker->player->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP ); attacker->player->ps.eFlags |= EF_AWARD_GAUNTLET; attacker->player->rewardTime = level.time + REWARD_SPRITE_TIME; // also play humiliation on target self->player->ps.persistant[PERS_PLAYEREVENTS] ^= PLAYEREVENT_GAUNTLETREWARD; } // check for two kills in a short amount of time // if this is close enough to the last kill, give a reward sound if ( level.time - attacker->player->lastKillTime < CARNAGE_REWARD_TIME ) { // play excellent on player attacker->player->ps.persistant[PERS_EXCELLENT_COUNT]++; // add the sprite over the player's head attacker->player->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP ); attacker->player->ps.eFlags |= EF_AWARD_EXCELLENT; attacker->player->rewardTime = level.time + REWARD_SPRITE_TIME; } attacker->player->lastKillTime = level.time; } } else { if ( ((level.time - self->player->lasthurt_time) <= ASSISTED_SUICIDE_TIME) && g_entities[self->player->lasthurt_player2].player && (self->player->lasthurt_player2 != self->s.number) ) { AddScore( &g_entities[self->player->lasthurt_player2], self->r.currentOrigin, 1 ); meansOfDeath = MOD_ASSISTED_SUICIDE; } else AddScore( self, self->r.currentOrigin, -1 ); } // don't send death obituary when swiching teams // allow mod to be changed by death type if (meansOfDeath != MOD_SUICIDE_TEAM_CHANGE) { // broadcast the death event to everyone ent = G_TempEntity( self->r.currentOrigin, EV_OBITUARY ); ent->s.eventParm = meansOfDeath; ent->s.otherEntityNum = self->s.number; ent->s.otherEntityNum2 = killer; ent->r.svFlags = SVF_BROADCAST; // send to everyone if (self->player && attacker->player && ((self->player->lasthurt_location & LOCATION_HEAD) || (self->player->lasthurt_location & LOCATION_FACE))) { ent->s.eFlags |= EF_HEADSHOT; headshot = qtrue; } } // Add team bonuses Team_FragBonuses(self, inflictor, attacker); // if I committed suicide, the flag does not fall, it returns. if (meansOfDeath == MOD_SUICIDE || meansOfDeath == MOD_SUICIDE_TEAM_CHANGE) { if ( self->player->ps.powerups[PW_NEUTRALFLAG] ) { // only happens in One Flag CTF Team_ReturnFlag( TEAM_FREE ); self->player->ps.powerups[PW_NEUTRALFLAG] = 0; } else if ( self->player->ps.powerups[PW_REDFLAG] ) { // only happens in standard CTF Team_ReturnFlag( TEAM_RED ); self->player->ps.powerups[PW_REDFLAG] = 0; } else if ( self->player->ps.powerups[PW_BLUEFLAG] ) { // only happens in standard CTF Team_ReturnFlag( TEAM_BLUE ); self->player->ps.powerups[PW_BLUEFLAG] = 0; } } TossPlayerItems( self ); #ifdef MISSIONPACK TossPlayerPersistantPowerups( self ); if( g_gametype.integer == GT_HARVESTER ) { TossPlayerCubes( self ); } #endif Cmd_Score_f( self ); // show scores // send updated scores to any clients that are following this one, // or they would get stale scoreboards for ( i = 0 ; i < level.maxplayers ; i++ ) { gplayer_t *player; player = &level.players[i]; if ( player->pers.connected != CON_CONNECTED ) { continue; } if ( player->sess.sessionTeam != TEAM_SPECTATOR ) { continue; } if ( player->sess.spectatorPlayer == self->s.number ) { Cmd_Score_f( g_entities + i ); } } self->takedamage = qtrue; // can still be gibbed self->s.weapon = WP_NONE; self->s.powerups = 0; self->player->ps.contents = self->s.contents = CONTENTS_CORPSE; self->s.angles[0] = 0; self->s.angles[2] = 0; LookAtKiller (self, inflictor, attacker); VectorCopy( self->s.angles, self->player->ps.viewangles ); self->s.loopSound = 0; self->player->ps.maxs[2] = self->s.maxs[2] = -8; // don't allow respawn until the death anim is done // g_forcerespawn may force spawning at some later time self->player->respawnTime = level.time + 1700; // remove powerups memset( self->player->ps.powerups, 0, sizeof(self->player->ps.powerups) ); // never gib in a nodrop contents = trap_PointContents( self->r.currentOrigin, -1 ); gibPlayer = ( (self->health <= GIB_HEALTH && !(contents & CONTENTS_NODROP)) || meansOfDeath == MOD_SUICIDE ); if ( gibPlayer ) { // gib death GibEntity( self, qfalse ); // do normal death for clients with gibs disable } else { if (headshot) gibPlayer = 3; // the body can still be gibbed self->die = body_die; #ifdef MISSIONPACK if (self->s.eFlags & EF_KAMIKAZE) { Kamikaze_DeathTimer( self ); } #endif } // normal death switch ( rndAnim ) { case 0: anim = BOTH_DEATH1; break; case 1: anim = BOTH_DEATH2; break; case 2: default: anim = BOTH_DEATH3; break; } self->player->ps.legsAnim = ( ( self->player->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | anim; self->player->ps.torsoAnim = ( ( self->player->ps.torsoAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | anim; G_AddEvent( self, EV_DEATH1 + rndAnim, gibPlayer ); if ( headshot ) GibEntity( self, qtrue ); else self->player->headless = qfalse; // globally cycle through the different death animations rndAnim = ( rndAnim + 1 ) % 3; trap_LinkEntity (self); }
/* =========== ClientConnect Called when a player begins connecting to the server. Called again for every map change or tournement restart. The session information will be valid after exit. Return NULL if the client should be allowed, otherwise return a string with the reason for denial. Otherwise, the client will be sent the current gamestate and will eventually get to ClientBegin. firstTime will be qtrue the very first time a client connects to the server machine, but qfalse on map changes and tournement restarts. ============ */ char *ClientConnect( int clientNum, qboolean firstTime, qboolean isBot ) { char *value; // char *areabits; gclient_t *client; char userinfo[MAX_INFO_STRING]; gentity_t *ent; ent = &g_entities[ clientNum ]; trap_GetUserinfo( clientNum, userinfo, sizeof( userinfo ) ); // IP filtering // https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=500 // recommanding PB based IP / GUID banning, the builtin system is pretty limited // check to see if they are on the banned IP list value = Info_ValueForKey (userinfo, "ip"); if ( G_FilterPacket( value ) ) { return "You are banned from this server."; } // we don't check password for bots and local client // NOTE: local client <-> "ip" "localhost" // this means this client is not running in our current process if ( !isBot && (strcmp(value, "localhost") != 0)) { // check for a password value = Info_ValueForKey (userinfo, "password"); if ( g_password.string[0] && Q_stricmp( g_password.string, "none" ) && strcmp( g_password.string, value) != 0) { return "Invalid password"; } } // they can connect ent->client = level.clients + clientNum; client = ent->client; // areabits = client->areabits; memset( client, 0, sizeof(*client) ); client->pers.connected = CON_CONNECTING; // read or initialize the session data if ( firstTime || level.newSession ) { G_InitSessionData( client, userinfo ); } G_ReadSessionData( client ); if( isBot ) { ent->r.svFlags |= SVF_BOT; ent->inuse = qtrue; if( !G_BotConnect( clientNum, !firstTime ) ) { return "BotConnectfailed"; } } // get and distribute relevent paramters G_LogPrintf( "ClientConnect: %i\n", clientNum ); ClientUserinfoChanged( clientNum ); // don't do the "xxx connected" messages if they were caried over from previous level if ( firstTime ) { trap_SendServerCommand( -1, va("print \"%s" S_COLOR_WHITE " connected\n\"", client->pers.netname) ); } if ( g_gametype.integer >= GT_TEAM && client->sess.sessionTeam != TEAM_SPECTATOR ) { BroadcastTeamChange( client, -1 ); } // count current clients and rank for scoreboard CalculateRanks(); // for statistics // client->areabits = areabits; // if ( !client->areabits ) // client->areabits = G_Alloc( (trap_AAS_PointReachabilityAreaIndex( NULL ) + 7) / 8 ); return NULL; }
/* ================== player_die ================== */ void player_die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int meansOfDeath ) { gentity_t *ent; int anim; int killer; int i; char *killerName, *obit; if( self->client->ps.pm_type == PM_DEAD ) return; if( level.intermissiontime ) return; self->client->ps.pm_type = PM_DEAD; self->suicideTime = 0; if( attacker ) { killer = attacker->s.number; if( attacker->client ) killerName = attacker->client->pers.netname; else killerName = "<world>"; } else { killer = ENTITYNUM_WORLD; killerName = "<world>"; } if( meansOfDeath < 0 || meansOfDeath >= ARRAY_LEN( modNames ) ) // fall back on the number obit = va( "%d", meansOfDeath ); else obit = modNames[ meansOfDeath ]; G_LogPrintf( "Die: %d %d %s: %s" S_COLOR_WHITE " killed %s\n", killer, (int)( self - g_entities ), obit, killerName, self->client->pers.netname ); // deactivate all upgrades for( i = UP_NONE + 1; i < UP_NUM_UPGRADES; i++ ) BG_DeactivateUpgrade( i, self->client->ps.stats ); // broadcast the death event to everyone ent = G_TempEntity( self->r.currentOrigin, EV_OBITUARY ); ent->s.eventParm = meansOfDeath; ent->s.otherEntityNum = self->s.number; ent->s.otherEntityNum2 = killer; ent->r.svFlags = SVF_BROADCAST; // send to everyone self->enemy = attacker; self->client->ps.persistant[ PERS_KILLED ]++; if( attacker && attacker->client ) { attacker->client->lastkilled_client = self->s.number; if( ( attacker == self || OnSameTeam( self, attacker ) ) && meansOfDeath != MOD_HSPAWN ) { //punish team kills and suicides if( attacker->client->ps.stats[ STAT_TEAM ] == TEAM_ALIENS ) { G_AddCreditToClient( attacker->client, -ALIEN_TK_SUICIDE_PENALTY, qtrue ); AddScore( attacker, -ALIEN_TK_SUICIDE_PENALTY ); } else if( attacker->client->ps.stats[ STAT_TEAM ] == TEAM_HUMANS ) { G_AddCreditToClient( attacker->client, -HUMAN_TK_SUICIDE_PENALTY, qtrue ); AddScore( attacker, -HUMAN_TK_SUICIDE_PENALTY ); } } } else if( attacker->s.eType != ET_BUILDABLE ) { if( self->client->ps.stats[ STAT_TEAM ] == TEAM_ALIENS ) AddScore( self, -ALIEN_TK_SUICIDE_PENALTY ); else if( self->client->ps.stats[ STAT_TEAM ] == TEAM_HUMANS ) AddScore( self, -HUMAN_TK_SUICIDE_PENALTY ); } // give credits for killing this player G_RewardAttackers( self ); ScoreboardMessage( self ); // show scores // send updated scores to any clients that are following this one, // or they would get stale scoreboards for( i = 0 ; i < level.maxclients ; i++ ) { gclient_t *client; client = &level.clients[ i ]; if( client->pers.connected != CON_CONNECTED ) continue; if( client->sess.spectatorState == SPECTATOR_NOT ) continue; if( client->sess.spectatorClient == self->s.number ) ScoreboardMessage( g_entities + i ); } VectorCopy( self->s.origin, self->client->pers.lastDeathLocation ); self->takedamage = qfalse; // can still be gibbed self->s.weapon = WP_NONE; self->r.contents = CONTENTS_CORPSE; self->s.angles[ PITCH ] = 0; self->s.angles[ ROLL ] = 0; self->s.angles[ YAW ] = self->s.apos.trBase[ YAW ]; LookAtKiller( self, inflictor, attacker ); VectorCopy( self->s.angles, self->client->ps.viewangles ); self->s.loopSound = 0; self->r.maxs[ 2 ] = -8; // don't allow respawn until the death anim is done // g_forcerespawn may force spawning at some later time self->client->respawnTime = level.time + 1700; // clear misc memset( self->client->ps.misc, 0, sizeof( self->client->ps.misc ) ); { // normal death static int i; if( !( self->client->ps.persistant[ PERS_STATE ] & PS_NONSEGMODEL ) ) { switch( i ) { case 0: anim = BOTH_DEATH1; break; case 1: anim = BOTH_DEATH2; break; case 2: default: anim = BOTH_DEATH3; break; } } else { switch( i ) { case 0: anim = NSPA_DEATH1; break; case 1: anim = NSPA_DEATH2; break; case 2: default: anim = NSPA_DEATH3; break; } } self->client->ps.legsAnim = ( ( self->client->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | anim; if( !( self->client->ps.persistant[ PERS_STATE ] & PS_NONSEGMODEL ) ) { self->client->ps.torsoAnim = ( ( self->client->ps.torsoAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | anim; } // use own entityid if killed by non-client to prevent uint8_t overflow G_AddEvent( self, EV_DEATH1 + i, ( killer < MAX_CLIENTS ) ? killer : self - g_entities ); // globally cycle through the different death animations i = ( i + 1 ) % 3; } trap_LinkEntity( self ); self->client->pers.infoChangeTime = level.time; }
/* =========== ClientDisconnect Called when a player drops from the server. Will not be called between levels. This should NOT be called directly by any game logic, call trap_DropClient(), which will call this and do server system housekeeping. ============ */ void ClientDisconnect( int clientNum ) { gentity_t *ent; gentity_t *tent; int i; // cleanup if we are kicking a bot that // hasn't spawned yet G_RemoveQueuedBotBegin( clientNum ); ent = g_entities + clientNum; if (!ent->client || ent->client->pers.connected == CON_DISCONNECTED) { return; } // stop any following clients for ( i = 0 ; i < level.maxclients ; i++ ) { if ( level.clients[i].sess.sessionTeam == TEAM_SPECTATOR && level.clients[i].sess.spectatorState == SPECTATOR_FOLLOW && level.clients[i].sess.spectatorClient == clientNum ) { StopFollowing( &g_entities[i] ); } } // send effect if they were completely connected if ( ent->client->pers.connected == CON_CONNECTED && ent->client->sess.sessionTeam != TEAM_SPECTATOR ) { tent = G_TempEntity( ent->client->ps.origin, EV_PLAYER_TELEPORT_OUT ); tent->s.clientNum = ent->s.clientNum; // They don't get to take powerups with them! // Especially important for stuff like CTF flags TossClientItems( ent ); #ifdef MISSIONPACK TossClientPersistantPowerups( ent ); if( g_gametype.integer == GT_HARVESTER ) { TossClientCubes( ent ); } #endif } G_LogPrintf( "ClientDisconnect: %i\n", clientNum ); // if we are playing in tourney mode and losing, give a win to the other player if ( (g_gametype.integer == GT_TOURNAMENT ) && !level.intermissiontime && !level.warmupTime && level.sortedClients[1] == clientNum ) { level.clients[ level.sortedClients[0] ].sess.wins++; ClientUserinfoChanged( level.sortedClients[0] ); } if( g_gametype.integer == GT_TOURNAMENT && ent->client->sess.sessionTeam == TEAM_FREE && level.intermissiontime ) { trap_Cmd_ExecuteText( EXEC_APPEND, "map_restart 0\n" ); level.restarted = qtrue; level.changemap = NULL; level.intermissiontime = 0; } trap_UnlinkEntity (ent); ent->s.modelindex = 0; ent->inuse = qfalse; ent->classname = "disconnected"; ent->client->pers.connected = CON_DISCONNECTED; ent->client->ps.persistant[PERS_TEAM] = TEAM_FREE; ent->client->sess.sessionTeam = TEAM_FREE; trap_SetConfigstring( CS_PLAYERS + clientNum, ""); CalculateRanks(); if ( ent->r.svFlags & SVF_BOT ) { BotAIShutdownClient( clientNum, qfalse ); } // clear player connection info level.connections[ent->client->pers.connectionNum].numLocalPlayers--; level.connections[ent->client->pers.connectionNum].localPlayerNums[ent->client->pers.localPlayerNum] = -1; ent->client->pers.localPlayerNum = ent->client->pers.connectionNum = -1; }
/** * @brief Log deconstruct/destroy events * @param self * @param actor * @param mod */ void G_LogDestruction( gentity_t *self, gentity_t *actor, int mod ) { buildFate_t fate; switch ( mod ) { case MOD_DECONSTRUCT: fate = BF_DECONSTRUCT; break; case MOD_REPLACE: fate = BF_REPLACE; break; case MOD_NOCREEP: fate = ( actor->client ) ? BF_UNPOWER : BF_AUTO; break; default: if ( actor->client ) { if ( actor->client->pers.team == BG_Buildable( self->s.modelindex )->team ) { fate = BF_TEAMKILL; } else { fate = BF_DESTROY; } } else { fate = BF_AUTO; } break; } G_BuildLogAuto( actor, self, fate ); // don't log when marked structures are removed if ( mod == MOD_REPLACE ) { return; } G_LogPrintf( "^3Deconstruct: %d %d %s %s: %s %s by %s", ( int )( actor - g_entities ), ( int )( self - g_entities ), BG_Buildable( self->s.modelindex )->name, modNames[ mod ], BG_Buildable( self->s.modelindex )->humanName, mod == MOD_DECONSTRUCT ? "deconstructed" : "destroyed", actor->client ? actor->client->pers.netname : "<world>" ); // No-power deaths for humans come after some minutes and it's confusing // when the messages appear attributed to the deconner. Just don't print them. if ( mod == MOD_NOCREEP && actor->client && actor->client->pers.team == TEAM_HUMANS ) { return; } if ( actor->client && actor->client->pers.team == BG_Buildable( self->s.modelindex )->team ) { G_TeamCommand( (team_t) actor->client->pers.team, va( "print_tr %s %s %s", mod == MOD_DECONSTRUCT ? QQ( N_("$1$ ^3DECONSTRUCTED^7 by $2$\n") ) : QQ( N_("$1$ ^3DESTROYED^7 by $2$\n") ), Quote( BG_Buildable( self->s.modelindex )->humanName ), Quote( actor->client->pers.netname ) ) ); } }
/* =========== ClientConnect Called when a player begins connecting to the server. Called again for every map change or tournement restart. The session information will be valid after exit. Return NULL if the client should be allowed, otherwise return a string with the reason for denial. Otherwise, the client will be sent the current gamestate and will eventually get to ClientBegin. firstTime will be qtrue the very first time a client connects to the server machine, but qfalse on map changes and tournement restarts. ============ */ char *ClientConnect( int clientNum, qboolean firstTime, qboolean isBot, int connectionNum, int localPlayerNum ) { char *value; // char *areabits; gclient_t *client; char userinfo[MAX_INFO_STRING]; gentity_t *ent; qboolean firstConnectionPlayer; ent = &g_entities[ clientNum ]; trap_GetUserinfo( clientNum, userinfo, sizeof( userinfo ) ); // Check if it's the first player on the client (i.e. not a splitscreen player) firstConnectionPlayer = ( level.connections[connectionNum].numLocalPlayers == 0 ); if ( firstConnectionPlayer ) { // IP filtering // https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=500 // recommanding PB based IP / GUID banning, the builtin system is pretty limited // check to see if they are on the banned IP list value = Info_ValueForKey (userinfo, "ip"); if ( G_FilterPacket( value ) ) { return "You are banned from this server."; } // we don't check password for bots and local client // NOTE: local client <-> "ip" "localhost" // this means this client is not running in our current process if ( !isBot && (strcmp(value, "localhost") != 0) ) { // check for a password value = Info_ValueForKey (userinfo, "password"); if ( g_password.string[0] && Q_stricmp( g_password.string, "none" ) && strcmp( g_password.string, value) != 0) { return "Invalid password"; } } } else { // Don't allow splitscreen players in single player. if ( g_singlePlayer.integer ) { return "Splitscreen not allowed in single player."; } } // if a player reconnects quickly after a disconnect, the client disconnect may never be called, thus flag can get lost in the ether if (ent->inuse) { G_LogPrintf("Forcing disconnect on active client: %i\n", clientNum); // so lets just fix up anything that should happen on a disconnect ClientDisconnect(clientNum); } // they can connect ent->client = level.clients + clientNum; client = ent->client; // areabits = client->areabits; memset( client, 0, sizeof(*client) ); client->pers.connected = CON_CONNECTING; // update client connection info level.connections[connectionNum].numLocalPlayers++; level.connections[connectionNum].localPlayerNums[localPlayerNum] = clientNum; client->pers.connectionNum = connectionNum; client->pers.localPlayerNum = localPlayerNum; // read or initialize the session data if ( firstTime || level.newSession ) { G_InitSessionData( client, userinfo ); } G_ReadSessionData( client ); if( isBot ) { ent->r.svFlags |= SVF_BOT; ent->inuse = qtrue; if( !G_BotConnect( clientNum, !firstTime ) ) { return "BotConnectfailed"; } } // get and distribute relevent paramters G_LogPrintf( "ClientConnect: %i\n", clientNum ); ClientUserinfoChanged( clientNum ); // don't do the "xxx connected" messages if they were caried over from previous level // or if they're an extra local player if ( firstTime && firstConnectionPlayer ) { trap_SendServerCommand( -1, va("print \"%s" S_COLOR_WHITE " connected\n\"", client->pers.netname) ); } if ( g_gametype.integer >= GT_TEAM && client->sess.sessionTeam != TEAM_SPECTATOR ) { BroadcastTeamChange( client, -1 ); } // count current clients and rank for scoreboard CalculateRanks(); // for statistics // client->areabits = areabits; // if ( !client->areabits ) // client->areabits = G_Alloc( (trap_AAS_PointReachabilityAreaIndex( NULL ) + 7) / 8 ); return NULL; }
void G_PlayerDie( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int meansOfDeath ) { gentity_t *ent; int anim; int killer; int i; const char *killerName, *obit; const gentity_t *assistantEnt; int assistant = ENTITYNUM_NONE; const char *assistantName = nullptr; team_t assistantTeam = TEAM_NONE; if ( self->client->ps.pm_type == PM_DEAD ) { return; } if ( level.intermissiontime ) { return; } self->client->ps.pm_type = PM_DEAD; self->suicideTime = 0; if ( attacker ) { killer = attacker->s.number; if ( attacker->client ) { killerName = attacker->client->pers.netname; } else { killerName = "<world>"; } } else { killer = ENTITYNUM_WORLD; killerName = "<world>"; } assistantEnt = G_FindKillAssist( self, attacker, &assistantTeam ); if ( assistantEnt ) { assistant = assistantEnt->s.number; if ( assistantEnt->client ) { assistantName = assistantEnt->client->pers.netname; } } if ( meansOfDeath < 0 || meansOfDeath >= (int) ARRAY_LEN( modNames ) ) { // fall back on the number obit = va( "%d", meansOfDeath ); } else { obit = modNames[ meansOfDeath ]; } if ( assistant != ENTITYNUM_NONE ) { G_LogPrintf( "Die: %d %d %s %d %d: %s^* killed %s^*; %s^* assisted", killer, ( int )( self - g_entities ), obit, assistant, assistantTeam, killerName, self->client->pers.netname, assistantName ); } else { G_LogPrintf( "Die: %d %d %s: %s^* killed %s", killer, ( int )( self - g_entities ), obit, killerName, self->client->pers.netname ); } // deactivate all upgrades for ( i = UP_NONE + 1; i < UP_NUM_UPGRADES; i++ ) { BG_DeactivateUpgrade( i, self->client->ps.stats ); } // broadcast the death event to everyone ent = G_NewTempEntity( self->r.currentOrigin, EV_OBITUARY ); ent->s.eventParm = meansOfDeath; ent->s.otherEntityNum = self->s.number; ent->s.otherEntityNum2 = killer; ent->s.otherEntityNum3 = assistant; ent->s.generic1 = assistantTeam; ent->r.svFlags = SVF_BROADCAST; // send to everyone if ( attacker && attacker->client ) { if ( ( attacker == self || G_OnSameTeam( self, attacker ) ) ) { //punish team kills and suicides if ( attacker->client->pers.team == TEAM_ALIENS ) { G_AddCreditToClient( attacker->client, -ALIEN_TK_SUICIDE_PENALTY, true ); G_AddCreditsToScore( attacker, -ALIEN_TK_SUICIDE_PENALTY ); } else if ( attacker->client->pers.team == TEAM_HUMANS ) { G_AddCreditToClient( attacker->client, -HUMAN_TK_SUICIDE_PENALTY, true ); G_AddCreditsToScore( attacker, -HUMAN_TK_SUICIDE_PENALTY ); } } else if ( g_showKillerHP.integer ) { trap_SendServerCommand( self - g_entities, va( "print_tr %s %s %3i", QQ( N_("Your killer, $1$^7, had $2$ HP.\n") ), Quote( killerName ), (int)std::ceil(attacker->entity->Get<HealthComponent>()->Health()) ) ); } } else if ( attacker->s.eType != entityType_t::ET_BUILDABLE ) { if ( self->client->pers.team == TEAM_ALIENS ) { G_AddCreditsToScore( self, -ALIEN_TK_SUICIDE_PENALTY ); } else if ( self->client->pers.team == TEAM_HUMANS ) { G_AddCreditsToScore( self, -HUMAN_TK_SUICIDE_PENALTY ); } } // give credits for killing this player G_RewardAttackers( self ); ScoreboardMessage( self ); // show scores // send updated scores to any clients that are following this one, // or they would get stale scoreboards for ( i = 0; i < level.maxclients; i++ ) { gclient_t *client; client = &level.clients[ i ]; if ( client->pers.connected != CON_CONNECTED ) { continue; } if ( client->sess.spectatorState == SPECTATOR_NOT ) { continue; } if ( client->sess.spectatorClient == self->s.number ) { ScoreboardMessage( g_entities + i ); } } VectorCopy( self->s.origin, self->client->pers.lastDeathLocation ); self->s.weapon = WP_NONE; if ( self->client->noclip ) { self->client->cliprcontents = CONTENTS_CORPSE; } else { self->r.contents = CONTENTS_CORPSE; } self->s.angles[ PITCH ] = 0; self->s.angles[ ROLL ] = 0; self->s.angles[ YAW ] = self->s.apos.trBase[ YAW ]; LookAtKiller( self, inflictor, attacker ); VectorCopy( self->s.angles, self->client->ps.viewangles ); self->s.loopSound = 0; self->r.maxs[ 2 ] = -8; // don't allow respawn until the death anim is done // g_forcerespawn may force spawning at some later time self->client->respawnTime = level.time + 1700; // clear misc memset( self->client->ps.misc, 0, sizeof( self->client->ps.misc ) ); { static int i; if ( !( self->client->ps.persistant[ PERS_STATE ] & PS_NONSEGMODEL ) ) { switch ( i ) { case 0: anim = BOTH_DEATH1; break; case 1: anim = BOTH_DEATH2; break; case 2: default: anim = BOTH_DEATH3; break; } } else { switch ( i ) { case 0: anim = NSPA_DEATH1; break; case 1: anim = NSPA_DEATH2; break; case 2: default: anim = NSPA_DEATH3; break; } } self->client->ps.legsAnim = ( ( self->client->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | anim; if ( !( self->client->ps.persistant[ PERS_STATE ] & PS_NONSEGMODEL ) ) { self->client->ps.torsoAnim = ( ( self->client->ps.torsoAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | anim; } // use own entityid if killed by non-client to prevent uint8_t overflow G_AddEvent( self, EV_DEATH1 + i, ( killer < MAX_CLIENTS ) ? killer : self - g_entities ); // globally cycle through the different death animations i = ( i + 1 ) % 3; } Beacon::DetachTags( self ); trap_LinkEntity( self ); self->client->pers.infoChangeTime = level.time; }
/* =========== ClientBegin Called when a client has finished connecting, and is ready to be placed into the level. This will happen on every level load and level restart, but doesn't happen on respawns. ============ */ void ClientBegin( int clientNum ) { gentity_t *ent; gclient_t *client; int flags; g_admin_admin_t *admin; ent = g_entities + clientNum; client = level.clients + clientNum; admin = client->pers.admin; // ignore if client already entered the game if ( client->pers.connected != CON_CONNECTING ) { return; } if ( ent->r.linked ) { trap_UnlinkEntity( ent ); } G_InitGentity( ent ); ent->touch = 0; ent->pain = 0; ent->client = client; client->pers.connected = CON_CONNECTED; client->pers.enterTime = level.time; if ( !client->pers.pubkey_authenticated && admin && admin->pubkey[ 0 ] ) { trap_SendServerCommand( ent - g_entities, va( "pubkey_decrypt %s", admin->msg2 ) ); // copy the decrypted message because generating a new message will overwrite it G_admin_writeconfig(); } // save eflags around this, because changing teams will // cause this to happen with a valid entity, and we // want to make sure the teleport bit is set right // so the viewpoint doesn't interpolate through the // world to the new position flags = client->ps.eFlags; memset( &client->ps, 0, sizeof( client->ps ) ); memset( &client->pmext, 0, sizeof( client->pmext ) ); client->ps.eFlags = flags; // locate ent at a spawn point ClientSpawn( ent, NULL, NULL, NULL ); trap_SendServerCommand( -1, va( "print_tr %s %s", QQ( N_("$1$^7 entered the game\n") ), Quote( client->pers.netname ) ) ); G_namelog_restore( client ); G_LogPrintf( "ClientBegin: %i\n", clientNum ); // count current clients and rank for scoreboard CalculateRanks(); // send the client a list of commands that can be used if ( !client->pers.admin ) { G_ListCommands( ent ); } }
int Pickup_Weapon( gentity_t *ent, gentity_t *other ) { int quantity; qboolean alreadyHave = qfalse; // JPW NERVE -- magic ammo for any two-handed weapon if( ent->item->giTag == WP_AMMO ) { AddMagicAmmo( other, ent->count ); // if LT isn't giving ammo to self or another LT or the enemy, give him some props if( other->client->ps.stats[STAT_PLAYER_CLASS] != PC_FIELDOPS ) { if ( ent->parent && ent->parent->client && other->client->sess.sessionTeam == ent->parent->client->sess.sessionTeam ) { if (!(ent->parent->client->PCSpecialPickedUpCount % LT_SPECIAL_PICKUP_MOD)) { AddScore(ent->parent, WOLF_AMMO_UP); if(ent->parent && ent->parent->client) { G_LogPrintf("Ammo_Pack: %d %d\n", ent->parent - g_entities, other - g_entities); // OSP } } ent->parent->client->PCSpecialPickedUpCount++; G_AddSkillPoints( ent->parent, SK_SIGNALS, 1.f ); G_DebugAddSkillPoints( ent->parent, SK_SIGNALS, 1.f, "ammo pack picked up" ); // extracted code originally here into AddMagicAmmo -xkan, 9/18/2002 // add 1 clip of magic ammo for any two-handed weapon } return RESPAWN_SP; } } quantity = ent->count; // check if player already had the weapon alreadyHave = COM_BitCheck( other->client->ps.weapons, ent->item->giTag ); // JPW NERVE prevents drop/pickup weapon "quick reload" exploit if( alreadyHave ) { Add_Ammo( other, ent->item->giTag, quantity, qfalse ); // Gordon: secondary weapon ammo if( ent->delay ) { Add_Ammo( other, weapAlts[ ent->item->giTag ], ent->delay, qfalse ); } } else { if( level.time - other->client->dropWeaponTime < 1000 ) { return 0; } if( other->client->ps.weapon == WP_MORTAR_SET || other->client->ps.weapon == WP_MOBILE_MG42_SET ) { return 0; } // See if we can pick it up if( G_CanPickupWeapon( ent->item->giTag, other ) ) { weapon_t primaryWeapon = G_GetPrimaryWeaponForClient( other->client ); // rain - added parens around ambiguous && if( primaryWeapon || (other->client->sess.playerType == PC_SOLDIER && other->client->sess.skill[SK_HEAVY_WEAPONS] >= 4) ) { if( primaryWeapon ) { // drop our primary weapon G_DropWeapon( other, primaryWeapon ); } // now pickup the other one other->client->dropWeaponTime = level.time; // add the weapon COM_BitSet( other->client->ps.weapons, ent->item->giTag ); // DHM - Fixup mauser/sniper issues if( ent->item->giTag == WP_FG42 ) { COM_BitSet( other->client->ps.weapons, WP_FG42SCOPE); } else if(ent->item->giTag == WP_GARAND) { COM_BitSet( other->client->ps.weapons, WP_GARAND_SCOPE); } else if( ent->item->giTag == WP_K43 ) { COM_BitSet( other->client->ps.weapons, WP_K43_SCOPE ); } else if( ent->item->giTag == WP_MORTAR ) { COM_BitSet( other->client->ps.weapons, WP_MORTAR_SET ); } else if( ent->item->giTag == WP_MOBILE_MG42 ) { COM_BitSet( other->client->ps.weapons, WP_MOBILE_MG42_SET ); } else if( ent->item->giTag == WP_CARBINE ) { COM_BitSet( other->client->ps.weapons, WP_M7 ); } else if( ent->item->giTag == WP_KAR98 ) { COM_BitSet( other->client->ps.weapons, WP_GPG40 ); } other->client->ps.ammoclip[BG_FindClipForWeapon(ent->item->giTag)] = 0; other->client->ps.ammo[BG_FindAmmoForWeapon(ent->item->giTag)] = 0; if( ent->item->giTag == WP_MORTAR ) { other->client->ps.ammo[BG_FindClipForWeapon(ent->item->giTag)] = quantity; // Gordon: secondary weapon ammo if( ent->delay ) { Add_Ammo( other, weapAlts[ ent->item->giTag ], ent->delay, qfalse ); } } else { other->client->ps.ammoclip[BG_FindClipForWeapon(ent->item->giTag)] = quantity; // Gordon: secondary weapon ammo if( ent->delay ) { other->client->ps.ammo[ weapAlts[ ent->item->giTag ] ] = ent->delay; } } } } else { return 0; } } // TAT 1/6/2003 - If we are a bot, call the pickup function if( other->r.svFlags & SVF_BOT ) BotPickupWeapon( other->s.number, ent->item->giTag, alreadyHave ); return -1; }
/* ================ LogExit Append information about this game to the log file ================ */ void LogExit( const char *string ) { int i, numSorted; gclient_t *cl; #ifdef MISSIONPACK qboolean won = qtrue; #endif G_LogPrintf( "Exit: %s\n", string ); level.intermissionQueued = level.time; // this will keep the clients from playing any voice sounds // that will get cut off when the queued intermission starts trap_SetConfigstring( CS_INTERMISSION, "1" ); // don't send more than 32 scores (FIXME?) numSorted = level.numConnectedClients; if ( numSorted > 32 ) { numSorted = 32; } if ( g_gametype.integer >= GT_TEAM ) { G_LogPrintf( "red:%i blue:%i\n", level.teamScores[TEAM_RED], level.teamScores[TEAM_BLUE] ); } for (i=0 ; i < numSorted ; i++) { int ping; cl = &level.clients[level.sortedClients[i]]; if ( cl->sess.sessionTeam == TEAM_SPECTATOR ) { continue; } if ( cl->pers.connected == CON_CONNECTING ) { continue; } ping = cl->ps.ping < 999 ? cl->ps.ping : 999; G_LogPrintf( "score: %i ping: %i client: %i %s\n", cl->ps.persistant[PERS_SCORE], ping, level.sortedClients[i], cl->pers.netname ); #ifdef MISSIONPACK if (g_singlePlayer.integer && g_gametype.integer == GT_TOURNAMENT) { if (g_entities[cl - level.clients].r.svFlags & SVF_BOT && cl->ps.persistant[PERS_RANK] == 0) { won = qfalse; } } #endif } #ifdef MISSIONPACK if (g_singlePlayer.integer) { if (g_gametype.integer >= GT_CTF) { won = level.teamScores[TEAM_RED] > level.teamScores[TEAM_BLUE]; } trap_SendConsoleCommand( EXEC_APPEND, (won) ? "spWin\n" : "spLose\n" ); } #endif }
/** * @brief Pick a weapon up. */ int Pickup_Weapon(gentity_t *ent, gentity_t *other) { int quantity; qboolean alreadyHave = qfalse; // magic ammo for any two-handed weapon if (ent->item->giTag == WP_AMMO) { AddMagicAmmo(other, ent->count); if (ent->parent && ent->parent->client) { other->client->pers.lastammo_client = ent->parent->s.clientNum; } // if LT isn't giving ammo to self or another LT or the enemy, give him some props if (other->client->ps.stats[STAT_PLAYER_CLASS] != PC_FIELDOPS) { if (ent->parent && ent->parent->client && other->client->sess.sessionTeam == ent->parent->client->sess.sessionTeam) { if (!(ent->parent->client->PCSpecialPickedUpCount % LT_SPECIAL_PICKUP_MOD)) { AddScore(ent->parent, WOLF_AMMO_UP); if (ent->parent && ent->parent->client) { G_LogPrintf("Ammo_Pack: %d %d\n", (int)(ent->parent - g_entities), (int)(other - g_entities)); } } ent->parent->client->PCSpecialPickedUpCount++; G_AddSkillPoints(ent->parent, SK_SIGNALS, 1.f); G_DebugAddSkillPoints(ent->parent, SK_SIGNALS, 1.f, "ammo pack picked up"); #ifdef FEATURE_OMNIBOT //omni-bot event if (ent->parent) { Bot_Event_RecievedAmmo(other - g_entities, ent->parent); } #endif // extracted code originally here into AddMagicAmmo // add 1 clip of magic ammo for any two-handed weapon } return RESPAWN_NEVER; } } quantity = ent->count; // check if player already had the weapon alreadyHave = COM_BitCheck(other->client->ps.weapons, ent->item->giTag); // prevents drop/pickup weapon "quick reload" exploit if (alreadyHave) { Add_Ammo(other, ent->item->giTag, quantity, qfalse); // secondary weapon ammo if (ent->delay) { Add_Ammo(other, weaponTable[ent->item->giTag].weapAlts, ent->delay, qfalse); } } else { if (level.time - other->client->dropWeaponTime < 1000) { return 0; } // don't pick up when MG or mortar is set if (IS_MORTAR_WEAPON_SET(other->client->ps.weapon) || IS_MG_WEAPON_SET(other->client->ps.weapon)) { return 0; } // see if we can pick it up if (G_CanPickupWeapon(ent->item->giTag, other)) { weapon_t primaryWeapon; if (other->client->sess.playerType == PC_SOLDIER && other->client->sess.skill[SK_HEAVY_WEAPONS] >= 4) { primaryWeapon = G_GetPrimaryWeaponForClientSoldier(ent->item->giTag, other->client); } else { primaryWeapon = G_GetPrimaryWeaponForClient(other->client); } // added parens around ambiguous && if (primaryWeapon) { // drop our primary weapon G_DropWeapon(other, primaryWeapon); // now pickup the other one other->client->dropWeaponTime = level.time; // add the weapon COM_BitSet(other->client->ps.weapons, ent->item->giTag); // fixup mauser/sniper issues switch (ent->item->giTag) { case WP_FG42: COM_BitSet(other->client->ps.weapons, WP_FG42SCOPE); break; case WP_GARAND: COM_BitSet(other->client->ps.weapons, WP_GARAND_SCOPE); break; case WP_K43: COM_BitSet(other->client->ps.weapons, WP_K43_SCOPE); break; case WP_MORTAR: COM_BitSet(other->client->ps.weapons, WP_MORTAR_SET); break; case WP_MORTAR2: COM_BitSet(other->client->ps.weapons, WP_MORTAR2_SET); break; case WP_MOBILE_MG42: COM_BitSet(other->client->ps.weapons, WP_MOBILE_MG42_SET); break; case WP_MOBILE_BROWNING: COM_BitSet(other->client->ps.weapons, WP_MOBILE_BROWNING_SET); break; case WP_CARBINE: COM_BitSet(other->client->ps.weapons, WP_M7); break; case WP_KAR98: COM_BitSet(other->client->ps.weapons, WP_GPG40); break; default: break; } other->client->ps.ammoclip[BG_FindClipForWeapon(ent->item->giTag)] = 0; other->client->ps.ammo[BG_FindAmmoForWeapon(ent->item->giTag)] = 0; if (ent->item->giTag == WP_MORTAR || ent->item->giTag == WP_MORTAR2) { other->client->ps.ammo[BG_FindClipForWeapon(ent->item->giTag)] = quantity; // secondary weapon ammo if (ent->delay) { Add_Ammo(other, weaponTable[ent->item->giTag].weapAlts, ent->delay, qfalse); } } else { other->client->ps.ammoclip[BG_FindClipForWeapon(ent->item->giTag)] = quantity; // secondary weapon ammo if (ent->delay) { other->client->ps.ammo[weaponTable[ent->item->giTag].weapAlts] = ent->delay; } } } } else { return 0; } } #ifdef FEATURE_OMNIBOT Bot_Event_AddWeapon(other->client->ps.clientNum, Bot_WeaponGameToBot(ent->item->giTag)); #endif return RESPAWN_NEVER; }
/* ============ G_InitGame ============ */ void G_InitGame( int levelTime, int randomSeed, int restart ) { int i; G_Printf ("------- Game Initialization -------\n"); G_Printf ("gamename: %s\n", GAMEVERSION); G_Printf ("gamedate: %s\n", __DATE__); srand( randomSeed ); G_RegisterCvars(); G_ProcessIPBans(); G_InitMemory(); // set some level globals memset( &level, 0, sizeof( level ) ); level.time = levelTime; level.startTime = levelTime; level.snd_fry = G_SoundIndex("sound/player/fry.wav"); // FIXME standing in lava / slime if ( g_gametype.integer != GT_SINGLE_PLAYER && g_logfile.string[0] ) { if ( g_logfileSync.integer ) { trap_FS_FOpenFile( g_logfile.string, &level.logFile, FS_APPEND_SYNC ); } else { trap_FS_FOpenFile( g_logfile.string, &level.logFile, FS_APPEND ); } if ( !level.logFile ) { G_Printf( "WARNING: Couldn't open logfile: %s\n", g_logfile.string ); } else { char serverinfo[MAX_INFO_STRING]; trap_GetServerinfo( serverinfo, sizeof( serverinfo ) ); G_LogPrintf("------------------------------------------------------------\n" ); G_LogPrintf("InitGame: %s\n", serverinfo ); } } else { G_Printf( "Not logging to disk.\n" ); } G_InitWorldSession(); // initialize all entities for this game memset( g_entities, 0, MAX_GENTITIES * sizeof(g_entities[0]) ); level.gentities = g_entities; // initialize all clients for this game level.maxclients = g_maxclients.integer; memset( g_clients, 0, MAX_CLIENTS * sizeof(g_clients[0]) ); level.clients = g_clients; // set client fields on player ents for ( i=0 ; i<level.maxclients ; i++ ) { g_entities[i].client = level.clients + i; } // always leave room for the max number of clients, // even if they aren't all used, so numbers inside that // range are NEVER anything but clients level.num_entities = MAX_CLIENTS; // let the server system know where the entites are trap_LocateGameData( level.gentities, level.num_entities, sizeof( gentity_t ), &level.clients[0].ps, sizeof( level.clients[0] ) ); // reserve some spots for dead player bodies InitBodyQue(); ClearRegisteredItems(); // parse the key/value pairs and spawn gentities G_SpawnEntitiesFromString(); // general initialization G_FindTeams(); // make sure we have flags for CTF, etc if( g_gametype.integer >= GT_TEAM ) { G_CheckTeamItems(); } SaveRegisteredItems(); G_Printf ("-----------------------------------\n"); if( g_gametype.integer == GT_SINGLE_PLAYER || trap_Cvar_VariableIntegerValue( "com_buildScript" ) ) { G_ModelIndex( SP_PODIUM_MODEL ); G_SoundIndex( "sound/player/gurp1.wav" ); G_SoundIndex( "sound/player/gurp2.wav" ); } if ( trap_Cvar_VariableIntegerValue( "bot_enable" ) ) { BotAISetup( restart ); BotAILoadMap( restart ); G_InitBots( restart ); } G_RemapTeamShaders(); }
/** * @brief Action when touching an item. */ void Touch_Item(gentity_t *ent, gentity_t *other, trace_t *trace) { int respawn; // only activated items can be picked up if (!ent->active) { return; } else { // need to set active to false if player is maxed out ent->active = qfalse; } if (!other->client) { return; } if (other->health <= 0) { return; // dead people can't pickup } // the same pickup rules are used for client side and server side if (!BG_CanItemBeGrabbed(&ent->s, &other->client->ps, other->client->sess.skill, other->client->sess.sessionTeam)) { return; } if (g_gamestate.integer == GS_PLAYING) { G_LogPrintf("Item: %i %s\n", other->s.number, ent->item->classname); } else { // Don't let them pickup winning stuff in warmup if (ent->item->giType != IT_WEAPON && ent->item->giType != IT_AMMO && ent->item->giType != IT_HEALTH) { return; } } //G_LogPrintf( "Calling item pickup function for %s\n", ent->item->classname ); // call the item-specific pickup function switch (ent->item->giType) { case IT_WEAPON: respawn = Pickup_Weapon(ent, other); break; case IT_HEALTH: respawn = Pickup_Health(ent, other); break; case IT_TEAM: respawn = Pickup_Team(ent, other); break; default: return; } //G_LogPrintf( "Finished pickup function\n" ); if (!respawn) { return; } // play sounds if (ent->noise_index) { // a sound was specified in the entity, so play that sound // (this G_AddEvent) and send the pickup as "EV_ITEM_PICKUP_QUIET" // so it doesn't make the default pickup sound when the pickup event is received G_AddEvent(other, EV_GENERAL_SOUND, ent->noise_index); G_AddEvent(other, EV_ITEM_PICKUP_QUIET, ent->s.modelindex); } else { G_AddEvent(other, EV_ITEM_PICKUP, ent->s.modelindex); } // powerup pickups are global broadcasts if (ent->item->giType == IT_TEAM) { gentity_t *te = G_TempEntity(ent->s.pos.trBase, EV_GLOBAL_ITEM_PICKUP); te->s.eventParm = ent->s.modelindex; te->r.svFlags |= SVF_BROADCAST; } //G_LogPrintf( "Firing item targets\n" ); // fire item targets G_UseTargets(ent, other); // dropped items will not respawn if (ent->flags & FL_DROPPED_ITEM) { ent->freeAfterEvent = qtrue; } // picked up items still stay around, they just don't // draw anything. This allows respawnable items // to be placed on movers. ent->r.svFlags |= SVF_NOCLIENT; ent->flags |= FL_NODRAW; ent->r.contents = 0; // A negative respawn times means to never respawn this item (but don't // delete it). This is used by items that are respawned by third party // events such as ctf flags if (respawn <= 0) { ent->nextthink = 0; ent->think = 0; } else { ent->nextthink = level.time + respawn * 1000; ent->think = RespawnItem; } trap_LinkEntity(ent); }
/* =========== ClientUserInfoChanged Called from ClientConnect when the player first connects and directly by the server system when the player updates a userinfo variable. The game can override any of the settings and call trap_SetUserinfo if desired. ============ */ void ClientUserinfoChanged( int clientNum ) { gentity_t *ent; int teamTask, teamLeader, health; char *s; char model[ MAX_QPATH ]; char buffer[ MAX_QPATH ]; char filename[ MAX_QPATH ]; char oldname[ MAX_NAME_LENGTH ]; char newname[ MAX_NAME_LENGTH ]; char err[ MAX_STRING_CHARS ]; qboolean revertName = qfalse; qboolean showRenameMsg = qtrue; gclient_t *client; char c1[ MAX_INFO_STRING ]; char c2[ MAX_INFO_STRING ]; char userinfo[ MAX_INFO_STRING ]; team_t team; ent = g_entities + clientNum; client = ent->client; trap_GetUserinfo( clientNum, userinfo, sizeof( userinfo ) ); // check for malformed or illegal info strings if( !Info_Validate(userinfo) ) strcpy( userinfo, "\\name\\badinfo" ); // check for local client s = Info_ValueForKey( userinfo, "ip" ); if( !strcmp( s, "localhost" ) ) client->pers.localClient = qtrue; // check the item prediction s = Info_ValueForKey( userinfo, "cg_predictItems" ); if( !atoi( s ) ) client->pers.predictItemPickup = qfalse; else client->pers.predictItemPickup = qtrue; // set name Q_strncpyz( oldname, client->pers.netname, sizeof( oldname ) ); s = Info_ValueForKey( userinfo, "name" ); ClientCleanName( s, newname, sizeof( newname ) ); if( strcmp( oldname, newname ) ) { if( !strlen( oldname ) && client->pers.connected != CON_CONNECTED ) showRenameMsg = qfalse; // in case we need to revert and there's no oldname ClientCleanName( va( "%s", client->pers.netname ), oldname, sizeof( oldname ) ); if( g_newbieNumbering.integer ) { if( !strcmp( newname, "UnnamedPlayer" ) ) Q_strncpyz( newname, G_NextNewbieName( ent ), sizeof( newname ) ); if( !strcmp( oldname, "UnnamedPlayer" ) ) Q_strncpyz( oldname, G_NextNewbieName( ent ), sizeof( oldname ) ); } if( client->pers.muted ) { trap_SendServerCommand( ent - g_entities, "print \"You cannot change your name while you are muted\n\"" ); revertName = qtrue; } else if( client->pers.nameChangeTime && ( level.time - client->pers.nameChangeTime ) <= ( g_minNameChangePeriod.value * 1000 ) ) { trap_SendServerCommand( ent - g_entities, va( "print \"Name change spam protection (g_minNameChangePeriod = %d)\n\"", g_minNameChangePeriod.integer ) ); revertName = qtrue; } else if( g_maxNameChanges.integer > 0 && client->pers.nameChanges >= g_maxNameChanges.integer ) { trap_SendServerCommand( ent - g_entities, va( "print \"Maximum name changes reached (g_maxNameChanges = %d)\n\"", g_maxNameChanges.integer ) ); revertName = qtrue; } else if( !G_admin_name_check( ent, newname, err, sizeof( err ) ) ) { trap_SendServerCommand( ent - g_entities, va( "print \"%s\n\"", err ) ); revertName = qtrue; } else if( client->pers.nlocked ) { trap_SendServerCommand( ent - g_entities, "print \"Your name is locked, you can no longer rename.\n\"" ); revertName = qtrue; } if( revertName ) { Q_strncpyz( client->pers.netname, oldname, sizeof( client->pers.netname ) ); Info_SetValueForKey( userinfo, "name", oldname ); trap_SetUserinfo( clientNum, userinfo ); } else { Q_strncpyz( client->pers.netname, newname, sizeof( client->pers.netname ) ); Info_SetValueForKey( userinfo, "name", newname ); trap_SetUserinfo( clientNum, userinfo ); if( client->pers.connected == CON_CONNECTED ) { client->pers.nameChangeTime = level.time; client->pers.nameChanges++; } } } if( client->sess.sessionTeam == TEAM_SPECTATOR ) { if( client->sess.spectatorState == SPECTATOR_SCOREBOARD ) Q_strncpyz( client->pers.netname, "scoreboard", sizeof( client->pers.netname ) ); } if( client->pers.connected >= CON_CONNECTING && showRenameMsg ) { if( strcmp( oldname, client->pers.netname ) ) { trap_SendServerCommand( -1, va( "print \"%s" S_COLOR_WHITE " renamed to %s^7\n\"", oldname, client->pers.netname ) ); if( g_decolourLogfiles.integer) { char decoloured[ MAX_STRING_CHARS ] = ""; if( g_decolourLogfiles.integer == 1 ) { Com_sprintf( decoloured, sizeof(decoloured), " (\"%s^7\" -> \"%s^7\")", oldname, client->pers.netname ); G_DecolorString( decoloured, decoloured ); G_LogPrintfColoured( "ClientRename: %i [%s] (%s) \"%s^7\" -> \"%s^7\"%s\n", clientNum, client->pers.ip, client->pers.guid, oldname, client->pers.netname, decoloured ); } else { G_LogPrintf( "ClientRename: %i [%s] (%s) \"%s^7\" -> \"%s^7\"%s\n", clientNum, client->pers.ip, client->pers.guid, oldname, client->pers.netname, decoloured ); } } else { G_LogPrintf( "ClientRename: %i [%s] (%s) \"%s^7\" -> \"%s^7\"\n", clientNum, client->pers.ip, client->pers.guid, oldname, client->pers.netname ); } G_admin_namelog_update( client, qfalse ); } } // set max health health = atoi( Info_ValueForKey( userinfo, "handicap" ) ); client->pers.maxHealth = health; if( client->pers.maxHealth < 1 || client->pers.maxHealth > 100 ) client->pers.maxHealth = 100; //hack to force a client update if the config string does not change between spawning if( client->pers.classSelection == PCL_NONE ) client->pers.maxHealth = 0; // set model if( client->ps.stats[ STAT_PCLASS ] == PCL_HUMAN && BG_InventoryContainsUpgrade( UP_BATTLESUIT, client->ps.stats ) ) { Com_sprintf( buffer, MAX_QPATH, "%s/%s", BG_FindModelNameForClass( PCL_HUMAN_BSUIT ), BG_FindSkinNameForClass( PCL_HUMAN_BSUIT ) ); } else if( client->pers.classSelection == PCL_NONE ) { //This looks hacky and frankly it is. The clientInfo string needs to hold different //model details to that of the spawning class or the info change will not be //registered and an axis appears instead of the player model. There is zero chance //the player can spawn with the battlesuit, hence this choice. Com_sprintf( buffer, MAX_QPATH, "%s/%s", BG_FindModelNameForClass( PCL_HUMAN_BSUIT ), BG_FindSkinNameForClass( PCL_HUMAN_BSUIT ) ); } else { Com_sprintf( buffer, MAX_QPATH, "%s/%s", BG_FindModelNameForClass( client->pers.classSelection ), BG_FindSkinNameForClass( client->pers.classSelection ) ); } Q_strncpyz( model, buffer, sizeof( model ) ); //don't bother setting model type if spectating if( client->pers.classSelection != PCL_NONE ) { //model segmentation Com_sprintf( filename, sizeof( filename ), "models/players/%s/animation.cfg", BG_FindModelNameForClass( client->pers.classSelection ) ); if( G_NonSegModel( filename ) ) client->ps.persistant[ PERS_STATE ] |= PS_NONSEGMODEL; else client->ps.persistant[ PERS_STATE ] &= ~PS_NONSEGMODEL; } // wallwalk follow s = Info_ValueForKey( userinfo, "cg_wwFollow" ); if( atoi( s ) ) client->ps.persistant[ PERS_STATE ] |= PS_WALLCLIMBINGFOLLOW; else client->ps.persistant[ PERS_STATE ] &= ~PS_WALLCLIMBINGFOLLOW; // wallwalk toggle s = Info_ValueForKey( userinfo, "cg_wwToggle" ); if( atoi( s ) ) client->ps.persistant[ PERS_STATE ] |= PS_WALLCLIMBINGTOGGLE; else client->ps.persistant[ PERS_STATE ] &= ~PS_WALLCLIMBINGTOGGLE; // teamInfo s = Info_ValueForKey( userinfo, "teamoverlay" ); if( ! *s || atoi( s ) != 0 ) client->pers.teamInfo = qtrue; else client->pers.teamInfo = qfalse; s = Info_ValueForKey( userinfo, "cg_unlagged" ); if( !s[0] || atoi( s ) != 0 ) client->pers.useUnlagged = qtrue; else client->pers.useUnlagged = qfalse; // team task (0 = none, 1 = offence, 2 = defence) teamTask = atoi( Info_ValueForKey( userinfo, "teamtask" ) ); // team Leader (1 = leader, 0 is normal player) teamLeader = client->sess.teamLeader; // colors strcpy( c1, Info_ValueForKey( userinfo, "color1" ) ); strcpy( c2, Info_ValueForKey( userinfo, "color2" ) ); team = client->pers.teamSelection; // send over a subset of the userinfo keys so other clients can // print scoreboards, display models, and play custom sounds Com_sprintf( userinfo, sizeof( userinfo ), "n\\%s\\t\\%i\\model\\%s\\hmodel\\%s\\c1\\%s\\c2\\%s\\" "hc\\%i\\w\\%i\\l\\%i\\tt\\%d\\" "tl\\%d\\ig\\%16s", client->pers.netname, team, model, model, c1, c2, client->pers.maxHealth, client->sess.wins, client->sess.losses, teamTask, teamLeader, BG_ClientListString( &client->sess.ignoreList ) ); trap_SetConfigstring( CS_PLAYERS + clientNum, userinfo ); /*G_LogPrintf( "ClientUserinfoChanged: %i %s\n", clientNum, userinfo );*/ }
/* =========== ClientUserInfoChanged Called from ClientConnect when the player first connects and directly by the server system when the player updates a userinfo variable. The game can override any of the settings and call trap_SetUserinfo if desired. ============ */ void ClientUserinfoChanged(int clientNum) { gentity_t *ent; char *s; char oldname[MAX_STRING_CHARS]; char userinfo[MAX_INFO_STRING]; gclient_t *client; char *ip = NULL; // Nico, used to store client ip char *rate = NULL; // Nico, used to store client rate char *snaps = NULL; // Nico, used to store client snaps char *name = NULL; // Nico, used to store client name char oldAuthToken[MAX_QPATH]; // Nico, used to see if auth token was changed ent = g_entities + clientNum; client = ent->client; client->ps.clientNum = clientNum; // Nico, flood protection if (ClientIsFlooding(ent)) { G_LogPrintf("Dropping client %d: flooded userinfo\n", clientNum); trap_DropClient(clientNum, "^1You were kicked because of flooded userinfo", 0); return; } trap_GetUserinfo(clientNum, userinfo, sizeof (userinfo)); // Nico, perform security checks on userinfo string if (!checkUserinfoString(clientNum, userinfo)) { return; } if (g_developer.integer || *g_log.string || g_dedicated.integer) { G_Printf("Userinfo: %s\n", userinfo); } // check for local client ip = Info_ValueForKey(userinfo, "ip"); Q_strncpyz(client->pers.ip, ip, IP_MAX_LENGTH); if (ip && !strcmp(ip, "localhost")) { client->pers.localClient = qtrue; level.fLocalHost = qtrue; client->sess.referee = RL_REFEREE; } // Nico, store rate and snaps rate = Info_ValueForKey(userinfo, "rate"); client->pers.rate = atoi(rate); snaps = Info_ValueForKey(userinfo, "snaps"); client->pers.snaps = atoi(snaps); // Nico, backup old auth token Q_strncpyz(oldAuthToken, client->pers.authToken, sizeof (oldAuthToken)); s = Info_ValueForKey(userinfo, "cg_uinfo"); sscanf(s, "%i %i %i %i %s %i %i %i %i %i %i %i %i %i", &client->pers.clientFlags, &client->pers.clientTimeNudge, &client->pers.clientMaxPackets, // Nico, max FPS &client->pers.maxFPS, // Nico, auth Token (char *)&client->pers.authToken, // Nico, load view angles on load &client->pers.loadViewAngles, // Nico, load weapon on load &client->pers.loadWeapon, // Nico, load position when player dies &client->pers.autoLoad, // Nico, cgaz &client->pers.cgaz, // Nico, hideme &client->pers.hideme, // Nico, client auto demo record setting &client->pers.autoDemo, // Nico, automatically load checkpoints &client->pers.autoLoadCheckpoints, // Nico, persistant specLock (int *)&client->sess.specLocked, // Nico, keep all demos &client->pers.keepAllDemos ); // Nico, check if auth token was changed if (oldAuthToken[0] != '\0' && Q_stricmp(oldAuthToken, client->pers.authToken) && client->sess.logged) { // Nico, auth token was changed => logout player if he was logged in CP("cp \"You are no longer logged in!\n\""); G_LogPrintf("ClientUserinfoChanged: authToken changed for client %d, forcing logout\n", clientNum); ent->client->sess.logged = qfalse; } client->pers.autoActivate = (client->pers.clientFlags & CGF_AUTOACTIVATE) ? PICKUP_TOUCH : PICKUP_ACTIVATE; client->pers.predictItemPickup = ((client->pers.clientFlags & CGF_PREDICTITEMS) != 0); if (client->pers.clientFlags & CGF_AUTORELOAD) { client->pers.bAutoReloadAux = qtrue; client->pmext.bAutoReload = qtrue; } else { client->pers.bAutoReloadAux = qfalse; client->pmext.bAutoReload = qfalse; } // Nico, pmove_fixed client->pers.pmoveFixed = client->pers.clientFlags & CGF_PMOVEFIXED; // Nico, autologin client->pers.autoLogin = client->pers.clientFlags & CGF_AUTOLOGIN; // // Nico, name handling // // Backup old name Q_strncpyz(oldname, client->pers.netname, sizeof (oldname)); // Get new name from userinfo string name = Info_ValueForKey(userinfo, "name"); // Clean the new name ClientCleanName(name, client->pers.netname, sizeof (client->pers.netname)); // Check it's valid if (CheckName(client->pers.netname) != qtrue) { // Invalid name, restore old name Q_strncpyz(client->pers.netname, oldname, sizeof (client->pers.netname)); Info_SetValueForKey(userinfo, "name", oldname); trap_SetUserinfo(clientNum, userinfo); CPx(clientNum, "print \"^1Invalid name, name change refused\n\""); G_LogPrintf("Client %d name change refused\n", clientNum); } else { // Name is valid // Now, check if name was changed or not if (client->pers.connected == CON_CONNECTED && strcmp(oldname, client->pers.netname) != 0) { // Name was changed // Now, check name changes limit if (g_maxNameChanges.integer > -1 && client->pers.nameChanges >= g_maxNameChanges.integer) { // Nico, limit reached, forbid name change Q_strncpyz(client->pers.netname, oldname, sizeof (client->pers.netname)); Info_SetValueForKey(userinfo, "name", oldname); trap_SetUserinfo(clientNum, userinfo); CPx(clientNum, "print \"^1You had too many namechanges\n\""); G_LogPrintf("Client %d name change refused\n", clientNum); return; } client->pers.nameChanges++; trap_SendServerCommand(-1, va("print \"%s" S_COLOR_WHITE " renamed to %s\n\"", oldname, client->pers.netname)); } } // // Nico, end of name handling // client->ps.stats[STAT_MAX_HEALTH] = client->pers.maxHealth; // To communicate it to cgame client->ps.stats[STAT_PLAYER_CLASS] = client->sess.playerType; // Gordon: Not needed any more as it's in clientinfo? // send over a subset of the userinfo keys so other clients can // print scoreboards, display models, and play custom sounds s = va("n\\%s\\t\\%i\\c\\%i\\w\\%i\\lw\\%i\\sw\\%i\\mu\\%i\\ref\\%i\\pm\\%i\\l\\%i\\h\\%i\\cc\\%i", client->pers.netname, client->sess.sessionTeam, client->sess.playerType, client->sess.playerWeapon, client->sess.latchPlayerWeapon, client->sess.latchPlayerWeapon2, client->sess.muted ? 1 : 0, client->sess.referee, client->pers.pmoveFixed ? 1 : 0, // Nico, pmove_fixed client->sess.logged ? 1 : 0, // Nico, login status client->pers.hideme, // Nico, hideme client->sess.countryCode// Nico, country code (GeoIP) ); trap_GetConfigstring(CS_PLAYERS + clientNum, oldname, sizeof (oldname)); trap_SetConfigstring(CS_PLAYERS + clientNum, s); if (!Q_stricmp(oldname, s)) { return; } G_LogPrintf("ClientUserinfoChanged: %i %s\n", clientNum, s); G_DPrintf("ClientUserinfoChanged: %i :: %s\n", clientNum, s); }