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,53 +24,93 @@ 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);
foreach (String filename in Directory.GetFiles(player.ActiveGame.DataPaths.Players)) Boolean passwordLegal = false;
{ String playerPwrd = "";
if (Path.GetFileNameWithoutExtension(filename).ToLower() == input.ToLower())
{
//TODO: Ask for password.
savedFile = filename;
playerFound = true;
break;
}
}
//Next search if there is an existing player already logged in with this name, if so disconnect them. while (!passwordLegal)
if (player.ActiveGame.IsMultiplayer)
{ {
for (Int32 i = 0; i <= player.ActiveGame.PlayerCollection.Length - 1; i++) player.Send("Enter Password: ", false);
playerPwrd = player.ReadInput();
if (!String.IsNullOrEmpty(playerPwrd))
passwordLegal = true;
if (playerPwrd.Length < 6)
{ {
if (player.ActiveGame.PlayerCollection[i].Name.ToLower() == input.ToLower()) passwordLegal = false;
player.Send("Invalid Password, minimum password length is 6 characters");
}
if (passwordLegal)
{
foreach (String filename in Directory.GetFiles(player.ActiveGame.DataPaths.Players))
{ {
player.ActiveGame.PlayerCollection[i].Disconnect(); if (Path.GetFileNameWithoutExtension(filename).ToLower() == playerName.ToLower())
{
//TODO: Ask for password.
savedFile = filename;
playerFound = true;
break;
}
}
//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() == 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.Create(playerName, playerPwrd);
player.Send("Welcome " + player.Name + "!");
}
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.");
}
} }
} }
} }
//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 + "!");
//Save the new player.
player.Save(player.ActiveGame.DataPaths.Players);
}
else
{
player.Load(savedFile);
player.Send("Welcome back " + player.Name + "!");
}
//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,377 +1,396 @@
//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
{ {
/// <summary> public class BaseCharacter : BaseObject
/// The current Room this Character is located at.
/// </summary>
public Room CurrentRoom { get; set; }
/// <summary>
/// Gets or Sets if this Character is controlled by the user. If not user controlled then it will be AI controlled.
/// </summary>
public Boolean IsControlled { get; set; }
/// <summary>
/// Gets if this user has Admin privileges or not.
/// </summary>
public SecurityRoles Role { get; private set; }
/// <summary>
/// Gets or if this character is active.
/// </summary>
public Boolean IsActive { get; internal set; }
/// <summary>
/// Gets the current inventory of the character
/// </summary>
public Bag Inventory { get; private set; }
/// <summary>
/// Gets a working copy of the CommandEngine used by the player.
/// </summary>
public CommandEngine CommandSystem { get; internal set; }
public BaseCharacter(Game game) : base(game)
{ {
ActiveGame = game; private String Password { get; set; }
IsActive = false; /// <summary>
/// The current Room this Character is located at.
/// </summary>
public Room CurrentRoom { get; set; }
if ((game.InitialRealm == null) || (game.InitialRealm.InitialZone == null) || (game.InitialRealm.InitialZone.InitialRoom == null)) /// <summary>
/// Gets or Sets if this Character is controlled by the user. If not user controlled then it will be AI controlled.
/// </summary>
public Boolean IsControlled { get; set; }
/// <summary>
/// Gets if this user has Admin privileges or not.
/// </summary>
public SecurityRoles Role { get; private set; }
/// <summary>
/// Gets or if this character is active.
/// </summary>
public Boolean IsActive { get; internal set; }
/// <summary>
/// Gets the current inventory of the character
/// </summary>
public Bag Inventory { get; private set; }
/// <summary>
/// Gets a working copy of the CommandEngine used by the player.
/// </summary>
public CommandEngine CommandSystem { get; internal set; }
public BaseCharacter(Game game) : base(game)
{ {
CurrentRoom = new Room(game); ActiveGame = game;
CurrentRoom.Name = "Abyss";
CurrentRoom.Description = "You are currently in the abyss.";
}
else
CurrentRoom = game.InitialRealm.InitialZone.InitialRoom;
Inventory = new Bag(game);
CommandSystem = new CommandEngine();
}
public override void Load(String filename)
{
base.Load(filename);
this.IsControlled = Convert.ToBoolean(FileManager.GetData(filename, "IsControlled"));
//Need to re-assign the enumerator value that was previously assigned to the Role property
Array values = Enum.GetValues(typeof(SecurityRoles));
foreach (Int32 value in values)
{
//Since enum values are not strings, we can't simply just assign the String to the enum
String displayName = Enum.GetName(typeof(SecurityRoles), value);
//If the value = the String saved, then perform the needed conversion to get our data back
if (displayName.ToLower() == FileManager.GetData(filename, "Role").ToLower())
{
Role = (SecurityRoles)Enum.Parse(typeof(SecurityRoles), displayName);
break;
}
}
//Restore the users current Room.
Realm realm = (Realm)ActiveGame.World.GetObject(ObjectTypes.Realm, FileManager.GetData(filename, "CurrentRealm"));
if (realm == null)
{
realm = new Realm(ActiveGame);
return;
}
List<Zone> zones = realm.GetZoneByFilename(FileManager.GetData(filename, "CurrentZone"));
Zone zone = new Zone(ActiveGame);
if (zones.Count == 0)
{
Log.Write("Error: Failed to find " + FileManager.GetData(filename, "CurrentZone") + " zone.");
return;
}
else if (zones.Count == 1)
{
zone = zones[0];
}
else
{
//TODO: determin which zone is the appropriate zone to assign if more than one exists.
}
List<Room> rooms = zone.GetRoomByFilename(FileManager.GetData(filename, "CurrentRoom"));
if (rooms.Count == 0)
{
Log.Write("Error: Failed to find " + FileManager.GetData(filename, "CurrentRoom") + " room.");
return;
}
else if (rooms.Count == 1)
{
CurrentRoom = rooms[0];
}
else
{
//TODO: Loop through each found room and determin in some manor what should be the correct Room to assign.
}
if (CurrentRoom == null)
{
CurrentRoom = new Room(ActiveGame);
CurrentRoom.Name = "Abyss";
CurrentRoom.Description = "You are in the Aybss. It is void of all life.";
return;
}
//TODO: Load player Inventory.
/* Due to private accessor Inv needs to be restored via
* foreach (Item in Inventory)
* this.AddItem(Item);
*/
}
public override void Save(String path)
{
base.Save(path);
path = Path.Combine(path, Filename);
FileManager.WriteLine(path, this.IsControlled.ToString(), "IsControlled");
FileManager.WriteLine(path, this.Role.ToString(), "Role");
FileManager.WriteLine(path, this.CurrentRoom.Filename, "CurrentRoom");
FileManager.WriteLine(path, this.CurrentRoom.Zone, "CurrentZone");
FileManager.WriteLine(path, this.CurrentRoom.Realm, "CurrentRealm");
}
/// <summary>
/// Moves the player from one Room to another if the supplied direction contains a doorway.
/// Returns false if no doorway is available.
/// </summary>
/// <param name="travelDirection"></param>
/// <returns></returns>
public Boolean Move(AvailableTravelDirections travelDirection)
{
//Check if the current room has a doorway in the supplied direction of travel.
if (!CurrentRoom.DoorwayExist(travelDirection))
{
return false;
}
//Let other players know that the user walked out.
for (Int32 i = 0; i != ActiveGame.PlayerCollection.Length; i++)
{
if (ActiveGame.PlayerCollection[i].Name == Name)
continue;
String room = ActiveGame.PlayerCollection[i].CurrentRoom.Filename;
String realm = ActiveGame.PlayerCollection[i].CurrentRoom.Realm;
String zone = ActiveGame.PlayerCollection[i].CurrentRoom.Zone;
if ((room == CurrentRoom.Filename) && (realm == CurrentRoom.Realm) && (zone == CurrentRoom.Zone))
{
ActiveGame.PlayerCollection[i].Send(Name + " walked out towards the " + travelDirection.ToString());
}
}
//We have a doorway, lets move to the next room.
CurrentRoom = CurrentRoom.GetDoor(travelDirection).ArrivalRoom;
OnTravel(travelDirection);
return true;
}
public virtual void OnTravel(AvailableTravelDirections travelDirection)
{
//TODO: Check the Room/Zone/Realm to see if anything needs to occure during travel.
//Let other players know that the user walked in.
for (Int32 i = 0; i != ActiveGame.PlayerCollection.Length; i++)
{
if (ActiveGame.PlayerCollection[i].Name == Name)
continue;
String room = ActiveGame.PlayerCollection[i].CurrentRoom.Name;
String realm = ActiveGame.PlayerCollection[i].CurrentRoom.Realm;
String zone = ActiveGame.PlayerCollection[i].CurrentRoom.Zone;
if ((room == CurrentRoom.Name) && (realm == CurrentRoom.Realm) && (zone == CurrentRoom.Zone))
{
ActiveGame.PlayerCollection[i].Send(Name + " walked in from the " + TravelDirections.GetReverseDirection(travelDirection));
}
}
}
public void ExecuteCommand(String command)
{
CommandSystem.ExecuteCommand(command, this);
Send(""); //Blank line to help readability.
//Now that the command has been executed, restore the Command: message
Send("Command: ", false);
}
internal void Initialize()
{
if (ActiveGame.IsMultiplayer)
client.Receive(new byte[255]);
//Ensure custom commands are loaded until everything is fleshed out.
if (Game.IsDebug)
{
foreach (String command in CommandEngine.GetCommands())
{
Log.Write("Command loaded: " + command);
}
}
//Set the players initial room
if ((ActiveGame.InitialRealm == null) || (ActiveGame.InitialRealm.InitialZone == null) || (ActiveGame.InitialRealm.InitialZone.InitialRoom == null))
{
CurrentRoom = new Room(ActiveGame);
CurrentRoom.Name = "Abyss";
CurrentRoom.Description = "You are in the Abyss. It is dark and void of life.";
}
else
CurrentRoom = ActiveGame.InitialRealm.InitialZone.InitialRoom;
ExecuteCommand("Login");
Log.Write(Name + " has logged in.");
ExecuteCommand("Look"); //MUST happen after Room setup is completed, otherwise the player default Abyss Room is printed.
}
internal void Receive(String data)
{
//data = ExecuteCommand(data);
ExecuteCommand(data);
//Send(data); //Results no longer returned as Player.Send() is used by the commands now.
if (!ActiveGame.IsRunning)
Disconnect();
}
/// <summary>
/// Sends data to the player.
/// </summary>
/// <param name="data"></param>
/// <param name="newLine"></param>
internal void Send(String data, Boolean newLine)
{
try
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
if (newLine)
data += "\n\r";
if (ActiveGame.IsMultiplayer)
client.Send(encoding.GetBytes(data));
else
Console.Write(data);
}
catch (Exception)
{
Disconnect();
}
}
/// <summary>
/// Sends data to the player.
/// </summary>
/// <param name="data"></param>
internal void Send(String data)
{
Send(data, true);
}
internal void FlushConsole()
{
try
{
if (ActiveGame.IsMultiplayer)
{
System.Text.ASCIIEncoding encoding = new ASCIIEncoding();
//\x1B is hex
//[2J is terminal sequences for clearing the screen.
client.Send(encoding.GetBytes("\x1B[2J"));
//[H is terminal sequence for sending the cursor back to its home position.
client.Send(encoding.GetBytes("\x1B[H"));
}
else
Console.Clear();
}
catch
{
Disconnect();
}
}
internal void Disconnect()
{
if (IsActive)
{
this.Save(ActiveGame.DataPaths.Players);
Send("Goodbye!");
IsActive = false; IsActive = false;
client.Close();
Log.Write(Name + " disconnected."); if ((game.InitialRealm == null) || (game.InitialRealm.InitialZone == null) || (game.InitialRealm.InitialZone.InitialRoom == null))
}
}
internal String ReadInput()
{
if (ActiveGame.IsMultiplayer)
{
List<byte> buffer = new List<byte>();
while (true)
{ {
try CurrentRoom = new Room(game);
CurrentRoom.Name = "Abyss";
CurrentRoom.Description = "You are currently in the abyss.";
}
else
CurrentRoom = game.InitialRealm.InitialZone.InitialRoom;
Inventory = new Bag(game);
CommandSystem = new CommandEngine();
}
public override void Load(String filename)
{
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
Array values = Enum.GetValues(typeof(SecurityRoles));
foreach (Int32 value in values)
{
//Since enum values are not strings, we can't simply just assign the String to the enum
String displayName = Enum.GetName(typeof(SecurityRoles), value);
//If the value = the String saved, then perform the needed conversion to get our data back
if (displayName.ToLower() == FileManager.GetData(filename, "Role").ToLower())
{ {
byte[] buf = new byte[1]; Role = (SecurityRoles)Enum.Parse(typeof(SecurityRoles), displayName);
Int32 recved = client.Receive(buf); break;
}
}
if (recved > 0) //Restore the users current Room.
Realm realm = (Realm)ActiveGame.World.GetObject(ObjectTypes.Realm, FileManager.GetData(filename, "CurrentRealm"));
if (realm == null)
{
realm = new Realm(ActiveGame);
return;
}
List<Zone> zones = realm.GetZoneByFilename(FileManager.GetData(filename, "CurrentZone"));
Zone zone = new Zone(ActiveGame);
if (zones.Count == 0)
{
Log.Write("Error: Failed to find " + FileManager.GetData(filename, "CurrentZone") + " zone.");
return;
}
else if (zones.Count == 1)
{
zone = zones[0];
}
else
{
//TODO: determin which zone is the appropriate zone to assign if more than one exists.
}
List<Room> rooms = zone.GetRoomByFilename(FileManager.GetData(filename, "CurrentRoom"));
if (rooms.Count == 0)
{
Log.Write("Error: Failed to find " + FileManager.GetData(filename, "CurrentRoom") + " room.");
return;
}
else if (rooms.Count == 1)
{
CurrentRoom = rooms[0];
}
else
{
//TODO: Loop through each found room and determin in some manor what should be the correct Room to assign.
}
if (CurrentRoom == null)
{
CurrentRoom = new Room(ActiveGame);
CurrentRoom.Name = "Abyss";
CurrentRoom.Description = "You are in the Aybss. It is void of all life.";
return;
}
//TODO: Load player Inventory.
/* Due to private accessor Inv needs to be restored via
* foreach (Item in Inventory)
* this.AddItem(Item);
*/
}
public override void Save(String path)
{
base.Save(path);
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");
FileManager.WriteLine(path, this.CurrentRoom.Zone, "CurrentZone");
FileManager.WriteLine(path, this.CurrentRoom.Realm, "CurrentRealm");
}
/// <summary>
/// Moves the player from one Room to another if the supplied direction contains a doorway.
/// Returns false if no doorway is available.
/// </summary>
/// <param name="travelDirection"></param>
/// <returns></returns>
public Boolean Move(AvailableTravelDirections travelDirection)
{
//Check if the current room has a doorway in the supplied direction of travel.
if (!CurrentRoom.DoorwayExist(travelDirection))
{
return false;
}
//Let other players know that the user walked out.
for (Int32 i = 0; i != ActiveGame.PlayerCollection.Length; i++)
{
if (ActiveGame.PlayerCollection[i].Name == Name)
continue;
String room = ActiveGame.PlayerCollection[i].CurrentRoom.Filename;
String realm = ActiveGame.PlayerCollection[i].CurrentRoom.Realm;
String zone = ActiveGame.PlayerCollection[i].CurrentRoom.Zone;
if ((room == CurrentRoom.Filename) && (realm == CurrentRoom.Realm) && (zone == CurrentRoom.Zone))
{
ActiveGame.PlayerCollection[i].Send(Name + " walked out towards the " + travelDirection.ToString());
}
}
//We have a doorway, lets move to the next room.
CurrentRoom = CurrentRoom.GetDoor(travelDirection).ArrivalRoom;
OnTravel(travelDirection);
return true;
}
public virtual void OnTravel(AvailableTravelDirections travelDirection)
{
//TODO: Check the Room/Zone/Realm to see if anything needs to occure during travel.
//Let other players know that the user walked in.
for (Int32 i = 0; i != ActiveGame.PlayerCollection.Length; i++)
{
if (ActiveGame.PlayerCollection[i].Name == Name)
continue;
String room = ActiveGame.PlayerCollection[i].CurrentRoom.Name;
String realm = ActiveGame.PlayerCollection[i].CurrentRoom.Realm;
String zone = ActiveGame.PlayerCollection[i].CurrentRoom.Zone;
if ((room == CurrentRoom.Name) && (realm == CurrentRoom.Realm) && (zone == CurrentRoom.Zone))
{
ActiveGame.PlayerCollection[i].Send(Name + " walked in from the " + TravelDirections.GetReverseDirection(travelDirection));
}
}
}
public void ExecuteCommand(String command)
{
CommandSystem.ExecuteCommand(command, this);
Send(""); //Blank line to help readability.
//Now that the command has been executed, restore the Command: message
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)
client.Receive(new byte[255]);
//Ensure custom commands are loaded until everything is fleshed out.
if (Game.IsDebug)
{
foreach (String command in CommandEngine.GetCommands())
{
Log.Write("Command loaded: " + command);
}
}
//Set the players initial room
if ((ActiveGame.InitialRealm == null) || (ActiveGame.InitialRealm.InitialZone == null) || (ActiveGame.InitialRealm.InitialZone.InitialRoom == null))
{
CurrentRoom = new Room(ActiveGame);
CurrentRoom.Name = "Abyss";
CurrentRoom.Description = "You are in the Abyss. It is dark and void of life.";
}
else
CurrentRoom = ActiveGame.InitialRealm.InitialZone.InitialRoom;
ExecuteCommand("Login");
Log.Write(Name + " has logged in.");
ExecuteCommand("Look"); //MUST happen after Room setup is completed, otherwise the player default Abyss Room is printed.
}
internal void Receive(String data)
{
//data = ExecuteCommand(data);
ExecuteCommand(data);
//Send(data); //Results no longer returned as Player.Send() is used by the commands now.
if (!ActiveGame.IsRunning)
Disconnect();
}
/// <summary>
/// Sends data to the player.
/// </summary>
/// <param name="data"></param>
/// <param name="newLine"></param>
internal void Send(String data, Boolean newLine)
{
try
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
if (newLine)
data += "\n\r";
if (ActiveGame.IsMultiplayer)
client.Send(encoding.GetBytes(data));
else
Console.Write(data);
}
catch (Exception)
{
Disconnect();
}
}
/// <summary>
/// Sends data to the player.
/// </summary>
/// <param name="data"></param>
internal void Send(String data)
{
Send(data, true);
}
internal void FlushConsole()
{
try
{
if (ActiveGame.IsMultiplayer)
{
System.Text.ASCIIEncoding encoding = new ASCIIEncoding();
//\x1B is hex
//[2J is terminal sequences for clearing the screen.
client.Send(encoding.GetBytes("\x1B[2J"));
//[H is terminal sequence for sending the cursor back to its home position.
client.Send(encoding.GetBytes("\x1B[H"));
}
else
Console.Clear();
}
catch
{
Disconnect();
}
}
internal void Disconnect()
{
if (IsActive)
{
this.Save(ActiveGame.DataPaths.Players);
Send("Goodbye!");
IsActive = false;
client.Close();
Log.Write(Name + " disconnected.");
}
}
internal String ReadInput()
{
if (ActiveGame.IsMultiplayer)
{
List<byte> buffer = new List<byte>();
while (true)
{
try
{ {
if (buf[0] == '\n' && buffer.Count > 0) byte[] buf = new byte[1];
{ Int32 recved = client.Receive(buf);
if (buffer[buffer.Count - 1] == '\r')
buffer.RemoveAt(buffer.Count - 1);
String str; if (recved > 0)
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); {
str = enc.GetString(buffer.ToArray()); if (buf[0] == '\n' && buffer.Count > 0)
return str; {
if (buffer[buffer.Count - 1] == '\r')
buffer.RemoveAt(buffer.Count - 1);
String str;
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
str = enc.GetString(buffer.ToArray());
return str;
}
else
buffer.Add(buf[0]);
} }
else }
buffer.Add(buf[0]); catch (Exception e)
{
Disconnect();
return e.Message;
} }
} }
catch (Exception e) }
{ else
Disconnect(); {
return e.Message; return Console.ReadLine();
}
} }
} }
else
{
return Console.ReadLine();
}
}
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);
} }
} }