void CGameControllerOpenFNG::HandleMelt(int Melter, int Meltee) { CCharacter *pMeltee = CHAR(Meltee); if (!pMeltee) //due to HandleFreeze, i suspect this COULD also possibly happen. { D("no pMeltee in HandleMelt(%d, %d)", Melter, Meltee); return; } int MeltTeam = pMeltee->GetPlayer()->GetTeam()&1; m_aTeamscore[MeltTeam] += CFG(MeltTeamscore); if (CFG(MeltTeamscore) && CFG(MeltBroadcast)) { char aBuf[64]; str_format(aBuf, sizeof aBuf, "%s melted (%+d)", GetTeamName(MeltTeam), CFG(MeltTeamscore)); m_Broadcast.Update(-1, aBuf, CFG(BroadcastTime) * TS); } CPlayer *pPlMelter = TPLAYER(Melter); if (!pPlMelter) return; pPlMelter->m_Score += CFG(MeltScore); SendFreezeKill(Melter, Meltee, WEAPON_HAMMER); if (pPlMelter->GetCharacter() && CFG(MeltLoltext) && CFG(MeltScore)) { char aBuf[64]; str_format(aBuf, sizeof aBuf, "%+d", CFG(MeltScore)); GS->CreateLolText(pPlMelter->GetCharacter(), false, vec2(0.f, -50.f), vec2(0.f, 0.f), 50, aBuf); } }
//========================================================= //========================================================= void CHalfLifeMultiplay :: ClientDisconnected( edict_t *pClient ) { if ( pClient ) { CBasePlayer *pPlayer = (CBasePlayer *)CBaseEntity::Instance( pClient ); if ( pPlayer ) { FireTargets( "game_playerleave", pPlayer, pPlayer, USE_TOGGLE, 0 ); #if !defined( THREEWAVE ) UTIL_LogPrintf( "\"%s<%i><%s><%i>\" disconnected\n", STRING( pPlayer->pev->netname ), GETPLAYERUSERID( pPlayer->edict() ), GETPLAYERAUTHID( pPlayer->edict() ), GETPLAYERUSERID( pPlayer->edict() ) ); #else UTIL_LogPrintf( "\"%s<%i><%s><%s>\" disconnected\n", STRING( pPlayer->pev->netname ), GETPLAYERUSERID( pPlayer->edict() ), GETPLAYERAUTHID( pPlayer->edict() ), GetTeamName( pPlayer->pev->team ) ); #endif pPlayer->RemoveAllItems( TRUE );// destroy all of the players weapons and items } } }
//------------------------------------------------------------------------ IMPLEMENT_RMI(CGameRules, ClSetTeam) { if (!params.entityId) // ignore these for now return true; int oldTeam = GetTeam(params.entityId); if (oldTeam==params.teamId) return true; TEntityTeamIdMap::iterator it=m_entityteams.find(params.entityId); if (it!=m_entityteams.end()) m_entityteams.erase(it); IActor *pActor=m_pActorSystem->GetActor(params.entityId); bool isplayer=pActor!=0; if (isplayer && oldTeam) { TPlayerTeamIdMap::iterator pit=m_playerteams.find(oldTeam); assert(pit!=m_playerteams.end()); stl::find_and_erase(pit->second, params.entityId); } if (params.teamId) { m_entityteams.insert(TEntityTeamIdMap::value_type(params.entityId, params.teamId)); if (isplayer) { TPlayerTeamIdMap::iterator pit=m_playerteams.find(params.teamId); assert(pit!=m_playerteams.end()); pit->second.push_back(params.entityId); } } if(IActor *pClient = g_pGame->GetIGameFramework()->GetClientActor()) { if(GetTeam(pClient->GetEntityId()) == params.teamId) { if(params.entityId == pClient->GetGameObject()->GetWorldQuery()->GetLookAtEntityId()) { if(g_pGame->GetHUD()) { g_pGame->GetHUD()->GetCrosshair()->SetUsability(0); } } } } if(isplayer) { ReconfigureVoiceGroups(params.entityId,oldTeam,params.teamId); if (pActor->IsClient()) m_pRadio->SetTeam(GetTeamName(params.teamId)); } ScriptHandle handle(params.entityId); CallScript(m_clientStateScript, "OnSetTeam", handle, params.teamId); return true; }
void CGameControllerOpenFNG::HandleSacr(int Killer, int Victim, int ShrineTeam) {//assertion: Killer >= 0, victim anyways CCharacter *pVictim = CHAR(Victim); if (!pVictim) //due to HandleFreeze, i suspect this COULD also possibly happen. { D("no pVictim in HandleSacr(%d, %d, %d)", Killer, Victim, ShrineTeam); return; } int FailTeam = pVictim->GetPlayer()->GetTeam(); bool Wrong = ShrineTeam != -1 && FailTeam == ShrineTeam; m_aTeamscore[1-FailTeam] += Wrong?CFG(WrongSacrTeamscore):(ShrineTeam == -1 ? CFG(SacrTeamscore) : CFG(RightSacrTeamscore)); if (!Wrong) { if (CFG(SacrSound) == 1) GameServer()->CreateSoundGlobal(SOUND_CTF_CAPTURE); else if (CFG(SacrSound) == 2) GameServer()->CreateSound(pVictim->m_Pos, SOUND_CTF_CAPTURE); } if (((Wrong && CFG(WrongSacrTeamscore)) || (!Wrong && (ShrineTeam == -1 ? CFG(SacrTeamscore) : CFG(RightSacrTeamscore)))) && CFG(SacrBroadcast)) { char aBuf[64]; str_format(aBuf, sizeof aBuf, "%s sacrificed%s (%+d)", GetTeamName(1-FailTeam), Wrong?" in wrong shrine":(ShrineTeam == -1 ? "" : ", pleasing their gods"), Wrong?CFG(WrongSacrTeamscore):(ShrineTeam == -1 ? CFG(SacrTeamscore):CFG(RightSacrTeamscore))); m_Broadcast.Update(-1, aBuf, CFG(BroadcastTime) * TS); } CPlayer *pPlKiller = TPLAYER(Killer); if (!pPlKiller) return; pPlKiller->m_Score += Wrong?CFG(WrongSacrScore):(ShrineTeam == -1 ? CFG(SacrScore) : CFG(RightSacrScore)); SendKill(Killer, Victim, WEAPON_NINJA); if(!Wrong && pPlKiller->GetCharacter()) GameServer()->GetPlayerChar(Killer)->AddSpree(); if (Wrong && pPlKiller->GetCharacter() && CFG(PunishWrongSacr)) { pPlKiller->GetCharacter()->Freeze(CFG(PunishWrongSacr) * TS); GS->CreateSound(pPlKiller->GetCharacter()->m_Pos, SOUND_PLAYER_PAIN_LONG); GS->SendChatTarget(pPlKiller->GetCID(), "The gods are not pleased with this sacrifice!"); } if (!Wrong && pPlKiller->GetCharacter()) pPlKiller->GetCharacter()->SetEmote(EMOTE_HAPPY, TICK + TS * 2); if (pPlKiller->GetCharacter() && CFG(SacrLoltext) && ((!Wrong && CFG(SacrScore)) || (Wrong && CFG(WrongSacrScore)))) { char aBuf[64]; str_format(aBuf, sizeof aBuf, "%+d", Wrong?CFG(WrongSacrScore):(ShrineTeam == -1 ? CFG(SacrScore) : CFG(RightSacrScore))); GS->CreateLolText(pPlKiller->GetCharacter(), false, vec2(0.f, -50.f), vec2(0.f, 0.f), 50, aBuf); } }
void CHalfLifeMultiplay :: InitHUD( CBasePlayer *pl ) { // notify other clients of player joining the game UTIL_ClientPrintAll( HUD_PRINTNOTIFY, UTIL_VarArgs( "%s has joined the game\n", ( pl->pev->netname && STRING(pl->pev->netname)[0] != 0 ) ? STRING(pl->pev->netname) : "unconnected" ) ); #if !defined( THREEWAVE ) UTIL_LogPrintf( "\"%s<%i><%s><%i>\" entered the game\n", STRING( pl->pev->netname ), GETPLAYERUSERID( pl->edict() ), GETPLAYERAUTHID( pl->edict() ), GETPLAYERUSERID( pl->edict() ) ); #else UTIL_LogPrintf( "\"%s<%i><%s><%s>\" entered the game\n", STRING( pl->pev->netname ), GETPLAYERUSERID( pl->edict() ), GETPLAYERAUTHID( pl->edict() ), GetTeamName( pl->pev->team ) ); #endif UpdateGameMode( pl ); // sending just one score makes the hud scoreboard active; otherwise // it is just disabled for single play MESSAGE_BEGIN( MSG_ONE, gmsgScoreInfo, NULL, pl->edict() ); WRITE_BYTE( ENTINDEX(pl->edict()) ); WRITE_SHORT( 0 ); WRITE_SHORT( 0 ); WRITE_SHORT( 0 ); MESSAGE_END(); SendMOTDToClient( pl->edict() ); // loop through all active players and send their score info to the new client for ( int i = 1; i <= gpGlobals->maxClients; i++ ) { // FIXME: Probably don't need to cast this just to read m_iDeaths CBasePlayer *plr = (CBasePlayer *)UTIL_PlayerByIndex( i ); if ( plr ) { MESSAGE_BEGIN( MSG_ONE, gmsgScoreInfo, NULL, pl->edict() ); WRITE_BYTE( i ); // client number WRITE_SHORT( plr->pev->frags ); WRITE_SHORT( plr->m_iDeaths ); WRITE_SHORT( plr->pev->team ); MESSAGE_END(); } } if ( g_fGameOver ) { MESSAGE_BEGIN( MSG_ONE, SVC_INTERMISSION, NULL, pl->edict() ); MESSAGE_END(); } }
void IGameController::DoTeamBalance() { if(!IsTeamplay() || !g_Config.m_SvTeambalanceTime || absolute(m_aTeamSize[TEAM_RED]-m_aTeamSize[TEAM_BLUE]) < NUM_TEAMS) return; GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", "Balancing teams"); float aTeamScore[NUM_TEAMS] = {0}; float aPlayerScore[MAX_CLIENTS] = {0.0f}; // gather stats for(int i = 0; i < MAX_CLIENTS; i++) { if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS) { aPlayerScore[i] = GameServer()->m_apPlayers[i]->m_Score*Server()->TickSpeed()*60.0f/ (Server()->Tick()-GameServer()->m_apPlayers[i]->m_ScoreStartTick); aTeamScore[GameServer()->m_apPlayers[i]->GetTeam()] += aPlayerScore[i]; } } int BiggerTeam = (m_aTeamSize[TEAM_RED] > m_aTeamSize[TEAM_BLUE]) ? TEAM_RED : TEAM_BLUE; int NumBalance = absolute(m_aTeamSize[TEAM_RED]-m_aTeamSize[TEAM_BLUE]) / NUM_TEAMS; // balance teams do { CPlayer *pPlayer = 0; float ScoreDiff = aTeamScore[BiggerTeam]; for(int i = 0; i < MAX_CLIENTS; i++) { if(!GameServer()->m_apPlayers[i] || !CanBeMovedOnBalance(i)) continue; // remember the player whom would cause lowest score-difference if(GameServer()->m_apPlayers[i]->GetTeam() == BiggerTeam && (!pPlayer || absolute((aTeamScore[BiggerTeam^1]+aPlayerScore[i]) - (aTeamScore[BiggerTeam]-aPlayerScore[i])) < ScoreDiff)) { pPlayer = GameServer()->m_apPlayers[i]; ScoreDiff = absolute((aTeamScore[BiggerTeam^1]+aPlayerScore[i]) - (aTeamScore[BiggerTeam]-aPlayerScore[i])); } } // move the player to the other team int Temp = pPlayer->m_LastActionTick; DoTeamChange(pPlayer, BiggerTeam^1); pPlayer->m_LastActionTick = Temp; pPlayer->Respawn(); char aBuf[128]; str_format(aBuf, sizeof(aBuf), "You were moved to %s due to team balancing", GetTeamName(pPlayer->GetTeam())); GameServer()->SendBroadcast(aBuf, pPlayer->GetCID()); } while(--NumBalance); m_UnbalancedTick = TBALANCE_OK; GameServer()->SendChat(-1, CGameContext::CHAT_ALL, "Teams have been balanced"); }
void SetTeamName( gedict_t * p ) { if ( p->isBot ) { if( p->team_no >0 && p->team_no <=4) trap_SetBotUserInfo(NUM_FOR_EDICT( p ),"team",team_names[p->team_no-1 ]); else trap_SetBotUserInfo(NUM_FOR_EDICT( p ),"team",""); }else stuffcmd( p, "team %s\n", GetTeamName( p->team_no ) ); }
void CGameControllerOpenFNG::HandleFreeze(int Killer, int Victim) { CCharacter *pVictim = CHAR(Victim); if (!pVictim) // for odd reasons, this can happen (confirmed by segfault). didn't yet track down why { D("no pVictim in HandleFreeze(%d, %d)", Killer, Victim); return; } if (CFG(BleedOnFreeze)) { pVictim->Bleed(1); GS->CreateSound(pVictim->m_Pos, SOUND_CTF_RETURN); } int FailTeam = pVictim->GetPlayer()->GetTeam() & 1; m_aTeamscore[1 - FailTeam] += CFG(FreezeTeamscore); if (CFG(FreezeTeamscore) && CFG(FreezeBroadcast)) //probably of no real use but for completeness... { char aBuf[64]; str_format(aBuf, sizeof aBuf, "%s froze (%+d)", GetTeamName(1-FailTeam), CFG(FreezeTeamscore)); m_Broadcast.Update(-1, aBuf, CFG(BroadcastTime) * TS); } CPlayer *pPlKiller = TPLAYER(Killer); CPlayer *pPlVictim = TPLAYER(Victim); if (!pPlKiller || !pVictim) return; //freezing counts as a hostile interaction m_aLastInteraction[pVictim->GetPlayer()->GetCID()] = pPlKiller->GetCID(); pPlKiller->m_Score += CFG(FreezeScore); pPlVictim->m_Score += CFG(FreezeScoreVic); SendFreezeKill(Killer, Victim, WEAPON_RIFLE); if (pPlKiller->GetCharacter()) { GS->CreateSound(pPlKiller->GetCharacter()->m_Pos, SOUND_HIT, (1<<pPlKiller->GetCID())); if (CFG(FreezeLoltext) && CFG(FreezeScore)) { char aBuf[64]; str_format(aBuf, sizeof aBuf, "%+d", CFG(FreezeScore)); GS->CreateLolText(pPlKiller->GetCharacter(), false, vec2(0.f, -50.f), vec2(0.f, 0.f), 50, aBuf); } } }
//------------------------------------------------------------------------ IMPLEMENT_RMI(CGameRules, ClSetTeam) { if (!params.entityId) // ignore these for now return true; int oldTeam = GetTeam(params.entityId); if (oldTeam==params.teamId) return true; TEntityTeamIdMap::iterator it=m_entityteams.find(params.entityId); if (it!=m_entityteams.end()) m_entityteams.erase(it); IActor *pActor=m_pActorSystem->GetActor(params.entityId); bool isplayer=pActor!=0; if (isplayer && oldTeam) { TPlayerTeamIdMap::iterator pit=m_playerteams.find(oldTeam); assert(pit!=m_playerteams.end()); stl::find_and_erase(pit->second, params.entityId); } if (params.teamId) { m_entityteams.insert(TEntityTeamIdMap::value_type(params.entityId, params.teamId)); if (isplayer) { TPlayerTeamIdMap::iterator pit=m_playerteams.find(params.teamId); assert(pit!=m_playerteams.end()); pit->second.push_back(params.entityId); } } if(isplayer) { ReconfigureVoiceGroups(params.entityId,oldTeam,params.teamId); if (pActor->IsClient()) m_pRadio->SetTeam(GetTeamName(params.teamId)); } m_pScript->CallMethod( "OnSetTeam", params.entityId, params.teamId); return true; }
void IGameController::DoTeamChange(CPlayer *pPlayer, int Team, bool DoChatMsg) { Team = ClampTeam(Team); if(Team == pPlayer->GetTeam()) return; int OldTeam = pPlayer->GetTeam(); pPlayer->SetTeam(Team); int ClientID = pPlayer->GetCID(); char aBuf[128]; if(DoChatMsg) { str_format(aBuf, sizeof(aBuf), "'%s' joined the %s", Server()->ClientName(ClientID), GetTeamName(Team)); GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf); } str_format(aBuf, sizeof(aBuf), "team_join player='%d:%s' m_Team=%d", ClientID, Server()->ClientName(ClientID), Team); GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); // update effected game settings if(OldTeam != TEAM_SPECTATORS) { --m_aTeamSize[OldTeam]; m_UnbalancedTick = TBALANCE_CHECK; } if(Team != TEAM_SPECTATORS) { ++m_aTeamSize[Team]; m_UnbalancedTick = TBALANCE_CHECK; if(m_GameState == IGS_WARMUP_GAME && HasEnoughPlayers()) SetGameState(IGS_WARMUP_GAME, 0); pPlayer->m_IsReadyToPlay = !IsPlayerReadyMode(); if(m_GameFlags&GAMEFLAG_SURVIVAL) pPlayer->m_RespawnDisabled = GetStartRespawnState(); } OnPlayerInfoChange(pPlayer); GameServer()->OnClientTeamChange(ClientID); }
//========================================================= // Deathnotice. //========================================================= void CHalfLifeMultiplay::DeathNotice( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pevInflictor ) { // Work out what killed the player, and send a message to all clients about it CBaseEntity *Killer = CBaseEntity::Instance( pKiller ); const char *killer_weapon_name = "world"; // by default, the player is killed by the world int killer_index = 0; // Hack to fix name change char *tau = "tau_cannon"; char *gluon = "gluon gun"; // QUAKECLASSIC // Might have overridden if (g_szDeathType) { killer_weapon_name = g_szDeathType; } else { if ( pKiller->flags & FL_CLIENT ) { killer_index = ENTINDEX(ENT(pKiller)); if ( pevInflictor ) { if ( pevInflictor == pKiller ) { // If the inflictor is the killer, then it must be their current weapon doing the damage CBasePlayer *pPlayer = (CBasePlayer*)CBaseEntity::Instance( pKiller ); switch( pPlayer->m_iQuakeWeapon ) { case IT_AXE: killer_weapon_name = "weapon_axe"; break; case IT_SHOTGUN: killer_weapon_name = "weapon_shotgun"; break; case IT_SUPER_SHOTGUN: killer_weapon_name = "weapon_doubleshotgun"; break; case IT_NAILGUN: killer_weapon_name = "weapon_nailgun"; break; case IT_SUPER_NAILGUN: killer_weapon_name = "weapon_supernail"; break; case IT_GRENADE_LAUNCHER: killer_weapon_name = "weapon_grenadel"; break; case IT_ROCKET_LAUNCHER: killer_weapon_name = "weapon_rocketl"; break; case IT_LIGHTNING: killer_weapon_name = "weapon_lightning"; break; default: killer_weapon_name = "Empty"; } } else { killer_weapon_name = STRING( pevInflictor->classname ); // it's just that easy } } } else { killer_weapon_name = STRING( pevInflictor->classname ); } // strip the monster_* or weapon_* from the inflictor's classname if ( strncmp( killer_weapon_name, "weapon_", 7 ) == 0 ) killer_weapon_name += 7; else if ( strncmp( killer_weapon_name, "monster_", 8 ) == 0 ) killer_weapon_name += 8; else if ( strncmp( killer_weapon_name, "func_", 5 ) == 0 ) killer_weapon_name += 5; } MESSAGE_BEGIN( MSG_ALL, gmsgDeathMsg ); WRITE_BYTE( killer_index ); // the killer WRITE_BYTE( ENTINDEX(pVictim->edict()) ); // the victim WRITE_STRING( killer_weapon_name ); // what they were killed by (should this be a string?) MESSAGE_END(); // replace the code names with the 'real' names if ( !strcmp( killer_weapon_name, "egon" ) ) killer_weapon_name = gluon; else if ( !strcmp( killer_weapon_name, "gauss" ) ) killer_weapon_name = tau; if ( pVictim->pev == pKiller ) { // killed self #if !defined( THREEWAVE ) UTIL_LogPrintf( "\"%s<%i><%s><%i>\" committed suicide with \"%s\"\n", STRING( pVictim->pev->netname ), GETPLAYERUSERID( pVictim->edict() ), GETPLAYERAUTHID( pVictim->edict() ), GETPLAYERUSERID( pVictim->edict() ), killer_weapon_name ); #else UTIL_LogPrintf( "\"%s<%i><%s><%s>\" committed suicide with \"%s\"\n", STRING( pVictim->pev->netname ), GETPLAYERUSERID( pVictim->edict() ), GETPLAYERAUTHID( pVictim->edict() ), GetTeamName( pVictim->pev->team ), killer_weapon_name ); #endif } else if ( pKiller->flags & FL_CLIENT ) { #if !defined( THREEWAVE ) UTIL_LogPrintf( "\"%s<%i><%s><%i>\" killed \"%s<%i><%s><%i>\" with \"%s\"\n", STRING( pKiller->netname ), GETPLAYERUSERID( ENT(pKiller) ), GETPLAYERAUTHID( ENT(pKiller) ), GETPLAYERUSERID( ENT(pKiller) ), STRING( pVictim->pev->netname ), GETPLAYERUSERID( pVictim->edict() ), GETPLAYERAUTHID( pVictim->edict() ), GETPLAYERUSERID( pVictim->edict() ), killer_weapon_name ); #else UTIL_LogPrintf( "\"%s<%i><%s><%s>\" killed \"%s<%i><%s><%s>\" with \"%s\"\n", STRING( pKiller->netname ), GETPLAYERUSERID( ENT(pKiller) ), GETPLAYERAUTHID( ENT(pKiller) ), GetTeamName( pKiller->team ), STRING( pVictim->pev->netname ), GETPLAYERUSERID( pVictim->edict() ), GETPLAYERAUTHID( pVictim->edict() ), GetTeamName( pVictim->pev->team ), killer_weapon_name ); #endif } else { // killed by the world #if !defined( THREEWAVE ) UTIL_LogPrintf( "\"%s<%i><%s><%i>\" committed suicide with \"%s\" (world)\n", STRING( pVictim->pev->netname ), GETPLAYERUSERID( pVictim->edict() ), GETPLAYERAUTHID( pVictim->edict() ), GETPLAYERUSERID( pVictim->edict() ), killer_weapon_name ); #else UTIL_LogPrintf( "\"%s<%i><%s><%s>\" committed suicide with \"%s\" (world)\n", STRING( pVictim->pev->netname ), GETPLAYERUSERID( pVictim->edict() ), GETPLAYERAUTHID( pVictim->edict() ), GetTeamName( pVictim->pev->team ), killer_weapon_name ); #endif } g_szDeathType = NULL; // HLTV event msg MESSAGE_BEGIN( MSG_SPEC, SVC_DIRECTOR ); WRITE_BYTE ( 9 ); // command length in bytes WRITE_BYTE ( DRC_CMD_EVENT ); // player killed WRITE_SHORT( ENTINDEX(pVictim->edict()) ); // index number of primary entity if (pevInflictor) WRITE_SHORT( ENTINDEX(ENT(pevInflictor)) ); // index number of secondary entity else WRITE_SHORT( ENTINDEX(ENT(pKiller)) ); // index number of secondary entity WRITE_LONG( 7 | DRC_FLAG_DRAMATIC); // eventflags (priority and flags) MESSAGE_END(); // Print a standard message // TODO: make this go direct to console return; // just remove for now }
qboolean ClientUserInfoChanged( ) { char key[1024]; char value[1024]; const char *sk; int color; self = PROG_TO_EDICT( g_globalvars.self ); trap_CmdArgv( 1, key, sizeof( key ) ); trap_CmdArgv( 2, value, sizeof( value ) ); if ( !strcmp( key, "team" ) ) { if ( !self->team_no ) return 0; sk = GetTeamName( self->team_no ); if ( strneq( value, sk ) ) { SetTeamName( self ); G_sprint( self, 2, "you cannot change your team setinfo\n" ); return 1; } return 0; } if ( !strcmp( key, "skin" ) ) { if ( !self->playerclass || !self->team_no ) return 0; sk = TeamFortress_GetSkin( self ); if ( strneq( value, sk ) ) { G_sprint( self, 2, "you cannot change your skin setinfo\n" ); TeamFortress_SetSkin( self ); return 1; } return 0; } if ( ( !strcmp( key, "topcolor" ) ) && tf_data.topcolor_check ) { if ( !self->team_no ) return 0; color = atoi( value ); if ( self->playerclass == PC_SPY && self->undercover_team ) { if ( TeamFortress_TeamGetTopColor( self->undercover_team ) != color ) { G_sprint( self, 2, "you cannot change your topcolor setinfo\n" ); return 1; } } else { if ( TeamFortress_TeamGetTopColor( self->team_no ) != color ) { G_sprint( self, 2, "you cannot change your topcolor setinfo\n" ); return 1; } } return 0; } if ( ( !strcmp( key, "bottomcolor" ) ) ) { if ( !self->team_no ) return 0; color = atoi( value ); if ( self->playerclass == PC_SPY && self->undercover_team ) { if ( TeamFortress_TeamGetColor( self->undercover_team ) - 1 != color ) { G_sprint( self, 2, "you cannot change your bottomcolor setinfo\n" ); return 1; } } else { if ( TeamFortress_TeamGetColor( self->team_no ) - 1 != color ) { G_sprint( self, 2, "you cannot change your bottomcolor setinfo\n" ); return 1; } } return 0; } SetClientSetting( self, Q_strlwr( key ), value); return 0; }
void CGameClient::DoTeamChangeMessage(const char *pName, int ClientID, int Team) { char aBuf[128]; str_format(aBuf, sizeof(aBuf), Localize("'%2d: %s' joined the %s"), ClientID, g_Config.m_ClShowsocial ? pName : "", GetTeamName(Team, m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS)); m_pChat->AddLine(-1, 0, aBuf); }
void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker) { Client()->RecordGameMessage(true); // special messages if(MsgId == NETMSGTYPE_SV_TUNEPARAMS && Client()->State() != IClient::STATE_DEMOPLAYBACK) { Client()->RecordGameMessage(false); // unpack the new tuning CTuningParams NewTuning; int *pParams = (int *)&NewTuning; for(unsigned i = 0; i < sizeof(CTuningParams)/sizeof(int); i++) pParams[i] = pUnpacker->GetInt(); // check for unpacking errors if(pUnpacker->Error()) return; m_ServerMode = SERVERMODE_PURE; // apply new tuning m_Tuning = NewTuning; return; } else if(MsgId == NETMSGTYPE_SV_VOTEOPTIONLISTADD) { int NumOptions = pUnpacker->GetInt(); for(int i = 0; i < NumOptions; i++) { const char *pDescription = pUnpacker->GetString(CUnpacker::SANITIZE_CC); if(pUnpacker->Error()) return; m_pVoting->AddOption(pDescription); } } else if(MsgId == NETMSGTYPE_SV_GAMEMSG) { int GameMsgID = pUnpacker->GetInt(); int aParaI[3]; int NumParaI = 0; // get paras switch(gs_GameMsgList[GameMsgID].m_ParaType) { case PARA_III: aParaI[NumParaI++] = pUnpacker->GetInt(); case PARA_II: aParaI[NumParaI++] = pUnpacker->GetInt(); case PARA_I: aParaI[NumParaI++] = pUnpacker->GetInt(); } // check for unpacking errors if(pUnpacker->Error()) return; // handle special messages static char aBuf[256]; if(gs_GameMsgList[GameMsgID].m_Action == DO_SPECIAL) { switch(GameMsgID) { case GAMEMSG_CTF_DROP: if(m_SuppressEvents) return; m_pSounds->Enqueue(CSounds::CHN_GLOBAL, SOUND_CTF_DROP); break; case GAMEMSG_CTF_RETURN: if(m_SuppressEvents) return; m_pSounds->Enqueue(CSounds::CHN_GLOBAL, SOUND_CTF_RETURN); break; case GAMEMSG_TEAM_BALANCE_VICTIM: str_format(aBuf, sizeof(aBuf), Localize(gs_GameMsgList[GameMsgID].m_pText), GetTeamName(aParaI[0], m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS)); m_pBroadcast->DoBroadcast(aBuf); break; case GAMEMSG_CTF_GRAB: if(m_SuppressEvents) return; if(m_LocalClientID != -1 && (m_aClients[m_LocalClientID].m_Team != aParaI[0] || (m_Snap.m_SpecInfo.m_Active && ((m_Snap.m_SpecInfo.m_SpectatorID != -1 && m_aClients[m_Snap.m_SpecInfo.m_SpectatorID].m_Team != aParaI[0]) || (m_Snap.m_SpecInfo.m_SpecMode == SPEC_FLAGRED && aParaI[0] != TEAM_RED) || (m_Snap.m_SpecInfo.m_SpecMode == SPEC_FLAGBLUE && aParaI[0] != TEAM_BLUE))))) m_pSounds->Enqueue(CSounds::CHN_GLOBAL, SOUND_CTF_GRAB_PL); else m_pSounds->Enqueue(CSounds::CHN_GLOBAL, SOUND_CTF_GRAB_EN); break; case GAMEMSG_CTF_CAPTURE: m_pSounds->Enqueue(CSounds::CHN_GLOBAL, SOUND_CTF_CAPTURE); int ClientID = clamp(aParaI[1], 0, MAX_CLIENTS - 1); if(aParaI[2] <= 60*Client()->GameTickSpeed()) str_format(aBuf, sizeof(aBuf), Localize("The %s flag was captured by '%2d: %s' (%.2f seconds)"), aParaI[0] ? Localize("blue") : Localize("red"), ClientID, g_Config.m_ClShowsocial ? m_aClients[ClientID].m_aName : "", aParaI[2]/(float)Client()->GameTickSpeed()); else str_format(aBuf, sizeof(aBuf), Localize("The %s flag was captured by '%2d: %s'"), aParaI[0] ? Localize("blue") : Localize("red"), ClientID, g_Config.m_ClShowsocial ? m_aClients[ClientID].m_aName : ""); m_pChat->AddLine(-1, 0, aBuf); } return; } // build message const char *pText = ""; if(NumParaI == 0) pText = Localize(gs_GameMsgList[GameMsgID].m_pText); else { if(NumParaI == 1) str_format(aBuf, sizeof(aBuf), Localize(gs_GameMsgList[GameMsgID].m_pText), aParaI[0]); else if(NumParaI == 2) str_format(aBuf, sizeof(aBuf), Localize(gs_GameMsgList[GameMsgID].m_pText), aParaI[0], aParaI[1]); else if(NumParaI == 3) str_format(aBuf, sizeof(aBuf), Localize(gs_GameMsgList[GameMsgID].m_pText), aParaI[0], aParaI[1], aParaI[2]); pText = aBuf; } // handle message switch(gs_GameMsgList[GameMsgID].m_Action) { case DO_CHAT: m_pChat->AddLine(-1, 0, pText); break; case DO_BROADCAST: m_pBroadcast->DoBroadcast(pText); } } void *pRawMsg = m_NetObjHandler.SecureUnpackMsg(MsgId, pUnpacker); if(!pRawMsg) { char aBuf[256]; str_format(aBuf, sizeof(aBuf), "dropped weird message '%s' (%d), failed on '%s'", m_NetObjHandler.GetMsgName(MsgId), MsgId, m_NetObjHandler.FailedMsgOn()); Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", aBuf); return; } // TODO: this should be done smarter for(int i = 0; i < m_All.m_Num; i++) m_All.m_paComponents[i]->OnMessage(MsgId, pRawMsg); if(MsgId == NETMSGTYPE_SV_CLIENTINFO && Client()->State() != IClient::STATE_DEMOPLAYBACK) { Client()->RecordGameMessage(false); CNetMsg_Sv_ClientInfo *pMsg = (CNetMsg_Sv_ClientInfo *)pRawMsg; if(pMsg->m_Local) { if(m_LocalClientID != -1) { if(g_Config.m_Debug) Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", "invalid local clientinfo"); return; } m_LocalClientID = pMsg->m_ClientID; } else { if(m_aClients[pMsg->m_ClientID].m_Active) { if(g_Config.m_Debug) Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", "invalid clientinfo"); return; } if(m_LocalClientID != -1) { DoEnterMessage(pMsg->m_pName, pMsg->m_ClientID, pMsg->m_Team); if(m_pDemoRecorder->IsRecording()) { CNetMsg_De_ClientEnter Msg; Msg.m_pName = pMsg->m_pName; Msg.m_ClientID = pMsg->m_ClientID; Msg.m_Team = pMsg->m_Team; Client()->SendPackMsg(&Msg, MSGFLAG_NOSEND|MSGFLAG_RECORD); } } } m_aClients[pMsg->m_ClientID].m_Active = true; m_aClients[pMsg->m_ClientID].m_Team = pMsg->m_Team; str_copy(m_aClients[pMsg->m_ClientID].m_aName, pMsg->m_pName, sizeof(m_aClients[pMsg->m_ClientID].m_aName)); str_copy(m_aClients[pMsg->m_ClientID].m_aClan, pMsg->m_pClan, sizeof(m_aClients[pMsg->m_ClientID].m_aClan)); m_aClients[pMsg->m_ClientID].m_Country = pMsg->m_Country; for(int i = 0; i < 6; i++) { str_copy(m_aClients[pMsg->m_ClientID].m_aaSkinPartNames[i], pMsg->m_apSkinPartNames[i], 24); m_aClients[pMsg->m_ClientID].m_aUseCustomColors[i] = pMsg->m_aUseCustomColors[i]; m_aClients[pMsg->m_ClientID].m_aSkinPartColors[i] = pMsg->m_aSkinPartColors[i]; } // update friend state m_aClients[pMsg->m_ClientID].m_Friend = Friends()->IsFriend(m_aClients[pMsg->m_ClientID].m_aName, m_aClients[pMsg->m_ClientID].m_aClan, true); m_aClients[pMsg->m_ClientID].UpdateRenderInfo(this, true); m_GameInfo.m_NumPlayers++; // calculate team-balance if(m_aClients[pMsg->m_ClientID].m_Team != TEAM_SPECTATORS) m_GameInfo.m_aTeamSize[m_aClients[pMsg->m_ClientID].m_Team]++; } else if(MsgId == NETMSGTYPE_SV_CLIENTDROP && Client()->State() != IClient::STATE_DEMOPLAYBACK) { Client()->RecordGameMessage(false); CNetMsg_Sv_ClientDrop *pMsg = (CNetMsg_Sv_ClientDrop *)pRawMsg; if(m_LocalClientID == pMsg->m_ClientID || !m_aClients[pMsg->m_ClientID].m_Active) { if(g_Config.m_Debug) Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", "invalid clientdrop"); return; } DoLeaveMessage(m_aClients[pMsg->m_ClientID].m_aName, pMsg->m_ClientID, pMsg->m_pReason); CNetMsg_De_ClientLeave Msg; Msg.m_pName = m_aClients[pMsg->m_ClientID].m_aName; Msg.m_ClientID = pMsg->m_ClientID; Msg.m_pReason = pMsg->m_pReason; Client()->SendPackMsg(&Msg, MSGFLAG_NOSEND|MSGFLAG_RECORD); m_GameInfo.m_NumPlayers--; // calculate team-balance if(m_aClients[pMsg->m_ClientID].m_Team != TEAM_SPECTATORS) m_GameInfo.m_aTeamSize[m_aClients[pMsg->m_ClientID].m_Team]--; m_aClients[pMsg->m_ClientID].Reset(this); } else if(MsgId == NETMSGTYPE_SV_GAMEINFO && Client()->State() != IClient::STATE_DEMOPLAYBACK) { Client()->RecordGameMessage(false); CNetMsg_Sv_GameInfo *pMsg = (CNetMsg_Sv_GameInfo *)pRawMsg; m_GameInfo.m_GameFlags = pMsg->m_GameFlags; m_GameInfo.m_ScoreLimit = pMsg->m_ScoreLimit; m_GameInfo.m_TimeLimit = pMsg->m_TimeLimit; m_GameInfo.m_MatchNum = pMsg->m_MatchNum; m_GameInfo.m_MatchCurrent = pMsg->m_MatchCurrent; } else if(MsgId == NETMSGTYPE_SV_SERVERSETTINGS && Client()->State() != IClient::STATE_DEMOPLAYBACK) { Client()->RecordGameMessage(false); CNetMsg_Sv_ServerSettings *pMsg = (CNetMsg_Sv_ServerSettings *)pRawMsg; if(!m_ServerSettings.m_TeamLock && pMsg->m_TeamLock) m_pChat->AddLine(-1, 0, Localize("Teams were locked")); else if(m_ServerSettings.m_TeamLock && !pMsg->m_TeamLock) m_pChat->AddLine(-1, 0, Localize("Teams were unlocked")); m_ServerSettings.m_KickVote = pMsg->m_KickVote; m_ServerSettings.m_KickMin = pMsg->m_KickMin; m_ServerSettings.m_SpecVote = pMsg->m_SpecVote; m_ServerSettings.m_TeamLock = pMsg->m_TeamLock; m_ServerSettings.m_TeamBalance = pMsg->m_TeamBalance; m_ServerSettings.m_PlayerSlots = pMsg->m_PlayerSlots; } else if(MsgId == NETMSGTYPE_SV_TEAM) { CNetMsg_Sv_Team *pMsg = (CNetMsg_Sv_Team *)pRawMsg; if(Client()->State() != IClient::STATE_DEMOPLAYBACK) { // calculate team-balance if(m_aClients[pMsg->m_ClientID].m_Team != TEAM_SPECTATORS) m_GameInfo.m_aTeamSize[m_aClients[pMsg->m_ClientID].m_Team]--; m_aClients[pMsg->m_ClientID].m_Team = pMsg->m_Team; if(m_aClients[pMsg->m_ClientID].m_Team != TEAM_SPECTATORS) m_GameInfo.m_aTeamSize[m_aClients[pMsg->m_ClientID].m_Team]++; m_aClients[pMsg->m_ClientID].UpdateRenderInfo(this, false); if(pMsg->m_ClientID == m_LocalClientID) m_TeamCooldownTick = pMsg->m_CooldownTick; } if(pMsg->m_Silent == 0) { DoTeamChangeMessage(m_aClients[pMsg->m_ClientID].m_aName, pMsg->m_ClientID, pMsg->m_Team); } } else if(MsgId == NETMSGTYPE_SV_READYTOENTER) { Client()->EnterGame(); } else if (MsgId == NETMSGTYPE_SV_EMOTICON) { CNetMsg_Sv_Emoticon *pMsg = (CNetMsg_Sv_Emoticon *)pRawMsg; // apply m_aClients[pMsg->m_ClientID].m_Emoticon = pMsg->m_Emoticon; m_aClients[pMsg->m_ClientID].m_EmoticonStart = Client()->GameTick(); } else if(MsgId == NETMSGTYPE_DE_CLIENTENTER && Client()->State() == IClient::STATE_DEMOPLAYBACK) { CNetMsg_De_ClientEnter *pMsg = (CNetMsg_De_ClientEnter *)pRawMsg; DoEnterMessage(pMsg->m_pName, pMsg->m_ClientID, pMsg->m_Team); } else if(MsgId == NETMSGTYPE_DE_CLIENTLEAVE && Client()->State() == IClient::STATE_DEMOPLAYBACK) { CNetMsg_De_ClientLeave *pMsg = (CNetMsg_De_ClientLeave *)pRawMsg; DoLeaveMessage(pMsg->m_pName, pMsg->m_ClientID, pMsg->m_pReason); } }
void TeamFortress_CheckTeamCheats( ) { char st[20]; const char *sk; int tc; if ( self->immune_to_check > g_globalvars.time ) return; if ( self->s.v.deadflag ) return; if ( !( self->s.v.netname[0] ) ) KickCheater( self ); else { if ( self->playerclass && !self->team_no && teamplay > 0 ) KickCheater( self ); } if ( self->team_no > 0 && teamplay > 0 ) { tc = GetInfokeyInt( self, "bottomcolor", NULL, 0 ); if ( self->playerclass == PC_SPY && self->undercover_team ) { if ( TeamFortress_TeamGetColor( self->undercover_team ) - 1 != tc ) { TeamFortress_SetColor( self, TeamFortress_TeamGetTopColor( self->undercover_team ), TeamFortress_TeamGetColor( self->undercover_team ) - 1 ); G_bprint( 1, "%s has been kicked for changing color.\n", self->s.v.netname ); G_sprint( self, 2, "You have been kicked for changing your pants color. Don't do it.\n" ); KickCheater( self ); return; } } else { if ( tc != TeamFortress_TeamGetColor( self->team_no ) - 1 ) { TeamFortress_SetColor( self, TeamFortress_TeamGetTopColor( self->team_no ), TeamFortress_TeamGetColor( self->team_no ) - 1 ); G_bprint( 1, "%s has been kicked for changing color.\n", self->s.v.netname ); G_sprint( self, 2, "You have been kicked for changing your pants color. Don't do it.\n" ); KickCheater( self ); return; } } if ( tf_data.topcolor_check ) { tc = GetInfokeyInt( self, "topcolor", NULL, 0 ); if ( self->playerclass == PC_SPY && self->undercover_team ) { if ( TeamFortress_TeamGetTopColor( self->undercover_team ) != tc ) { TeamFortress_SetColor( self, TeamFortress_TeamGetTopColor( self->undercover_team ), TeamFortress_TeamGetColor( self->undercover_team ) - 1 ); G_bprint( 1, "%s has been kicked for changing color.\n", self->s.v.netname ); G_sprint( self, 2, "You have been kicked for changing your top color. Don't do it.\n" ); KickCheater( self ); return; } } else { if ( tc != TeamFortress_TeamGetTopColor( self->team_no ) ) { TeamFortress_SetColor( self, TeamFortress_TeamGetTopColor( self->undercover_team ), TeamFortress_TeamGetColor( self->undercover_team ) - 1 ); G_bprint( 1, "%s has been kicked for changing color.\n", self->s.v.netname ); G_sprint( self, 2, "You have been kicked for changing your top color. Don't do it.\n" ); KickCheater( self ); return; } } } if ( self->playerclass ) { GetInfokeyString( self, "skin", NULL, st, sizeof( st ), "" ); tc = 0; sk = TeamFortress_GetSkin( self ); if ( strneq( st, sk ) ) { TeamFortress_SetSkin( self ); G_bprint( 1, "%s has been kicked for changing skin.\n", self->s.v.netname ); G_sprint( self, 2, "You have been kicked for changing your skin. Don't do it.\n" ); KickCheater( self ); } if ( tc == 8 ) self->playerclass = 8; } sk = GetTeamName( self->team_no ); GetInfokeyString( self, "team", NULL, st, sizeof( st ), "" ); if ( strneq( st, sk ) ) { SetTeamName( self ); G_bprint( 1, " has been kicked for changing team.\n", self->s.v.netname ); G_sprint( self, 2, "You have been kicked for changing your team. Don't do it.\n" ); KickCheater( self ); return; } } }
void CGameClient::DoTeamChangeMessage(const char *pName, int Team) { char aBuf[128]; str_format(aBuf, sizeof(aBuf), Localize("'%s' joined the %s"), pName, GetTeamName(Team, m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS)); m_pChat->AddLine(-1, 0, aBuf); }
void TeamFortress_TeamShowMemberClasses_New( gedict_t * Player ) { int stf; gedict_t* e,*te; int found = 0; stf = self->settings_bits; for(e= world; (e = trap_find( e, FOFS( s.v.classname ), "player" )); ) { if ( ( e->team_no == Player->team_no /*|| !e->team_no*/ ) && e != Player ) { if ( e->s.v.model && e->s.v.model[0] ) { if ( !found ) { found = 1; G_sprint( Player, 2, "The other members of your team are:\n" ); } G_sprint( Player, 2, "%s : %s", e->s.v.netname, TeamFortress_GetClassName(e->playerclass) ); if ( e->tfstate & TFSTATE_RANDOMPC) G_sprint(Player, 2, " (Random)"); if( !e->playerclass) { G_sprint(Player, 2, "\n"); continue; } if((stf & TF_STATUS_STATS_MASK) ==0) { if(e->s.v.armortype == (float) 0.8) G_sprint(Player, 2, " R"); else if(e->s.v.armortype == (float) 0.6) G_sprint(Player, 2, " Y"); else if(e->s.v.armortype == (float) 0.3) G_sprint(Player, 2, " G"); else G_sprint(Player, 2, " "); G_sprint(Player, 2, "%.0f/%.0f",e->s.v.armorvalue,e->s.v.health); if((e->playerclass == PC_SPY) && ((stf & TF_STATUS_SPY_MASK) ==0)) { if( e->undercover_team ) G_sprint(Player, 2, " %s", GetTeamName(e->undercover_team)); if( e->undercover_skin ) G_sprint(Player, 2, " %s", TeamFortress_GetClassName(e->undercover_skin)); } if((e->playerclass == PC_DEMOMAN) && ((stf & TF_STATUS_DETPACK_MASK) !=0)) { for(te= world; (te = trap_find( te, FOFS( s.v.classname ), "detpack" )); ) { if (te->s.v.owner == EDICT_TO_PROG(e)) { G_sprint(Player, 2, " DTP:%.0f", te->s.v.nextthink - g_globalvars.time); break; } } } if((e->playerclass == PC_ENGINEER) && ((stf & TF_STATUS_SENTRY_MASK) !=0)) { if( e->has_sentry) { for(te= world; (te = trap_find( te, FOFS( s.v.classname ), "building_sentrygun" )); ) { if (te->real_owner == e) { G_sprint(Player, 2, " SENTRY:%.0f", te->s.v.weapon ); break; } } }else { G_sprint(Player, 2, " NOSENTRY"); } } if((stf & TF_STATUS_COORD_MASK) !=0) G_sprint(Player, 2, " '%3.0f %3.0f %3.0f'",PASSVEC3(e->s.v.origin)); G_sprint(Player, 2, "\n"); } } } } if ( !found ) G_sprint( Player, 2, "There are no other players on your team.\n" ); }