game.GetIpAddress() working hook

Is there any hook that I can use if the server has initialized completely? Because GetIpAddress() only works after the first player connected, but a PlayerInit hook isn’t always working for this.

Regards,

ibot3

You could use InitPostEntity, which gets called as soon as the Server (Or Client if ran Clientside) has finished initialising.

No, it’s not working with that hook.

What are you exactly trying to do?
If you’re trying to get their IP address before they fully connect you can use the PlayerConnect hook.
Lots of hooks don’t run until a player has connected at least once, to workaround that you can spawn a bot on Initialize, then immediately kick it.

What I usually do is to just wait for the first player to join then save it in SQL or a txt file. This way you can read it on server star.

It’s not always working with a PlayerConnect hook. I now used a timer that looks up every 5 seconds if the serverip is available. Starting on the first PlayerConnect call.



function game.GetIP()
    local hostip = GetConVarString( "hostip" )
    hostip = tonumber( hostip )
    local ip = {}
    ip[ 1 ] = bit.rshift( bit.band( hostip, 0xFF000000 ), 24 )
    ip[ 2 ] = bit.rshift( bit.band( hostip, 0x00FF0000 ), 16 )
    ip[ 3 ] = bit.rshift( bit.band( hostip, 0x0000FF00 ), 8 )
    ip[ 4 ] = bit.band( hostip, 0x000000FF )

    return table.concat( ip, "." )
end


This has always seemed to work, don’t remember where I originally got it from though.

this only works if the user has +hostip set in their startup line

I want to use it serverside. And it seems to work. Is there also a way to get the used port?

[lua]GetConVar(“hostport”):GetString()[/lua]

please use game.GetIPAddress() though, just find a working hook if you want the most compatibility