Vastly improved Online & Offline support in Mud Designer
The Mud Designer engine received a much better system for supporting multi-player and single-player games. The previous version of the engine did not ship with single-player support out of the box, and implementing single-player support required you to re-write the BasePlayer
Type, the Game
Type and a large percentage of the IState
Types that shipped with the engine because they all relied on the ServerDirector.
Things are much more flexible this time around and the engine will ship with both single-player and multi-player support out of the box (when I finally get it shipped). With the new version, any Type that implements IPlayer
can be used both online and offline. The player sends and receives it's messages in the same manor, regardless if it is online or not. The engine contains a DefaultGame
object that is used for offline games, and a MultiplayerGame
object that is used for online MMO styled games. The MultiplayerGame
object creates an IServerPlayer
object that can hold an instance of an existing IPlayer
Type. The IPlayer
Type has an event for when a message is both sent and received from the player. The IGame
object registers to receive those events and can handle them accordingly.
For instance, DefaultGame
can receive the message that the player is supposed to receive (like from a look command) and it will display them to the user via Console.WriteLine
. The MultiplayerGame
can receive the same message, but rather than writing it to the Console
, it will write it the the Socket
connection, sending it to the players telnet client. This all takes place within a new IGame.BroadcastToPlayer
method. If a developer wishes to create a special UI that will display the received messages (such as a local test client UI), then the developer only needs to create a new IGame
object that inherits from MultiplayerGame
or DefaultGame
, and override the BroadcastToPlayer
method to route the content to where the developer wants to display it. This essentially allows the engine to work independently of the network status, with the only thing relying on it being an IGame
implemented object.
The following shows an example MUD game server wrote in C# using the Mud Designer
. The MultiplayerGame
object implements both IServer
and IGame
. The IServer
interface exposes the Start
method that is used to start the server.
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Server app starting...");
// Instance the server.
var game = new EngineFactory< MultiplayerGame>().GetObject();
game.Initialize< DefaultPlayer>(null);
game.Start< ServerPlayer, DefaultPlayer>();
Console.WriteLine("Server running...");
while (game.IsRunning)
{
}
}
}
If you want to use the same DefaultPlayer
object in a single player game, you can. You just fetch a DefaultGame
Type from the EngineFactory
and invoke it's Initialize
method. Since DefaultGame
doesn't implement IServer
, there is no Start()
method used to start the server.
class Program
{
static void Main(string[] args)
{
Console.WriteLine("App starting...");
// Instance the game.
var game = new EngineFactory< DefaultGame>().GetObject();
game.Initialize< DefaultPlayer>(null);
Console.WriteLine("Game running...");
while (game.IsRunning)
{
}
}
}
There are a lot of other improvements made that I will cover in a series of blog posts associate with the new IGame
, IServer
and IServerPlayer
implementations.