I am pleased to release an improved version of the "tiny MUD server" which I had previously released a year ago. This has compiled without errors or warnings using g++ on:
- Linux
- Cygwin (Windows)
- Macintosh OS/X
This program is only a simple example (under 1500 lines of code in a single source file), however if you are interested in seeing how a server works, or wanting to write your own, you could use this as a basis for it.
The reason I wrote it is that sometimes I want to see how to make a simple server, but the main 'established' servers tend to be thousands of lines of code, and it is hard to see in the middle of all that code what is essential to writing a server, and what is an add-in.
The code is Copyright 2004 by myself, however you are permitted to copy, use, modify, sell and
distribute it provided this copyright notice appears
in all copies. This gets around the problem that people have by deriving a server from Diku or other MUDs which have restrictive licenses on them (eg. no pay MUDs). The Copyright notice is simply to stop people taking the code and adding their own, more restrictive, copyright to it.
Download it from http://www.gammon.com.au/files/muds/tinymudserver_v2.tgz (16 Kb) or http://www.gammon.com.au/files/muds/tinymudserver_v2.zip (18 Kb).
Description
This program demonstrates a simple MUD (Multi-User Dungeon) server - in a single file.
It does the following:
- Accepts multiple connections from players
- Maintains a list of connected players
- Asks players for a name and password
- Saves player files to disk (name, password, current room, player flags)
- Implements the commands: quit, look, say, tell, help, goto, transfer, shutdown, setflag, clearflag
- Implements movement commands (eg. n, s, e, w)
- Illustrates sending messages to a single player (eg. a tell) or all players (eg. a say)
- Handles players disconnecting or quitting
- Illustrates a "connection dialog" - players get asked their name, then their password.
- Allows new players to create a character by specifying a name and password.
- Demonstrates using the Standard Template Library for lists, strings, vectors, maps and sets.
- Illustrates periodic messages using a timer (at present it just shows a message every few seconds)
- Illustrates rudimentary player control (eg. gagging players from talking)
- Loads room descriptions and exits from a disk file
- Loads messages from a disk file
- Loads control parameters from a disk file
What you could add
As it stands the program is too simple to be used for a full MUD, however it could be the
basis for writing your own. You would want to add things like this:
- Objects (eg. swords), taking/dropping things, etc.
- Fighting (if required)
- Building/extending online
- Logging events (eg. connections, disconnections, faults)
- Colour
- MCCP (compression)
- MXP (MUD Extension Protocol)
- Telnet negotiation
Easy to modify
The code has been designed to allow for easy additions, as a lot of "helper" routines have already been written. In the following posts I will describe how to add extra commands, to show the general idea.
Example session
Initial connection
Welcome to the Tiny MUD Server version 2.0.0
|-------------------- Tiny MUD Server --------------------|
|
| Written by Nick Gammon.
|
| July 2004.
|
| http://www.gammon.com.au/
|
| Welcome to tinymudserver version 2! Have fun. :)
|---------------------------------------------------------|
Enter your name, or 'new' to create a new character ...
Creating a new player
Enter your name, or 'new' to create a new character ...
new
Please choose a name for your new character ...
Magnum
Choose a password for Magnum ...
swordfish
Re-enter password to confirm it ...
swordfish
Welcome, Magnum
Welcome to our MUD!
Please read the help files to become familiar with our rules. :)
Message Of The Day (MOTD)
Here is where you place announcements to be given to people
once they have joined the game.
Starting room (room 1000).
You are standing in a fabulous, fabulous, exotic room, with
all sorts of things that go 'hum' and 'plink' in the night.
As you glance around the room, you wonder what else might exist in this world.
Exits: e n s w
> You hear creepy noises ...
Connecting to an existing player
Enter your name, or 'new' to create a new character ...
magnum
Enter your password ...
swordfish
Welcome, Magnum
Welcome back! We hope you enjoy playing today.
Message Of The Day (MOTD)
Here is where you place announcements to be given to people
once they have joined the game.
Starting room (room 1000).
You are standing in a fabulous, fabulous, exotic room, with
all sorts of things that go 'hum' and 'plink' in the night.
As you glance around the room, you wonder what else might
exist in this world.
Exits: e n s w
> You hear creepy noises ...
Moving and talking
n
You go n
Room 1004.
This is the training room. One day you might receive all
sorts of interesting training here.
Perhaps you might even purchase shields and armour. But not today.
Exits: s
You also see Nick.
>
say hi there
You say, "hi there"
>
The room descriptions and exits have been read from a rooms.txt file. Most of the messages are in a messages.txt file (eg. the message-of-the-day).
|