SA-MP Forums Archive
Creating a stock of offline ban - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Creating a stock of offline ban (/showthread.php?tid=659021)



Creating a stock of offline ban - Zeus666 - 20.09.2018

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?


Re: Creating a stock of offline ban - v1k1nG - 20.09.2018

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.


Re: Creating a stock of offline ban - Zeus666 - 20.09.2018

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); 
?


Re: Creating a stock of offline ban - UFF - 20.09.2018

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


Re: Creating a stock of offline ban - solstice_ - 20.09.2018

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


Re: Creating a stock of offline ban - Zeus666 - 20.09.2018

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?


Re: Creating a stock of offline ban - Calisthenics - 20.09.2018

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: 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.