Command for checking who is registered on that ip
#1

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;
    }

Reply
#2

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);
Reply
#3

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)