View Single Post
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-19-2015 , 00:37   Re: [ANY/TF2] Get Server IP, Port & Update Version
Reply With Quote #6

hostip is returning the IP in its binary form. Not sure if SourceMod has the equivalent of inet_ntoa to turn it from its binary form back to its numbers-and-dots notation.

Here's a quick version I wrote:

PHP Code:
stock Inet_NtoA(binaryString:address[], maxlength)
{
    new 
quads[4];
    
quads[0] = binary >> 24 0x000000FF// mask isn't necessary for this one, but do it anyway
    
quads[1] = binary >> 16 0x000000FF;
    
quads[2] = binary >> 0x000000FF;
    
quads[3] = binary 0x000000FF;
    
    
Format(addressmaxlength"%d.%d.%d.%d"quads[0], quads[1], quads[2], quads[3]);

The attached test plugin registers the getip admin command which prints the server IP from the hostip cvar.

Having said that, if you start the server with the -ip command-line switch, the dotted quad IP will appear in the "ip" cvar as well.
Attached Files
File Type: sp Get Plugin or Get Source (getip.sp - 912 views - 2.6 KB)
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 01-19-2015 at 00:38.
Powerlord is offline