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.Send("Enter Character Name: ", false);
String input = player.ReadInput();
Boolean playerFound = false;
Boolean playerLegal = false;
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.
if (!Directory.Exists(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))
{
if (Path.GetFileNameWithoutExtension(filename).ToLower() == input.ToLower())
if (Path.GetFileNameWithoutExtension(filename).ToLower() == playerName.ToLower())
{
//TODO: Ask for password.
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)
{
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();
}
}
}
}
//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.Create(playerName, playerPwrd);
player.Send("Welcome " + player.Name + "!");
//Save the new player.
player.Save(player.ActiveGame.DataPaths.Players);
}
else
{
BaseCharacter p = new BaseCharacter(player.ActiveGame);
p.Load(savedFile);
if (p.VarifyPassword(playerPwrd))
{
player.Load(savedFile);
player.Send("Welcome back " + player.Name + "!");
}
else
{
passwordLegal = false;
player.Send("Invalid password.");
}
}
}
}
//Look to see if there are players in the Room
//Let other players know that the user walked in.

View file

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

View file

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

View file

@ -1,25 +1,26 @@
//Microsoft .NET Framework
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
 //Microsoft .NET Framework
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
//MUD Engine
using MudEngine.FileSystem;
using MudEngine.Commands;
using MudEngine.GameManagement;
using MudEngine.GameObjects;
using MudEngine.GameObjects.Environment;
using MudEngine.GameObjects.Items;
//MUD Engine
using MudEngine.FileSystem;
using MudEngine.Commands;
using MudEngine.GameManagement;
using MudEngine.GameObjects;
using MudEngine.GameObjects.Environment;
using MudEngine.GameObjects.Items;
using System.Net;
using System.Net.Sockets;
using System.Net;
using System.Net.Sockets;
namespace MudEngine.GameObjects.Characters
{
namespace MudEngine.GameObjects.Characters
{
public class BaseCharacter : BaseObject
{
private String Password { get; set; }
/// <summary>
/// The current Room this Character is located at.
/// </summary>
@ -71,6 +72,7 @@ namespace MudEngine.GameObjects.Characters
{
base.Load(filename);
Password = FileManager.GetData(filename, "Password");
this.IsControlled = Convert.ToBoolean(FileManager.GetData(filename, "IsControlled"));
//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);
FileManager.WriteLine(path, this.Password, "Password");
FileManager.WriteLine(path, this.IsControlled.ToString(), "IsControlled");
FileManager.WriteLine(path, this.Role.ToString(), "Role");
FileManager.WriteLine(path, this.CurrentRoom.Filename, "CurrentRoom");
@ -225,6 +228,22 @@ namespace MudEngine.GameObjects.Characters
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()
{
if (ActiveGame.IsMultiplayer)
@ -374,4 +393,4 @@ namespace MudEngine.GameObjects.Characters
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 California Cali;
public MyGame()
: base()
{
@ -11,42 +13,7 @@ public class MyGame : Game
Version = "Example Game Version 1.0";
MaximumPlayers = 5000;
//Instance our Realm
Realm myRealm = new Realm(this);
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);
Cali = new California(this);
Cali.Create();
}
}