diff --git a/MudEngine/WinPC_Engine/DAL/XMLData.cs b/MudEngine/WinPC_Engine/DAL/XMLData.cs index b255c94..cb68780 100644 --- a/MudEngine/WinPC_Engine/DAL/XMLData.cs +++ b/MudEngine/WinPC_Engine/DAL/XMLData.cs @@ -28,8 +28,15 @@ namespace MudEngine.DAL public Boolean Save(String filename) { - this.SaveData.Save(filename); - return true; + try + { + this.SaveData.Save(filename); + return true; + } + catch + { + return false; + } } } } diff --git a/MudEngine/WinPC_Engine/Game/Characters/StandardCharacter.cs b/MudEngine/WinPC_Engine/Game/Characters/StandardCharacter.cs index b3751d9..d287a31 100644 --- a/MudEngine/WinPC_Engine/Game/Characters/StandardCharacter.cs +++ b/MudEngine/WinPC_Engine/Game/Characters/StandardCharacter.cs @@ -101,9 +101,13 @@ namespace MudEngine.Game.Characters this.Enabled = true; } + /// + /// Destroys any resources used by this character. + /// Assumes that Save() has already been invoked. + /// public void Destroy() { - throw new NotImplementedException(); + this.Commands = null; } internal void ExecuteCommand(string command) @@ -183,6 +187,9 @@ namespace MudEngine.Game.Characters { Console.WriteLine("Disconnecting..."); + //Purge all of this characters commands. + this.Destroy(); + //Close our currently open socket. this._Connection.Close(); //this._LoopThread.Abort(); diff --git a/MudEngine/WinPC_Engine/Game/StandardGame.cs b/MudEngine/WinPC_Engine/Game/StandardGame.cs index 3f0e16e..5d7bf07 100644 --- a/MudEngine/WinPC_Engine/Game/StandardGame.cs +++ b/MudEngine/WinPC_Engine/Game/StandardGame.cs @@ -6,37 +6,86 @@ using System.Text; using MudEngine.Networking; using MudEngine.Core; +using MudEngine.Game.Characters; namespace MudEngine.Game { + /// + /// 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. + /// public class StandardGame { + /// + /// Gets or Sets the Name of this game. + /// public String Name { get; set; } - + + /// + /// Gets or Sets the website where this game can be played at. + /// public String Website { get; set; } + /// + /// Gets or Sets the Description of this game. This is often displayed upon first connection. + /// Note that this is displayed BEFORE the Servers MOTD. + /// public String Description { get; set; } + /// + /// Gets or Sets the Version of this game. + /// public String Version { get; set; } + /// + /// Gets or Sets if Room Names will be shown to the player each time they travel to a new Room. + /// public Boolean HiddenRoomNames { get; set; } + /// + /// Gets or Sets if this Game is currently being played on a Server + /// public Boolean Multiplayer { get; set; } + /// + /// Gets or Sets the minimum password size required for user account passwords + /// public Int32 MinimumPasswordSize { get; set; } + /// + /// 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. + /// public Boolean AutoSave { get; set; } + /// + /// Gets if the game is currently running or not. + /// public Boolean Enabled { get; private set; } + /// + /// Gets or Sets if the game is in debug more or not. + /// public Boolean Debugging { get; set; } + /// + /// Gets or reference to the currently running Server. + /// public Server Server { get; protected set; } + /// + /// StandardGame constructor. If no Port number is provided, 4000 is used. + /// + /// public StandardGame(String name) : this(name, 4000) { } + /// + /// StandardGame constructor. + /// + /// + /// public StandardGame(String name, Int32 port) { Logger.WriteLine("Initializing Standard Mud Game"); @@ -52,6 +101,13 @@ namespace MudEngine.Game this.Server = new Server(this, port); } + /// + /// Starts the game by getting all of the game scripts, loading the world + /// loading all of the games commands and starting the server. + /// + /// + /// + /// public Boolean Start(Int32 maxPlayers, Int32 maxQueueSize) { Logger.WriteLine("Starting up Standard Game"); @@ -75,13 +131,28 @@ namespace MudEngine.Game return this.Enabled; } + /// + /// Stops the game but unloading the world, shutting down the server and unloading all scripts/commands. + /// 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() + { + + } } } diff --git a/MudEngine/WinPC_Engine/GameScripts/Commands/CommandStop.cs b/MudEngine/WinPC_Engine/GameScripts/Commands/CommandStop.cs new file mode 100644 index 0000000..5266318 --- /dev/null +++ b/MudEngine/WinPC_Engine/GameScripts/Commands/CommandStop.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; + +using MudEngine.Core.Interface; +using MudEngine.Game; +using MudEngine.Game.Characters; +using MudEngine.Networking; + +namespace MudEngine.GameScripts.Commands +{ + public class CommandStop : ICommand + { + public string Name { get; set; } + + public string Description { get; set; } + + public List Help { get; set; } + + public CommandStop() + { + this.Name = "Stop"; + this.Description = "Chat command that allows objects to communicate."; + } + + public void Execute(string command, StandardCharacter character) + { + //Grab a reference to the character for simplifying access. + StandardGame game = character.Game; + + //Stop the game. + new Thread(game.Stop).Start(); + } + } +} diff --git a/MudEngine/WinPC_Engine/Networking/ConnectionManager.cs b/MudEngine/WinPC_Engine/Networking/ConnectionManager.cs index 18eb765..ac78dea 100644 --- a/MudEngine/WinPC_Engine/Networking/ConnectionManager.cs +++ b/MudEngine/WinPC_Engine/Networking/ConnectionManager.cs @@ -75,6 +75,7 @@ namespace MudEngine.Networking /// public void RemoveConnection(StandardCharacter character) { + character.Save(character.Filename); character.Disconnect(); foreach (StandardCharacter c in this._ConnectedCharacters) { diff --git a/MudEngine/WinPC_Engine/Networking/Server.cs b/MudEngine/WinPC_Engine/Networking/Server.cs index f7d444c..b50ef5d 100644 --- a/MudEngine/WinPC_Engine/Networking/Server.cs +++ b/MudEngine/WinPC_Engine/Networking/Server.cs @@ -79,6 +79,15 @@ namespace MudEngine.Networking public void Stop() { + this.ConnectionManager.DisconnectAll(); + + this._ServerThread.Abort(); + + this._Server.Close(); + this._Server = null; + + this.Enabled = false; + this.Status = ServerStatus.Stopped; } private void ServerLoop() diff --git a/MudEngine/WinPC_Engine/WinPC_Engine.csproj b/MudEngine/WinPC_Engine/WinPC_Engine.csproj index ee41ce2..585759b 100644 --- a/MudEngine/WinPC_Engine/WinPC_Engine.csproj +++ b/MudEngine/WinPC_Engine/WinPC_Engine.csproj @@ -37,6 +37,7 @@ + @@ -56,6 +57,7 @@ + diff --git a/MudEngine/WinPC_Server/Program.cs b/MudEngine/WinPC_Server/Program.cs index 0ada462..e36a04e 100644 --- a/MudEngine/WinPC_Server/Program.cs +++ b/MudEngine/WinPC_Server/Program.cs @@ -38,28 +38,28 @@ namespace WinPC_Server game.Start(100, 20); //Setup our Server console input class + /* ConsoleInput input = new ConsoleInput(); //Run the console input on its own thread. Thread inputThread = new Thread(input.GetInput); inputThread.Start(); - + */ //Game loops until it is disabled. while (game.Enabled) { - //Check the queued Console Input - if (input.Message.ToLower().Equals("exit")) - { - //If the server console has a exit command entered. - //stop the game. This will set game.Enabled to false. - game.Stop(); - } - else - input.Message = String.Empty; + game.Update(); } //Kill the Console Input thread. + /* inputThread.Abort(); + inputThread = null; + input = null; + */ + game = null; + + System.Windows.Forms.Application.Exit(); } } } \ No newline at end of file