Ban system
#1

It doesn't check if player banned or not

PHP код:
// On PlayerConnect
MySQL_BanCheck(playerid); 
Commands and the stock

PHP код:
CMD:ban(playeridparams[]) //ban a player
    
{
            if(
pData[playerid][Admin] >= 4)
            {
                    new 
targetidreason[100];
                    if(
sscanf(params,"ds[100]"targetidreason)) return SendClientMessage(playeridC_WHITE,"USAGE: /ban [playerid][reason]");
                    if(!
IsPlayerConnected(playerid) && targetid != INVALID_PLAYER_ID) return SendClientMessage(playeridC_RED,"SERVER: Player is not connected!");
                new 
bquery[200], IPm[16];
                
GetPlayerIp(targetidIPm16);
                
mysql_format(mysql ,bquerysizeof(bquery),"INSERT INTO bandata(admin, player, reason, IP, banned) VALUES('%s', '%s', '%s','%s', 1)"GetName(playerid),GetName(targetid), reasonIPm);
                
mysql_tquery(mysqlbquery"""");
                new 
string[256];
                
format(stringsizeof(string),"%s (ID:%d) has been banned by Admin %s (ID:%d) for %s"GetName(targetid), targetidGetName(playerid), playeridreason);
                
SendClientMessageToAll(C_REDstring);
                
Kick(playerid);
            }
            else return 
SendClientMessage(playeridC_RED,"You are not authorized to use this command!");
            return 
1;
    }
CMD:unban(playeridparams[]) //unban a player
    
{
                    if(
pData[playerid][Admin] >= 4)
                    {
                            new 
target[50];
                            if(
sscanf(params,"s[50]"target)) return SendClientMessage(playeridC_RED,"USAGE: /unban [player name]");
                            new 
query[200];
                            new 
rowsfields//a variable that will be used to retrieve rows and fields in the database.
                    
cache_get_data(rowsfieldsmysql);//let's get the rows and fields from the database.
                            
format(querysizeof(query),"SELECT * FROM `bandata` WHERE `player`='%s' AND `banned`=1 LIMIT 1"target);
                            
mysql_tquery(mysqlquery"""");
                            if(
rows//if there is row
                            
{
                                    new 
uquery[200];
                                    
format(uquerysizeof(uquery),"DELETE FROM `bandata` WHERE player='%s'"target);
                                    
mysql_tquery(mysqluquery"""");
                                    new 
string[200];
                                    
format(stringsizeof(string),"You have unbanned %s"target);
                                    
SendClientMessage(playeridC_BLUE,string);
                            }
                            else if(!
rows)
                            {
                                    new 
str[128];
                                    
format(strsizeof(str),"[ERROR]: No ban was found on this name %s"target);
                                    
SendClientMessage(playeridC_REDstr);
                            }
                    }
                    else return 
SendClientMessage(playeridC_RED,"You are not authorized to use this command!");
                    return 
1;
    }
CMD:playerbans(playeridparams[])// search for existing bans
    
{
            if(
pData[playerid][Admin] >= 4)
            {
                    new 
target[50], admin[50], player[50], reason[100], IPm[16];
                    if(
sscanf(params,"s[50]"target)) return SendClientMessage(playeridC_RED,"USAGE: /playerbans [player name]");
                    new 
query[200];
                    new 
rowsfields//a variable that will be used to retrieve rows and fields in the database.
                    
cache_get_data(rowsfieldsmysql);//let's get the rows and fields from the database.
                    
format(querysizeof(query),"SELECT admin,player,reason,IP FROM `bandata` WHERE `player`='%s' AND `banned`=1 LIMIT 1"target);
                    
mysql_tquery(mysqlquery"""");
                    if(
rows)
                    {
                    
cache_get_field_content(0"admin",adminmysql24);
                    
cache_get_field_content(0"player"playermysql24);
                    
cache_get_field_content(0"IP"IPmmysql16);
                    
cache_get_field_content(0"reason"reasonmysql100);
                            new 
string[128];
                            
format(stringsizeof(string),"Admin: %s  | Player:%s | Reason:%s | IP:%s " adminplayerreasonIPm);
                            
SendClientMessage(playeridC_REDstring);
                    }
                    if(!
rows)
                    {
                                    
SendClientMessage(playeridC_RED,"SERVER: No ban found on this name!");
                    }
            }
            else return 
SendClientMessage(playeridC_RED,"You are not authorized to use this command!");
            return 
1;
    }
stock MySQL_BanCheck(playerid)
    {
            new 
query[200], admin[50], player[50], IPm[16], string1[100];
            new 
rowsfields//a variable that will be used to retrieve rows and fields in the database.
            
cache_get_data(rowsfieldsmysql);//let's get the rows and fields from the database.
            
GetPlayerIp(playeridIPm16);
            
format(querysizeof(query),"SELECT * FROM `bandata` WHERE(`player`='%s' OR `IP`='%s') AND `banned`=1 LIMIT 1"escpname(playerid), IPm);
            
mysql_tquery(mysqlquery"""");
            if(
rows)
            {
             
cache_get_field_content(0"admin",adminmysql24);
             
cache_get_field_content(0"player"playermysql24);
             
cache_get_field_content(0"IP"IPmmysql16);
             
cache_get_field_content(0"reason"string1mysql100);
                     new 
string[50], str[50], str1[100], str3[50];
                     
format(stringsizeof(string),"Admin: %s"admin);
                     
format(strsizeof(str),"Player: %s"player);
                     
format(str1sizeof(str1),"Reason: %s"string1);
                     
format(str3sizeof(str3), "IP: %s"IPm);
                     
SendClientMessage(playeridC_RED,"You are banned from this server!");
                     
SendClientMessage(playeridC_RED,"___________________");
                     
SendClientMessage(playeridC_REDstr);
                     
SendClientMessage(playeridC_REDstring);
                     
SendClientMessage(playeridC_REDstr3);
                     
SendClientMessage(playeridC_REDstr1);
                     
SendClientMessage(playeridC_RED,"___________________");
                     
SendClientMessage(playeridC_RED"If you think that this BAN was a mistake, then post a screenshot(using F8) on our website");
                     
SendClientMessage(playeridC_RED"www.realone.site11.com");
                     
Kick(playerid);
            }
            return 
1;
    } 
Reply
#2

Mate... I think it's bug in Mysql.
Reply
#3

I don't think that but its saved in database that my name is banned but i can join? How that happend?
Reply
#4

I think there is a bug in one of the Mysql and CMD Script.
I Think that.
Reply
#5

How to fix this bug?
Reply
#6

I found problem i think [ In my database is "Username" and in the codes its "playername"

Edit: not this the problem
Reply
#7

Learn more about threaded MySQL queries: <https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_tquery>.
Reply
#8

then should i use Mysql_query?
Reply
#9

I do not recommend. You will get more efficient result with threading.
Reply
#10

Its not working.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)