Raised This Month: $12 Target: $400
 3% 

Best way to get server ip and port


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kahl_Drogo
Senior Member
Join Date: Apr 2012
Old 01-19-2019 , 08:10   Best way to get server ip and port
Reply With Quote #1

Hi, is any better way to get serwer ip and port on this moment than this one for example : https://forums.alliedmods.net/showpo...36&postcount=6 ?
__________________
Kahl_Drogo is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 01-19-2019 , 09:11   Re: Best way to get server ip and port
Reply With Quote #2

If you want to make sure that you get the public IP address, and not a local RFC1918 (192.168.x, 10.x, etc) for servers behind NAT, you want to use GetPublicIP from SteamWorks.
__________________
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
Kahl_Drogo
Senior Member
Join Date: Apr 2012
Old 01-19-2019 , 11:42   Re: Best way to get server ip and port
Reply With Quote #3

Yes this answer i needed thx ;)
__________________
Kahl_Drogo is offline
Kahl_Drogo
Senior Member
Join Date: Apr 2012
Old 02-07-2019 , 09:32   Re: Best way to get server ip and port
Reply With Quote #4

Hi, I used GetPublicIP from SteamWorks like below:

PHP Code:
#define DEBUG

#define PLUGIN_NAME           "TF2 Pro Stats"
#define PLUGIN_AUTHOR         "Szkalownik"
#define PLUGIN_DESCRIPTION    ""
#define PLUGIN_VERSION        "1.0"
#define PLUGIN_URL            ""

#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <SteamWorks>

char dbconfig[] = "tf2_pro_stats";
Database databaseHandler;

enum struct ServerData {
    
int id[11];
    
char ip[64];
    
char port[16];
}

ServerData serverData;

public 
Plugin:myinfo =
{
    
name PLUGIN_NAME,
    
author PLUGIN_AUTHOR,
    
description PLUGIN_DESCRIPTION,
    
version PLUGIN_VERSION,
    
url PLUGIN_URL
};

public 
OnPluginStart()
{
    
setServer();
}

public 
void setServer()
{
    
char serverIp[64];
    
char serverPort[10];
    
int ipaddr[4];
    
    
SteamWorks_GetPublicIP(ipaddr);
    
Format(serverIpsizeof(serverIp), "%d.%d.%d.%d",ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
    
strcopy(serverData.ipsizeof(serverData.ip), serverIp); 
    
    
GetConVarString(FindConVar("hostport"), serverPortsizeof(serverPort));
    
strcopy(serverData.portsizeof(serverData.port), serverPort); 

But SteamWorks_GetPublicIP return 0.0.0.0 as my server ip after restart.
So question is where is the best place/event etc to put SteamWorks_GetPublicIP ? Looks like OnPluginStart is not a good place .
__________________
Kahl_Drogo is offline
Facksy
Senior Member
Join Date: Apr 2017
Location: +2+2
Old 02-07-2019 , 10:44   Re: Best way to get server ip and port
Reply With Quote #5

I suggest you OnMapStart() or OnConfigsExecuted()
__________________
My Steam I take private requests if related with TF2
My Plugins
Facksy is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:34.


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