Raised This Month: $32 Target: $400
 8% 

Getting certain IP adress


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GhostMan
Senior Member
Join Date: Jun 2012
Old 09-26-2012 , 07:45   Getting certain IP adress
Reply With Quote #1

I'm making plugin with would write a message to a connected player by the IP adress.
And I'm not sure do i need to check once again IP in "announcment" function?

PHP Code:
#include <amxmodx>
#include <amxmisc>

new ip_set;
new 
g_IP[33];

public 
plugin_init()
{
    
register_plugin("IP Announc""1.0""GhostMan");
    
ip_set register_cvar("amx_ipannounc""11.22.33.44");
}

public 
client_putinserver(id)
{
    
get_user_ip(idp_IPcharsmax(p_IP), 0);

    if(
g_IP[id] == ip_set)
    {
        
set_task(35.0"announcment")
    }
}

public 
announcment(id)
{
    if(
g_IP[id] == ip_set)
    {
        new 
p_Name[33];
        
get_user_name(idp_Namecharsmax(p_Name))

        
set_hudmessage(2552550, -1.0, -1.016.08.0)
        
show_hudmessage(id"Hello %s"p_Name)
    }


Last edited by GhostMan; 09-26-2012 at 07:50.
GhostMan is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 09-26-2012 , 07:52   Re: Getting certain IP adress
Reply With Quote #2

That won't even function as you want it to

PHP Code:
#include <amxmodx>
#include <amxmisc>

new ip_set;
new 
p_IP[33][16];

public 
plugin_init()
{
    
register_plugin("IP Anounc""1.0""GhostMan");
    
ip_set register_cvar("amx_ipanounc""11.22.33.44");
}

public 
client_putinserver(id)
{
    new 
ip[16];

    
get_user_ip(idp_IP[id], charsmax(p_IP[]), 1);
    
get_pcvar_string(ip_setipcharsmax(ip));

    if(
equal(ipp_IP[id]))
    {
        
set_task(35.0"anouncment"id)
    }
}

public 
announcment(id)
{
    new 
ip[16];
    
get_pcvar_string(ip_setipcharsmax(ip));

    if(
equal(ipp_IP[id]))
    {
        new 
p_Name[33];
        
get_user_name(idp_Namecharsmax(p_Name))

        
set_hudmessage(2552550, -1.0, -1.016.08.0)
        
show_hudmessage(id"Hello %s! We have been waiting for you!"p_Name)
    }

__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).

Last edited by YamiKaitou; 09-26-2012 at 07:53.
YamiKaitou is offline
GhostMan
Senior Member
Join Date: Jun 2012
Old 09-27-2012 , 07:27   Re: Getting certain IP adress
Reply With Quote #3

For some reason your given come not working too. I dont get any message after 35sec

I'v changed ip_set to my ip ofc

Last edited by GhostMan; 09-27-2012 at 07:28.
GhostMan is offline
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 09-27-2012 , 09:04   Re: Getting certain IP adress
Reply With Quote #4

Try deleting the 1 from the get_user_ip.
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 09-27-2012 , 10:41   Re: Getting certain IP adress
Reply With Quote #5

Quote:
Originally Posted by lucas_7_94 View Post
Try deleting the 1 from the get_user_ip.
Doing that will retrieve ip with port and he doesn't need that.
This will never work if
PHP Code:
set_task(35.0"anouncment"id// forgot a "n" => announcment

...

public 
announcment(id
also global variable p_IP it's useless. Just retrieve user ip in a temp var when he connect then call the task with user id. When the task it's been executed check if player it's still connected, don't need to recheck for ip.
__________________
Still...lovin' . Connor noob! Hello

Last edited by Alka; 09-27-2012 at 10:48.
Alka is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-27-2012 , 19:23   Re: Getting certain IP adress
Reply With Quote #6

Quote:
Originally Posted by Alka View Post
global variable p_IP it's useless. Just retrieve user ip in a temp var when he connect then call the task with user id. When the task it's been executed check if player it's still connected, don't need to recheck for ip.
That is not true. If I connect and it checks my IP then it will set the task. Now, I leave (before task completes). Yami connects and gets my entity index (before task completes). Function now executes on Yami because he is "connected".

The longer the task, the more likely this is to happen.

However, one alternative is to remove the task on disconnect which should theoretically prevent the above mentioned race condition.
__________________

Last edited by fysiks; 09-27-2012 at 19:24.
fysiks is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 09-27-2012 , 21:11   Re: Getting certain IP adress
Reply With Quote #7

@fysiks - Yeah, forgot to tell about that. Remove task at disconnect :-) thanks for pointing that out
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
GhostMan
Senior Member
Join Date: Jun 2012
Old 09-29-2012 , 15:28   Re: Getting certain IP adress
Reply With Quote #8

I'm not really familiar with tasks, should it look like that when i'm removing it?

PHP Code:
    if(task_exists(id))
    {
        
remove_task(id)
    } 
GhostMan is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-29-2012 , 15:33   Re: Getting certain IP adress
Reply With Quote #9

Quote:
Originally Posted by GhostMan View Post
I'm not really familiar with tasks, should it look like that when i'm removing it?

PHP Code:
    if(task_exists(id))
    {
        
remove_task(id)
    } 
If you don't know the inner workings of remove_task() then yes, but technically, you don't need to check if the task exists before executing remove_task().
__________________
fysiks is offline
Reply


Thread Tools
Display Modes

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


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