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

[ANY TFS] Catch scripts that freeze server

Infernum

Asshole
Support Team
Joined
Feb 14, 2015
Messages
5,390
Best answers
531
Reaction score
3,164
put this code in a lib file (global.lua if tfs 1.x):
Lua:
local start = os.time()
local linecount = 0
debug.sethook(function(event, line)
    linecount = linecount + 1
    if os.time() - start >= 1 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.time()
    end
end, "l")
example output:
Code:
possible infinite loop in file @data/global.lua near line 83
reason: i forced this infinite loop to hang server
Lua:
local i = 1
while true do
    i = i + 1
end
if this script is producing false positives, change linecount >= 30000 to linecount >= 1000000, there should be no way other than an infinite loop to produce 1,000,000 line executions in 1 second
 
Last edited:

Fresh

Quack!
Joined
Oct 21, 2009
Messages
1,595
Best answers
11
Reaction score
191
Location
Poland
Oh my god! That guy is supa dupa amazing!
I wish to give him +rep and follow~
 
OP
Infernum

Infernum

Asshole
Support Team
Joined
Feb 14, 2015
Messages
5,390
Best answers
531
Reaction score
3,164
says any tfs in the title
 

adric21

Member
Joined
Apr 26, 2016
Messages
212
Best answers
1
Reaction score
19
@Stigma if its tfs 0.4 where i need paste the code data/libs/???
 

Shadow_

Intermediate OT User
Joined
Jun 2, 2018
Messages
489
Best answers
17
Reaction score
116
Location
Cairo, Egypt
Code:
Lua Script Error: [Main Interface]
data/global.lua
data/global.lua:22: attempt to index global 'debug' (a boolean value)
[Warning - ScriptingManager::loadScriptSystems] Can not load data/global.lua
Not working with tfs 1.3
Its a clean tfs just compiled it
 

Awesomedudei

Revolutionot.com
Joined
Jan 20, 2010
Messages
322
Best answers
0
Reaction score
67
Location
Sweden
Code:
Lua Script Error: [Main Interface]
data/global.lua
data/global.lua:22: attempt to index global 'debug' (a boolean value)
[Warning - ScriptingManager::loadScriptSystems] Can not load data/global.lua
Not working with tfs 1.3
Its a clean tfs just compiled it
Same here :/
 
OP
Infernum

Infernum

Asshole
Support Team
Joined
Feb 14, 2015
Messages
5,390
Best answers
531
Reaction score
3,164
Apparently this script wasn't working for over a year because I somehow managed to release it after testing and put snuck in an os.mtime() where it shouldn't have been, I updated the script and retested and now it works.

If you get an error with global debug, some script you have is overriding the debug library which is why you should be careful with variable names.
 

Shadow_

Intermediate OT User
Joined
Jun 2, 2018
Messages
489
Best answers
17
Reaction score
116
Location
Cairo, Egypt
Apparently this script wasn't working for over a year because I somehow managed to release it after testing and put snuck in an os.mtime() where it shouldn't have been, I updated the script and retested and now it works.

If you get an error with global debug, some script you have is overriding the debug library which is why you should be careful with variable names.
Thank you!
 
Top