Raised This Month: $32 Target: $400
 8% 

Get Server IP?


Post New Thread Reply   
 
Thread Tools Display Modes
sslice
Senior Member
Join Date: Feb 2005
Location: Texas, USA
Old 06-26-2007 , 14:44   Re: Get Server IP?
Reply With Quote #11

You should do the same with the "hostip" ConVar, although it is not in string format. Here is how you could do it, though:

Code:
new Handle:hostIP;
new longIP;
new pieces[4];
new String:strIP[32];

hostip = FindConVar("hostip");
longip = GetConVarInt(hostip);

pieces[0] = (longip & 0xFF000000) >> 24;
pieces[1] = (longip & 0x00FF0000) >> 16;
pieces[2] = (longip & 0x0000FF00) >> 8;
pieces[3] = longip & 0x000000FF;

FormatEx(strIP, sizeof(strIP), "%d.%d.%d.%d", pieces[0], pieces[1], pieces[2], pieces[3]);
I'm not sure on the byte order, but if it gives you a reverse IP you can just reverse the order of the pieces.
__________________

Last edited by sslice; 06-26-2007 at 14:47.
sslice is offline
sskillz
Member
Join Date: Apr 2005
Old 06-26-2007 , 15:27   Re: Get Server IP?
Reply With Quote #12

Nice idea!

It showed me:
-84.27.171.16
instead of:
172.27.171.16

Strage the first byte is a bit off and I can't see any error in the code.
sskillz is offline
Spinner
Member
Join Date: Nov 2004
Location: Michcigan
Old 06-26-2007 , 23:43   Re: Get Server IP?
Reply With Quote #13

Its net_status now Instead of Net_address
Spinner is offline
sskillz
Member
Join Date: Apr 2005
Old 06-27-2007 , 06:26   Re: Get Server IP?
Reply With Quote #14

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
sskillz is offline
sslice
Senior Member
Join Date: Feb 2005
Location: Texas, USA
Old 06-27-2007 , 14:24   Re: Get Server IP?
Reply With Quote #15

Ah, ok.. didn't think about signed. Nice work.
__________________
sslice 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 10:16.


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