Prevalence In Musty

This is an example of a PrevalenceLayer that I designed 6-8 years ago.

Musty is a MUD written in Smalltalk. It was built as a group project for my class on object-oriented programming and design, and has been added on three or four times. Some of the people who have worked on it have experience programming other MUDs, and they are impressed by its clean, powerful design, but it is still just a class project.

A MUD is a Multi-User Dungeon. It is a game. When you log on, you are in a world with other players, and you can interact with them. A MUD can contain puzzles to solve, monsters to fight, and treasures to find. Some MUDs focus on combat, many do not have any combat. MUDs usually have an extension language. Some players, wizards, are allowed to make new rooms, new objects, and new commands.

Musty has a model of the world that runs on one computer. Each player has a process that parses his/her input and creates command objects. Once the computer successfully translates the input into a command, the command is executed. Commands are executed in serial (there is ONE lock) and logged. The state of the system is saved periodically (say, at 4 a.m.) but in general it is all kept in memory. If the system crashes, it is recovered by going back to the most recent saved state and replaying all the commands.

One of the great things about Musty is that it is easy to debug. Most bugs in a MUD are caused by some weird interaction between commands. The system crashes, and there is no way for the programmers to figure out exactly what went wrong. But Musty keeps a record of everything that happened, so programmers can usually reproduce the failures.

The Command class has a public "execute" method that is a classic example of the TemplateMethodPattern. This method acquires the lock, logs the command, calls a private execute method defined by a subclass, records that the command is finished, and releases the lock. This method is at the heart of any PrevalenceLayer.

-- RalphJohnson


EditText of this page (last edited November 3, 2011) or FindPage with title or text search