You are not logged in.

1

Monday, April 29th 2013, 9:07pm

Hostip zu *.*.*.* format ändern

Einige kennen vielleicht hostip und wundern sich was für ein Wert da hintersteckt nun es ist die Server IP Addresse.
Nun wie machen wir das ganze wieder Lesbar mit dem kleinen Schnipsel hier:

PS: Der ist nicht von mir fand ihn aber zufälligerweise.

PHP Source code

1
2
3
4
5
6
7
8
9
10
    new String:NetIP[64];
    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(NetIPsizeof(NetIP), "%d.%d.%d.%d"pieces[0], pieces[1], pieces[2], pieces[3]);
    PrintToServer("Host IP ist: %s",NetIP); // Wichtig das es ein %s und kein %d da es als ein String umgewandelt wird.

MadMakz

Super Moderator

Posts: 1,878

Location: ~#

wcf.user.option.userOption53: Ja

  • Send private message

2

Monday, April 29th 2013, 9:23pm

https://forums.alliedmods.net/showpost.p…849&postcount=6
Alternativ: SteamTools Steam_GetPublicIP()

TeC

Beginner

Posts: 45

wcf.user.option.userOption53: Ja

  • Send private message

3

Monday, April 29th 2013, 9:48pm

Alternativ:

IP im Format: xxx.xxx.xxx.xxx

PHP Source code

1
GetConVarString(FindConVar("ip"), YOUR_STRINGsizeof(YOUR_STRING));

Impact

Super Moderator

Posts: 1,276

wcf.user.option.userOption53: Nein

  • Send private message

4

Monday, April 29th 2013, 10:03pm

@TE
Code wie dieser hier:

Source code

1
GetConVarInt(FindConVar("hostip"));

Sollte möglichst vermieden werden, oder aber das Handle sollte statisch für den nächsten Aufruf gecached werden.
Zudem genügt eine Größe von 15-16 Chars für eine IP.

@Tec
Auch du solltest das obere vermeiden, zudem muss die Cvar ip nicht immer gesetzt sein.

MfG
Impact

TeC

Beginner

Posts: 45

wcf.user.option.userOption53: Ja

  • Send private message

5

Monday, April 29th 2013, 10:13pm

Mein Posting stellt auch nur eine Möglichkeit dar, die IP zu beziehen. Sinnvollerweise sollte man das z.B. bei OnConfigsExecuted() machen und in einen globalen String schreiben, wenn man die IP später noch benötigt.

Similar threads