Anti-Cheat Lag.
#1

I wrote myself a simple server and money sided anti-cheat into my gamemode which seems to work fine for the most part. However their are bits of lag where client and server dont seem to quite match up. I added debug statements into the code to watch the steps of the Anti-Cheat and consistently alert me of a second or so when the client and server are not synced up. This is normally not a problem but sometimes, especially when a player spawns, if the client freezes up a bit, the sync is not complete enough for them to either lose the money/weapons or for them to be banned due to hacks. Anoter instance is I have a part of code that will consistently give player money and if that happens too much, they seem to end up getting banned from cash hacks.

My question is, is there anyway to avoid this apparant lag or a better way to do the code more efficiently. I hope I have explained myself clearly :P

pawn Код:
GivePlayerCash(playerid, money)
{
    dailyEarning[playerid] += money;
    playerCash[playerid] += money;
    GivePlayerMoney(playerid, money);
}

TakePlayerCash(playerid, money)
{
    GivePlayerMoney(playerid, 0 - money);
    playerCash[playerid] -= money;
}

ResetPlayerCash(playerid)
{
    new money = GetPlayerCash(playerid);
    dailyEarning[playerid] -= money;
    playerCash[playerid] -= money;
    ResetPlayerMoney(playerid);
}

ResetPWeapons(playerid)
{
    ResetPlayerWeapons(playerid);
    for (new i = 0; i < 13; i++) {
        playerWeapon[playerid][i] = 0;
    }
}

GivePWeapon(playerid, weapon, ammo)
{
    switch (weapon)
    {
        case 0,1: playerWeapon[playerid][0] = weapon;
        case 2,3,4,5,6,7,8,9: playerWeapon[playerid][1] = weapon;
        case 10,11,12,13,14,15: playerWeapon[playerid][10] = weapon;
        case 16,17,18: playerWeapon[playerid][8] = weapon;
        case 22,23,24: playerWeapon[playerid][2] = weapon;
        case 25,26,27: playerWeapon[playerid][3] = weapon;
        case 28,29,32: playerWeapon[playerid][4] = weapon;
        case 30,31: playerWeapon[playerid][5] = weapon;
        case 33,34: playerWeapon[playerid][6] = weapon;
        case 35,36,37,38: playerWeapon[playerid][7] = weapon;
        case 39: playerWeapon[playerid][8] = weapon;
        case 40: playerWeapon[playerid][12] = weapon;
        case 41,42,43: playerWeapon[playerid][9] = weapon;
        case 44,45,46: playerWeapon[playerid][11] = weapon;
    }
    GivePlayerWeapon(playerid, weapon, ammo);
}
The function beneath is within a one second timer

pawn Код:
if (GetPlayerMoney(i) > playerCash[i])
                {
                    cashHackWarn[i]++;
                    format(string, sizeof(string), "Cash hack warn! %d %d", GetPlayerMoney(i), playerCash[i]);
                    SendClientMessage(i, COLOUR_ERROR, string);
                    //if (cashHackWarn[i] == 2) BanPlayer(i, "AUTO", "Anti-Cheat", "Cheat ID 0 was detected!");
                    if (cashHackWarn[i] >= 4) {
                        KickPlayer(i, "AUTO", "Cheat ID 0 Detected!");
                    }
                }
                else if (GetPlayerMoney(i) < playerCash[i])
                {
                    cashHackWarn[i]++;
                    format(string, sizeof(string), "Money shortage warn! %d %d", GetPlayerMoney(i), playerCash[i]);
                    SendClientMessage(i, COLOUR_ERROR, string);
                    if (cashHackWarn[i] >= 3) playerCash[i] = GetPlayerMoney(i);
                }
                else
                {
                    if (cashHackWarn[i] > 0) SendClientMessage(i, COLOUR_ERROR, "Cash false alarm!");
                    cashHackWarn[i] = 0; // False alarm! Reset cash warning!
                }
            }

            // Weapon anti-cheat
            new weapon;
            new ammo;
            for (new x = 0; x < 13; x++)
            {
                if (tazerDrawn[i]) weaponHackWarn[i][x] = 0;
                else
                {
                    if (timeoutCount[i] < 2)
                    {
                        GetPlayerWeaponData(i, x, weapon, ammo);
                        if (weapon != 0)
                        {
                            playerAmmo[i][x] = ammo;
                            if (playerWeapon[i][x] != weapon) {
                                weaponHackWarn[i][x]++;
                                format(string, sizeof(string), "Weapon hack warn! %d %d", weapon, playerWeapon[i][x]);
                                printf("%s Weapon hack warn! %d %d", ReturnPlayerName(i), weapon, playerWeapon[i][x]);
                                SendClientMessage(i, COLOUR_ERROR, string);
                                if (weaponHackWarn[i][x] >= 4) {
                                    KickPlayer(i, "AUTO", "Cheat ID 1 Detected!");
                                }
                            }
                            else { weaponHackWarn[i][x] = 0; }
                        }
                        else
                        {
                            if (playerWeapon[i][x] > 0)
                            {
                                weaponHackWarn[i][x]++;
                                format(string, sizeof(string), "Weapon loss warn! %d %d", weapon, playerWeapon[i][x]);
                                SendClientMessage(i, COLOUR_ERROR, string);
                                printf("%s Weapon loss warn! %d %d", ReturnPlayerName(i), weapon, playerWeapon[i][x]);
                                if (weaponHackWarn[i][x] >= 4) {
                                    printf("%s Weapons were removed %d %d", ReturnPlayerName(i), weapon, playerWeapon[i][x]);
                                    playerWeapon[i][x] = 0;
                                    playerAmmo[i][x] =0;
                                }
                            }
                            else { weaponHackWarn[i][x] = 0; }
                        }
                    }
                }
            }
Reply


Messages In This Thread
Anti-Cheat Lag. - by viper_viper - 28.11.2013, 10:47
Re: Anti-Cheat Lag. - by xVIP3Rx - 28.11.2013, 11:00
Re: Anti-Cheat Lag. - by viper_viper - 28.11.2013, 11:12

Forum Jump:


Users browsing this thread: 1 Guest(s)