* StandardCharacter now automatically invokes the Login command upon connection to the server. Login command not implemented completely yet.
* Telnet client header information is now successfully (finally) stripped out of the first stream received. * Command System underwent some optimizations along with now always returning a Boolean value once execution of a command is completed. * ICommand interface now forces all ICommand.Execute methods to return a Boolean value. * DataPaths class re-wrote and is now simi in-use by StandardGame and the Login command * Minor adjustments to how characters are initialized upon connection in various classes.
This commit is contained in:
parent
0720393626
commit
ec5a674062
10 changed files with 185 additions and 74 deletions
|
@ -46,8 +46,28 @@ namespace MudEngine.Game.Characters
|
|||
/// </summary>
|
||||
public Boolean Immovable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets if this character is enabled.
|
||||
/// </summary>
|
||||
public Boolean Enabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets if this client is fully logged into the account.
|
||||
/// </summary>
|
||||
public Boolean LoggedIn
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._LoggedIn;
|
||||
}
|
||||
private set
|
||||
{
|
||||
if (value)
|
||||
this.OnLoginEvent();
|
||||
this._LoggedIn = value;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Add current location to characters
|
||||
//public IEnvironment CurrentLocation
|
||||
|
||||
|
@ -76,7 +96,6 @@ namespace MudEngine.Game.Characters
|
|||
this._Writer = new StreamWriter(new NetworkStream(this._Connection, true));
|
||||
|
||||
this._Writer.AutoFlush = true; //Flushes the stream automatically.
|
||||
this._InitialMessage = true; //Strips Telnet client garbage text from initial message sent from client.
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
|
@ -111,21 +130,27 @@ namespace MudEngine.Game.Characters
|
|||
base.Load(filename);
|
||||
}
|
||||
|
||||
internal void ExecuteCommand(string command)
|
||||
internal Boolean ExecuteCommand(string command)
|
||||
{
|
||||
if (this.Enabled)
|
||||
{
|
||||
Commands.Execute(command, this);
|
||||
Boolean result = Commands.Execute(command, this);
|
||||
|
||||
SendMessage("");
|
||||
SendMessage("Command:", false);
|
||||
|
||||
return result;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Connect(Socket connection)
|
||||
{
|
||||
this._Connection = connection;
|
||||
|
||||
//this.Initialize();
|
||||
|
||||
OnConnectEvent();
|
||||
}
|
||||
|
||||
|
@ -186,7 +211,8 @@ namespace MudEngine.Game.Characters
|
|||
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
|
||||
input = enc.GetString(buffer.ToArray());
|
||||
buffer.Clear();
|
||||
return input;
|
||||
//Return a trimmed string.
|
||||
return CleanString(input);
|
||||
}
|
||||
else
|
||||
buffer.Add(buf[0]);
|
||||
|
@ -206,6 +232,10 @@ namespace MudEngine.Game.Characters
|
|||
}
|
||||
}
|
||||
|
||||
public void FlushBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
String CleanString(String line)
|
||||
{
|
||||
/*
|
||||
|
@ -224,22 +254,22 @@ namespace MudEngine.Game.Characters
|
|||
else
|
||||
return String.Empty;
|
||||
* */
|
||||
|
||||
Regex invalidChars = new Regex(
|
||||
@"(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F\uFEFF\uFFFE\uFFFF]",
|
||||
RegexOptions.Compiled);
|
||||
|
||||
if (String.IsNullOrEmpty(line))
|
||||
return "";
|
||||
else
|
||||
return invalidChars.Replace(line, "");
|
||||
Match m = Regex.Match(line, @"\w+"); // Regex.Replace(line, @"[^\u0000-\u007F]", "");
|
||||
line = m.Value;
|
||||
return line.Trim();
|
||||
}
|
||||
|
||||
public delegate void OnConnectHandler();
|
||||
public event OnConnectHandler OnConnectEvent;
|
||||
public void OnConnect()
|
||||
{
|
||||
this.SendMessage(this.Game.Server.MOTD);
|
||||
//Greet the user with the game information
|
||||
this.SendMessage(this.Game.Name);
|
||||
this.SendMessage(this.Game.Description);
|
||||
this.SendMessage(String.Empty);
|
||||
|
||||
//Log the user in.
|
||||
this.LoggedIn = this.ExecuteCommand("Login");
|
||||
}
|
||||
|
||||
public delegate void OnDisconnectHandler();
|
||||
|
@ -252,13 +282,13 @@ namespace MudEngine.Game.Characters
|
|||
public event OnLoginHandler OnLoginEvent;
|
||||
public void OnLogin()
|
||||
{
|
||||
|
||||
this.SendMessage(this.Game.Server.MOTD);
|
||||
}
|
||||
|
||||
private Socket _Connection;
|
||||
private StreamReader _Reader;
|
||||
private StreamWriter _Writer;
|
||||
private Boolean _InitialMessage;
|
||||
private Boolean _LoggedIn;
|
||||
private List<byte> buffer = new List<byte>();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue