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

Csgo get server ip adress


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
neatek
AlliedModders Donor
Join Date: Jul 2010
Location: Russia
Old 02-07-2016 , 03:24   Csgo get server ip adress
Reply With Quote #1

Hello all, i know was a lot of same topics but they all on old syntax i tried everything, so i need help.
I need to detect server type in my plugin, because i need to add different functions on servers.

So, how to get server ip adress?
__________________
neatek is offline
Wilczek
AlliedModders Donor
Join Date: Oct 2012
Location: Poland
Old 02-07-2016 , 05:48   Re: Csgo get server ip adress
Reply With Quote #2

PHP Code:
public OnMapStart()  
{  
    
CreateTimer(1.0GetStatus);


public 
Action GetStatus(Handle Timer)
{
    
char Output[600]; char IP_Port[100];
    
ServerCommandEx(Output600"status");
    
    
char Derp[8][100];
    
ExplodeString(Output"\n"Derp8100);
    
    
IP_Port Derp[2];

__________________
Wilczek is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 02-07-2016 , 08:55   Re: Csgo get server ip adress
Reply With Quote #3

just use the old syntax code...? o.o
Miu is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 02-07-2016 , 12:45   Re: Csgo get server ip adress
Reply With Quote #4

This question has been asked many times. Do some searching


Edit :




Quote:
Originally Posted by sskillz View Post
Yey I found a fix
Because only the first byte of the DWORD is signed, I first move the wanted byte in it to the lower part (first byte) which is unsigned and then use AND to get it..

Heres the code:
Code:
	new pieces[4];
	new longip = GetConVarInt(FindConVar("hostip"));
	
	pieces[0] = (longip >> 24) & 0x000000FF;
	pieces[1] = (longip >> 16) & 0x000000FF;
	pieces[2] = (longip >> 8) & 0x000000FF;
	pieces[3] = longip & 0x000000FF;

	Format(NetIP, sizeof(NetIP), "%d.%d.%d.%d", pieces[0], pieces[1], pieces[2], pieces[3]);
Thanks you all

Last edited by headline; 02-07-2016 at 12:47.
headline is offline
neatek
AlliedModders Donor
Join Date: Jul 2010
Location: Russia
Old 02-07-2016 , 16:29   Re: Csgo get server ip adress
Reply With Quote #5

Quote:
Originally Posted by Wilczek View Post
PHP Code:
public OnMapStart()  
{  
    
CreateTimer(1.0GetStatus);


public 
Action GetStatus(Handle Timer)
{
    
char Output[600]; char IP_Port[100];
    
ServerCommandEx(Output600"status");
    
    
char Derp[8][100];
    
ExplodeString(Output"\n"Derp8100);
    
    
IP_Port Derp[2];

Can i use it OnPluginStart? Why are you using timer?
__________________
neatek is offline
Wilczek
AlliedModders Donor
Join Date: Oct 2012
Location: Poland
Old 02-07-2016 , 18:32   Re: Csgo get server ip adress
Reply With Quote #6

I think OnPluginStart should be fine unless some other plugin interferes the process.

You'd better ask Potato Uno for the timer, as it's basically his code ;)
__________________
Wilczek is offline
Nanochip
Senior Member
Join Date: Jan 2014
Old 02-07-2016 , 22:04   Re: Csgo get server ip adress
Reply With Quote #7

the timer is because the information in the "status" menu changes when people leave/join the server. but only to get the ip of the server, his code is not a good tool to use.

Just use this in OnPluginStart:
Quote:
Originally Posted by sskillz View Post
Code:
	new pieces[4];
	new longip = GetConVarInt(FindConVar("hostip"));
	
	pieces[0] = (longip >> 24) & 0x000000FF;
	pieces[1] = (longip >> 16) & 0x000000FF;
	pieces[2] = (longip >> 8) & 0x000000FF;
	pieces[3] = longip & 0x000000FF;

	Format(NetIP, sizeof(NetIP), "%d.%d.%d.%d", pieces[0], pieces[1], pieces[2], pieces[3]);
__________________
Nanochip is offline
Wilczek
AlliedModders Donor
Join Date: Oct 2012
Location: Poland
Old 02-08-2016 , 04:04   Re: Csgo get server ip adress
Reply With Quote #8

Hostip may return wrong value if the server is behind NAT, and hostport returns wrong value if the server is crawling ports up (tested by myself).
__________________
Wilczek is offline
Reply



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 11:48.


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