Description
!info recently underwent a complete rewrite, and the behaviour has changed somewhat.
When a client requests info on a subject foo, the server checks for info/info-foo.txt, or info/info-default.txt if no subject was specified.
If the requested file is not found, an error is printed - note that the latest version of info does not fall back on the default info file if the specified subject file does not exist.
If a file is found, then it goes through a parser, which does the following:
- The text is read until the first $ not preceded by a \
- If the next character is a {, it skips it
- It reads a variable name consisting of alphanumeric characters and underscores
- If the next character is a }, it is skipped
- The cvar name given, including the $, is substituted for its value as a string
- When the entire string has been read and all cvarssubstituted, if any changes were made then the systemloops and cvar-substitutes the string again
- If the system loops 100 times then it automatically stops looping and prints a warning to the console
- Having completed cvar substitution, escapes are handled: \n becomes a newline, \$ becomes $, \\ becomes\ etc.
The implications of this system are not obvious at first, so I shall present some examples.
In each, the green represents console or config settings, the blue shows the contents of info files, and the red shows the output of relevant info commands.
info/info-default.txt:
Welcome to benmachine's server!
]/!info
Welcome to benmachine's server!
set g_motd "Careful of the dinosaurs in the basement!"
info/info-motd.txt:
$g_motd
]/!info motd
Careful of the dinosaurs in the basement!
set timelimit 60
set g_suddenDeathTime 55
info/info-timers.txt:
Sudden Death: ${g_suddenDeathTime}min
Timelimit: ${timelimit}min
]/!info timers
Sudden Death: 55min
Timelimit: 60min
set bool "$bool_"
set bool_1 "ON"
set bool_0 "OFF"
set g_unlagged 1
set g_allowShare 0
info/info-settings.txt:
Unlagged: $bool$g_unlagged
Share: $bool$g_allowShare
]/!info settings
Unlagged: ON
Share: OFF