Skip to content

Commit 7372573

Browse files
committed
Add UTIL_IsValidPlayer
Ignore dormant players Minor refactoring
1 parent c08e6d0 commit 7372573

22 files changed

+263
-204
lines changed

regamedll/dlls/bot/cs_bot.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ int GetBotFollowCount(CBasePlayer *pLeader)
4343
{
4444
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
4545

46-
if (!pPlayer)
47-
continue;
48-
49-
if (FNullEnt(pPlayer->pev))
46+
if (!UTIL_IsValidPlayer(pPlayer))
5047
continue;
5148

5249
if (FStrEq(STRING(pPlayer->pev->netname), ""))
@@ -685,10 +682,7 @@ CBasePlayer *CCSBot::GetImportantEnemy(bool checkVisibility) const
685682
{
686683
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
687684

688-
if (!pPlayer)
689-
continue;
690-
691-
if (FNullEnt(pPlayer->pev))
685+
if (!UTIL_IsValidPlayer(pPlayer))
692686
continue;
693687

694688
if (FStrEq(STRING(pPlayer->pev->netname), ""))

regamedll/dlls/bot/cs_bot_chatter.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ void BotMeme::Transmit(CCSBot *pSender) const
6565
{
6666
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
6767

68-
if (!pPlayer)
69-
continue;
70-
71-
if (FNullEnt(pPlayer->pev))
68+
if (!UTIL_IsValidPlayer(pPlayer))
7269
continue;
7370

7471
if (FStrEq(STRING(pPlayer->pev->netname), ""))
@@ -1525,10 +1522,7 @@ BotStatement *BotChatterInterface::GetActiveStatement()
15251522
{
15261523
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
15271524

1528-
if (!pPlayer)
1529-
continue;
1530-
1531-
if (FNullEnt(pPlayer->pev))
1525+
if (!UTIL_IsValidPlayer(pPlayer))
15321526
continue;
15331527

15341528
if (FStrEq(STRING(pPlayer->pev->netname), ""))

regamedll/dlls/bot/cs_bot_manager.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ void CCSBotManager::ClientDisconnect(CBasePlayer *pPlayer)
337337
pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pevTemp);
338338
AddEntityHashValue(pPlayer->pev, STRING(pPlayer->pev->classname), CLASSNAME);
339339
pPlayer->pev->flags = FL_DORMANT;
340+
341+
#ifdef REGAMEDLL_FIXES
342+
pPlayer->has_disconnected = true;
343+
#endif
340344
}
341345

342346
void PrintAllEntities()
@@ -396,10 +400,8 @@ void CCSBotManager::ServerCommand(const char *pcmd)
396400
for (int i = 1; i <= gpGlobals->maxClients; i++)
397401
{
398402
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
399-
if (!pPlayer)
400-
continue;
401403

402-
if (FNullEnt(pPlayer->pev))
404+
if (!UTIL_IsValidPlayer(pPlayer))
403405
continue;
404406

405407
const char *name = STRING(pPlayer->pev->netname);
@@ -425,10 +427,8 @@ void CCSBotManager::ServerCommand(const char *pcmd)
425427
for (int i = 1; i <= gpGlobals->maxClients; i++)
426428
{
427429
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
428-
if (!pPlayer)
429-
continue;
430430

431-
if (FNullEnt(pPlayer->pev))
431+
if (!UTIL_IsValidPlayer(pPlayer))
432432
continue;
433433

434434
const char *name = STRING(pPlayer->pev->netname);
@@ -665,6 +665,9 @@ void CCSBotManager::ServerCommand(const char *pcmd)
665665
CBaseEntity *pEntity = nullptr;
666666
while ((pEntity = UTIL_FindEntityByClassname(pEntity, "player")))
667667
{
668+
if (FNullEnt(pEntity->edict()))
669+
break;
670+
668671
if (!pEntity->IsPlayer())
669672
continue;
670673

@@ -1580,7 +1583,8 @@ void CCSBotManager::OnFreeEntPrivateData(CBaseEntity *pEntity)
15801583
for (int i = 1; i <= gpGlobals->maxClients; i++)
15811584
{
15821585
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
1583-
if (!pPlayer || pPlayer->IsDormant())
1586+
1587+
if (!UTIL_IsValidPlayer(pPlayer))
15841588
continue;
15851589

15861590
if (pPlayer->IsBot())

regamedll/dlls/bot/cs_bot_pathfind.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,10 +1118,7 @@ bool CCSBot::IsFriendInTheWay(const Vector *goalPos) const
11181118
{
11191119
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
11201120

1121-
if (!pPlayer)
1122-
continue;
1123-
1124-
if (FNullEnt(pPlayer->pev))
1121+
if (!UTIL_IsValidPlayer(pPlayer))
11251122
continue;
11261123

11271124
if (!pPlayer->IsAlive())

regamedll/dlls/bot/cs_bot_vision.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ bool CCSBot::IsVisible(CBasePlayer *pPlayer, bool testFOV, unsigned char *visPar
253253
if ((pPlayer->pev->flags & FL_NOTARGET) || (pPlayer->pev->effects & EF_NODRAW))
254254
return false;
255255
#endif
256-
256+
257257
Vector spot = pPlayer->pev->origin;
258258
unsigned char testVisParts = NONE;
259259

@@ -701,10 +701,7 @@ CBasePlayer *CCSBot::FindMostDangerousThreat()
701701
{
702702
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
703703

704-
if (!pPlayer)
705-
continue;
706-
707-
if (FNullEnt(pPlayer->pev))
704+
if (!UTIL_IsValidPlayer(pPlayer))
708705
continue;
709706

710707
// is it a player?

regamedll/dlls/career_tasks.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,11 @@ void CCareerTaskManager::HandleDeath(int team, CBasePlayer *pAttacker)
545545
for (int i = 1; i <= gpGlobals->maxClients; i++)
546546
{
547547
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
548-
if (pPlayer && pPlayer->m_iTeam == enemyTeam && pPlayer->IsAlive())
548+
549+
if (!UTIL_IsValidPlayer(pPlayer))
550+
continue;
551+
552+
if (pPlayer->m_iTeam == enemyTeam && pPlayer->IsAlive())
549553
numEnemies++;
550554
}
551555

regamedll/dlls/client.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ NOXREF int CountTeams()
438438
if (FNullEnt(pEntity->edict()))
439439
break;
440440

441+
if (pEntity->IsDormant())
442+
continue;
443+
441444
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
442445

443446
if (pPlayer->m_iTeam == UNASSIGNED)
@@ -499,7 +502,8 @@ int CountTeamPlayers(int iTeam)
499502
if (pEntity->IsDormant())
500503
continue;
501504

502-
if (GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev)->m_iTeam == iTeam)
505+
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
506+
if (pPlayer->m_iTeam == iTeam)
503507
{
504508
nCount++;
505509
}
@@ -534,6 +538,9 @@ void ProcessKickVote(CBasePlayer *pVotingPlayer, CBasePlayer *pKickPlayer)
534538
if (FNullEnt(pTempEntity->edict()))
535539
break;
536540

541+
if (pTempEntity->IsDormant())
542+
continue;
543+
537544
pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pTempEntity->pev);
538545

539546
if (!pTempPlayer || pTempPlayer->m_iTeam == UNASSIGNED)
@@ -571,6 +578,9 @@ void ProcessKickVote(CBasePlayer *pVotingPlayer, CBasePlayer *pKickPlayer)
571578
if (FNullEnt(pTempEntity->edict()))
572579
break;
573580

581+
if (pTempEntity->IsDormant())
582+
continue;
583+
574584
pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pTempEntity->pev);
575585

576586
if (!pTempPlayer || pTempPlayer->m_iTeam == UNASSIGNED)
@@ -976,6 +986,9 @@ void Host_Say(edict_t *pEntity, BOOL teamonly)
976986
if (pReceiver->edict() == pEntity)
977987
continue;
978988

989+
if (pReceiver->IsDormant())
990+
continue;
991+
979992
// Not a client ? (should never be true)
980993
if (!pReceiver->IsNetClient())
981994
continue;
@@ -2343,6 +2356,9 @@ CBaseEntity *EntityFromUserID(int userID)
23432356
if (FNullEnt(pTempEntity->edict()))
23442357
break;
23452358

2359+
if (pTempEntity->IsDormant())
2360+
continue;
2361+
23462362
CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pTempEntity->pev);
23472363

23482364
if (pTempPlayer->m_iTeam != UNASSIGNED && userID == GETPLAYERUSERID(pTempEntity->edict()))
@@ -2363,6 +2379,9 @@ NOXREF int CountPlayersInServer()
23632379
if (FNullEnt(pTempEntity->edict()))
23642380
break;
23652381

2382+
if (pTempEntity->IsDormant())
2383+
continue;
2384+
23662385
CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pTempEntity->pev);
23672386

23682387
if (pTempPlayer->m_iTeam != UNASSIGNED)
@@ -3343,7 +3362,11 @@ void EXT_FUNC InternalCommand(edict_t *pEntity, const char *pcmd, const char *pa
33433362
for (int i = 1; i <= gpGlobals->maxClients; i++)
33443363
{
33453364
CBasePlayer *pObserver = UTIL_PlayerByIndex(i);
3346-
if (pObserver && pObserver->IsObservingPlayer(pPlayer))
3365+
3366+
if (!UTIL_IsValidPlayer(pObserver))
3367+
continue;
3368+
3369+
if (pObserver->IsObservingPlayer(pPlayer))
33473370
{
33483371
EMIT_SOUND(ENT(pObserver->pev), CHAN_ITEM, "items/nvg_off.wav", RANDOM_FLOAT(0.92, 1), ATTN_NORM);
33493372

@@ -3368,7 +3391,11 @@ void EXT_FUNC InternalCommand(edict_t *pEntity, const char *pcmd, const char *pa
33683391
for (int i = 1; i <= gpGlobals->maxClients; i++)
33693392
{
33703393
CBasePlayer *pObserver = UTIL_PlayerByIndex(i);
3371-
if (pObserver && pObserver->IsObservingPlayer(pPlayer))
3394+
3395+
if (!UTIL_IsValidPlayer(pObserver))
3396+
continue;
3397+
3398+
if (pObserver->IsObservingPlayer(pPlayer))
33723399
{
33733400
EMIT_SOUND(ENT(pObserver->pev), CHAN_ITEM, "items/nvg_on.wav", RANDOM_FLOAT(0.92, 1), ATTN_NORM);
33743401

regamedll/dlls/cmdhandler.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ void SV_Continue_f()
3737
{
3838
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
3939

40-
if (pPlayer && !pPlayer->IsBot())
40+
if (!UTIL_IsValidPlayer(pPlayer))
41+
continue;
42+
43+
if (!pPlayer->IsBot())
4144
{
4245
// at the end of the round is showed window with the proposal surrender or continue
4346
// now of this time HUD is completely hidden
@@ -96,7 +99,7 @@ void SV_Career_EndRound_f()
9699
{
97100
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
98101

99-
if (!pPlayer || FNullEnt(pPlayer->pev))
102+
if (!UTIL_IsValidPlayer(pPlayer))
100103
continue;
101104

102105
if (pPlayer->IsBot() && pPlayer->m_iTeam == pLocalPlayer->m_iTeam)

regamedll/dlls/combat.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ void PlayerBlind(CBasePlayer *pPlayer, entvars_t *pevInflictor, entvars_t *pevAt
99
for (int i = 1; i <= gpGlobals->maxClients; i++)
1010
{
1111
CBasePlayer *pObserver = UTIL_PlayerByIndex(i);
12-
if (pObserver && pObserver->IsObservingPlayer(pPlayer))
12+
13+
if (!UTIL_IsValidPlayer(pObserver))
14+
continue;
15+
16+
if (pObserver->IsObservingPlayer(pPlayer))
1317
{
1418
UTIL_ScreenFade(pObserver, color, fadeTime, fadeHold, alpha, 0);
1519
}

regamedll/dlls/hostage/hostage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ void CHostage::SendHostagePositionMsg()
12421242
if (!pEntity->IsPlayer())
12431243
continue;
12441244

1245-
if (pEntity->pev->flags == FL_DORMANT)
1245+
if (pEntity->IsDormant())
12461246
continue;
12471247

12481248
CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
@@ -1271,7 +1271,7 @@ void CHostage::SendHostageEventMsg()
12711271
if (!pEntity->IsPlayer())
12721272
continue;
12731273

1274-
if (pEntity->pev->flags == FL_DORMANT)
1274+
if (pEntity->IsDormant())
12751275
continue;
12761276

12771277
CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);

0 commit comments

Comments
 (0)