Fixes #258 & remove redundant dispose code
This commit is contained in:
parent
05a6b10e21
commit
a68c7a0ba3
@ -70,7 +70,7 @@ namespace TrueCraft
|
|||||||
public ItemStack ItemStaging { get; set; }
|
public ItemStack ItemStaging { get; set; }
|
||||||
public IWindow CurrentWindow { get; internal set; }
|
public IWindow CurrentWindow { get; internal set; }
|
||||||
public bool EnableLogging { get; set; }
|
public bool EnableLogging { get; set; }
|
||||||
public IPacket LastSuccessfulPacket { get; set; }
|
//public IPacket LastSuccessfulPacket { get; set; }
|
||||||
public DateTime ExpectedDigComplete { get; set; }
|
public DateTime ExpectedDigComplete { get; set; }
|
||||||
|
|
||||||
public Socket Connection { get; private set; }
|
public Socket Connection { get; private set; }
|
||||||
@ -326,36 +326,46 @@ namespace TrueCraft
|
|||||||
{
|
{
|
||||||
Server.DisconnectClient(this);
|
Server.DisconnectClient(this);
|
||||||
return;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
catch (NotSupportedException)
|
||||||
var packets = PacketReader.ReadPackets(this, e.Buffer, e.Offset, e.BytesTransferred);
|
{
|
||||||
|
// Usually thrown when we do not have the requested packet definition/type.
|
||||||
foreach (IPacket packet in packets)
|
|
||||||
{
|
// Might want to create its own Exception type for being more specific.
|
||||||
LastSuccessfulPacket = packet;
|
Server.Log(LogCategory.Debug, "Disconnecting client due to unsupported packet received.");
|
||||||
|
return;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sem != null)
|
if (sem != null)
|
||||||
@ -538,8 +548,8 @@ namespace TrueCraft
|
|||||||
deflate.CopyTo(ms);
|
deflate.CopyTo(ms);
|
||||||
result = ms.ToArray();
|
result = ms.ToArray();
|
||||||
}
|
}
|
||||||
Profiler.Done();
|
Profiler.Done();
|
||||||
|
|
||||||
return new ChunkDataPacket(X * Chunk.Width, 0, Z * Chunk.Depth,
|
return new ChunkDataPacket(X * Chunk.Width, 0, Z * Chunk.Depth,
|
||||||
Chunk.Width, Chunk.Height, Chunk.Depth, result);
|
Chunk.Width, Chunk.Height, Chunk.Depth, result);
|
||||||
}
|
}
|
||||||
@ -547,8 +557,6 @@ namespace TrueCraft
|
|||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
protected virtual void Dispose(bool disposing)
|
||||||
@ -564,15 +572,9 @@ namespace TrueCraft
|
|||||||
sem.Dispose();
|
sem.Dispose();
|
||||||
|
|
||||||
if (Disposed != null)
|
if (Disposed != null)
|
||||||
Disposed(this, null);
|
Disposed(this, null);
|
||||||
|
sem = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
sem = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
~RemoteClient()
|
|
||||||
{
|
|
||||||
Dispose(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user