Several players have been cheating on my server by abusing a oversight in my code logic (the oversight was verifying a coection status to other players before allowing a flag to be picked up). I've created a patch for this, however, one of the integers in my forloop isn't incrementing correctly. I've tried debugging, and I've verified that under the conditions the cheaters are using, the if statement evaluates as true and then jumps in to increment the integer, but it just isn't incrementing it correctly, the value stays 0. If anyone could give me some tips on what I'm doing wrong i would be extremely grateful. Here's a snippet of the code:
//If PlayerCount < 4 let them grab the flag even if they cheat, no bonus exp is received.
if ((int)GetMatch()->GetCharacters()->size() >= 4 && GetMatch()->GetMatchType() == MT_CTF)
{
int nFoulCount = 0;
int nPlayerCount = 0;
for (auto itor = GetMatch()->GetPeers()->begin(); itor != GetMatch()->GetPeers()->end(); ++itor)
{
Character* pCharacter = GetMatch()->FindCharacter((*itor).first);
//Valid coection to teamm8's is uecessary for this fix
if (pCharacter->GetTeamID() == GetGame()->GetMyCharacter()->GetTeamID())
continue;
//ignore a coection to yourself
if (pCharacter->nUniqueID == GetGame()->GetMyCharacter()->nUniqueID)
continue;
//Increment based on enemies team size
++nPlayerCount;
//if you fail to coect to a player of the opposite team,increment foulcount
if ((*itor).second->GetPing(GetGame()->GetTickRate()) == MAX_PING)
{
++nFoulCount; //this evaluates and should be incremented, but isn't.
}
}
// self explanatory, you should never be unable to coect to all enemy players
if (nFoulCount >= nPlayerCount)
{
//add a check to prevent spam if you want, i think it's rather useful to spam the message. aoy the people until they rejoin
OutputErrMsg("Error: Unable to obtain flag, please check your coection and rejoin.");
retu;
}
//all is well, allow the player to capture the flag
RequestObtainFlag(GetGame()->GetMyCharacter()->nUniqueID, pItem->GetItemID());
}
