limit depth of game_tick, just in case.

This commit is contained in:
gnembon committed 2020-12-20 22:58:41 -04:00
1 parent faa0c65af4
commit d99ab4fc24
2 files changed
+13 -2

No files matched your search

@@ -51,6 +51,7 @@ public class CarpetScriptServer
public Set<String> unloadableModules; public Set<String> unloadableModules;
public long tickStart; public long tickStart;
public boolean stopAll; public boolean stopAll;
public int tickDepth;
private Set<String> holyMoly; private Set<String> holyMoly;
public CarpetEventServer events; public CarpetEventServer events;
+12 -2
View File
@@ -634,8 +634,13 @@ public class Auxiliary {
expression.addLazyFunction("game_tick", -1, (c, t, lv) -> { expression.addLazyFunction("game_tick", -1, (c, t, lv) -> {
ServerCommandSource s = ((CarpetContext)c).s; CarpetContext cc = (CarpetContext)c;
ServerCommandSource s = cc.s;
if (!s.getMinecraftServer().isOnThread()) throw new InternalExpressionException("Unable to run ticks from threads"); if (!s.getMinecraftServer().isOnThread()) throw new InternalExpressionException("Unable to run ticks from threads");
if (CarpetServer.scriptServer.tickDepth > 16) throw new InternalExpressionException("'game_tick' function caused other 'game_tick' functions to run. You should not allow that.");
try
{
CarpetServer.scriptServer.tickDepth ++;
((MinecraftServerInterface) s.getMinecraftServer()).forceTick(() -> System.nanoTime() - CarpetServer.scriptServer.tickStart < 50000000L); ((MinecraftServerInterface) s.getMinecraftServer()).forceTick(() -> System.nanoTime() - CarpetServer.scriptServer.tickStart < 50000000L);
if (lv.size() > 0) if (lv.size() > 0)
{ {
@@ -655,9 +660,14 @@ public class Auxiliary {
} }
CarpetServer.scriptServer.tickStart = System.nanoTime(); // for the next tick CarpetServer.scriptServer.tickStart = System.nanoTime(); // for the next tick
Thread.yield(); Thread.yield();
}
finally
{
CarpetServer.scriptServer.tickDepth --;
}
if(CarpetServer.scriptServer.stopAll) if(CarpetServer.scriptServer.stopAll)
throw new ExitStatement(Value.NULL); throw new ExitStatement(Value.NULL);
return (cc, tt) -> Value.TRUE; return (_c, _t) -> Value.TRUE;
}); });
expression.addLazyFunction("seed", -1, (c, t, lv) -> { expression.addLazyFunction("seed", -1, (c, t, lv) -> {