Raised This Month: $ Target: $400
 0% 

Show IP plugin help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
st0kata
Member
Join Date: Aug 2007
Old 12-26-2007 , 15:54   Show IP plugin help
Reply With Quote #1

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


Last edited by st0kata; 12-27-2007 at 10:37.
st0kata is offline
Vet
Veteran Member
Join Date: Jul 2006
Location: I|O wa
Old 12-27-2007 , 09:59   Re: Show IP plugin help
Reply With Quote #2

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.
__________________
=====================================
- My Plugins -
=====================================
Vet is offline
Send a message via MSN to Vet
st0kata
Member
Join Date: Aug 2007
Old 12-27-2007 , 10:30   Re: Show IP plugin help
Reply With Quote #3

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

st0kata is offline
M249-M4A1
I <3 Mac
Join Date: May 2005
Location: Not interested
Old 12-27-2007 , 23:47   Re: Show IP plugin help
Reply With Quote #4

You verify admin names and IP's in users.ini and anyone can see your IP address by typing "status" in the console.
__________________
M249-M4A1 is offline
st0kata
Member
Join Date: Aug 2007
Old 12-28-2007 , 04:58   Re: Show IP plugin help
Reply With Quote #5

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 ) I've just wanted to know what's wrong so that I can avoid such mistake in future "ideas"
st0kata is offline
Vet
Veteran Member
Join Date: Jul 2006
Location: I|O wa
Old 12-28-2007 , 09:46   Re: Show IP plugin help
Reply With Quote #6

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])).
__________________
=====================================
- My Plugins -
=====================================

Last edited by Vet; 12-28-2007 at 09:54.
Vet is offline
Send a message via MSN to Vet
st0kata
Member
Join Date: Aug 2007
Old 12-28-2007 , 10:21   Re: Show IP plugin help
Reply With Quote #7

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 :>
st0kata is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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