Ejemplo n.º 1
0
        public void Close()
        {
            if (!ConnectionInfo.RakSessions.TryRemove(EndPoint, out _))
            {
                return;
            }

            State   = ConnectionState.Unconnected;
            Evicted = true;
            CustomMessageHandler = null;

            // Send with high priority, bypass queue
            SendDirectPacket(DisconnectionNotification.CreateObject());

            SendQueueAsync(500).Wait();

            _cancellationToken.Cancel();
            _packetQueuedWaitEvent.Set();
            _packetHandledWaitEvent.Set();
            _orderingBufferQueue.Clear();

            _packetSender.Close(this);

            try
            {
                _orderedQueueProcessingThread = null;
                _cancellationToken.Dispose();
                _packetQueuedWaitEvent.Close();
                _packetHandledWaitEvent.Close();
            }
            catch
            {
                // ignored
            }

            if (Log.IsDebugEnabled)
            {
                Log.Info($"Closed network session for player {Username}");
            }
        }