From c3c2d22ec792bca5442445534c79916f929cb0af Mon Sep 17 00:00:00 2001 From: Scionwest_cp Date: Thu, 5 Aug 2010 17:46:30 -0700 Subject: [PATCH] MudEngine: - Login command now automatically disconnects a user if they are currently logged into the server when another user attempts to login with the same credentials. - Login command now loads saved players when a character name is entered that has previously been saved. - FileManager.GetData() now supports ignoring simi-colons in data files. These can be used as comments if needed. - MudEngine.GameManagement.Game.TimeOfDayOptions has been removed from the Game Type. It is now just MudEngine.GameManagement.TimeOfDayOptions. - BaseCharacter will no longer try to save the character if the supplied filename is blank - BaseCharacter will now send a disconnect message of 'Goodbye!' upon the player being disconnected from the server. - ScriptEngine.ScriptPath now returns a absolute path. - Script File compilation within ScriptEngine.Initialization is now supported. This allows developers to write their MUD's using Scripts and letting the server compile them during server startup rather than use the ScriptCompiler.exe to pre-compile scripts now. - Custom Game Types are now supported. Only 1 Type may inherit from MudEngine.GameManagement.Game at a time. To use, create a file, write a script that inherits from Game and run the server. - ScriptEngine.GetObjectOf(string) method adding. Returns a object that inherits from the Type supplied in the parameter. - Deleted StartupObject.cs - Deleted Startup.dat MudOfflineExample: - Updated to reflect the TimeOfDayOptions change in MudEngine.csproj MudServer: - Added MyGame.cs inside Debug/bin/scripts. This is a example script showing how to inherit from Game and write a custom Game Type. This Type is used when the Server runs rather than the Engine Game Type. - Server startup re-wrote to compile scripts during startup, scan them via the script engine for any custom Types that inherit from Game, and use the if needed instead of the default Engine Type. - Server now uses a Settings.ini file to allow configuration of the Script Engine by users. Provides them the ability to now customize where scripts are stored and their file extension. - Deleted Scripts.dll, as the Server now generates one at runtime each time it is ran. As of this commit, users will not need to use C# to compile their MUD's any longer. Compile the Server and run it. Scripts are now fully implemented (however not fully tested). --- MudEngine/Commands/CommandExit.cs | 8 ++- MudEngine/Commands/CommandLogin.cs | 59 ++++++++++-------- MudEngine/FileSystem/FileManager.cs | 4 ++ MudEngine/GameManagement/Game.cs | 36 +++++------ .../GameObjects/Characters/BaseCharacter.cs | 5 ++ MudEngine/MudEngine.csproj | 6 -- MudEngine/Scripting/ScriptEngine.cs | 47 ++++++++++++-- MudEngine/Scripting/StartupObject.cs | 14 ----- MudEngine/startup.dat | 1 - MudOfflineExample/Program.cs | 2 +- MudServer/..svnbridge/.svnbridge | 2 + MudServer/MudServer.csproj | 5 ++ MudServer/Program.cs | 46 +++++++++++++- MudServer/bin/Debug/..svnbridge/.svnbridge | 12 ++++ .../bin/Debug/Scripts/..svnbridge/Scripts.dll | 1 - MudServer/bin/Debug/Scripts/MyGame.cs | 7 +++ MudServer/bin/Debug/Scripts/Scripts.dll | Bin 3072 -> 0 bytes 17 files changed, 181 insertions(+), 74 deletions(-) delete mode 100644 MudEngine/Scripting/StartupObject.cs delete mode 100644 MudEngine/startup.dat delete mode 100644 MudServer/bin/Debug/Scripts/..svnbridge/Scripts.dll create mode 100644 MudServer/bin/Debug/Scripts/MyGame.cs delete mode 100644 MudServer/bin/Debug/Scripts/Scripts.dll diff --git a/MudEngine/Commands/CommandExit.cs b/MudEngine/Commands/CommandExit.cs index 7a686f1..7957ec1 100644 --- a/MudEngine/Commands/CommandExit.cs +++ b/MudEngine/Commands/CommandExit.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; +using System.IO; using System.Text; +using MudEngine.FileSystem; using MudEngine.GameObjects.Characters; using MudEngine.GameManagement; using MudEngine.Commands; @@ -20,8 +22,12 @@ namespace MudEngine.Commands if (player.ActiveGame.IsMultiplayer) player.Disconnect(); else + { + //Save the player prior to attempting to shutdown. + //Player saving is handled in the server disconnect code but not in game shutdown. + player.Save(Path.Combine(player.ActiveGame.DataPaths.Players, player.Filename)); player.ActiveGame.Shutdown(); - + } return new CommandResults(); } } diff --git a/MudEngine/Commands/CommandLogin.cs b/MudEngine/Commands/CommandLogin.cs index cbb5977..6a073b6 100644 --- a/MudEngine/Commands/CommandLogin.cs +++ b/MudEngine/Commands/CommandLogin.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; +using System.IO; using System.Text; +using MudEngine.FileSystem; using MudEngine.GameObjects.Characters; using MudEngine.GameManagement; using MudEngine.Commands; @@ -22,37 +24,44 @@ namespace MudEngine.Commands player.Send(player.ActiveGame.Story); player.Send(""); - bool isLegal = false; + player.Send("Enter Character Name: ", false); + + string input = player.ReadInput(); + Boolean playerFound = false; + string savedFile = ""; - while (!isLegal) + //See if this character already exists. + foreach (string filename in Directory.GetFiles(player.ActiveGame.DataPaths.Players)) { - player.Send("Enter Character Name: ", false); - string input = player.ReadInput(); - bool foundName = false; - - foreach (BaseCharacter bc in player.ActiveGame.PlayerCollection) + if (Path.GetFileNameWithoutExtension(filename).ToLower() == input.ToLower()) { - if (bc.Name == input) - { - player.Send("Character name already taken."); - foundName = true; - break; - } - } - - if (!foundName) - { - if (input == "") - continue; - else - { - isLegal = true; - player.Name = input; - } + //TODO: Ask for password. + savedFile = filename; + playerFound = true; + break; } } - player.Send("Welcome " + player.Name + "!"); + //Next search if there is an existing player already logged in with this name, if so disconnect them. + foreach (BaseCharacter character in player.ActiveGame.PlayerCollection) + { + if (character.Name.ToLower() == input.ToLower()) + { + character.Disconnect(); + } + } + + //Now assign this name to this player if this is a new toon or load the player if the file exists. + if (!playerFound) + { + player.Name = input; + player.Send("Welcome " + player.Name + "!"); + } + else + { + player.Load(savedFile); + player.Send("Welcome back " + player.Name + "!"); + } player.CommandSystem.ExecuteCommand("Look", player); return new CommandResults(); } diff --git a/MudEngine/FileSystem/FileManager.cs b/MudEngine/FileSystem/FileManager.cs index 9b8505d..97dcf4b 100644 --- a/MudEngine/FileSystem/FileManager.cs +++ b/MudEngine/FileSystem/FileManager.cs @@ -56,6 +56,10 @@ namespace MudEngine.FileSystem { foreach (string line in File.ReadAllLines(filename)) { + //Ignore comments + if (line.StartsWith(";")) + continue; + if (line.StartsWith(name)) return line.Substring(name.Length + 1); //Accounts for name=value; } diff --git a/MudEngine/GameManagement/Game.cs b/MudEngine/GameManagement/Game.cs index 56f6c83..85cf690 100644 --- a/MudEngine/GameManagement/Game.cs +++ b/MudEngine/GameManagement/Game.cs @@ -20,6 +20,16 @@ using MudEngine.Scripting; namespace MudEngine.GameManagement { + + #region Custom Types + public enum TimeOfDayOptions + { + AlwaysDay, + AlwaysNight, + Transition, + } + #endregion + /// /// Manages all of the projects settings. /// @@ -28,25 +38,6 @@ namespace MudEngine.GameManagement public class Game { #region ==== Properties & Types ==== - #region Custom Types - public enum TimeOfDayOptions - { - AlwaysDay, - AlwaysNight, - Transition, - } - - /// - /// Gets or Sets what time of day the world is currently in. - /// - [Category("Day Management")] - [Description("Set what time of day the world will take place in.")] - public TimeOfDayOptions TimeOfDay - { - get; - set; - } - #endregion #region Game Object Setup /// @@ -129,6 +120,13 @@ namespace MudEngine.GameManagement /// public bool HideRoomNames { get; set; } + /// + /// Gets or Sets what time of day the world is currently in. + /// + [Category("Day Management")] + [Description("Set what time of day the world will take place in.")] + public TimeOfDayOptions TimeOfDay { get; set; } + /// /// Gets or Sets how long in minutes it takes to transition from day to night. /// diff --git a/MudEngine/GameObjects/Characters/BaseCharacter.cs b/MudEngine/GameObjects/Characters/BaseCharacter.cs index 8623915..cf1fcbf 100644 --- a/MudEngine/GameObjects/Characters/BaseCharacter.cs +++ b/MudEngine/GameObjects/Characters/BaseCharacter.cs @@ -89,6 +89,10 @@ namespace MudEngine.GameObjects.Characters public override void Save(string filename) { + //Don't attempt to save a blank filename. + if (String.IsNullOrEmpty(filename)) + return; + base.Save(filename); FileManager.WriteLine(filename, this.IsControlled.ToString(), "IsControlled"); @@ -224,6 +228,7 @@ namespace MudEngine.GameObjects.Characters string filePath = Path.Combine(ActiveGame.DataPaths.Players, Filename); this.Save(filePath); + Send("Goodbye!"); IsActive = false; client.Close(); diff --git a/MudEngine/MudEngine.csproj b/MudEngine/MudEngine.csproj index 24bf0b2..b66dd88 100644 --- a/MudEngine/MudEngine.csproj +++ b/MudEngine/MudEngine.csproj @@ -83,14 +83,8 @@ - - - - PreserveNewest - -