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
-
-