MudEngine:

- Corrected CommandLogin to support the Player.Send/Receive methods.
 - Re-organized the Game class source code and added additional commenting.
 - Began adding code to remove un-wanted characters in the received byte stream in Player.Receive()
This commit is contained in:
Scionwest_cp 2010-08-01 17:34:59 -07:00
parent 942b038b1b
commit 29cdae3b1a
5 changed files with 199 additions and 129 deletions

View file

@ -154,11 +154,19 @@ namespace MudEngine.GameObjects.Characters
Disconnect();
}
internal void Send(string data)
/// <summary>
/// Sends data to the player.
/// </summary>
/// <param name="data"></param>
/// <param name="newLine"></param>
internal void Send(string data, bool newLine)
{
try
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
if (newLine)
data += "\n\r";
client.Send(encoding.GetBytes(data));
}
catch (Exception) // error, connection failed: close client
@ -166,11 +174,22 @@ namespace MudEngine.GameObjects.Characters
Disconnect();
}
}
/// <summary>
/// Sends data to the player.
/// </summary>
/// <param name="data"></param>
internal void Send(string data)
{
Send(data, true);
}
internal void Disconnect()
{
string filePath = Path.Combine(ActiveGame.DataPaths.Players, Filename);
this.Save(filePath);
Send("Disconnecting...");
IsActive = false;
client.Close();
// TODO: Reset game so it can be used again
@ -193,8 +212,18 @@ namespace MudEngine.GameObjects.Characters
buffer.RemoveAt(buffer.Count-1);
String str;
List<byte> correctedBuffer = new List<byte>();
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
str = enc.GetString(buffer.ToArray());
foreach (byte i in buffer)
{
if (i == 255)
continue;
else if (i == 251)
continue;
else
correctedBuffer.Add(i);
}
str = enc.GetString(correctedBuffer.ToArray());
return str;
}
else