muddesigner/MudEngine/WinPC_Engine/Game/StandardGame.cs
Scionwest_cp f0ec29c240 * XMLData.Save now has exception handling code in-place.
* Added better commenting to the majority of the projects files.
* Removed command support from the server console.
* Added a Client side command STOP that can be used to shut down the server.  In the future that will be specific to Admins only.
* Characters now have their save code invoked during server shut down.
* Server shut down code added.  Server.Stop() fully implemented.
2012-03-03 13:24:35 -08:00

158 lines
5 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using MudEngine.Networking;
using MudEngine.Core;
using MudEngine.Game.Characters;
namespace MudEngine.Game
{
/// <summary>
/// StandardGame will be the base of all Mud Games created with the engine.
/// It manages all of the game components including the Server and the Game World.
/// </summary>
public class StandardGame
{
/// <summary>
/// Gets or Sets the Name of this game.
/// </summary>
public String Name { get; set; }
/// <summary>
/// Gets or Sets the website where this game can be played at.
/// </summary>
public String Website { get; set; }
/// <summary>
/// Gets or Sets the Description of this game. This is often displayed upon first connection.
/// Note that this is displayed BEFORE the Servers MOTD.
/// </summary>
public String Description { get; set; }
/// <summary>
/// Gets or Sets the Version of this game.
/// </summary>
public String Version { get; set; }
/// <summary>
/// Gets or Sets if Room Names will be shown to the player each time they travel to a new Room.
/// </summary>
public Boolean HiddenRoomNames { get; set; }
/// <summary>
/// Gets or Sets if this Game is currently being played on a Server
/// </summary>
public Boolean Multiplayer { get; set; }
/// <summary>
/// Gets or Sets the minimum password size required for user account passwords
/// </summary>
public Int32 MinimumPasswordSize { get; set; }
/// <summary>
/// Get or Sets if the game will automatically save the world. For servers with poor specifications, this can be disabled to
/// help with performance. Manually saving the world will be required.
/// </summary>
public Boolean AutoSave { get; set; }
/// <summary>
/// Gets if the game is currently running or not.
/// </summary>
public Boolean Enabled { get; private set; }
/// <summary>
/// Gets or Sets if the game is in debug more or not.
/// </summary>
public Boolean Debugging { get; set; }
/// <summary>
/// Gets or reference to the currently running Server.
/// </summary>
public Server Server { get; protected set; }
/// <summary>
/// StandardGame constructor. If no Port number is provided, 4000 is used.
/// </summary>
/// <param name="name"></param>
public StandardGame(String name) : this(name, 4000)
{
}
/// <summary>
/// StandardGame constructor.
/// </summary>
/// <param name="name"></param>
/// <param name="port"></param>
public StandardGame(String name, Int32 port)
{
Logger.WriteLine("Initializing Standard Mud Game");
this.Name = name;
this.Website = "http://scionwest.net";
this.Description = "A sample Mud game created using the Mud Designer kit.";
this.Version = "1.0";
this.Multiplayer = true;
this.MinimumPasswordSize = 8;
this.AutoSave = true;
//Setup our server.
this.Server = new Server(this, port);
}
/// <summary>
/// Starts the game by getting all of the game scripts, loading the world
/// loading all of the games commands and starting the server.
/// </summary>
/// <param name="maxPlayers"></param>
/// <param name="maxQueueSize"></param>
/// <returns></returns>
public Boolean Start(Int32 maxPlayers, Int32 maxQueueSize)
{
Logger.WriteLine("Starting up Standard Game");
//Instance Script Engine
//Compile any scripts
//Load our Commands
CommandSystem.LoadCommands();
//Load World
//Start our server.
this.Server.Start(maxPlayers, maxQueueSize);
//If the server started without error, flag the Game as enabled.
if (this.Server.Enabled)
this.Enabled = true;
return this.Enabled;
}
/// <summary>
/// Stops the game but unloading the world, shutting down the server and unloading all scripts/commands.
/// </summary>
public void Stop()
{
//Save the world.
//Stop the server
this.Server.Stop();
//Stop the world.
//Purge all scripts and commands.
CommandSystem.PurgeCommands();
//Disable the game.
this.Enabled = false;
}
public void Update()
{
}
}
}