fix(core): Fixes a few netstate issues (#436)

- [X] Fixes the order of disconnect/dispose
- [X] Removes IsDisposing
This commit is contained in:
Kamron Batman 2021-02-01 20:37:51 -08:00 committed by GitHub
parent f147cb119f
commit c6e93a6814
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 29 deletions

View file

@ -50,15 +50,12 @@ namespace Server.Network
public static NetStateCreatedCallback CreatedCallback { get; set; }
private readonly string _toString;
private int _disposing;
private ClientVersion _version;
private byte[] _recvBuffer;
private byte[] _sendBuffer;
private long _nextActivityCheck;
private volatile bool _running;
private volatile DecodePacket _packetDecoder;
private volatile EncodePacket _packetEncoder;
private bool _flushQueued = false;
private bool _flushQueued;
internal int _authId;
internal int _seed;
@ -87,10 +84,10 @@ namespace Server.Network
HuePickers = new List<HuePicker>();
Menus = new List<IMenu>();
Trades = new List<SecureTrade>();
_recvBuffer = GC.AllocateUninitializedArray<byte>(RecvPipeSize);
RecvPipe = new Pipe<byte>(_recvBuffer);
_sendBuffer = GC.AllocateUninitializedArray<byte>(SendPipeSize);
SendPipe = new Pipe<byte>(_sendBuffer);
var recvBuffer = GC.AllocateUninitializedArray<byte>(RecvPipeSize);
RecvPipe = new Pipe<byte>(recvBuffer);
var sendBuffer = GC.AllocateUninitializedArray<byte>(SendPipeSize);
SendPipe = new Pipe<byte>(sendBuffer);
_nextActivityCheck = Core.TickCount + 30000;
try
@ -164,8 +161,6 @@ namespace Server.Network
public IAccount Account { get; set; }
public bool IsDisposing => _disposing != 0;
public int CompareTo(NetState other) => string.CompareOrdinal(_toString, other?._toString);
public void ValidateAllTrades()
@ -751,12 +746,12 @@ namespace Server.Network
public virtual void Dispose()
{
if (Connection == null || Interlocked.CompareExchange(ref _disposing, 1, 0) == 1)
if (Connection == null || !_running)
{
return;
}
SendPipe.Writer.Close();
_running = false;
try
{
@ -781,11 +776,10 @@ namespace Server.Network
private void Disconnect()
{
_running = false;
Connection = null;
RecvPipe.Writer.Flush();
RecvPipe.Writer.Close();
SendPipe.Writer.Close();
var m = Mobile;
var a = Account;