otland / forgottenserver

A free and open-source MMORPG server emulator written in C++
https://otland.net
GNU General Public License v2.0
1.6k stars 1.06k forks source link

TFS IP address format #1969

Closed gunzino closed 8 years ago

gunzino commented 8 years ago

TFS saving IP addresses in opposite way. For example IP 0.0.0.1 should be in long format 1 but in TFS it is 16777216.

Expected behaviour

I am not 100% about that but PHP functions long2ip and ip2long should be working with TFS databases. Instead, you need to create special functions that swap the quads of an ip address.

Actual behaviour

I need to use edited functions to get the IP from long. There is an example code: `
public static function TfsLong2Ip($tfs_ip) { $ipp = long2ip($tfs_ip); $quads = explode(".", $ipp); $ip = $quads[3].".".$quads[2].".".$quads[1].".".$quads[0]; return $ip; }

public static function Ip2TfsLong($ip) {
    $quads = explode(".", $ip);
    $tfs_ip = $quads[3].".".$quads[2].".".$quads[1].".".$quads[0];
    return ip2long($tfs_ip);
}`

Environment

TFS & PHP

Shawak commented 8 years ago

Are you running on a 32 bit machine? If yes read the notes: http://php.net/manual/de/function.long2ip.php

Mkalo commented 8 years ago

There is nothing wrong with TFS, it is converting in big endian as PHP uses little endian. You should do a function to get the string from a big endian encoded long as Game.convertIpToString: https://github.com/otland/forgottenserver/blob/33d074fe1cb28d7f094e0e6896ada65d9cd472a2/data/lib/core/game.lua#L11

And one to convert big endian long to little endian long.

gunzino commented 8 years ago

Yeah thats what I do. If you copy TFS long to any converter on the web you will get bad result.

Is there some special reason to use big endian ?

marksamman commented 8 years ago

It was inherited from https://github.com/opentibia/server. It can't be fixed without breaking everything that depends on the old format.