SA-MP Forums Archive
How I can get server's IP - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How I can get server's IP (/showthread.php?tid=266838)



How I can get server's IP - IstuntmanI - 06.07.2011

Hi, I want to know how I can get server's IP, something like:
Код:
new string[ 128 ];
format( string, 128, "Server's IP is: %s", GetServerVarAsString("ip", string, 128) );
SendClientMessage( playerid, -1, string );
So ... how I can get server's IP ?


Re: How I can get server's IP - SmileyForCheat - 06.07.2011

pawn Код:
new mess[256],IP[256];
    GetPlayerIp(playerid,IP,sizeof(IP));

format(mess,sizeof(mess),"IP: %s ",IP);
SendClientMessageToAll(COLOR_LIGHTBLUE,mess);



Re: How I can get server's IP - IstuntmanI - 06.07.2011

Quote:
Originally Posted by SmileyForCheat
Посмотреть сообщение
pawn Код:
format(mess,sizeof(mess),"IP: %s ",IP);
    SendClientMessageToAll(COLOR_LIGHTBLUE,mess);
Lol, I think this don't work, IP is not defined ... and I don't want player's IP, I want server's IP.


Re: How I can get server's IP - SmileyForCheat - 06.07.2011

Player Can See it In SAMP The IP
Or maybe you mean Obtain an IP
START>RUN>In Run Type>"CMD"(Without("))>In CMD Type "IPCONFIG(Without("))>Show The IP Adress You Understand??


Re: How I can get server's IP - cessil - 06.07.2011

256 sized strings, I'm not sure if smiley is joking or serious.

you can put in the server.cfg
"nosign ipaddress"
and then use GetServerVarAsString("nosign",string,sizeof(string ));
afaik nosign doesn't do anything but you can retrieve it from the cfg


Re: How I can get server's IP - IstuntmanI - 06.07.2011

No, I want to get server's IP, to make a secure script, if server's IP is not my IP, or IP of the host, the server will exit ( SendRconCommand("exit"); )

I know, I'm not the best at english xD


Re: How I can get server's IP - Jochemd - 06.07.2011

Quote:
Originally Posted by cessil
Посмотреть сообщение
256 sized strings, I'm not sure if smiley is joking or serious.

you can put in the server.cfg
"nosign ipaddress"
and then use GetServerVarAsString("nosign",string,sizeof(string ));
afaik nosign doesn't do anything but you can retrieve it from the cfg
That is just one worthless solution, you could #define the IP in that case in the script as well instead of doing that.


Re: How I can get server's IP - IstuntmanI - 06.07.2011

Quote:
Originally Posted by Jochemd
Посмотреть сообщение
That is just one worthless solution, you could #define the IP in that case in the script as well instead of doing that.
I want to do something like this:
Код:
public OnGameModeInit( )
{
    SERVER_IP = GetServerIP( );
    if( SERVER_IP != MY_IP && SERVER_IP != HOST_IP )
        SendRconCommand( "exit" );
}
A define don't detect current server IP.


Re: How I can get server's IP - PrawkC - 06.07.2011

This is probably a really bad idea, but you could make a NPC join, grab its IP, then kick it.


Re: How I can get server's IP - Mean - 06.07.2011

Quote:
Originally Posted by SmileyForCheat
Посмотреть сообщение
pawn Код:
new mess[256],IP[256];
    GetPlayerIp(playerid,IP,sizeof(IP));

format(mess,sizeof(mess),"IP: %s",IP);
SendClientMessageToAll(COLOR_LIGHTBLUE,mess);
Here, you are using 2KB of memory...

IP has 16 cells, not 256, "mess" has 21, in total that is 340 bytes if I calculated correctly.
So, here you are wasting 1708 (2048 - 340) extra bytes of memory in that code... This code needs 340 bytes, yours is 2048 bytes.
The calculation might not be correct, but you are wasting hell lot of memory! I suggest you to read this.