AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Show IP plugin help (https://forums.alliedmods.net/showthread.php?t=64877)

st0kata 12-26-2007 15:54

Show IP plugin help
 
This is my first plugin which shows the IPs of the players in the server and I can't continue working on it before I get what's wrong with this code :/ The idea is to read from an .ini file and if there's a line:
Code:

"stk" "1.2.3.4"
(in-game name of an admin and his/her ip)
and the admin is not with that nickname the plugin will show different IP than the real one. The problem is that it still shows my real IP when I test it. Hope I didn't make some terrible mistakes :oops:
PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Show IP"
#define VERSION "1.0"
#define AUTHOR "st0ka"

new admin_fake_ip[32]
new 
admin_real_ip[32]
new 
filename[256]

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_concmd("amx_ips","cmd_showip",ADMIN_ALL,"Shows all users with their IP adresses")
    
get_configsdir(filename,255)
    
format(filename,255,"%s/show_ip.ini",filename)
}

public 
client_connect(id)
{
    new 
random1=random_num(128,160)
    new 
random2=random_num(25,250)
    
    new 
filepointer fopen(filename,"r")
    if(
filepointer)
    {
        new 
read_data[128],admin_ip[32],admin_name[32]
        new 
parsed_admin_ip[32],parsed_admin_name[32]
        while(
fgets(filepointer,readdata,127))
        {
            
parse(read_data,parsed_admin_ip,31,parsed_admin_name,31)
            
remove_quotes(parsed_admin_ip)
            
remove_quotes(parsed_admin_name)
            if(
is_user_admin(id))
            {
                
get_user_ip(id,admin_ip,31,0)
                
get_user_name(id,admin_name,31)
                if(
equal(parsed_admin_ip,admin_ip) && !equal(parsed_admin_name,admin_name))
                {
                    
format(admin_fake_ip,31,"84.43.%d.%d:27005",random1,random2)
                    
format(admin_real_ip,31,"%s",admin_ip)
                }
            }
        }
        
fclose(filepointer)
    }
}

public 
cmd_showip(id
{
    
console_print(id,"================ Users and IP Adresses =============")
    new 
date[32]
    
format_time(date,31,"%d/%m/%Y",-1)
    
console_print(id,"Current date - %s",date)
    new 
time[32]
    
format_time(time,31,"%H:%M",-1)
    
console_print(id,"Current time - %s",time)
    new 
players[32], name[32], ip[32], numids
    get_players
(playersnum
    for(new 
i=0;i<num;i++) 
    {
        
ids players[i]
        
get_user_ip(ids,ip,31,0)
        
get_user_name(ids,name,31
        if(!
is_user_admin(id))
        {
            if(
equal(ip,admin_real_ip))
            {
                
console_print(id,"%s     ->        %s"name,admin_fake_ip)
            }
            else
            {
                
console_print(id,"%s     ->        %s"name,ip)
            }
        }
        else
        {
            
console_print(id,"%s     ->        %s"name,ip)
        }
    }
    
console_print(id""
    
console_print(id"================ Users and IP Adresses =============")
    return 
PLUGIN_HANDLED 



Vet 12-27-2007 09:59

Re: Show IP plugin help
 
I just looked over it real quick-like and noticed this...

In the client_connect routine, you say 'if player IS an admin, substitute a fake IP'.

Code:

if(is_user_admin(id))
{
  get_user_ip(id,admin_ip,31,0)
  get_user_name(id,admin_name,31)
  if(equal(parsed_admin_ip,admin_ip) && !equal(parsed_admin_name,admin_name))
  {
      format(admin_fake_ip,31,"84.43.%d.%d:27005",random1,random2)
      format(admin_real_ip,31,"%s",admin_ip)
  }
}

But in the cmd_showip routine, you say 'if player IS NOT an admin, display the fake ip'.

Code:


for(new i=0;i<num;i++)
{
new ids = players[i]
new name[32]
new ip[32]
get_user_ip(ids,ip,31,0)
get_user_name(ids,name,31)
if(!is_user_admin(id))
{
    if(equal(ip,admin_real_ip))
    {
        console_print(id,"%s    ->        %s",name,admin_fake_ip)
    }
    else
    {
        console_print(id,"%s    ->        %s",name,ip)
}
}

Also, for efficiency, place the variable definitions above the for statement. Otherwise you're recreating them with every pass.

st0kata 12-27-2007 10:30

Re: Show IP plugin help
 
In client_connect I check whether the player who's connecting to the server is an admin if he/she is an admin then the plugin reads show_ip.ini and compares the name and the ip/steamid (I haven't added this yet)
But in cmd_showip i check whether the person which is calling the command is amin or not :)
I want other admins to be able to see player's (including admins) real IPs/SteamIDs.
Thank you for pointing out my mistake regarding the efficiency of the plugin :P


M249-M4A1 12-27-2007 23:47

Re: Show IP plugin help
 
You verify admin names and IP's in users.ini and anyone can see your IP address by typing "status" in the console.

st0kata 12-28-2007 04:58

Re: Show IP plugin help
 
Yeah I know that but I couldn't block it. I guess it's client-side cmd :/
Anyway since it's my first plugin (excluding some say /test ones :D) I've just wanted to know what's wrong so that I can avoid such mistake in future "ideas" :)

Vet 12-28-2007 09:46

Re: Show IP plugin help
 
Maybe a typo, and probably not your problem, but if your .ini is set up as you show with "name" "IP", then you're parsing the parameters backwards with
parse(read_data,parsed_admin_ip,31,parsed_admin_name,31.

Also, you are only using 1 variable array for the real ip (admin_real_ip). If you don't want them all to be the same, then you need to set up a multidimentional array like admin_real_ip[33][32]. Then put the IP in admin_real_ip[id] and test with if(equal(ip,admin_real_ip[id])).

st0kata 12-28-2007 10:21

Re: Show IP plugin help
 
Ahh I see :) Thanks again Vet! I've seen these multidimentional arrays in some plugins but I wasn't sure how exactly to use them. Now I got it. I'll try to fix the code when I have some time but the plugin won't be useful at all if it's impossible to block "status". Thank you guys :>


All times are GMT -4. The time now is 11:02.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.