• 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!

[LINUX] Dinamic IP // Automatic Restarter

Sebasbe

New Member
Joined
May 14, 2008
Messages
84
Reaction score
0
I got three scripts on linux and one globalevent

/usr/bin/tibia-up
Code:
cd /home/tibia/otserv/
./theforgottenserver
tibia-up

/usr/bin/tibia-down
Code:
kill -8 `ps -A | grep theforgottense | cut -c1-5`

/usr/bin/tibia-ip
Code:
#!/bin/bash

ipnow=`wget -q -O - checkip.dyndns.org | sed -e 's/[^[:digit:]|.]//g'`

ipfile=`cat /tmp/myip`

if [ "$ipfile" != "$ipnow" ]; then
        date >> /tmp/iplog
        echo "CHANGED" >> /tmp/iplog
        echo "CHNAGED"
        echo $ipnow > /tmp/myip
        exit 0;
else
        date >> /tmp/iplog
        echo "NOCHANGED" >> /tmp/iplog
        echo "NOCHANGED"
        exit 1;
fi;

In globalevents, add this line
Code:
<globalevent name="connection" interval="240000" script="connection.lua" />

In scripts/connection.lua
Code:
function onThink(interval, lastExecution)
        local response = os.execute("tibia-ip")

        if response == 0 then
                doBroadcastMessage("Server Info: IPChanged, restarting server.", MESSAGE_STATUS_CONSOLE_ORANGE)
                doSaveServer("no")
                doSetGameState(GAMESTATE_SHUTDOWN)
        end

return TRUE
end

IMPORTANT! in your config.lua, put your dns at ip global.

Version OT: 0.4DEV


Credits to me!
 
Code:
require('socket.http')

local data, status = socket.http.request('http://automation.whatismyip.com/n09230945.asp')
if status == 200 then
	if data ~= getConfigInfo('ip') then
		doSaveServer(false)
		doSetGameState(GAMESTATE_SHUTDOWN)
	else
		print('>> IP address didn\'t change.')
	end
else
	print('>> Couldn\'t parse IP.')
end

ez
 
Back
Top