* DataPaths now has two new helper methods. GetFilePath for returning the path to a supplied filename for a specified object type. GetExtension which returns a file extension for the specified object type.
* XMLData now contains a GetData() method for returning data from the stored data collection. * XMLData now contains a Load() method for loading a previously saved XML data file. * StandardCharacter now automatically generates a filename. * StandardCharacter.Connected added. Use Connected to check if they are connected to the server regardless of the values for Enabled and LoggedIn. LoggedIn is now true once the Login command is completed. * Default Character Role is now Player. * Server.ServerOwner property added. When a character is logged in matching the ServerOwner name, it will automatically be assigned the Admin role. * StandardCharacter.ExecuteSilentCommand() method added for executing a command and not having the "Command: " line printed to the screen when the command is completed. Useful for daisy chained commands. * StandardCharacter login code is now 100% completed. Including save/load code and new character creation. * StandardCharacter.SetRole() method added. Admins can set the role of any other character in the game if they want to. * BaseScript & StandardCharacter now have their Load() code fully implemented. They can save and load their files now. * Player creation command added. Can only be executed from within the login command. If it is executed from any other object it will bail. * Stop command now only works when a Character with Role = Admin issues the command. During development of a MUD Game, this would typically be the Server.ServerOwner character who will have Admin rights. * ConnectionManager had some bugs fixed such as not removing Threads from the Thread collection when a character disconnected. Also re-organized the character connection code some.
This commit is contained in:
parent
4b6c394f43
commit
f2c5b594c5
13 changed files with 307 additions and 34 deletions
|
@ -8,6 +8,7 @@ using System.IO;
|
|||
|
||||
using MudEngine.Game;
|
||||
using MudEngine.DAL;
|
||||
using MudEngine.Core;
|
||||
|
||||
namespace MudEngine.GameScripts
|
||||
{
|
||||
|
@ -44,6 +45,7 @@ namespace MudEngine.GameScripts
|
|||
|
||||
try
|
||||
{
|
||||
this.SaveData = new XMLData(this.GetType().Name);
|
||||
this.SaveData.AddSaveData("Name", Name);
|
||||
this.SaveData.AddSaveData("ID", ID);
|
||||
this.SaveData.AddSaveData("Description", Description);
|
||||
|
@ -65,11 +67,15 @@ namespace MudEngine.GameScripts
|
|||
{
|
||||
if (!File.Exists(filename))
|
||||
return;
|
||||
this.SaveData.Load(filename);
|
||||
|
||||
//XElement data = XElement.Load(filename);
|
||||
this.Name = this.SaveData.GetData("Name");
|
||||
this.ID = this.SaveData.GetData("ID");
|
||||
this.Description = this.SaveData.GetData("Description");
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.WriteLine(ex.Message);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
|
||||
using MudEngine.Core.Interface;
|
||||
using MudEngine.Game;
|
||||
using MudEngine.Game.Characters;
|
||||
using MudEngine.Game.Environment;
|
||||
using MudEngine.GameScripts;
|
||||
|
||||
namespace MudEngine.GameScripts.Commands
|
||||
{
|
||||
public class CommandCreatePlayer : ICommand
|
||||
{
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public List<string> Help { get; set; }
|
||||
|
||||
public CommandCreatePlayer()
|
||||
{
|
||||
Help = new List<string>();
|
||||
Name = "CreatePlayer";
|
||||
Description = "Account login command.";
|
||||
}
|
||||
|
||||
public Boolean Execute(string command, Game.Characters.StandardCharacter character)
|
||||
{
|
||||
//reference to the Characters Game.
|
||||
StandardGame game = character.Game;
|
||||
Boolean buildingPassword = true;
|
||||
|
||||
//We need to check if the 3rd Frame on the stack is the CommandLogin Type.
|
||||
//If it isn't, then another Type executed this command and we don't allow it.
|
||||
StackTrace trace = new StackTrace();
|
||||
String callingType = trace.GetFrame(3).GetMethod().ReflectedType.Name;
|
||||
|
||||
//Don't allow anything other than the Login command to start the
|
||||
//character creation process.
|
||||
if (callingType != "CommandLogin")
|
||||
{
|
||||
character.SendMessage("Invalid Command Used.");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Make sure we build a proper password.
|
||||
while (buildingPassword)
|
||||
{
|
||||
character.SendMessage("Please enter a password for this character: ", false);
|
||||
String password1, password2;
|
||||
password1 = character.GetInput();
|
||||
|
||||
//We do not perform any IsLetterOrDigit() checks on passwords. The more
|
||||
//special characters the better.
|
||||
//We do however want to make sure the length of the password is sufficient
|
||||
if (password1.Length < character.Game.MinimumPasswordSize)
|
||||
{
|
||||
character.SendMessage("Passwords must have a minimum of " + character.Game.MinimumPasswordSize.ToString() + " characters!");
|
||||
continue;
|
||||
}
|
||||
|
||||
character.SendMessage("Please re-enter your password for confirmation: ", false);
|
||||
password2 = character.GetInput();
|
||||
|
||||
if (password1 == password2)
|
||||
{
|
||||
buildingPassword = false;
|
||||
character.Password = password1;
|
||||
}
|
||||
else
|
||||
{
|
||||
character.SendMessage("Passwords did not match!");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Create a class and setup Stats.
|
||||
character.Save(character.Filename, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,7 +47,7 @@ namespace MudEngine.GameScripts.Commands
|
|||
String name = String.Empty;
|
||||
|
||||
//Repeat the login process until we get a valid name.
|
||||
while (String.IsNullOrEmpty(name))
|
||||
while (String.IsNullOrEmpty(name) && character.Connected)
|
||||
{
|
||||
character.SendMessage("Enter your character name: ", false);
|
||||
|
||||
|
@ -92,9 +92,9 @@ namespace MudEngine.GameScripts.Commands
|
|||
continue;
|
||||
|
||||
//Look if the file exists.
|
||||
String filename = game.SavePaths.GetPath(DAL.DataTypes.Players) + name;
|
||||
String filename = game.SavePaths.GetFilePath(DAL.DataTypes.Players, name);
|
||||
|
||||
if (File.Exists(game.SavePaths.GetPath(DAL.DataTypes.Players) + name))
|
||||
if (File.Exists(filename))
|
||||
isFound = true;
|
||||
|
||||
//if the character name supplied exists, load it.
|
||||
|
@ -112,10 +112,10 @@ namespace MudEngine.GameScripts.Commands
|
|||
}
|
||||
|
||||
//Load the character from file.
|
||||
character.Load(game.SavePaths.GetPath(DAL.DataTypes.Players) + name);
|
||||
character.Load(filename);
|
||||
|
||||
//Check if the characters password matches that of the saved player password
|
||||
if ("1234" != password)
|
||||
if (character.Password != password)
|
||||
{
|
||||
//No match, bail.
|
||||
character.SendMessage("Invalid password provided.");
|
||||
|
@ -127,7 +127,6 @@ namespace MudEngine.GameScripts.Commands
|
|||
character.SendMessage("Welcome back " + character.Name + "!");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -135,10 +134,25 @@ namespace MudEngine.GameScripts.Commands
|
|||
String result = character.GetInput();
|
||||
if (result.ToLower() == "yes")
|
||||
{
|
||||
return CreateCharacter(name);
|
||||
//Store the character name.
|
||||
character.Name = name;
|
||||
|
||||
|
||||
if (!character.ExecuteSilentCommand("CreatePlayer"))
|
||||
{
|
||||
name = String.Empty;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
//We complete the login process..
|
||||
character.SendMessage(character.Name + " created!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
name = String.Empty;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -146,11 +160,6 @@ namespace MudEngine.GameScripts.Commands
|
|||
return false;
|
||||
}
|
||||
|
||||
private Boolean CreateCharacter(String name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private StandardCharacter _Character;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,8 +31,18 @@ namespace MudEngine.GameScripts.Commands
|
|||
StandardGame game = character.Game;
|
||||
|
||||
//Stop the game.
|
||||
new Thread(game.Stop).Start();
|
||||
return true;
|
||||
if (character.Role == CharacterRoles.Admin)
|
||||
{
|
||||
new Thread(game.Stop).Start();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Since a non-admin character attempted this command,
|
||||
//tell them they used a invalid command
|
||||
character.SendMessage("Invalid command used.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue