-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetip.sp
41 lines (32 loc) · 795 Bytes
/
getip.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <steamtools>
public void OnPluginStart() {
RegConsoleCmd("sm_getip", Command_GetIP);
}
public Action Command_GetIP(int iClient, int iArgs) {
ReplyToCommand(iClient, "Server IP: %s", GetServerIp());
}
stock char[] GetServerIp()
{
char
sOutput[128];
int
iHostIP;
// iHostIP = GetConVarInt(FindConVar("hostip"));
int iOctets[4];
Steam_GetPublicIP(iOctets);
iHostIP =
iOctets[0] << 24 |
iOctets[1] << 16 |
iOctets[2] << 8 |
iOctets[3];
char sHostPort[16];
GetConVarString(FindConVar("hostport"), sHostPort, sizeof(sHostPort));
Format(sOutput, sizeof(sOutput), "%d.%d.%d.%d:%s",
(iHostIP >> 24 & 0xFF),
(iHostIP >> 16 & 0xFF),
(iHostIP >> 8 & 0xFF),
(iHostIP & 0xFF),
sHostPort
);
return sOutput;
}