Fixes #258 & remove redundant dispose code

This commit is contained in:
FICTURE7 2017-05-24 21:17:54 +04:00
parent 05a6b10e21
commit a68c7a0ba3

View File

@ -70,7 +70,7 @@ namespace TrueCraft
public ItemStack ItemStaging { get; set; }
public IWindow CurrentWindow { get; internal set; }
public bool EnableLogging { get; set; }
public IPacket LastSuccessfulPacket { get; set; }
//public IPacket LastSuccessfulPacket { get; set; }
public DateTime ExpectedDigComplete { get; set; }
public Socket Connection { get; private set; }
@ -326,36 +326,46 @@ namespace TrueCraft
{
Server.DisconnectClient(this);
return;
}
var packets = PacketReader.ReadPackets(this, e.Buffer, e.Offset, e.BytesTransferred);
try
{
foreach (IPacket packet in packets)
{
//LastSuccessfulPacket = packet;
if (PacketHandlers[packet.ID] != null)
{
try
{
PacketHandlers[packet.ID](packet, this, Server);
}
catch (PlayerDisconnectException)
{
Server.DisconnectClient(this);
}
catch (Exception ex)
{
Server.Log(LogCategory.Debug, "Disconnecting client due to exception in network worker");
Server.Log(LogCategory.Debug, ex.ToString());
Server.DisconnectClient(this);
}
}
else
{
Log("Unhandled packet {0}", packet.GetType().Name);
}
}
}
var packets = PacketReader.ReadPackets(this, e.Buffer, e.Offset, e.BytesTransferred);
foreach (IPacket packet in packets)
{
LastSuccessfulPacket = packet;
if (PacketHandlers[packet.ID] != null)
{
try
{
PacketHandlers[packet.ID](packet, this, Server);
}
catch (PlayerDisconnectException)
{
Server.DisconnectClient(this);
}
catch (Exception ex)
{
Server.Log(LogCategory.Debug, "Disconnecting client due to exception in network worker");
Server.Log(LogCategory.Debug, ex.ToString());
Server.DisconnectClient(this);
}
}
else
{
Log("Unhandled packet {0}", packet.GetType().Name);
}
catch (NotSupportedException)
{
// Usually thrown when we do not have the requested packet definition/type.
// Might want to create its own Exception type for being more specific.
Server.Log(LogCategory.Debug, "Disconnecting client due to unsupported packet received.");
return;
}
if (sem != null)
@ -538,8 +548,8 @@ namespace TrueCraft
deflate.CopyTo(ms);
result = ms.ToArray();
}
Profiler.Done();
Profiler.Done();
return new ChunkDataPacket(X * Chunk.Width, 0, Z * Chunk.Depth,
Chunk.Width, Chunk.Height, Chunk.Depth, result);
}
@ -547,8 +557,6 @@ namespace TrueCraft
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
@ -564,15 +572,9 @@ namespace TrueCraft
sem.Dispose();
if (Disposed != null)
Disposed(this, null);
Disposed(this, null);
sem = null;
}
sem = null;
}
~RemoteClient()
{
Dispose(false);
}
}
}