AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Getting certain IP adress (https://forums.alliedmods.net/showthread.php?t=196872)

GhostMan 09-26-2012 07:45

Getting certain IP adress
 
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)
    }



YamiKaitou 09-26-2012 07:52

Re: Getting certain IP adress
 
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)
    }



GhostMan 09-27-2012 07:27

Re: Getting certain IP adress
 
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

lucas_7_94 09-27-2012 09:04

Re: Getting certain IP adress
 
Try deleting the 1 from the get_user_ip.

Alka 09-27-2012 10:41

Re: Getting certain IP adress
 
Quote:

Originally Posted by lucas_7_94 (Post 1807483)
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.

fysiks 09-27-2012 19:23

Re: Getting certain IP adress
 
Quote:

Originally Posted by Alka (Post 1807573)
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.

Alka 09-27-2012 21:11

Re: Getting certain IP adress
 
@fysiks - Yeah, forgot to tell about that. Remove task at disconnect :-) thanks for pointing that out

GhostMan 09-29-2012 15:28

Re: Getting certain IP adress
 
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)
    } 


fysiks 09-29-2012 15:33

Re: Getting certain IP adress
 
Quote:

Originally Posted by GhostMan (Post 1809085)
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().


All times are GMT -4. The time now is 04:23.

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