• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved Lasip why is it varbinary? TFS 1.4.2

Erikas Kontenis

Board Moderator
Staff member
Board Moderator
Joined
Jul 3, 2009
Messages
1,864
Reaction score
567
Location
Lithuania
What is the reasoning of lastip column being varbinary? How to translate it in human ip readable trough sql? I have tried chatgpt for this issue but I never can translate lastip to regular ip string. I also believe I haven't changed much code of this functionality so maybe lastip parse/set doesn't work properly in general for 1.4.2?
 
SQL:
SELECT INET_NTOA(lastip) AS ip_address FROM players WHERE name = "Erikas";

This should work, but I actually ran it against a bunch of players on Dura and it came out with incorrect (but properly formatted) results. Converting in-game does seem to work though, so I guess the methods are different?

Just for fun, this is essentially what the INET_NTOA() function does:
SQL:
SELECT
  (lastip >> 24) & 0xFF as first_octet,
  (lastip >> 16) & 0xFF as second_octet,
  (lastip >> 8) & 0xFF as third_octet,
  lastip & 0xFF as fourth_octet
FROM
  players
WHERE
  name = "Erikas"


Edit:
Alright so the different between what TFS does and what MySQL wants to do with INET_NTOA() is the byte order (reversed), you can read up about this by researching big & little-endian. Anyway, this is how we can get the correct full IP back in MySQL:

SQL:
SELECT CONCAT(
  (lastip & 0xFF), '.',
  ((lastip >> 8) & 0xFF), '.',
  ((lastip >> 16) & 0xFF), '.',
  (lastip >> 24)
) AS ip_address
FROM players
WHERE name = "Erikas";
 
Last edited:
Thank you a lot for your detailed answer Michael. I probably have fuckedup something with this IP inserting then... Because all my records are 0.0.0.0 ip. I will fix this issue on myself and will submit my experiences here when I'm done :D
1699132948213.png
Post automatically merged:

Also, regarding your query. When I debug player save and the lastip line. The
player->lastIP.to_string() returns me "::ffff:127.0.0.1". Apart idk what means ::ffff: it looks so far so good. However your select query doesn't work for my test case like
SQL:
SELECT CONCAT(
  (INET6_ATON("::ffff:127.0.0.1") & 0xFF), '.',
  ((INET6_ATON("::ffff:127.0.0.1") >> 8) & 0xFF), '.',
  ((INET6_ATON("::ffff:127.0.0.1") >> 16) & 0xFF), '.',
  (INET6_ATON("::ffff:127.0.0.1") >> 24)
) AS ip_address
1699134653811.png

And in game I see the IP address quite OK, however cannot parse it through SQL. So simple thing makes it so complicated :D
Post automatically merged:

Allright! So saving the ip address works ok in my side. Finally after 10x attempt of annoying chatgpt prompting she gave me the solution!
SELECT INET_NTOA(CONV(SUBSTRING(Hex(INET6_ATON("::ffff:127.0.0.1")), -8), 16, 10)) AS ip_address
returns 127.0.0.1.
So in result such query retruns all expected results. Thank you a lot everyone for trying to help me. Perhaps it will be useful research for someone else too!
SQL:
SELECT
INET_NTOA(CONV(SUBSTRING(Hex(lastip), -8), 16, 10)) AS lastip
from onlyfortress.players where name = 'Erikas'
 
Last edited:
Back
Top