Module Documentation

Mudmaker. Make MUD-style games easily.

class mudmaker.Attribute(value, description, type=NOTHING, save=NOTHING, visible=NOTHING)

An attribute for an object. Can be marked as not to be dumped with the object by setting the same flag to False, and not to be visible to players by setting the visible flag to False.

class mudmaker.text

A string which supports new line characters.

class mudmaker.Direction(game, name, x, y, z)

A direction to be used with an exit.

coordinates_from(start)

Apply this direction to coordinates start and return the destination coordinates.

opposite

Get the opposite direction.

class mudmaker.Exit(game, **kwargs)

Link two rooms together.

close(obj)

Have Object obj close this exit and leave it closed.

get_name(verbose=False)

Return a proper name for this object.

lock(obj)

Have Object obj lock this exit.

classmethod on_delete(instance)

Called when this object is deleted.

classmethod on_init(instance)

Add this exit to self.game.exits.

open(obj)

Have Object obj open this exit and leave it closable.

unlock(obj)

Have Object obj unlock this exit and leave it closed.

use(obj)

Use this exit as the Object obj.

class mudmaker.Game(interface=NOTHING, http_port=NOTHING, logger=NOTHING, websocket_class=NOTHING, websocket_factory=NOTHING, websocket_port=NOTHING, site_port=NOTHING, web_root=NOTHING, socials_factory=NOTHING, welcome_msg=NOTHING, error_msg=NOTHING, started=NOTHING, directions=NOTHING, account_store=NOTHING, filename=NOTHING, tasks=NOTHING)

A game instance.

add_direction(name, *aliases, x=0, y=0, z=0)

Add a new direction. You can add as many aliases as you like. These will be used as commands to invoke exits. The x, y, and z coordinates allow you to set sensible coordinates for rooms should you want to. The name of the direction should be a full name like “northeast”.

as_dict()

Return a dictionary which can be dumped to save the state of this game.

call_on_init(bases, obj)

Call base.on_init(obj) for base in bases.

dump(filename=None)

Dump game state to disk.

dump_task()

Dump this game on a task.

dump_value(value)

Dump a singl object, paying particular attention to database objects.

finish_login(con, player)

Connection an Object instance player to the connection con.

from_dict(data)

Load the data loaded with self.load.

load()

Load some yaml and run it through self.from_dict.

load_value(data)

Load a single value from data, paying particular attention to database objects.

make_class(class_name, bases)

Make a class from a class name and a tuple of bases.

make_object(class_name, bases, **attributes)

Make an object - which could be anything - and add it to this game. class_name is the name used for the newly-created class, and attributes will be passed to the new class’s __init__ method.

on_index_page(request)

Get the index page. By default redirects to /static/index.html.

on_websocket_page(request)

Return the websocket port number.

players

Return a list of players.

register_base(name)

Decorate a class to have it registered as a possible base.

run()

Start this game listening, and start the reactor.

start_listening()

Start listening for network connections. Usually called from Game.run.

task(*args, **kwargs)

Decorate a function to be made into a task, using twisted.internet.task.LoopingCall. All arguments will be passed to the LoopingCall instance’s start method.

use_exit(direction, player, location)

Have a player use an exit.

class mudmaker.Zone(game, **kwargs)

A zone with a list of rooms.

add_room(room)

Add a Room object to this zone.

classmethod on_delete(instance)

Called when this object is deleted.

classmethod on_init(instance)

Add this zone to self.game.zones.

rooms

Get a list of rooms contained in this zone.

class mudmaker.Room(game, **kwargs)

A room which contains objects.

entrances

Get a list of entrances.

exits

Get a list of exits.

Link this room to other via the given direction. Also add an optional name.

match_exit(direction)

Return an exit in the given direction, or None if there is no match.

message_all(text)

Send a message text to everyone else in this room.

message_all_but(objects, text)

Message everyone in this room with text, apart from those in the objects list.

classmethod on_delete(instance)

Called when this object is deleted.

classmethod on_init(instance)

Add this room to self.game.rooms.

class mudmaker.WebSocketConnection

A protocol to use with a web client.

connectionLost(reason)

Called when the connection is shut down.

Clear any circular references here, and any external references to this Protocol. The connection has been closed.

@type reason: L{twisted.python.failure.Failure}

disconnect(text=None)

Close this websocket, sending text as reason.

get_context()

Get a context to be sent to self.parser.

handle_string(string)

Handle a string as a command.

huh(string, tried_commands)

Called when no command was found. The tried_commands variable might contain already-tried commands.

message(text)

Send some text to this connection.

onMessage(payload, is_binary)

Implements autobahn.websocket.interfaces.IWebSocketChannel.onMessage()

onOpen()

Web socket is now open.

send(name, *args)

Send JSON to the player’s browser.

class mudmaker.Object(game, **kwargs)

An object in the database.

account

Get any account object associated with this object.

clear_following()

Stop this object following anyone.

do_say(string)

Say something as this object.

do_social(string, _perspectives=None, **kwargs)

Perform a social as this object. If _perspectives is not None, it will be treated as a list, and this object will be prepended. All extra keyword arguments will be passed to self.game.socials_factory.get_strings.

follow(obj)

Start this object following obj.

followers

Returns a list of objects who are following this one.

look_here()

Have this object look at its surroundings.

match_object(obj, string)

See if obj matches string.

message(text)

Send some text to this object’s connection.

multiple_matches(string, objects)

Multiple matches were found. By default, send a message explaining that to this object.

no_location_match(string)

No matches may be performed at this location. By default, sends a message to this object explaining that.

no_match(string)

No match was found. By default, a message explaining that is sent to this object.

classmethod on_delete(instance)

Called when this object is deleted.

classmethod on_init(instance)

Add this object to self.game.objects.

single_match(string, objects=None)

Return a single match from the given list of objects. If objects is None, self.location.contents will be used.

If objects is None, and this object has no location, the result of calling self.no_location_match with string will be returned.

If the match string is “me”, then this object will be considered in the match if it is in the list of objects.

If no matches are found, then the result of calling self.no_match with string will be returned.

If multiple matches are found, then the result of calling self.multiple_matches with string and the list of objects that were matched will be returned.

If this object is a member of staff, and the string starts with a hash symbol (#), the remaining string will be considered an object ID, and the object with that ID will be returned.

class mudmaker.Account(username, password, object_id, game, admin=NOTHING, builder=NOTHING)

An account in the default accounts system. You do not have to use this class, but it is recommended you use it as a parent for your own class if you decide to extend the default AccountStore class.

verify(password)

Return a boolean representing whether the supplied password matches the account’s password.

class mudmaker.AccountStore(game, account_class=NOTHING, accounts=NOTHING, objects=NOTHING, filename=NOTHING, last_dump=NOTHING)

A generic account store. If you’re going to use another storage system, you should implement the add_account, remove_account, account_exists, number_of_accounts, and authenticate methods.

account_exists(username)

Returns a boolean representing whether or not an account exists with the given username.

account_for(obj)

Return the account object associated with an Object instance obj.

add_account(username, password, obj, *args, **kwargs)

Add a user to the accounts database.

Once the account is created, the user will be able to log in with the supplied username and password, and be connected to the supplied Object instance obj.

This method uses self.encrypt_password to encrypt the password.

If an account already exists with the given username, DuplicateUsernameError should be raised with the username as the only argument.

If there is already an account bound to obj, then DuplicateObjectError should be raised with obj as the only argument.

All extra arguments will passed to the constructor of self.account_class.

as_list()

Returns a list of dictionaries representing all the registered accounts. Used by self.dump.

authenticate(username, password)

Given a username and password combination, return an Object instance with a matching account. If the username is invalid, InvalidUsernameError is raised. If the password is invalid, InvalidPasswordError will be raised.

dump()

Write all the registered accounts to self.filename.

encrypt_password(password)

Returns an encrypted version of the password for use by self.add_account. The default implementation uses passlib.hash.sha256_crypt with 10000 rounds.

load()

Load registered accounts from self.filename. If there are already accounts loaded, RuntimeError will be raised.

maybe_load()

If self.loaded is not True, load from self.filename.

remove_account(obj)

Remove an account for an Object instance obj.

class mudmaker.Task(game, func)

A task. Uses twisted.internet.task.LoopingCall.

start(*args, **kwargs)

Call self.loop.start with all arguments, and store the resulting Deferred in self.deferred.

class mudmaker.Social(game, **kwargs)

A social.

classmethod on_delete(instance)

Called when this object is deleted.

classmethod on_init(instance)

Called when the object is initialised.

use_target(player, target)

Perform a social as player.

class mudmaker.Menu(title, items=NOTHING, header=NOTHING, invalid_selection_msg=NOTHING, prompt_msg=NOTHING, help_msg=NOTHING, abort_msg=NOTHING)

A menu wich presents the player with various options.

add_item(title, func)

Add an item to this menu.

add_label(title)

Add a label to this menu.

as_string()

Return this men as a string.

item(title)

A decorator to add an item.

Usage:

m = Menu('Test Menu')

@m.item('quit')
def do_quit(obj):
    obj.message('Goodbye.')
    obj.connection.disconnect('Player quit.')
match(obj, string)

Return the first menu item that matches. If there are no matches, tell the player that and return None.

send(obj)

Send this menu to a player.

send_and_handle(obj, *args, **kwargs)

Send this menu and handle the input using self._send_and_handle. This method catches the MenuDone except which is raised as a result of typing a full stop on a blank line. All extra arguments are sent along to self._send_and_handle as well.

send_forever(obj, *args, before_send=None, **kwargs)

Keep sending this menu to obj until MenuDone is raised or a full stop is received as input. If before_send is not None, it will be called with this menu and obj as positional arguments before the menu is sent. All extra arguments are sent to self._send_and_handle.