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

TFS 1.X+ Server Crash...Or maybe not?

Ramirow

Veteran OT User
Joined
Aug 22, 2009
Messages
584
Solutions
15
Reaction score
301
Location
Argentina
YouTube
ramirogrant
Hello everyone, I'm facing an strange issue with my server, running TFS 1.2
Sometimes, when I login within my local network or some player (from the internet) logs in WHILE im online, the server just hangs.
No error code, the console just stays open but everyone gets Connection Lost and server basically closes.

What I did:
Thought that I was something with the player, after restarting server he just logged in fine.
After that, thought it was something caused by login itself. Tried to logout and login more than 100 times with no luck.

It happens sometimes, and sometimes it doesn't, what could possibly be? Or what additional data I need to have for you guys to help me identify the issue? Thanks in advance!
 
if the server hangs it's caused by an infinite loop, which most likely means it's a script unless you've made recent source changes
like bogart said, it's most likely a login script you have in creaturescripts but it could also be some new system you added which has a loop with a condition that can result in an infinite loop
 
Hmmm...my login script is the following:
Code:
function onLogin(player)
    local loginStr = "Welcome to " .. configManager.getString(configKeys.SERVER_NAME) .. "!"
    if player:getLastLoginSaved() <= 0 then
        loginStr = loginStr .. " Please choose your outfit."
        player:sendOutfitWindow()
    else
        if loginStr ~= "" then
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
        end
        loginStr = string.format("Your last visit was on %s.", os.date("%a %b %d %X %Y", player:getLastLoginSaved()))
    end
    player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)

    -- Stamina
    nextUseStaminaTime[player.uid] = 0

    -- Promotion
    local vocation = player:getVocation()
    local promotion = vocation:getPromotion()
    if player:isPremium() then
        local value = player:getStorageValue(STORAGEVALUE_PROMOTION)
        if not promotion and value ~= 1 then
            player:setStorageValue(STORAGEVALUE_PROMOTION, 1)
        elseif value == 1 then
            player:setVocation(promotion)
        end
    elseif not promotion then
        player:setVocation(vocation:getDemotion())
    end

    -- Events
    player:registerEvent("statHP")
    player:registerEvent("dragonKill")
    player:registerEvent("cycKill")
    player:registerEvent("boneKill")
    player:registerEvent("rotKill")
    player:registerEvent("wolfKill")
    player:registerEvent("spiderKill")
    player:registerEvent("PlayerDeath")
    player:registerEvent("DropLoot")
    return true
end
 
Hmmm...my login script is the following:
Code:
function onLogin(player)
    local loginStr = "Welcome to " .. configManager.getString(configKeys.SERVER_NAME) .. "!"
    if player:getLastLoginSaved() <= 0 then
        loginStr = loginStr .. " Please choose your outfit."
        player:sendOutfitWindow()
    else
        if loginStr ~= "" then
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
        end
        loginStr = string.format("Your last visit was on %s.", os.date("%a %b %d %X %Y", player:getLastLoginSaved()))
    end
    player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)

    -- Stamina
    nextUseStaminaTime[player.uid] = 0

    -- Promotion
    local vocation = player:getVocation()
    local promotion = vocation:getPromotion()
    if player:isPremium() then
        local value = player:getStorageValue(STORAGEVALUE_PROMOTION)
        if not promotion and value ~= 1 then
            player:setStorageValue(STORAGEVALUE_PROMOTION, 1)
        elseif value == 1 then
            player:setVocation(promotion)
        end
    elseif not promotion then
        player:setVocation(vocation:getDemotion())
    end

    -- Events
    player:registerEvent("statHP")
    player:registerEvent("dragonKill")
    player:registerEvent("cycKill")
    player:registerEvent("boneKill")
    player:registerEvent("rotKill")
    player:registerEvent("wolfKill")
    player:registerEvent("spiderKill")
    player:registerEvent("PlayerDeath")
    player:registerEvent("DropLoot")
    return true
end
go to data/global.lua and put this code at the bottom:
Lua:
local start = os.mtime()
local linecount = 0
debug.sethook(function(event, line)
    linecount = linecount + 1
    if os.mtime() - start >= 1000 then
        if linecount >= 30000 then
            print(string.format("possible infinite loop in file %s near line %s", debug.getinfo(2).source, line))
            debug.sethook()
        end
        linecount = 0
        start = os.mtime()
    end
end, "l")
now when you have a possible infinite loop somewhere in your code it will print out something like this
Code:
possible infinite loop in file @data/global.lua near line 80
you just have to wait for it to hang again, if nothing pops up in the server after a few seconds then it's related to source and not a script
 
Last edited:
Thank you sir! I have already inserted the code, got a similar message after starting the server:

Code:
possible infinite loop in file @data/npc/lib/npc.lua near line 2
That line contains:
Code:
dofile('data/npc/lib/npcsystem/npcsystem.lua')

I think I can ignore that event as my issue arises at login, I don't see how an NPC file could affect that, I will just wait now!
 
change >= 30000 to >= 500000 so it's less likely to give a false positive, if you still get false positives change it to higher
the highest line count i've tested was 1million
 
Back
Top