MudEngine:

- Bug fixes with object saving and restoration
 - Game Deconstructor removed.
 - Player Password saving, restoring and varification implemented fully.

MudGame:
 - Revised scripts to demonstrate the latest environment creation updates.
This commit is contained in:
Scionwest_cp 2010-08-15 12:24:54 -07:00
parent 5aa5504171
commit 9792bfcd32
6 changed files with 503 additions and 432 deletions

View file

@ -24,19 +24,46 @@ namespace MudEngine.Commands
player.Send(player.ActiveGame.Story); player.Send(player.ActiveGame.Story);
player.Send(""); player.Send("");
player.Send("Enter Character Name: ", false);
String input = player.ReadInput();
Boolean playerFound = false; Boolean playerFound = false;
Boolean playerLegal = false;
String savedFile = ""; String savedFile = "";
String playerName = "";
while (!playerLegal)
{
player.Send("Enter Character Name: ", false);
playerName = player.ReadInput();
if (!String.IsNullOrEmpty(playerName))
playerLegal = true;
}
//See if this character already exists. //See if this character already exists.
if (!Directory.Exists(player.ActiveGame.DataPaths.Players)) if (!Directory.Exists(player.ActiveGame.DataPaths.Players))
Directory.CreateDirectory(player.ActiveGame.DataPaths.Players); Directory.CreateDirectory(player.ActiveGame.DataPaths.Players);
Boolean passwordLegal = false;
String playerPwrd = "";
while (!passwordLegal)
{
player.Send("Enter Password: ", false);
playerPwrd = player.ReadInput();
if (!String.IsNullOrEmpty(playerPwrd))
passwordLegal = true;
if (playerPwrd.Length < 6)
{
passwordLegal = false;
player.Send("Invalid Password, minimum password length is 6 characters");
}
if (passwordLegal)
{
foreach (String filename in Directory.GetFiles(player.ActiveGame.DataPaths.Players)) foreach (String filename in Directory.GetFiles(player.ActiveGame.DataPaths.Players))
{ {
if (Path.GetFileNameWithoutExtension(filename).ToLower() == input.ToLower()) if (Path.GetFileNameWithoutExtension(filename).ToLower() == playerName.ToLower())
{ {
//TODO: Ask for password. //TODO: Ask for password.
savedFile = filename; savedFile = filename;
@ -45,32 +72,45 @@ namespace MudEngine.Commands
} }
} }
//Next search if there is an existing player already logged in with this name, if so disconnect them. //Loop through all the players currently logged in and disconnect anyone that is currently logged
//in with this account.
if (playerFound)
{
if (player.ActiveGame.IsMultiplayer) if (player.ActiveGame.IsMultiplayer)
{ {
for (Int32 i = 0; i <= player.ActiveGame.PlayerCollection.Length - 1; i++) for (Int32 i = 0; i <= player.ActiveGame.PlayerCollection.Length - 1; i++)
{ {
if (player.ActiveGame.PlayerCollection[i].Name.ToLower() == input.ToLower()) if (player.ActiveGame.PlayerCollection[i].Name.ToLower() == playerName.ToLower())
{ {
player.ActiveGame.PlayerCollection[i].Disconnect(); player.ActiveGame.PlayerCollection[i].Disconnect();
} }
} }
} }
}
//Now assign this name to this player if this is a new toon or load the player if the file exists. //Now assign this name to this player if this is a new toon or load the player if the file exists.
if (!playerFound) if (!playerFound)
{ {
player.Name = input; player.Create(playerName, playerPwrd);
player.Send("Welcome " + player.Name + "!"); player.Send("Welcome " + player.Name + "!");
//Save the new player.
player.Save(player.ActiveGame.DataPaths.Players);
} }
else else
{
BaseCharacter p = new BaseCharacter(player.ActiveGame);
p.Load(savedFile);
if (p.VarifyPassword(playerPwrd))
{ {
player.Load(savedFile); player.Load(savedFile);
player.Send("Welcome back " + player.Name + "!"); player.Send("Welcome back " + player.Name + "!");
} }
else
{
passwordLegal = false;
player.Send("Invalid password.");
}
}
}
}
//Look to see if there are players in the Room //Look to see if there are players in the Room
//Let other players know that the user walked in. //Let other players know that the user walked in.

View file

@ -36,7 +36,7 @@ namespace MudEngine.Commands
player.CommandSystem.ExecuteCommand("Look", player); player.CommandSystem.ExecuteCommand("Look", player);
if (player.ActiveGame.AutoSave) if (player.ActiveGame.AutoSave)
player.Save(player.Filename); player.Save(player.ActiveGame.DataPaths.Players);
return null; return null;
} }

View file

@ -230,11 +230,6 @@ namespace MudEngine.GameManagement
AutoSave = true; AutoSave = true;
AutoSaveInterval = 30; AutoSaveInterval = 30;
} }
~Game()
{
Save();
}
#endregion #endregion
#region ==== Methods ==== #region ==== Methods ====

View file

@ -1,25 +1,26 @@
//Microsoft .NET Framework  //Microsoft .NET Framework
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.IO; using System.IO;
//MUD Engine //MUD Engine
using MudEngine.FileSystem; using MudEngine.FileSystem;
using MudEngine.Commands; using MudEngine.Commands;
using MudEngine.GameManagement; using MudEngine.GameManagement;
using MudEngine.GameObjects; using MudEngine.GameObjects;
using MudEngine.GameObjects.Environment; using MudEngine.GameObjects.Environment;
using MudEngine.GameObjects.Items; using MudEngine.GameObjects.Items;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
namespace MudEngine.GameObjects.Characters namespace MudEngine.GameObjects.Characters
{ {
public class BaseCharacter : BaseObject public class BaseCharacter : BaseObject
{ {
private String Password { get; set; }
/// <summary> /// <summary>
/// The current Room this Character is located at. /// The current Room this Character is located at.
/// </summary> /// </summary>
@ -71,6 +72,7 @@ namespace MudEngine.GameObjects.Characters
{ {
base.Load(filename); base.Load(filename);
Password = FileManager.GetData(filename, "Password");
this.IsControlled = Convert.ToBoolean(FileManager.GetData(filename, "IsControlled")); this.IsControlled = Convert.ToBoolean(FileManager.GetData(filename, "IsControlled"));
//Need to re-assign the enumerator value that was previously assigned to the Role property //Need to re-assign the enumerator value that was previously assigned to the Role property
@ -150,6 +152,7 @@ namespace MudEngine.GameObjects.Characters
path = Path.Combine(path, Filename); path = Path.Combine(path, Filename);
FileManager.WriteLine(path, this.Password, "Password");
FileManager.WriteLine(path, this.IsControlled.ToString(), "IsControlled"); FileManager.WriteLine(path, this.IsControlled.ToString(), "IsControlled");
FileManager.WriteLine(path, this.Role.ToString(), "Role"); FileManager.WriteLine(path, this.Role.ToString(), "Role");
FileManager.WriteLine(path, this.CurrentRoom.Filename, "CurrentRoom"); FileManager.WriteLine(path, this.CurrentRoom.Filename, "CurrentRoom");
@ -225,6 +228,22 @@ namespace MudEngine.GameObjects.Characters
Send("Command: ", false); Send("Command: ", false);
} }
public void Create(string playerName, string password)
{
Name = playerName;
Password = password;
Save(ActiveGame.DataPaths.Players);
}
public bool VarifyPassword(string password)
{
if (Password == password)
return true;
else
return false;
}
internal void Initialize() internal void Initialize()
{ {
if (ActiveGame.IsMultiplayer) if (ActiveGame.IsMultiplayer)
@ -374,4 +393,4 @@ namespace MudEngine.GameObjects.Characters
internal Socket client; internal Socket client;
} }
} }

View file

@ -0,0 +1,50 @@
public class California
{
private Game _Game;
public California(Game game)
{
_Game = game;
}
public void Create()
{
//Instance our Realm
Realm myRealm = new Realm(_Game);
myRealm.Name = "California";
myRealm.Description = "The Beaches of California are relaxing and fun to be at.";
myRealm.IsInitialRealm = true;
_Game.World.AddRealm(myRealm);
Zone myZone = new Zone(_Game);
myZone.Name = "San Diego";
myZone.Realm = myRealm.Name;
myZone.Description = "San Diego has many attractions, including Sea World!";
myZone.IsInitialZone = true;
myRealm.AddZone(myZone);
//Create our HotelRoom
Room myRoom = new Room(_Game);
myRoom.Name = "Hotel Room B33";
myRoom.IsInitialRoom = true;
myZone.AddRoom(myRoom);
myRoom.DetailedDescription.Add("Your Hotel Room is pretty clean, it is small but not to far off from the beach so you can't complain.");
myRoom.DetailedDescription.Add("You can exit your Hotel Room by walking West");
Room myHallway = new Room(_Game);
myHallway.Name = "Hotel Hallway";
myHallway.DetailedDescription.Add("The Hotel Hallway is fairly narrow, but there is plenty of room for people to traverse through it.");
myHallway.DetailedDescription.Add("Your Hotel Room B33 is to the East.");
myHallway.DetailedDescription.Add("Hotel Room B34 is to your West.");
myZone.AddRoom(myHallway);
myZone.LinkRooms(AvailableTravelDirections.West, myHallway, myRoom);
Room nextRoom = new Room(_Game);
nextRoom.Name = "Hotel Room B34";
nextRoom.DetailedDescription.Add("This Hotel Room is pretty dirty, they must not have cleaned it yet.");
nextRoom.DetailedDescription.Add("You can exit this room by walking East");
myZone.AddRoom(nextRoom);
//Link
myZone.LinkRooms(AvailableTravelDirections.East, myHallway, nextRoom);
}
}

View file

@ -1,5 +1,7 @@
public class MyGame : Game public class MyGame : Game
{ {
public California Cali;
public MyGame() public MyGame()
: base() : base()
{ {
@ -11,42 +13,7 @@ public class MyGame : Game
Version = "Example Game Version 1.0"; Version = "Example Game Version 1.0";
MaximumPlayers = 5000; MaximumPlayers = 5000;
//Instance our Realm Cali = new California(this);
Realm myRealm = new Realm(this); Cali.Create();
myRealm.Name = "California";
myRealm.Description = "The Beaches of California are relaxing and fun to be at.";
myRealm.IsInitialRealm = true;
World.AddRealm(myRealm);
Zone myZone = new Zone(this);
myZone.Name = "San Diego";
myZone.Realm = myRealm.Name;
myZone.Description = "San Diego has many attractions, including Sea World!";
myZone.IsInitialZone = true;
myRealm.AddZone(myZone);
//Create our HotelRoom
Room myRoom = new Room(this);
myRoom.Name = "Hotel Room B33";
myRoom.IsInitialRoom = true;
myZone.AddRoom(myRoom);
myRoom.DetailedDescription.Add("Your Hotel Room is pretty clean, it is small but not to far off from the beach so you can't complain.");
myRoom.DetailedDescription.Add("You can exit your Hotel Room by walking West");
Room myHallway = new Room(this);
myHallway.Name = "Hotel Hallway";
myHallway.DetailedDescription.Add("The Hotel Hallway is fairly narrow, but there is plenty of room for people to traverse through it.");
myHallway.DetailedDescription.Add("Your Hotel Room B33 is to the East.");
myHallway.DetailedDescription.Add("Hotel Room B34 is to your West.");
myZone.AddRoom(myHallway);
myZone.LinkRooms(AvailableTravelDirections.West, myHallway, myRoom);
Room nextRoom = new Room(this);
nextRoom.Name = "Hotel Room B34";
nextRoom.DetailedDescription.Add("This Hotel Room is pretty dirty, they must not have cleaned it yet.");
nextRoom.DetailedDescription.Add("You can exit this room by walking East");
myZone.AddRoom(nextRoom);
//Link
myZone.LinkRooms(AvailableTravelDirections.East, myHallway, nextRoom);
} }
} }