* Began writing the code for player login support.
* Re-organized the StandardCharacter source code. * StandardGame now implements DataPaths in its Constructor.
This commit is contained in:
parent
f0ec29c240
commit
40b0d2be79
5 changed files with 101 additions and 67 deletions
|
@ -21,8 +21,13 @@ namespace MudEngine.DAL
|
||||||
public String Environments { get; set; }
|
public String Environments { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Path to the engines saved objects (Equipment etc).
|
/// Gets the Path to the Characters save directory
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public String Objects { get; set; }
|
public String Characters { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the path to the saved players directory.
|
||||||
|
/// </summary>
|
||||||
|
public String Players { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace MudEngine.Game.Characters
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Standard Character class used by all character based objects
|
/// Standard Character class used by all character based objects
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class StandardCharacter : BaseScript, INetworked, ISavable, IUpdatable, IGameComponent
|
public class StandardCharacter : BaseScript, INetworked, ISavable, IGameComponent
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a reference to the currently active game.
|
/// Gets a reference to the currently active game.
|
||||||
|
@ -63,6 +63,8 @@ namespace MudEngine.Game.Characters
|
||||||
this.Commands = new CommandSystem(CommandSystem.Commands);
|
this.Commands = new CommandSystem(CommandSystem.Commands);
|
||||||
|
|
||||||
this.OnConnectEvent += new OnConnectHandler(OnConnect);
|
this.OnConnectEvent += new OnConnectHandler(OnConnect);
|
||||||
|
this.OnDisconnectEvent += new OnDisconnectHandler(OnDisconnect);
|
||||||
|
this.OnLoginEvent += new OnLoginHandler(OnLogin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StandardCharacter(StandardGame game, String name, String description, Socket connection)
|
public StandardCharacter(StandardGame game, String name, String description, Socket connection)
|
||||||
|
@ -77,24 +79,6 @@ namespace MudEngine.Game.Characters
|
||||||
this._InitialMessage = true; //Strips Telnet client garbage text from initial message sent from client.
|
this._InitialMessage = true; //Strips Telnet client garbage text from initial message sent from client.
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Save(String filename)
|
|
||||||
{
|
|
||||||
base.Save(filename, true);
|
|
||||||
|
|
||||||
SaveData.AddSaveData("Immovable", Immovable.ToString());
|
|
||||||
SaveData.AddSaveData("Password", Password);
|
|
||||||
|
|
||||||
this.SaveData.Save(filename);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public override void Load(string filename)
|
|
||||||
{
|
|
||||||
base.Load(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
//throw new NotImplementedException();
|
//throw new NotImplementedException();
|
||||||
|
@ -110,6 +94,23 @@ namespace MudEngine.Game.Characters
|
||||||
this.Commands = null;
|
this.Commands = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Save(String filename)
|
||||||
|
{
|
||||||
|
base.Save(filename, true);
|
||||||
|
|
||||||
|
SaveData.AddSaveData("Immovable", Immovable.ToString());
|
||||||
|
SaveData.AddSaveData("Password", Password);
|
||||||
|
|
||||||
|
this.SaveData.Save(filename);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Load(string filename)
|
||||||
|
{
|
||||||
|
base.Load(filename);
|
||||||
|
}
|
||||||
|
|
||||||
internal void ExecuteCommand(string command)
|
internal void ExecuteCommand(string command)
|
||||||
{
|
{
|
||||||
if (this.Enabled)
|
if (this.Enabled)
|
||||||
|
@ -121,6 +122,28 @@ namespace MudEngine.Game.Characters
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Connect(Socket connection)
|
||||||
|
{
|
||||||
|
this._Connection = connection;
|
||||||
|
|
||||||
|
OnConnectEvent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Disconnect()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Disconnecting...");
|
||||||
|
|
||||||
|
//Purge all of this characters commands.
|
||||||
|
this.Destroy();
|
||||||
|
|
||||||
|
//Close our currently open socket.
|
||||||
|
this._Connection.Close();
|
||||||
|
|
||||||
|
this.OnDisconnectEvent();
|
||||||
|
|
||||||
|
Console.WriteLine("Disconnect Complete.");
|
||||||
|
}
|
||||||
|
|
||||||
public void SendMessage(String data)
|
public void SendMessage(String data)
|
||||||
{
|
{
|
||||||
this.SendMessage(data, true);
|
this.SendMessage(data, true);
|
||||||
|
@ -183,49 +206,6 @@ namespace MudEngine.Game.Characters
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Disconnect()
|
|
||||||
{
|
|
||||||
Console.WriteLine("Disconnecting...");
|
|
||||||
|
|
||||||
//Purge all of this characters commands.
|
|
||||||
this.Destroy();
|
|
||||||
|
|
||||||
//Close our currently open socket.
|
|
||||||
this._Connection.Close();
|
|
||||||
//this._LoopThread.Abort();
|
|
||||||
//Remove this character from the Connection Manager
|
|
||||||
//ConnectionManager.RemoveConnection(this, );
|
|
||||||
Console.WriteLine("Disconnect Complete.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Connect(Socket connection)
|
|
||||||
{
|
|
||||||
this._Connection = connection;
|
|
||||||
|
|
||||||
OnConnectEvent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
while (this.Game.Enabled)
|
|
||||||
{
|
|
||||||
_Writer.Flush();
|
|
||||||
//String line = CleanString(GetInput());
|
|
||||||
//Console.WriteLine(line);
|
|
||||||
//ExecuteCommand(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
this.Disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String CleanString(String line)
|
String CleanString(String line)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -266,7 +246,6 @@ namespace MudEngine.Game.Characters
|
||||||
public event OnDisconnectHandler OnDisconnectEvent;
|
public event OnDisconnectHandler OnDisconnectEvent;
|
||||||
public void OnDisconnect()
|
public void OnDisconnect()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public delegate void OnLoginHandler();
|
public delegate void OnLoginHandler();
|
||||||
|
|
|
@ -7,6 +7,7 @@ using System.Text;
|
||||||
using MudEngine.Networking;
|
using MudEngine.Networking;
|
||||||
using MudEngine.Core;
|
using MudEngine.Core;
|
||||||
using MudEngine.Game.Characters;
|
using MudEngine.Game.Characters;
|
||||||
|
using MudEngine.DAL;
|
||||||
|
|
||||||
namespace MudEngine.Game
|
namespace MudEngine.Game
|
||||||
{
|
{
|
||||||
|
@ -73,6 +74,11 @@ namespace MudEngine.Game
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Server Server { get; protected set; }
|
public Server Server { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or Sets the paths that content is saved to.
|
||||||
|
/// </summary>
|
||||||
|
public DataPaths SavePaths { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// StandardGame constructor. If no Port number is provided, 4000 is used.
|
/// StandardGame constructor. If no Port number is provided, 4000 is used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -99,6 +105,15 @@ namespace MudEngine.Game
|
||||||
|
|
||||||
//Setup our server.
|
//Setup our server.
|
||||||
this.Server = new Server(this, port);
|
this.Server = new Server(this, port);
|
||||||
|
|
||||||
|
//Setup default save paths.
|
||||||
|
DataPaths paths = new DataPaths();
|
||||||
|
paths.Environments = @"\Environment";
|
||||||
|
paths.Characters = @"\Characters";
|
||||||
|
paths.Players = @"\SavedPlayer";
|
||||||
|
paths.Scripts = @"\Scripts";
|
||||||
|
|
||||||
|
this.SavePaths = paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
using MudEngine.Core.Interface;
|
using MudEngine.Core.Interface;
|
||||||
using MudEngine.Game;
|
using MudEngine.Game;
|
||||||
|
@ -29,12 +30,46 @@ namespace MudEngine.GameScripts.Commands
|
||||||
|
|
||||||
public void Execute(string command, Game.Characters.StandardCharacter character)
|
public void Execute(string command, Game.Characters.StandardCharacter character)
|
||||||
{
|
{
|
||||||
|
StandardGame game = character.Game;
|
||||||
|
|
||||||
character.SendMessage("Please enter character name: ");
|
character.SendMessage("Please enter character name: ");
|
||||||
String name = String.Empty;
|
String name = String.Empty;
|
||||||
|
|
||||||
|
while (String.IsNullOrEmpty(name))
|
||||||
|
{
|
||||||
|
character.SendMessage("Enter your character name: ", false);
|
||||||
|
|
||||||
|
String name = String.Empty;
|
||||||
|
Boolean isFound = false;
|
||||||
|
|
||||||
while (String.IsNullOrEmpty(name))
|
while (String.IsNullOrEmpty(name))
|
||||||
{
|
{
|
||||||
name = character.GetInput();
|
name = character.GetInput();
|
||||||
|
|
||||||
|
if (String.IsNullOrEmpty(name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
//Look if the file exists.
|
||||||
|
if (File.Exists(game.SavePaths.Players + @"\" + name))
|
||||||
|
isFound = true;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
character.SendMessage("Enter your password: ", false);
|
||||||
|
|
||||||
|
String password = character.GetInput();
|
||||||
|
|
||||||
|
if (String.IsNullOrEmpty(password))
|
||||||
|
{
|
||||||
|
//Reset the process if no password supplied.
|
||||||
|
name = String.Empty;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace WinPC_Server
|
||||||
game.Description = "This is a very simple game that was created to demonstrate MUD game creation with the Mud Designer Game Engine.";
|
game.Description = "This is a very simple game that was created to demonstrate MUD game creation with the Mud Designer Game Engine.";
|
||||||
game.HiddenRoomNames = false;
|
game.HiddenRoomNames = false;
|
||||||
game.Multiplayer = true;
|
game.Multiplayer = true;
|
||||||
game.Server.MOTD = "Welcome to the Sample Game demonstration server!";
|
game.Server.MOTD = "Welcome to the Sample Game demonstration server! This is the Servers MOTD!";
|
||||||
game.Version = "1.0";
|
game.Version = "1.0";
|
||||||
game.Website = "http://muddesigner.codeplex.com";
|
game.Website = "http://muddesigner.codeplex.com";
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue