muddesigner/MudGame/MudGame.cs
Scionwest_cp 3bd493c1cd Mud Designer:
Removed old forms and prepared for new designer layouts

MudEngine:
Server - Now starts and runs, however sending information to the client crashes telnet clients for some reason.
BaseCharacter - Removed OnConnect() source code and changed method into an abstract method.  This is now implemented via MudGame.MudCharacter
BaseCommand - BaseCommand.Name now implemented.  Constructor defaults to the Type name.  Note all command names must begin with 'Command'
BaseGame - Now has a Server propety
BaseServer - Added IsRunning property
ICharacter - Added Send() method
ICommunicate - Added Shutdown() method for use with servers.
CommandSystem - Bug fix.  Was checking to see if the command was an Interface rather than checking if it inherits from one.
CommandSystem - Bug fix.  No longer attempts to add abstract commands to collection
ScriptSystem - Bug fix.  Corrected the name of the Mud Compiler during compiler loading.

MudGame:
Added initial MudCharacter class.  Will be the standard class that all characters will inherit from.
Added CommandLogin for processing user server logins.
MudGame - Now calls Server.Initialize during Game.Initialize()
MudGame - Uses Server.IsRunning property checks rather than Server.EnableServer
MudGame - Added initial code for player connections.
2011-10-02 20:40:51 -07:00

104 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Reflection;
using System.Text;
using MudEngine.Core;
using MudEngine.Runtime;
using MudEngine.Communication;
using MudGame.Characters;
namespace MudGame
{
public class MudGame : BaseGame
{
/// <summary>
/// Gets a reference to the game scripting system
/// </summary>
protected ScriptSystem ScriptSystem { get; private set; }
/// <summary>
/// Gets a reference to the games command execution system
/// </summary>
protected CommandSystem CommandSystem { get; private set; }
public MudGame()
: base()
{
ScriptSystem = new ScriptSystem(".mud");
CommandSystem = new CommandSystem();
Server = new Server(this);
}
public override void Initialize()
{
//Setup the example game.
this.Name = "Mud Example Game";
this.Description = "An simple Mud Game class that manages the basics";
this.AutoSaveInterval = 5;
this.EnableAutoSave = true;
this.PasswordMinimumSize = 8;
this.Version = "Alpha 2.0";
//Add the engine.dll.
string assembly = Assembly.GetExecutingAssembly().GetName().Name + ".dll";
this.ScriptSystem.AddAssemblyReference(assembly);
//If a scripts directory exists, compile them.
if (Directory.Exists("Scripts"))
{
this.ScriptSystem.Compile("Scripts");
// if (this.ScriptSystem.HasErrors)
//TODO: Output script system compile errors
//return; //temp. Shouldn't return.
}
//Scripts are compiled, now load all of the commands, if any script commands exist.
CommandSystem.LoadCommandLibrary(Assembly.GetExecutingAssembly());
CommandSystem.LoadCommandLibrary(ScriptSystem.CompiledAssembly);
//TODO: Initialize the game world.
//TODO: Load previously saved state.
//TODO: Enable server.
if (this.EnableServer)
this.Server.Initialize();
this.IsRunning = true;
}
public override void Shutdown()
{
if (Server.IsRunning)
this.EnableServer = false;
this.Save();
}
public override void Update()
{
if (this.Server.IsRunning)
this.Server.Update();
}
public override void OnConnect(System.Net.Sockets.TcpClient client)
{
MudCharacter character = new MudCharacter(this);
character.Role = CharacterRoles.Player;
character.OnConnect(client);
}
public override void OnDisconnect(System.Net.Sockets.TcpClient client)
{
throw new NotImplementedException();
}
public override int GetAvailableID()
{
return 1;
}
}
}