SA-MP Forums Archive
Command for checking who is registered on that ip - 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: Command for checking who is registered on that ip (/showthread.php?tid=607745)



Command for checking who is registered on that ip - justjamie - 23.05.2016

Hello.
I wanna make a irc command (!checkip), and when i put in a IP, it should display every username that uses that IP.
Right now, it only displays 1 user, but i want it to show EVERY player that has that ip.
This is my code:

PHP код:
//the command
IRCCMD:checkip(botidchannel[], user[], host[], params[])
{
if(!
IsEchoChannel(channel)) return iNoticeuserIRC_WRONG_CHANNEL);
new 
query[128],temp_ip[40];
if(
sscanf(params"s"temp_ip)) return iEchoUse("!checkip [ IP ADRESS ]");
format(query,sizeof(query),"SELECT * FROM user WHERE regip ='%s'",temp_ip);
mysql_function_query(dbhandle,query,true,"CheckIp","s",temp_ip);
return 
1;

PHP код:
//the public
forward CheckIp(temp_ip[]);
public 
CheckIp(temp_ip[])
{
    new 
num_rows,num_fields;
    
cache_get_data(num_rows,num_fields,dbhandle);
    if(
num_rows==0)
    {
    return 
iEchoUse("That ip adress isn't found in our database!");
    }
    else
    {
    new 
string[128],temp_username[35];
    
cache_get_field_content(0"username"temp_username);
    
format(string,sizeof(string),"%s",temp_username);
       
iEcho(string);
    return 
true;
    }




Re: Command for checking who is registered on that ip - Konstantinos - 23.05.2016

That's because you get the data from the row 0 only. You should use a loop for that:
pawn Код:
for (new i; i != num_rows; i++)
{
    cache_get_row(i, 0, temp_username); // only 1 field so no need to let it search for the fieldid
    iEcho(temp_username);
}
EDIT:
Also escape your strings to avoid from being victim of SQL Injection and also selecting only the field you want and not all the data.

pawn Код:
mysql_format(dbhandle,query,sizeof(query),"SELECT username FROM user WHERE regip ='%e'",temp_ip);



Re: Command for checking who is registered on that ip - justjamie - 23.05.2016

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
That's because you get the data from the row 0 only. You should use a loop for that:
pawn Код:
for (new i; i != num_rows; i++)
{
    cache_get_field_content(i, "username", temp_username);
    iEcho(temp_username);
}
thanks haha i never used loops before :3