MySQL spammed due to slow timer.
#1

pawn Код:
new query[256];
        GetPlayerIp(playerid, ip, sizeof(ip));
        format(query, sizeof(query), "INSERT INTO `bans` (playername, ip, Reason, Date, BanBy) VALUES ('%s', '%s', 'Weapon Hacking', %d, 0)", GetName(playerid), ip, gettime());
        mysql_tquery(dbHandle, query, "", "");


        SavePlayerData(playerid);
        ClearPlayerID(playerid);
        SetTimerEx("KickPlayer", 100,false,"i",playerid);
Bans are spammed in mysql 5 or 6 times before the player is kicked, is there a way to avoid duplicate inserts?
Reply
#2

Make a variable:

new bool:HasBeenKicked[MAX_PLAYERS] = false; //At the top of the script

HasBeenKicked[playerid] = false; //OnPlayerConnect

HasBeenKicked[playerid] = true; //Above the timer and below ClearPlayerID(playerid)


Then wrap it in:

pawn Код:
new bool:HasBeenKicked[MAX_PLAYERS] = false;

public OnPlayerConnect(playerid)
{
    HasBeenKicked[playerid] = false;
    return 1;
}

if(!HasBeenKicked[playerid]){
    new query[256];
    GetPlayerIp(playerid, ip, sizeof(ip));
    format(query, sizeof(query), "INSERT INTO `bans` (playername, ip, Reason, Date, BanBy) VALUES ('%s', '%s', 'Weapon Hacking', %d, 0)", GetName(playerid), ip, gettime());
    mysql_tquery(dbHandle, query, "", "");

    SavePlayerData(playerid);
    ClearPlayerID(playerid);
    HasBeenKicked[playerid] = true;
    SetTimerEx("KickPlayer", 100,false,"i",playerid);
}
Reply
#3

Thank you.

I'm having another issue with something else, could I kindly add you on skype or the sorts?
Reply
#4

Quote:
Originally Posted by Dokins
Посмотреть сообщение
Thank you.

I'm having another issue with something else, could I kindly add you on skype or the sorts?
I don't have Skype mate, sorry.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)