Skip to content
SpiraMirabilisPublic
forked from toddsundsted/stunt

About

LambdaMOO with multiple inheritance, HTTP, JSON <-> MOO literal parsing/generation, better crypto, a map datatype and a RESTful interface. And MySQL now.

Resources

Contributing

Stars

3 stars

Watchers

2 watching

Forks

 
 

Latest commit

 

History

721 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stunt

Stunt is a set of extensions to the LambdaMOO server. This repository is a fork of toddsundsted/stunt (Release 10-wip, the C++ version, based on LambdaMOO "1.8.3+"). It adds an SQLite database backend, Unicode strings, two new value types, verb source that is kept as written, and SQL client built-ins.

See README.lambdamoo for general information on LambdaMOO, and http://stunt.io/ for Stunt. To get a running MOO quickly, start with Improvise, the Stunt starter kit.

What this fork adds

Area Summary Details
Database A pluggable database layer with four formats: text, JSONL, SQLite and libmdbx README.sqlite, README.mdbx
Strings Unicode text, indexed by character; any character allowed README.unicode
Bytes A type for raw bytes, b"..." README.unicode
Colours A type for terminal colours, $#FF8800 and $#yellow README.color
Verb source verb_code() returns the code as it was written README.source
SQL from MOO code sqlite_* and mysql_* built-ins README.sqlite

The database

The server's database code sits behind one interface (database.h), so the format on disk is a choice. The input format is detected; an option picks the output format:

moo [-J|-M|-S|-T] ... input-db output-db [port]

-T    text, the traditional format
-J    JSONL, one JSON object per line
-S    SQLite
-M    libmdbx (high-speed memory-mapped binary store)

Without an option, an SQLite input is written as SQLite and anything else as text. For example:

moo -S Minimal.db minimal.sqlite 7777    convert text to SQLite and run
moo minimal.sqlite minimal.sqlite 7777   run on an SQLite database
moo -T minimal.sqlite minimal.db 7777    convert SQLite back to text

To convert without starting the server, use emergency mode:

echo quit | moo -e -S Minimal.db minimal.sqlite 0

An SQLite database behaves exactly like a text one, with two differences:

  • Saving. The server writes only what changed, about once a second, in a transaction, from a background thread. A crash loses at most the last second or so, and a checkpoint no longer forks the server.
  • Memory. The database need not fit in memory. Starting the server reads only the objects themselves; property values and verb programs are read when first used. They can be dropped again under a memory limit ($server_options.sqlite_cache_mb) or after an idle time ($server_options.sqlite_cache_seconds).

README.sqlite covers the command line, saving, memory, the schema and the testing switches.

Unicode strings

A string is Unicode text. length(), indexes, ranges and the positions that built-ins take and return count characters (code points):

length("héllo")            => 5
"héllo"[2]                 => "é"
  • A string can hold any character, including newline, NUL and ESC.
  • String literals have escapes: \n, \r, \t, \e, \0, \xHH and \u{H...}. "\n" used to mean the letter n.
  • Comparison ignores case for all of Unicode (simple case folding).
  • chr() and ord() convert between characters and their codes.
  • A connection has an encoding (utf-8 by default, latin-1 or ascii), set with set_connection_option().
  • parse_json() and generate_json() use real characters where they used ~XX.

The bytes type

Raw bytes that are not text are a type of their own, BYTES:

b"abc"[1]                  => 97
b"ab" + b"cd"              => b"abcd"
encode("é")                => b"\xC3\xA9"
decode(b"\xC3\xA9")        => "é"

The built-ins that take a ~XX binary string take bytes as well.

The colour type

A colour is a value, COLOR, that turns into the escape code a terminal needs:

$#red:fg("warning")        => "\e[31mwarning\e[39m"
$#FF0000:code(256)         => "\e[38;5;196m"
color(255, 136, 0)         => $#FF8800

The sixteen named colours are the terminal's own; a colour given by digits is sent as truecolor, or as the nearest of 256 or 16 colours when a depth is given.

Verb source

A verb keeps the text it was programmed with. verb_code() returns it exactly, comments and spacing included, and line numbers in tracebacks are lines of that text. decompiled_verb_code() returns the listing rebuilt from the compiled program, which is what verb_code() used to return. Verbs from an older database have no source until they are programmed again.

SQL from MOO code

Both sets of built-ins are for wizards only.

  • SQLite: sqlite_open(), sqlite_close(), sqlite_query(), sqlite_prepare(), sqlite_next_row(), sqlite_column_names(), sqlite_finalize(), sqlite_status(), sqlite_handles() and sqlite_delete(). The databases are files in the fileio directory, and values are passed as bound parameters. See README.sqlite.

    h = sqlite_open("notes.db", "rwc");
    sqlite_query(h, "create table if not exists notes (who, body)");
    sqlite_query(h, "insert into notes values (?, ?)", {player, text});
    sqlite_close(h);
    
  • MySQL: mysql_connect(), mysql_close(), mysql_status(), mysql_query(), mysql_next_row(), mysql_field_names(), mysql_ping(), mysql_connections(), mysql_set_options() and mysql_escape_string(). mysql_connect() needs OUTBOUND_NETWORK, which options.h turns on. $server_options.max_mysql_connections sets the number of connections allowed (10 by default).

Database compatibility

WARNING: Stunt changes the database format in a non-backward compatible way in order to persist multiple-parent relationships. The server upgrades version 4 databases automatically, and there is no way back.

For the formats this fork adds, a text dump is only as new as its contents need:

Text format Written when the database has
13 nothing new: the dump is byte for byte what the original Stunt server writes
14 a string with a non-ASCII character, newline or NUL; a bytes value; verb code that uses the new string escapes or bytes
15 a verb with stored source; a colour value or literal

Earlier servers refuse versions 14 and 15. A verb gets stored source as soon as it is programmed, so a database that is edited on this server becomes version 15; set MOO_KEEP_SOURCE=0 in the environment to keep it readable by the original server.

Strings in older databases that contain bytes above 127 are read as UTF-8 when they are valid UTF-8, and as Latin-1 otherwise.

Building

The server is built with Meson and ninja. It needs a C++17 compiler, bison and libsqlite3 (on Debian/Ubuntu: libsqlite3-dev).

meson setup build
ninja -C build

The server is then build/moo. Nothing is written into the source directory, so several builds can exist side by side:

meson setup build-asan -Db_sanitize=address,undefined

Options, given to meson setup as -Dname=value:

Option Meaning
mysql auto (the default) builds the mysql_* built-ins when the MySQL or MariaDB client library is found (libmysqlclient-dev); enabled requires it; disabled leaves them out
random_device the file the random number generator is seeded from; /dev/random by default
version_src a file to use as version_src.h, see version_src.txt
optimization, buildtype, ... Meson's own; the default is -O2 -g

The settings in options.h are edited by hand, as before. The build instructions in README.lambdamoo (configure and make) no longer apply.

Other targets, built only when named: ninja -C build keywords regenerates keywords.cc from keywords.gperf; client_bsd and client_sysv are the simple clients; ProgrammersManual.info (and .txt, .html, .pdf, .dvi, .ps) build the manual when the texinfo tools are installed.

README.tests describes the test suite.

What Stunt adds to LambdaMOO

  1. Multiple inheritance. create() takes either an object number or a list of object numbers in the first argument position. parents() and chparents() manipulate an object's parents. parent() and chparent() exist for backward compatibility; when an object has multiple parents they operate on the first.
  2. Anonymous objects. Objects without an object number, reached through unforgeable references and garbage collected when no longer reachable.
  3. Task local storage. task_local() and set_task_local() retrieve and store a value that is freed when the task finishes.
  4. Map datatype. A native map based on a red-black tree, with in-order traversal and efficient lookup, insertion and deletion. Values may be any MOO type; keys may not be lists or maps. Index, range and looping operations on lists and strings also work on maps.
  5. JSON. parse_json() and generate_json() transform MOO values from and to JSON.
  6. Cryptographic operations. SHA-1 and SHA-256 hashes, with SHA-256 the default for string_hash(), binary_hash() and value_hash(); HMAC-SHA-1 and HMAC-SHA-256; Bcrypt passwords in crypt(). The random number subsystem is based on the SOSEMANUK cipher and seeds itself from /dev/random.
  7. Base64. encode_base64() and decode_base64().
  8. An improved FileIO patch. It fixes the flaws of the 1.5p1 patch, including two server-crashing bugs, without changing the API.
  9. Secure suspending process exec. exec() forks and execs an external executable without system(). It takes a list of strings (the program and its arguments) and a binary string sent to stdin, suspends the task, and returns the termination code, stdout and stderr in a list.
  10. Verb calls on primitive types. Calls like "foo bar":split() go to prototype objects ($int_proto, $float_proto, $str_proto and so on), with the primitive value as this.
  11. In-server HTTP parsing. The Node HTTP parsing library parses requests and responses into a map, and supports HTTP upgrade.
  12. Colorized logging and line editing. The log is colorized when attached to a console, server_log() can write colorized output, and emergency wizard mode has line editing.
  13. Bitwise operators. And (&.), or (|.), xor (^.), logical shifts (<< and >>) and complement (~).
  14. Testing framework. Unit tests based on Ruby's Test-Unit, with a Parslet parser that turns MOO values into Ruby values.

Credits

Stunt is by Todd Sundsted, who also made the C++ port with thanks to Steve Wainstead. The MySQL built-ins and the work described under "What this fork adds" are by Michael Munson. See CONTRIBUTING for how to contribute.

About

LambdaMOO with multiple inheritance, HTTP, JSON <-> MOO literal parsing/generation, better crypto, a map datatype and a RESTful interface. And MySQL now.

Resources

Contributing

Stars

3 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages