Offline Ban
#1

PHP код:
CMD:oban(playerid,params[])
{
    new 
string[128];
    new 
cmdreason[100];
    new 
name[MAX_PLAYER_NAME];
    if(
AdminLevel[playerid] < 4) return SendClientMessage(playeridCOLOR_ERROR"[ERROR]:{FFFFFF}This command is only restricted to administrators");
    if(
sscanf(params,"us[100]",name,cmdreason))
    {
        
SendClientMessage(playerid,COLOR_ERROR,"[USAGE]:{FFFFFF} /oban (Player Name/ID) (Reason)");
        return 
1;
    }
    if(!
udb_Exists(name))
    {
        
SendClientMessage(playeridCOLOR_ERROR"[ERROR]:{FFFFFF} The account does not exist in files, please try again with correct name.");
        return 
1;
    }
    
format(string,sizeof(string),"[ADMIN]:{FFFFFF} Administrator %s has offline banned %s from the server. Reason: %s.",PlayerName(playerid), namecmdreason);
    
SendClientMessageToAll(COLOR_ADMIN,string);
    
format(string,sizeof(string),"9[ADMIN] Administrator %s has offline banned %s from the server. Reason: %s.",PlayerName(playerid), namecmdreason);
    
IRC_GroupSay(gGroupID,IRC_CHANNEL,string);
    
    
dUserSetINT(name).("Nameban",1);
    return 
1;

Код:
if(!udb_Exists(name))
    {
        SendClientMessage(playerid, COLOR_ERROR, "[ERROR]:{FFFFFF} The account does not exist in files, please try again with correct name.");
        return 1;
    }
I know it checks if the file exists in scriptfiles or not but even though there is a file in the scriptfiles, it returns the send client message line. What's wrong with this?
Reply
#2

Using INI saving systems is a very big mistake and it'd be good if you use SQLite. It's a lot faster, doesn't have these issues, globally used (not restricted to one language). And, is native-ly support by SA-MP.

PHP код:
#include <a_samp>
new DBSQLite;
public 
OnGameModeInit() {
    
SQLite db_open("ban.db");
    if (
SQLite == DB0) {
        print(
"Ban database was not initiated.");
    }
    else {
        
db_free_result(db_query(SQLite"CREATE TABLE IF NOT EXSITS `Bans` (`SQL_ID` INTEGER PRIMARY KEY AUTO INCREMENT, `Name` TEXT)"));
    }
    return 
1;
}
public 
OnGameModeExit() {
    
db_close(SQLite);
    return 
1;
}
public 
OnPlayerConnect(playerid) {
    new 
Player_Name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridPlayer_NameMAX_PLAYER_NAME);
    
    if (
CheckBan(Player_Name)) { // if CheckBan returns anything else than 0. Same as CheckBan(Player_Name) != 0 OR CheckBan(Player_Name) > 0 or CheckBan(Player_Name) >= 1
        
Kick(playerid);
        return 
1;
    }
    return 
1;
}
BanPlayer(playerid) {
    new 
query[40 MAX_PLAYER_NAME], Player_Name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridPlayer_NameMAX_PLAYER_NAME);
    
format(querysizeof query"INSERT INTO `Bans` (`Name`) VALUES('%q')"Player_Name);
    
db_free_result(db_query(SQLitequery));
    return 
1;
}
UnbanPlayer(name[]) {
    new 
query[38 MAX_PLAYER_NAME];
    
format(querysizeof query"DELETE FROM `Bans` WHERE `Name` = '%q'"name);
    
db_free_result(db_query(SQLitequery));
    return 
1;
}
CheckBan(name[]) {
    new 
query[40 MAX_PLAYER_NAME], DBResultresultnum_rows;
    
format(querysizeof query"SELECT * FROM `Bans` WHERE `Name` = '%q'"name);
    
result db_query(SQLitequery);
    
num_rows db_num_rows(result);
    
db_free_result(result);
    return 
num_rows// Returns the number of rows (0 is not banned, anything else than 0 is banned)

Reply
#3

I've been thinking about converting to SQL lately but currently I want a solution to my current problem. Thanks for the code though, i'll look forward to it.
Reply
#4

There must be something wrong with your udb_Exists function. Just stop using it and move towards SQLite. Take this as an advice and adapt it.
Reply
#5

The problem is that you're confusing offline banning with banning players who are in-game.

The part where it goes wrong:

PHP код:
if(sscanf(params,"us[100]",name,cmdreason)) 
    { 
        
SendClientMessage(playerid,COLOR_ERROR,"[USAGE]:{FFFFFF} /oban (Player Name/ID) (Reason)"); 
        return 
1
    } 
'name' is now specified as a user via sscanf. If you type a name your script will look up any user who's name contains whatever you typed there. You should change the 'u' to 's' and give it a maximum length. In this case it's MAX_PLAYER_NAME.


Full code:
PHP код:
CMD:oban(playerid,params[]) 

    new 
string[128]; 
    new 
cmdreason[100]; 
    new 
name[MAX_PLAYER_NAME]; 
    if(
AdminLevel[playerid] < 4) return SendClientMessage(playeridCOLOR_ERROR"[ERROR]:{FFFFFF}This command is only restricted to administrators"); 
    if(
sscanf(params,"s[25]s[100]",name,cmdreason)) 
    { 
        
SendClientMessage(playerid,COLOR_ERROR,"[USAGE]:{FFFFFF} /oban (Player Name/ID) (Reason)"); 
        return 
1
    } 
    if(!
udb_Exists(name)) 
    { 
        
SendClientMessage(playeridCOLOR_ERROR"[ERROR]:{FFFFFF} The account does not exist in files, please try again with correct name."); 
        return 
1
    } 
    
format(string,sizeof(string),"[ADMIN]:{FFFFFF} Administrator %s has offline banned %s from the server. Reason: %s.",PlayerName(playerid), namecmdreason); 
    
SendClientMessageToAll(COLOR_ADMIN,string); 
    
format(string,sizeof(string),"9[ADMIN] Administrator %s has offline banned %s from the server. Reason: %s.",PlayerName(playerid), namecmdreason); 
    
IRC_GroupSay(gGroupID,IRC_CHANNEL,string); 
     
    
dUserSetINT(name).("Nameban",1); 
    return 
1

Reply
#6

Quote:
Originally Posted by Robin96
Посмотреть сообщение
The problem is that you're confusing offline banning with banning players who are in-game.

The part where it goes wrong:

PHP код:
if(sscanf(params,"us[100]",name,cmdreason)) 
    { 
        
SendClientMessage(playerid,COLOR_ERROR,"[USAGE]:{FFFFFF} /oban (Player Name/ID) (Reason)"); 
        return 
1
    } 
'name' is now specified as a user via sscanf. If you type a name your script will look up any user who's name contains whatever you typed there. You should change the 'u' to 's' and give it a maximum length. In this case it's MAX_PLAYER_NAME.


Full code:
PHP код:
CMD:oban(playerid,params[]) 

    new 
string[128]; 
    new 
cmdreason[100]; 
    new 
name[MAX_PLAYER_NAME]; 
    if(
AdminLevel[playerid] < 4) return SendClientMessage(playeridCOLOR_ERROR"[ERROR]:{FFFFFF}This command is only restricted to administrators"); 
    if(
sscanf(params,"s[25]s[100]",name,cmdreason)) 
    { 
        
SendClientMessage(playerid,COLOR_ERROR,"[USAGE]:{FFFFFF} /oban (Player Name/ID) (Reason)"); 
        return 
1
    } 
    if(!
udb_Exists(name)) 
    { 
        
SendClientMessage(playeridCOLOR_ERROR"[ERROR]:{FFFFFF} The account does not exist in files, please try again with correct name."); 
        return 
1
    } 
    
format(string,sizeof(string),"[ADMIN]:{FFFFFF} Administrator %s has offline banned %s from the server. Reason: %s.",PlayerName(playerid), namecmdreason); 
    
SendClientMessageToAll(COLOR_ADMIN,string); 
    
format(string,sizeof(string),"9[ADMIN] Administrator %s has offline banned %s from the server. Reason: %s.",PlayerName(playerid), namecmdreason); 
    
IRC_GroupSay(gGroupID,IRC_CHANNEL,string); 
     
    
dUserSetINT(name).("Nameban",1); 
    return 
1

This should help.

BTW Hi Uvais... seen you after a long time. I thought you left SAMP haha..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)