Creating a stock of offline ban
#1

PHP код:
stock offlineban(player_nameplayer_bannerreason[], time 0system 0)
{
    if(
system == 0)
    {
        if(
strlen(reason) > MAX_REASON_LENGTH) return SendClientMessage(player_banner0xFFFFFF""chat" Sorry, the maximum reason length is "#MAX_REASON_LENGTH" characters!");
        
if(gotBanned[player_name] == 0)
        {
            
gotBanned[player_name] = 1;
            
format(jQueryMAX_QUERY_LENGTH"INSERT INTO `"#J_TABLE"` (player_name, user_banned_ip, user_banner, ban_reason, ban_timestamp, ban_time) VALUES ('%s', '%s', 'System', '%s', CURRENT_TIMESTAMP, %d)", jNames[player_banned], jIP[player_banned], reason, time);
            
mysql_tquery(handlejQuery"""");
            
gotBanned[player_name] = 1;
            
printf(jQuery);
        }
    }
    else
    {
        if(
strlen(reason) > MAX_REASON_LENGTH) return SendClientMessage(player_banner0xFFFFFF""chat" Sorry, the maximum reason length is "#MAX_REASON_LENGTH" characters!");
        
if(gotBanned[player_name] == 0)
        {
            
gotBanned[player_name] = 1;
            
format(jQueryMAX_QUERY_LENGTH"INSERT INTO `"#J_TABLE"` (player_name, user_banned_ip, user_banner, ban_reason, ban_timestamp, ban_time) VALUES ('%s', '%s', '%s', '%s', CURRENT_TIMESTAMP, %d)", jNames[player_banned], jIP[player_banned], jNames[player_banner], reason, time);
            
mysql_tquery(handlejQuery"""");
            
printf(jQuery);
            
KickEx(player_banned);
        }
    }
    return 
1;

PHP код:
CMD:offlinetban(playeridparams[]) 

    if(
pInfo[playerid][pAdminLevel] >= 2
    { 
        new 
ban_target2[24], string[128]; 
          if(
sscanf(params"s[24]"ban_targetban_timeban_reason)) return SendClientMessage(playerid, -1,""COL_RED"AdmCmds: /offlineban [Nickname] [Days] [Reason]"); 
        
format(stringsizeof(string),"*COL_RED*""%s %s has banned %s for %i days [Reason: %s]",GetAdminName(playerid),PlayerName(playerid),ban_targetban_timeban_reason); 
        
SendClientMessageToAll(-1string); 
        
offlineban(ban_target2playeridban_reasonban_time1); 
    } 
    else { 
        
SendClientMessage(playerid,-1,""COL_RED"EROARE: U aint admin!"); 
    } 
    return 
1

CMD:offlineban(playeridparams[]) 

    if(
pInfo[playerid][pAdminLevel] >= 2
    { 
        new 
ban_target3[24], string[128]; 
        if(
sscanf(params"s[24]"ban_target3)) return SendClientMessage(playerid, -1,""COL_RED"AdmCmds: /offlineban [Nickname]"); 
        
format(stringsizeof(string), ""COL_RED"AdmCmds: %s %s  has  permanent  banned %s [Reason: %s]",GetAdminName(playerid),PlayerName(playerid),ban_target3ban_reason); 
        
SendClientMessageToAll(-1string); 
        
offlineban(ban_target3playeridban_reason01); 
    } 
    else { 
        
SendClientMessage(playerid,-1,""COL_RED"EROARE: U aint admin"); 
    } 
    return 
1

My question is, if I ban someone by it's username even if he's not online, how can stock detect his IP from mysql?


ex. in mysql username: Zeus. IP: 160.0.0.0


In Game command: /offlinetban Zeus 5(days) Reason

but how can script detects zeus's IP if he's not online?
Reply
#2

You said it yourself!
Using MySql? Saving player account infos? Save the IP too, query the results searching by username get the saved IP address and the job is done.
Reply
#3

Quote:
Originally Posted by v1k1nG
Посмотреть сообщение
You said it yourself!
Using MySql? Saving player account infos? Save the IP too, query the results searching by username get the saved IP address and the job is done.
PHP код:
format(querysizeof(query), "SELECT IP FROM `users` WHERE `Username`= '%s'"player_name); 
?
Reply
#4

Quote:
Originally Posted by Zeus666
Посмотреть сообщение
PHP код:
format(querysizeof(query), "SELECT IP FROM `users` WHERE `Username`= '%s'"player_name); 
?
Yeah exactly.
Reply
#5

It's best you use mysql_format and escape the string using %e
Reply
#6

Quote:
Originally Posted by UFF
Посмотреть сообщение
Yeah exactly.
and where should i put query ? and how can I insert IP got from query in the stock offlineban?
Reply
#7

The code will not compile as the first parameter of function offlineban takes a string (player's name) as argument but in the function itself, you have it as integer and have variables for it. This will not work for offline, here is what you should do:
  • Execute a SELECT query to fetch the last ip used by the said player and pass in mysql_tquery callback parameters (admin's name, reason)
    • No rows? Player does not exist in database
    • Rows found? Retrieve ip, format a new query with all the information you now have and execute the INSERT query.
Before doing anything of it, pass the player's name in sscanf to check if the player is online and inform admins to use the normal commands to avoid more job than really needed.

Your sscanf specifiers are also wrong. You never store to ban_reason or ban_time.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)