AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Server IP (https://forums.alliedmods.net/showthread.php?t=214259)

Jhob94 04-24-2013 19:51

Server IP
 
hi
How i can read server ip?
I want set the Server IP in a Hud, but i dont want use hardcode because i have more then one server, and is better if i can use same plugin for all servers

fysiks 04-24-2013 21:27

Re: Server IP
 
get_user_ip(0, ...

or

get the "ip" cvar (I think it's a cvar)

ConnorMcLeod 04-25-2013 00:58

Re: Server IP
 
"ip" cvar can be false.

^SmileY 04-25-2013 12:36

Re: Server IP
 
net_address..

EDIT:

PHP Code:

#include <amxmodx>

new p_Server;
new 
g_szServer[32];

public 
plugin_init()
{
    
register_plugin("Server IP in Hud Text",AMXX_VERSION_STR,"SmileY");
    
    
p_Server get_cvar_pointer("net_address");
}

public 
plugin_cfg()
{
    
get_pcvar_string(p_Server,g_szServer,charsmax(g_szServer));
    
    
ServerIP();
}

public 
ServerIP()
{
    
set_hudmessage(random_num(50,255),random_num(50,255),random_num(50,255),0.02,0.9,1,6.0,30.0, .channel=4);
    
show_hudmessage(0,"Server Address: %s",g_szServer);
    
    
set_task(20.0,"ServerIP",1337);



Jhob94 04-25-2013 18:05

Re: Server IP
 
Thanks all.
But fysiks are you sure get_user_ip(0,...) will show server ip?

Blizzard_87 04-25-2013 20:52

Re: Server IP
 
Quote:

Originally Posted by Jhob94 (Post 1939995)
Thanks all.
But fysiks are you sure get_user_ip(0,...) will show server ip?

yep its how I check that my plugin is loaded on my server and noone elses.

Code:
public Check_Legal() {     new szIp[22];     get_user_ip(0, szIp, charsmax(szIp));     if(!equal(szIp, SERVERIP))     {         Plugin_Protection()         return PLUGIN_HANDLED;     }     console_print(0, "* Registered Server Detected *");     console_print(0, "* Registered Server Detected *");     console_print(0, "* Registered Server Detected *");         return PLUGIN_HANDLED; }

^SmileY 04-25-2013 22:48

Re: Server IP
 
get the fuc*ing net_address! its always shows a real IP..

the ip cvar its only works if used in command line of HLDS like: ./hlds_run -game cstrike +ip xxx.xxx.xxx.xxx

Ps.
For get a: xxx.xxx.xxx.xxx:27015 for example, you need to get 2 cvars: ip cvar and port cvar

And later use in a string or in a format() funcions... net_address its only use one cvar :)

>>
Quote:

Originally Posted by Blizzard_87 (Post 1940067)
yep its how I check that my plugin is loaded on my server and noone elses.

Code:
public Check_Legal() {     new szIp[22];     get_user_ip(0, szIp, charsmax(szIp));     if(!equal(szIp, SERVERIP))     {         Plugin_Protection()         return PLUGIN_HANDLED;     }     console_print(0, "* Registered Server Detected *");     console_print(0, "* Registered Server Detected *");     console_print(0, "* Registered Server Detected *");         return PLUGIN_HANDLED; }


Send-me any plugin with using this and i will be breaking whole file using a fake cvars..

Blizzard_87 04-25-2013 23:19

Re: Server IP
 
Quote:

Originally Posted by ^SmileY (Post 1939785)
PHP Code:

#include <amxmodx>

new p_Server;
new 
g_szServer[32];

public 
plugin_init()
{
    
register_plugin("Server IP in Hud Text",AMXX_VERSION_STR,"SmileY");
    
    
p_Server get_cvar_pointer("net_address");
}

public 
plugin_cfg()
{
    
get_pcvar_string(p_Server,g_szServer,charsmax(g_szServer));
    
    
ServerIP();
}

public 
ServerIP()
{
    
set_hudmessage(random_num(50,255),random_num(50,255),random_num(50,255),0.02,0.9,1,6.0,30.0, .channel=4);
    
show_hudmessage(0,"Server Address: %s",g_szServer);
    
    
set_task(20.0,"ServerIP",1337);



i'll use this method from now on.... as you say its a better solution.


All times are GMT -4. The time now is 10:54.

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