Skip to content

Commit

Permalink
Better loops over players and bugfix with auto-ban
Browse files Browse the repository at this point in the history
  • Loading branch information
necropotame committed Oct 30, 2016
1 parent 6e9ae67 commit 1c45d7f
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 169 deletions.
34 changes: 4 additions & 30 deletions src/game/server/gamecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1233,34 +1233,7 @@ void CGameContext::OnClientConnected(int ClientID)

void CGameContext::OnClientDrop(int ClientID, int Type, const char *pReason)
{
if(m_apPlayers[ClientID] && m_apPlayers[ClientID]->IsInfected())
{
int InfectedCounter = 0;
int HumanCounter = 0;
for(int i = 0; i < MAX_CLIENTS; i ++)
{
if(i == ClientID) continue;
CPlayer *pPlayer = m_apPlayers[i];
if(!pPlayer) continue;
if(pPlayer->GetTeam() == TEAM_SPECTATORS) continue;
if(pPlayer->IsInfected()) InfectedCounter++;
else HumanCounter++;
}

if(HumanCounter + InfectedCounter >= 2)
{
int nbInfectedNeeded = 2;
if(InfectedCounter + HumanCounter < 4)
nbInfectedNeeded = 1;

if(InfectedCounter < nbInfectedNeeded)
{
//Leaver, ban him for 10 minutes
Server()->Ban(ClientID, 10*60, "Leaver");
}
}
}

m_pController->OnClientDrop(ClientID, Type);

AbortVoteKickOnDisconnect(ClientID);
m_apPlayers[ClientID]->OnDisconnect(Type, pReason);
Expand Down Expand Up @@ -1614,9 +1587,10 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
if(m_apPlayers[ClientID]->IsInfected() && pMsg->m_Team == TEAM_SPECTATORS)
{
int InfectedCount = 0;
for(int i = 0; i < MAX_CLIENTS; i++)
CPlayerIterator<PLAYERITER_INGAME> Iter(m_apPlayers);
while(Iter.Next())
{
if(m_apPlayers[i] && m_apPlayers[i]->IsInfected() && m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS)
if(Iter.Player()->IsInfected())
InfectedCount++;
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/server/gamecontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class CGameContext : public IGameServer
};
array<HammerDotState> m_HammerDots;

int m_aHitSoundState[MAX_CLIENTS]; //1 for hit, 2 for kill (no sounds must be sent)
int m_aHitSoundState[MAX_CLIENTS]; //1 for hit, 2 for kill (no sounds must be sent)
/* INFECTION MODIFICATION END *****************************************/
};

Expand Down
1 change: 1 addition & 0 deletions src/game/server/gamecontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class IGameController
virtual int ChooseInfectedClass(CPlayer* pPlayer);
virtual bool IsChoosableClass(int PlayerClass);
virtual bool IsSpawnable(vec2 Position);
virtual void OnClientDrop(int ClientID, int Type) {};

int GetRoundId() { return m_RoundId; }
/* INFECTION MODIFICATION END *****************************************/
Expand Down
Loading

0 comments on commit 1c45d7f

Please sign in to comment.