Mimsy Were the Borogoves

Hacks: Articles about programming in Python, Perl, PHP, and whatever else I happen to feel like hacking at.

Compiling MOO on Mac OS X

Jerry Stratton, December 16, 2006

Despite many years of non-support, MOO remains the only MUD/MUSH I’m willing to use. Its “object-oriented” object creation is second to none that I have seen in a virtual world. The LambdaMOO code still compiles on OS X, although it takes some work.

This is based on MOO 1.8.1.

If you want to compile MOO on your system, you will need to have the developer’s tools installed, and be comfortable editing C .h files.

First, acquire the source code

  1. curl -LO 'http://prdownloads.sourceforge.net/lambdamoo/LambdaMOO-1.8.1.tar.gz'
  2. gunzip LambdaMOO-1.8.1.tar.gz
  3. tar -xvf LambdaMOO-1.8.1.tar
  4. cd MOO-1.8.1

Then, make the changes

All you need to do is comment out the inappropriate lines in some header files. Comment them out by adding two slashes ('//') at the beginning of the line.

  1. my-string.h: comment out memset on lines 28 and 83
  2. my-socket.h:

    1. comment out setsockopt on line 32
    2. comment out bind in on line 37
    3. comment out connect on line 39
  3. my-signal.h:

    1. comment out sigemptyset on line 34
    2. comment out sigaddset on line 35
    3. comment out sigprocmask on line 39
  4. my-ioctl.h: comment out ioctl on line 23
  5. my-sys-time.h: comment out setitimer on line 33
  6. regexpr.h:

    1. comment out re_comp on line 105
    2. comment out re_exec on line 110
  7. utils.h and db_io.c: add “#include "string.h"” to the list of #includes.

Outbound Network Connections

If you want to enable outbound network connections (that is, if you plan on programming MOO objects that access Internet protocols), you need to uncomment line 158 of options.h.

Compile the result

Depending on the version of GCC you are using, you might get a lot of warnings when you compile MOO, including one with the word “panic” in it that looks serious. You should still get a successful compile, however. With GCC 3.3 and 4.0.1 I don’t get any warnings except a “comparison is always false” warning in execute.c and a few sign warnings in net_bsd_tcp.

  1. ./configure
  2. make
  3. sudo mkdir -p /usr/local/sbin
  4. sudo mv moo /usr/local/sbin

You can test the result on the provided test world, Minimal.db:

  1. /usr/local/sbin/moo Minimal.db Minimal.1.db
  2. open a new terminal window
  3. telnet localhost 7777

You should see the message that you’ve connected on your original terminal window, and see the minimal db on your new terminal window. Without being an expert in MOO, you can’t really do much there, so just CTRL-C in your original terminal window to terminate the MOO process.

Finally, you need to acquire a world

The most famous such world is LambdaMOO.

  1. curl -LO 'http://moo.kcc.hawaii.edu/~moo/MOO/documentation/LambdaCore-latest.db.gz'
  2. gunzip LambdaCore-latest.db.gz
  3. /usr/local/sbin/moo LambdaCore-latest.db LambdaCore.1.db
  4. open a new terminal window
  5. telnet localhost 7777
  6. connect wizard
  7. @password SOMEPASSWORD

It is important to change your wizard password immediately. Otherwise, anyone can log in as the wizard and do anything to your world.

Running a MOO Server

You can do all of this from the GUI, except running the program. First, make a folder where you can store your MOO database, and, if you use the File Utilities Package, create your ‘files’ and your ‘bin’ folders. (They need to be named exactly that, in all lower case.) Place your world database (most likely the basic LambdaCore) in that directory. Name it something simple and cool, like “WestWorld.db” or “PuppetLand.db”. Unless you are familiar with Unix, try to keep spaces out of the filename, and out of the folder name that you create (I suggest “MOO” in the root level of your home directory, in your system’s Library folder, or in the root level of a second volume).

Once you have your MOO folder set up, it is time to start up the server. We’ve been starting it up and watching the output on the terminal window, but usually you will want to be able to log out without forcing your MOO users off-line. So, go to a terminal window and ‘cd’ into your new MOO directory. Then (replacing MOOWorld.db with your world’s filename), type:

  • nohup /usr/local/sbin/moo MOOWorld.db MOOWorld.1.db >& MOOWorld.log&

The “nohup” tells the Mac not to quit this program when you leave the terminal. The ‘>’ tells Unix to send both normal output and errors to the fille “MOOWorld.log”. The final ampersand tells your Macintosh to let this program run on its own. It will keep running even if you log out, as long as you do not shut down or restart your computer. Before shutting down or restarting your computer, you should log in to your world and type:

  • @shutdown in 5 for restart

This will cleanly shutdown your world in five minutes (giving your users time to finish what they are doing), saving any changes that have occurred since the MOO started up. The next time you start up, you will want to start from the newly saved world file. In the above example, your newly saved world file will be MOOWorld.1.db, not MOOWorld.db:

  • nohup /usr/local/sbin/moo MOOWorld.1.db MOOWorld.2.db >& MOOWorld.1.log&

Note that we changed the first world name to the second one on the previous line; the second world name to .2, and we are writing to a new log file. You will want to keep doing this; every time you restart your computer, use the latest copy of the world, and create a new log file for that version of your world.

If your world files start taking up too much space, you can go ahead and throw out your older ones, but always keep backups in case you need to “back up” to a previous version for any reason.

You can look at your log file with a program like “Smultron” or with the Unix “more” command. If your system is set up normally, double-clicking a file ending in “.log” will bring up the console viewer to view the log. The console viewer will show changes to the log as they happen even while it is in the background.

Regular Backups

By default, your MOO world will probably back itself up every hour, and when you shutdown cleanly. Note, however, that it backs itself up to the same file every time. One of the first things you should do after you start up your world and log in as your wizard is to check and set a regular backup time, and then make backups of your backup.

You don’t want to back up too often, because backing up blocks people from doing anything. But you need to back up often enough that you lose as little as possible in case of a power outage or some idiot unplugging your computer.

You can see what your current backup interval is by logging in as wizard and typing “@show #0.dump_interval”. If it is greater than 59, that is the number of seconds between dumps. If it is less than 60, the server will ignore that number and dump every hour. Experiment with that number if an hour seems too often or not often enough to you. Even if you decide to leave it at an hour (I do), I recommend explicitly setting the dump interval to an hour rather than just leave it at 0, just to keep things clear:

  • ;#0.dump_interval=3600;

You will also want to do regular backups of your backup files. Especially now with OS X, your MOO might go for months without getting shut down. A single mistake by a wizard could do major damage—and if your MOO checkpoints right after the mistake, you have no way to restore your world except by going back to the version from a few months past. Set up a simple cron job or launchd job (using crontab -e or using a nice GUI like Lingon) to keep a couple of backups of your backup. How often you do this will depend on your world’s activity level, but I recommend keeping both recent and old backups. If recent means a day, also keep a backup for previous weeks. If recent means an hour, keep backups from the past few days. And store your backups on a different hard drive, if not a different computer altogether!

File security

You should create a non-admin user for your MOO if you install the File Utilities Package, as they allow access to the file system and access to programs.

November 15, 2008 note: I just tested this with Mac OS X 10.5.5 Leopard; it works with these steps, using the default compiler on Leopard. I also updated the link to the MOO-cows mailing list.

  1. <- AppleScript Web Browser
  2. mod_rewrite ->