Skip to content

Configuration

As the owner of a server, you configure Wizards of Lua with files in the folder config/wizards-of-lua/, and with settings a spell makes, for example in a startup.lua.

Setting Where What it decides
Spell limits spells.luaconf How much of each game tick a spell may spend
Network access net.luaconf Which hosts spells can reach
Tokens and passwords a Lua file of your own Where a spell finds the secrets of the services it uses
Log output WizardsOfLua.log Where the output of log(...) goes

A .luaconf file is Lua: each global it sets is a setting. It can read an environment variable with env("NAME"), which keeps a secret out of the file. Spells can't read these files. Each file appears with its default values the first time it is needed, and the server reads it again when it changes, without a restart. If a file is broken, the server log says why, and each file falls back on what is safe for what it controls: spells.luaconf keeps its last values, net.luaconf allows no host.


Spell limits: spells.luaconf

A spell runs on the server's main thread, between the game's own work. So that a busy spell can't slow the game down, it has a budget for each game tick: its tickLimit. When the budget is used up, the spell pauses and goes on in the next tick, exactly where it left off.

The budget counts Lua operations, and the time the spell spends in the game's own code: reading a block in a chunk that must be generated first takes only a few Lua operations, but milliseconds of the server's time. By default each millisecond counts as 5000 operations, so with the default tickLimit of 50000 a spell gets about 10 ms of each 50 ms tick. Compiling the modules of require doesn't count. load counts the size of the code it compiles: a large chunk still loads, and the spell pauses sooner afterwards.

A spell can raise or lower its own limit:

spell.tickLimit = 200000 -- more work per tick, at the cost of the server's tick rate

In config/wizards-of-lua/spells.luaconf you set the default, a maximum, and what a millisecond counts as. The file appears when the server starts, with these values:

-- The tickLimit a new spell starts with: Lua operations per game tick.
defaultTickLimit = 50000

-- The highest tickLimit a spell can set; a higher one is lowered to this. nil for no limit.
maxTickLimit = nil

-- How many Lua operations a millisecond in the game's own code counts as, like loading
-- chunks. 0 counts only the Lua operations, as before Wizards of Lua 8.1.0.
operationsPerMillisecond = 5000

-- The Lua operations an event interceptor gets for each call. As it can't pause, using
-- them up ends its spell.
interceptorTickLimit = 50000
Setting Default Meaning
defaultTickLimit 50000 The tickLimit a new spell starts with
maxTickLimit nil (none) The highest tickLimit a spell can set. A higher value is lowered to it, with a warning in the server log
operationsPerMillisecond 5000 How many Lua operations a millisecond in the game's own code counts as. 0 counts only the Lua operations. Not for event interceptors: for them it is always 0
interceptorTickLimit 50000 The Lua operations an event interceptor gets for each call, whatever its spell's tickLimit. Only its Lua operations count, not its time

A new defaultTickLimit applies to spells cast afterwards, and a new interceptorTickLimit to interceptors made afterwards. A new maxTickLimit applies whenever a spell sets its tickLimit, and a lower one also lowers the tickLimit of running spells above it, with a warning in the server log. A new operationsPerMillisecond applies to all spells at once. A setting that is missing keeps its default, and so does every setting if there is no file.

If the file is broken, the server log says why, and the values that loaded last stay in force until it is fixed, so that a typo can't lift your maxTickLimit. Only if the file has been broken since the server started do the defaults apply.

maxTickLimit and operationsPerMillisecond together limit the time a spell can take per tick: with maxTickLimit = 200000 and the default operationsPerMillisecond, about 40 ms. Two things can add to it. A single call of a Lua library function, like string.find with a pattern that has to try many ways, or string.rep building a long string, may do up to one whole tickLimit of work (here roughly another 40 ms) even if little of the tick's budget was left; a call that needs more fails with an error. This counts the work, not the time: on a busy server such a call takes longer, but it doesn't fail for it. And a single call into the game, like one that has to generate a chunk, can't be stopped once it has started. With operationsPerMillisecond = 0, only Lua operations count: a spell that keeps the game busy, like one that generates chunks in a loop, can then hold up a tick for seconds.

What spells shouldn't rely on

Where a spell pauses depends on the server: how fast it is, and how long the game takes for what the spell asks of it. So don't rely on a spell finishing within the tick it was started in. What a spell prints after its first pause, and the errors it has then, show up neither in a command block's output nor in the reply to an RCON command: a spell cast over RCON writes them to the server log.

Event interceptors can't pause. Each call has a budget of Lua operations of its own, interceptorTickLimit, and using it up ends the spell. So you can lower defaultTickLimit for a smoother tick rate without making interceptors fail. The time an interceptor spends in the game's own code doesn't count against it, as if operationsPerMillisecond were always 0 for it, but against the spell code that fired the event.


Network access: net.luaconf

Spells can call web services with Http and stay connected to one with WebSocket, but they only reach the hosts you list in config/wizards-of-lua/net.luaconf. The file appears the first time a spell uses the network, with an empty list, so at first spells reach nothing at all. It looks like this when you have filled it in:

hosts = {
  "discord.com",     -- this name, at any port
  "*.discord.gg",    -- every name below this one, but not discord.gg itself
}
Entry Allows
"example.org" This name, at any port, and nothing below it
"*.example.org" Every name below this one, at any depth, but not example.org itself
"*" Every host, including the server's own computer and its local network
"127.0.0.1", "::1" This address. 127.0.0.1 is not the same as localhost
  • A change applies to the next request. You don't need to restart the server.
  • A broken file allows nothing. Spells then get the reason config_error, and the server log says what's wrong. An entry with a scheme, a port or a path counts as broken, as it would otherwise silently allow nothing.
  • Redirects aren't followed. A redirect reaches the spell as a normal response, so it can't lead a request to a host that isn't listed.

What the list protects

Spells can't read or change the file. So the list keeps spell code from reaching further than you want, like a spell someone downloaded, or a spell that was written for another server. Whatever a bad spell does, it stays inside your server and the hosts you listed. An update of Wizards of Lua doesn't open network access by itself either.

The list doesn't protect you from someone who can edit files on your server. And it can't stop a spell from sending anything it knows to a host that is listed.

Be careful with "*", which reaches the computer the server runs on, and your local network too. A router's admin page or a database without a password is then in reach of every spell.

NeoForge and IPv6

Most servers never notice this. It matters in two cases, and only on NeoForge.

A program on the server's own computer. Say you run a small program next to your Minecraft server, at port 8080. Use the address 127.0.0.1 for it, not localhost, in the host list and in the spell:

-- config/wizards-of-lua/net.luaconf
hosts = { "127.0.0.1" }
local response = Http:request({ url = "http://127.0.0.1:8080/status" })

On NeoForge, localhost can mean the IPv6 address ::1, and a program that only listens on 127.0.0.1 isn't found there.

A web service that fails only on NeoForge. This spell shows what happens when it calls the service:

local response, reason = Http:request({ url = "https://api.example.org/" })
print(response and response.status or reason)

If it prints connect_failed, although the service works on a Fabric server or in your browser, then the service has an IPv6 address that your server can't reach. NeoForge tells Java to try the addresses in the order your system gives, which can put IPv6 first, and Java tries only that one. To make Java try IPv4 first:

  1. Stop the server.
  2. In your server folder, open libraries/net/neoforged/neoforge/<version>/, where <version> is your NeoForge version, like 26.3.0.83.
  3. In win_args.txt (on Windows) or unix_args.txt (on Linux and macOS), change the line -Djava.net.preferIPv6Addresses=system into -Djava.net.preferIPv6Addresses=false.
  4. Start the server.

An update of NeoForge brings new files, so do this again after each update. The line doesn't work in user_jvm_args.txt or in your start script: NeoForge's own line comes later, and the later one wins. If your server runs at a hosting company and you can't open these files, ask their support to change that line for you.


Tokens and passwords

Many services want a token or a password. Keep it in a Lua file of its own that returns a table, in config/wizards-of-lua/, and let the spell require it:

-- config/wizards-of-lua/my-service-settings.lua
return {
  token = "...",
}
local settings = require("my-service-settings")
  • Don't put it into the examples folder. /wol extract examples overwrite replaces that folder.
  • Don't write it into a command, and don't paste it into the chat: commands end up in logs.
  • Keep the file out of git, and out of backups and worlds that you hand on.

Wizards of Lua leaves tokens out of what it writes itself: its error messages name a host at most, never a URL or the value of a header.

That protects a token from accidents, not from the people who run spells: every spell can require that file. Whoever can use /lua can read the token. See who you can trust with /lua.


Log output: WizardsOfLua.log

log(...) prints like print(...), but to the target set in WizardsOfLua.log, independently of the sendCommandFeedback game rule:

Value Where the output goes
"source" To the spell's command source (the default)
"operators" To all server operators
"console" To the server console and the server log
"none" Nowhere: the output is discarded

This setting is no file: a spell sets it, and it applies to all spells. It goes back to "source" whenever the startup sequence runs, at server start and with /wol startup. To keep a value, set it in a startup.lua in config/wizards-of-lua/:

-- config/wizards-of-lua/startup.lua
WizardsOfLua.log = "console"

logToConsole(...) always writes to the server console and the server log, whatever this setting says.