- Fixed server
- Works for multiplayer now, exit doesn't shut down everything. - Less memory usage. - TODO: If startup message, handle it.
This commit is contained in:
parent
e822537128
commit
7f39821216
3 changed files with 21 additions and 10 deletions
|
@ -17,7 +17,10 @@ namespace MudEngine.Commands
|
|||
|
||||
public CommandResults Execute(string command, BaseCharacter player)
|
||||
{
|
||||
player.ActiveGame.Shutdown();
|
||||
if (player.ActiveGame.IsMultiplayer)
|
||||
player.Disconnect();
|
||||
else
|
||||
player.ActiveGame.Shutdown();
|
||||
|
||||
return new CommandResults();
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ namespace MudEngine.GameObjects.Characters
|
|||
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
|
||||
Send(encoding.GetBytes(str));
|
||||
if (!ActiveGame.IsRunning)
|
||||
Clear();
|
||||
Disconnect();
|
||||
}
|
||||
|
||||
internal void Send(byte[] data)
|
||||
|
@ -130,10 +130,10 @@ namespace MudEngine.GameObjects.Characters
|
|||
}
|
||||
catch (Exception) // error, connection failed: close client
|
||||
{
|
||||
Clear();
|
||||
Disconnect();
|
||||
}
|
||||
}
|
||||
internal void Clear()
|
||||
internal void Disconnect()
|
||||
{
|
||||
// TODO: Save();
|
||||
Save();
|
||||
|
@ -142,6 +142,7 @@ namespace MudEngine.GameObjects.Characters
|
|||
client.Close();
|
||||
// TODO: Reset game so it can be used again
|
||||
}
|
||||
|
||||
internal Socket client;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,17 +101,23 @@ namespace MudEngine.Networking
|
|||
{
|
||||
byte[] buf = new byte[1];
|
||||
int recved = players[sub].client.Receive(buf);
|
||||
|
||||
if (recved > 0)
|
||||
buffer.Add(buf[0]);
|
||||
else if (buffer.Count > 0)
|
||||
{
|
||||
players[sub].Send(buffer.ToArray());
|
||||
buffer.Clear();
|
||||
if (buf[0] == '\n' && buffer.Count > 0)
|
||||
{
|
||||
if (buffer[buffer.Count-1] == '\r')
|
||||
buffer.RemoveAt(buffer.Count-1);
|
||||
players[sub].Receive(buffer.ToArray());
|
||||
buffer.Clear();
|
||||
}
|
||||
else
|
||||
buffer.Add(buf[0]);
|
||||
}
|
||||
}
|
||||
catch (Exception) // error receiving, close player
|
||||
{
|
||||
players[sub].Clear();
|
||||
this.Disconnect(sub);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +126,8 @@ namespace MudEngine.Networking
|
|||
if (sub > 0 && sub < players./*Capacity*/Length)
|
||||
{
|
||||
clientThreads[sub].Abort();
|
||||
players[sub].Clear();
|
||||
if(players[sub].IsActive)
|
||||
players[sub].Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue