Skip to content

Commit aea936c

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

22 files changed

Lines changed: 287 additions & 247 deletions

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 & 10 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,10 +665,10 @@ void CCSBotManager::ServerCommand(const char *pcmd)
665665
CBaseEntity *pEntity = nullptr;
666666
while ((pEntity = UTIL_FindEntityByClassname(pEntity, "player")))
667667
{
668-
if (!pEntity->IsPlayer())
669-
continue;
668+
if (FNullEnt(pEntity->edict()))
669+
break;
670670

671-
if (pEntity->IsDormant())
671+
if (!pEntity->IsPlayer() || pEntity->IsDormant())
672672
continue;
673673

674674
CBasePlayer *playerOrBot = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
@@ -1580,7 +1580,8 @@ void CCSBotManager::OnFreeEntPrivateData(CBaseEntity *pEntity)
15801580
for (int i = 1; i <= gpGlobals->maxClients; i++)
15811581
{
15821582
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
1583-
if (!pPlayer || pPlayer->IsDormant())
1583+
1584+
if (!UTIL_IsValidPlayer(pPlayer))
15841585
continue;
15851586

15861587
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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@ NOXREF int CountTeams()
439439
break;
440440

441441
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
442+
if (!pPlayer->IsPlayer() || pPlayer->IsDormant())
443+
continue;
442444

443445
if (pPlayer->m_iTeam == UNASSIGNED)
444446
continue;
@@ -469,10 +471,10 @@ void ListPlayers(CBasePlayer *current)
469471
if (FNullEnt(pEntity->edict()))
470472
break;
471473

472-
if (pEntity->IsDormant())
474+
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
475+
if (!pPlayer->IsPlayer() || pPlayer->IsDormant())
473476
continue;
474477

475-
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
476478
int iUserID = GETPLAYERUSERID(ENT(pPlayer->pev));
477479

478480
Q_sprintf(cNumber, "%d", iUserID);
@@ -496,10 +498,11 @@ int CountTeamPlayers(int iTeam)
496498
if (FNullEnt(pEntity->edict()))
497499
break;
498500

499-
if (pEntity->IsDormant())
501+
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
502+
if (!pPlayer->IsPlayer() || pPlayer->IsDormant())
500503
continue;
501504

502-
if (GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev)->m_iTeam == iTeam)
505+
if (pPlayer->m_iTeam == iTeam)
503506
{
504507
nCount++;
505508
}
@@ -535,10 +538,12 @@ void ProcessKickVote(CBasePlayer *pVotingPlayer, CBasePlayer *pKickPlayer)
535538
break;
536539

537540
pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pTempEntity->pev);
538-
539541
if (!pTempPlayer || pTempPlayer->m_iTeam == UNASSIGNED)
540542
continue;
541543

544+
if (!pTempPlayer->IsPlayer() || pTempPlayer->IsDormant())
545+
continue;
546+
542547
if (pTempPlayer->m_iTeam == pVotingPlayer->m_iTeam && pTempPlayer->m_iCurrentKickVote == iVoteID)
543548
iValidVotes++;
544549
}
@@ -576,6 +581,9 @@ void ProcessKickVote(CBasePlayer *pVotingPlayer, CBasePlayer *pKickPlayer)
576581
if (!pTempPlayer || pTempPlayer->m_iTeam == UNASSIGNED)
577582
continue;
578583

584+
if (!pTempPlayer->IsPlayer() || pTempPlayer->IsDormant())
585+
continue;
586+
579587
if (pTempPlayer->m_iTeam == pVotingPlayer->m_iTeam && pTempPlayer->m_iCurrentKickVote == iVoteID)
580588
pTempPlayer->m_iCurrentKickVote = 0;
581589
}
@@ -976,6 +984,9 @@ void Host_Say(edict_t *pEntity, BOOL teamonly)
976984
if (pReceiver->edict() == pEntity)
977985
continue;
978986

987+
if (!pReceiver->IsPlayer() || pReceiver->IsDormant())
988+
continue;
989+
979990
// Not a client ? (should never be true)
980991
if (!pReceiver->IsNetClient())
981992
continue;
@@ -2344,6 +2355,8 @@ CBaseEntity *EntityFromUserID(int userID)
23442355
break;
23452356

23462357
CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pTempEntity->pev);
2358+
if (!pTempPlayer->IsPlayer() || pTempPlayer->IsDormant())
2359+
continue;
23472360

23482361
if (pTempPlayer->m_iTeam != UNASSIGNED && userID == GETPLAYERUSERID(pTempEntity->edict()))
23492362
{
@@ -2364,6 +2377,8 @@ NOXREF int CountPlayersInServer()
23642377
break;
23652378

23662379
CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pTempEntity->pev);
2380+
if (!pTempPlayer->IsPlayer() || pTempPlayer->IsDormant())
2381+
continue;
23672382

23682383
if (pTempPlayer->m_iTeam != UNASSIGNED)
23692384
{
@@ -3343,7 +3358,11 @@ void EXT_FUNC InternalCommand(edict_t *pEntity, const char *pcmd, const char *pa
33433358
for (int i = 1; i <= gpGlobals->maxClients; i++)
33443359
{
33453360
CBasePlayer *pObserver = UTIL_PlayerByIndex(i);
3346-
if (pObserver && pObserver->IsObservingPlayer(pPlayer))
3361+
3362+
if (!UTIL_IsValidPlayer(pObserver))
3363+
continue;
3364+
3365+
if (pObserver->IsObservingPlayer(pPlayer))
33473366
{
33483367
EMIT_SOUND(ENT(pObserver->pev), CHAN_ITEM, "items/nvg_off.wav", RANDOM_FLOAT(0.92, 1), ATTN_NORM);
33493368

@@ -3368,7 +3387,11 @@ void EXT_FUNC InternalCommand(edict_t *pEntity, const char *pcmd, const char *pa
33683387
for (int i = 1; i <= gpGlobals->maxClients; i++)
33693388
{
33703389
CBasePlayer *pObserver = UTIL_PlayerByIndex(i);
3371-
if (pObserver && pObserver->IsObservingPlayer(pPlayer))
3390+
3391+
if (!UTIL_IsValidPlayer(pObserver))
3392+
continue;
3393+
3394+
if (pObserver->IsObservingPlayer(pPlayer))
33723395
{
33733396
EMIT_SOUND(ENT(pObserver->pev), CHAN_ITEM, "items/nvg_on.wav", RANDOM_FLOAT(0.92, 1), ATTN_NORM);
33743397

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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,10 +1239,7 @@ void CHostage::SendHostagePositionMsg()
12391239
if (FNullEnt(pEntity->edict()))
12401240
break;
12411241

1242-
if (!pEntity->IsPlayer())
1243-
continue;
1244-
1245-
if (pEntity->pev->flags == FL_DORMANT)
1242+
if (!pEntity->IsPlayer() || pEntity->IsDormant())
12461243
continue;
12471244

12481245
CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
@@ -1268,10 +1265,7 @@ void CHostage::SendHostageEventMsg()
12681265
if (FNullEnt(pEntity->edict()))
12691266
break;
12701267

1271-
if (!pEntity->IsPlayer())
1272-
continue;
1273-
1274-
if (pEntity->pev->flags == FL_DORMANT)
1268+
if (!pEntity->IsPlayer() || pEntity->IsDormant())
12751269
continue;
12761270

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

0 commit comments

Comments
 (0)