Offline Ban
#1

So i've created a offline ban system, now i wonder how can i create something that will sheck if the value `Banovan` is already at 1 and if it is command will not proceed.

pawn Код:
public OfflineBan(resultid, extraid, name[], razlog[])
{
    new szRows, szFields, query[178], ip[17], str[128];
    cache_get_data(szRows, szFields);
   
    switch(resultid)
    {
        case THREAD_OFFBAN:
        {
            if(szRows)
            {
                format(query, sizeof(query), "UPDATE `Igraci` SET `Banovan` = '1' WHERE `Ime` = '%s'", name);
                mysql_function_query(konekt, query, true, "OnQueryFinish", "i", THREAD_OSTALO);
               
                GetPlayerIp(extraid, ip, sizeof(ip));
               
                format(query, sizeof(query), "INSERT INTO `Banovi` (`Igrac`, `Admin`, `Razlog`, `Vreme`, `IP`) VALUES ('%s', '%s', '%s', '%s', '%s')", name, ImeIgraca(extraid), razlog, TimeDate(), ip);
                mysql_function_query(konekt, query, true, "OnQueryFinish", "ii", THREAD_OSTALO, extraid);
               
                format(str, sizeof(str), "Server: Admin %s je banovao(offline) racun igraca %s", ImeIgraca(extraid), name);
                SAM(TOMATO, str);
            }
            else
            {
                format(query, sizeof(query), "Racun igraca '%s' ne postoji, proverite da li ste upisali ime pravilno !", name);
                SCM(extraid, TOMATO, query);
            }
        }
    }
    return 1;
}
Reply
#2

Send a query first selecting everything (*) from the desired player, get filed int then check if he is already banned
pawn Код:
new query[126];
format(query, sizeof(query), "SELECT * FROM `Igraci` WHERE Banovan = '%s' ", name);
Sorry i can't provide the full example because i don't know how to use older mysql versions
Reply
#3

Well actually this is a newer version of mysql R38.

And value `Banovan` is numeric which means if it's on 0 player is not banned, and if its 1 he is banned. Now in the command i gave i want to create something that will check if player's value is on 1 the command will not proceed.
Reply
#4

Sorry i am using mysql r35, i thought mysql_function_query is from old versions, i can provide example now.
pawn Код:
CMD:ban(playerid, params[])
{
    new name[24];
    if(sscanf(params,"s[24]",name)) return SendClientMessage(playerid,-1,"invalid name");
    new query[126];
    format(query, sizeof(query), "SELECT * FROM `Igraci` WHERE name = '%s' ", name);
    mysql_tquery(mysql, query,"BanResults","i",playerid);
    return 1;
}
forward BanResults(playerid);
public BanResults(playerid)
{
    new query[126];
    new checkban;
    checkban = cache_get_field_content_int(0,"Banovan");
    if(checkban ==1)
    {
        //already banned
    }
    if(checkban ==0)
    {
        //not banned
    }
   
   
   
    //Another way to do this is to check if this name existing on ban list or not
    if(cache_num_rows() >0)
    {
        //existing
    }
    if(cache_num_rows() ==0)
    {
        //not existing
    }
    return 1;
}
Reply
#5

so I've created something like this, but its not working I can ban offline account as many times as I want.

pawn Код:
public OfflineBan(resultid, extraid, name[], razlog[])
{
    new szRows, szFields, query[178], ip[17], str[128], proveriban;
    cache_get_data(szRows, szFields);
   
    switch(resultid)
    {
        case THREAD_OFFBAN:
        {
            if(szRows)
            {
                proveriban = cache_get_field_content_int(0,"Banovan");
               
                if(proveriban == 1)
                {
                    SCM(extraid, TOMATO, " (greska) {FFFFFF}Ovaj racun je vec banovan !");
                }
                else if(proveriban == 0)
                {
                    format(query, sizeof(query), "UPDATE `Igraci` SET `Banovan` = '1' WHERE `Ime` = '%s'", name);
                    mysql_function_query(konekt, query, true, "OnQueryFinish", "i", THREAD_OSTALO);

                    GetPlayerIp(extraid, ip, sizeof(ip));

                    format(query, sizeof(query), "INSERT INTO `Banovi` (`Igrac`, `Admin`, `Razlog`, `Vreme`, `IP`) VALUES ('%s', '%s', '%s', '%s', '%s')", name, ImeIgraca(extraid), razlog, TimeDate(), ip);
                    mysql_function_query(konekt, query, true, "OnQueryFinish", "ii", THREAD_OSTALO, extraid);

                    format(str, sizeof(str), "Server: Admin %s je banovao(offline) racun igraca %s", ImeIgraca(extraid), name);
                    SAM(TOMATO, str);
                }
            }
            else
            {
                format(query, sizeof(query), "Racun igraca '%s' ne postoji, proverite da li ste upisali ime pravilno !", name);
                SCM(extraid, TOMATO, query);
            }
        }
    }
    return 1;
}
Reply
#6

Show me your ban command?
Reply
#7

pawn Код:
CMD:offban(playerid, params[])
{
    new imea[MAX_PLAYER_NAME], query[128], escaped[24], razlog[128], erazlog[128];
    if(PI[playerid][Admin] < 2) return SCM(playerid, RED, " (greska) {FFFFFF}Nemate ovlastenje za koristenje ove komande !");
    if(sscanf(params, "s[MAX_PLAYER_NAME]s[128]", imea, razlog)) return SCM(playerid, GREY, "Koristite: /offban [Ime Igraca] [Razlog]");
    foreach(Player, i)
    {
        if(strcmp(imea, ImeIgraca(i)) == 0) return SCM(playerid, RED, " (greska) Taj igrac je online !");
    }
    mysql_real_escape_string(razlog, erazlog);
    mysql_real_escape_string(imea, escaped);
   
    format(query, sizeof(query), "SELECT `Ime` FROM `Igraci` WHERE `Ime` = '%s'", escaped);
    mysql_function_query(konekt, query, true, "OfflineBan", "iiss", THREAD_OFFBAN, playerid, escaped, erazlog);
    return 1;
}
Reply
#8

pawn Код:
CMD:offban(playerid, params[])
{
    new imea[MAX_PLAYER_NAME], query[128], escaped[24], razlog[128], erazlog[128];
    if(PI[playerid][Admin] < 2) return SCM(playerid, RED, " (greska) {FFFFFF}Nemate ovlastenje za koristenje ove komande !");
    if(sscanf(params, "s[MAX_PLAYER_NAME]s[128]", imea, razlog)) return SCM(playerid, GREY, "Koristite: /offban [Ime Igraca] [Razlog]");
    foreach(Player, i)
    {
        if(strcmp(imea, ImeIgraca(i)) == 0) return SCM(playerid, RED, " (greska) Taj igrac je online !");
    }
    mysql_real_escape_string(razlog, erazlog);
    mysql_real_escape_string(imea, escaped);
   
    format(query, sizeof(query), "SELECT `Ime`,`Banovan` FROM `Igraci` WHERE `Ime` = '%s'", escaped);//you didn't select the `Banovan` to get the int value.
    mysql_function_query(konekt, query, true, "OfflineBan", "iiss", THREAD_OFFBAN, playerid, escaped, erazlog);
    return 1;
}

public OfflineBan(resultid, extraid, name[], razlog[])
{
    new szRows, szFields, query[178], ip[17], str[128], proveriban;
    cache_get_data(szRows, szFields);
   
    switch(resultid)
    {
        case THREAD_OFFBAN:
        {
            if(szRows)
            {
                proveriban = cache_get_field_content_int(0,"Banovan");
               
                if(proveriban == 1) return SCM(extraid, TOMATO, " (greska) {FFFFFF}Ovaj racun je vec banovan !");
                else if(proveriban == 0)
                {
                    format(query, sizeof(query), "UPDATE `Igraci` SET `Banovan` = '1' WHERE `Ime` = '%s'", name);
                    mysql_function_query(konekt, query, true, "OnQueryFinish", "i", THREAD_OSTALO);

                    GetPlayerIp(extraid, ip, sizeof(ip));

                    format(query, sizeof(query), "INSERT INTO `Banovi` (`Igrac`, `Admin`, `Razlog`, `Vreme`, `IP`) VALUES ('%s', '%s', '%s', '%s', '%s')", name, ImeIgraca(extraid), razlog, TimeDate(), ip);
                    mysql_function_query(konekt, query, true, "OnQueryFinish", "ii", THREAD_OSTALO, extraid);

                    format(str, sizeof(str), "Server: Admin %s je banovao(offline) racun igraca %s", ImeIgraca(extraid), name);
                    SAM(TOMATO, str);
                }
            }
            else
            {
                format(query, sizeof(query), "Racun igraca '%s' ne postoji, proverite da li ste upisali ime pravilno !", name);
                SCM(extraid, TOMATO, query);
            }
        }
    }
    return 1;
}
Reply
#9

Thanks man
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)