- Added BaseCharacter.FlushConsole() method. Sends a hex sequence to the clients telnet terminal that clears the screen. If IsMultiplayer=false then it just clears the C# Console. - Added a 'Clear' command for users to use. It invokes the new FlushConsole command. - Removed the need for a full file path and filename when calling an objects save method. Now it just needs the path. - Adjusted the Exit command, Login command and Save command to reflect the objects save parameter changes. - Removed the Unique ID from objects. - All objects now reference each other via their filenames rather than their object names. Allows for 3 objects with the name Bedroom to exist, but with different filenames such as Bedroom1, Bedroom2 etc. - Zone now has a GetRoomByName method that replace the removed GetRoomByID method. Returns a List<> collection of Rooms found with a matching filename. - BaseCharacter updated to work with the new Zone.GetRoomByName method. - Realm.GetZoneByID renamed to GetZoneByName()
98 lines
3.6 KiB
C#
98 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
using MudEngine.FileSystem;
|
|
using MudEngine.GameObjects.Characters;
|
|
using MudEngine.GameManagement;
|
|
using MudEngine.Commands;
|
|
using MudEngine.GameObjects.Environment;
|
|
|
|
namespace MudEngine.Commands
|
|
{
|
|
public class CommandLogin : IGameCommand
|
|
{
|
|
public bool Override { get; set; }
|
|
public string Name { get; set; }
|
|
|
|
public CommandResults Execute(string command, BaseCharacter player)
|
|
{
|
|
player.Send(player.ActiveGame.GameTitle);
|
|
player.Send(player.ActiveGame.Version);
|
|
player.Send(player.ActiveGame.Story);
|
|
player.Send("");
|
|
|
|
player.Send("Enter Character Name: ", false);
|
|
|
|
string input = player.ReadInput();
|
|
Boolean playerFound = false;
|
|
string savedFile = "";
|
|
|
|
//See if this character already exists.
|
|
if (!Directory.Exists(player.ActiveGame.DataPaths.Players))
|
|
Directory.CreateDirectory(player.ActiveGame.DataPaths.Players);
|
|
|
|
foreach (string filename in Directory.GetFiles(player.ActiveGame.DataPaths.Players))
|
|
{
|
|
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.
|
|
if (player.ActiveGame.IsMultiplayer)
|
|
{
|
|
for (int i = 0; i <= player.ActiveGame.PlayerCollection.Length - 1; i++)
|
|
{
|
|
if (player.ActiveGame.PlayerCollection[i].Name.ToLower() == input.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.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
|
|
//Let other players know that the user walked in.
|
|
if (player.ActiveGame.IsMultiplayer)
|
|
{
|
|
for (int i = 0; i != player.ActiveGame.PlayerCollection.Length; i++)
|
|
{
|
|
if (player.ActiveGame.PlayerCollection[i].Name == player.Name)
|
|
continue;
|
|
|
|
string room = player.ActiveGame.PlayerCollection[i].CurrentRoom.Name;
|
|
string realm = player.ActiveGame.PlayerCollection[i].CurrentRoom.Realm;
|
|
string zone = player.ActiveGame.PlayerCollection[i].CurrentRoom.Zone;
|
|
|
|
if ((room == player.CurrentRoom.Name) && (realm == player.CurrentRoom.Realm) && (zone == player.CurrentRoom.Zone))
|
|
{
|
|
player.ActiveGame.PlayerCollection[i].Send(player.Name + " arrived.");
|
|
}
|
|
}
|
|
}
|
|
|
|
return new CommandResults();
|
|
}
|
|
}
|
|
}
|