View Single Post
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 03-03-2021 , 12:05   Re: SourceMod extension: how to get server's IP?
Reply With Quote #2

PHP Code:
#include <SteamWorks>

// [... all your other code ...]
    
char sPublicIP[64];
    
int iPublicIP[4];
    if (
SteamWorks_GetPublicIP(iPublicIP)) {
        
Format(sPublicIPsizeof(sPublicIP), "%d.%d.%d.%d:%d"iPublicIP[0], iPublicIP[1], iPublicIP[2], iPublicIP[3], GetConVarInt(FindConVar("hostport")));
    } else {
        
LogError("Appears like we had an error on getting the Public IP address.");
    }
// [... all your other code ...] 
Now, the string variable "sPublicIP" holds the data "192.0.2.123:27015", assuming that the Steam network sees the public IP as "192.0.2.123", and the port is "27015".

PHP Code:
    Format(sPublicIPsizeof(sPublicIP), "%d.%d.%d.%d"iPublicIP[0], iPublicIP[1], iPublicIP[2], iPublicIP[3])); 
can eventually be used, if you don't like the port number to be a part of it.
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL is offline