コード例 #1
0
        public void Close()
        {
            if (Server == null)             // EMULATOR
            {
                _tickerHighPrecisionTimer?.Dispose();

                return;
            }

            if (!Server.ServerInfo.PlayerSessions.TryRemove(EndPoint, out PlayerNetworkSession session))
            {
                return;
            }

            if (PlayerAckQueue.Count > 0)
            {
                Thread.Sleep(50);
            }

            _tickerHighPrecisionTimer?.Dispose();

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

            SendQueueAsync().Wait();

            _cancellationToken.Cancel();
            _waitEvent.Set();
            _mainWaitEvent.Set();
            _queue.Clear();

            var queue = WaitingForAcksQueue;

            foreach (var kvp in queue)
            {
                if (queue.TryRemove(kvp.Key, out Datagram datagram))
                {
                    datagram.PutPool();
                }
            }

            foreach (var kvp in Splits)
            {
                if (Splits.TryRemove(kvp.Key, out SplitPartPacket[] splitPartPackets))
コード例 #2
0
        public void Clean()
        {
            _cancellationToken.Cancel();

            var queue = WaitingForAcksQueue;

            foreach (var kvp in queue)
            {
                Datagram datagram;
                if (queue.TryRemove(kvp.Key, out datagram))
                {
                    datagram.PutPool();
                }
            }

            foreach (var kvp in Splits)
            {
                SplitPartPackage[] splitPartPackagese;
                if (Splits.TryRemove(kvp.Key, out splitPartPackagese))
                {
                    if (splitPartPackagese == null)
                    {
                        continue;
                    }

                    foreach (SplitPartPackage package in splitPartPackagese)
                    {
                        if (package != null)
                        {
                            package.PutPool();
                        }
                    }
                }
            }

            queue.Clear();
            Splits.Clear();
        }
コード例 #3
0
ファイル: PlayerNetworkSession.cs プロジェクト: Polo1K/MiNET
        public void Close()
        {
            if (Server == null)             // EMULATOR
            {
                if (_tickerHighPrecisionTimer != null)
                {
                    _tickerHighPrecisionTimer.Dispose();
                }

                return;
            }

            PlayerNetworkSession session;

            if (!Server.ServerInfo.PlayerSessions.TryRemove(EndPoint, out session))
            {
                return;
            }

            if (PlayerAckQueue.Count > 0)
            {
                Thread.Sleep(50);
            }

            if (_tickerHighPrecisionTimer != null)
            {
                _tickerHighPrecisionTimer.Dispose();
            }

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

            SendQueue();

            _cancellationToken.Cancel();
            _waitEvent.Set();
            _mainWaitEvent.Set();
            _queue.Clear();

            var queue = WaitingForAcksQueue;

            foreach (var kvp in queue)
            {
                Datagram datagram;
                if (queue.TryRemove(kvp.Key, out datagram))
                {
                    datagram.PutPool();
                }
            }

            foreach (var kvp in Splits)
            {
                SplitPartPackage[] splitPartPackagese;
                if (Splits.TryRemove(kvp.Key, out splitPartPackagese))
                {
                    if (splitPartPackagese == null)
                    {
                        continue;
                    }

                    foreach (SplitPartPackage package in splitPartPackagese)
                    {
                        if (package != null)
                        {
                            package.PutPool();
                        }
                    }
                }
            }

            queue.Clear();
            Splits.Clear();

            try
            {
                _processingThread = null;
                _cancellationToken.Dispose();
                _waitEvent.Close();
                _mainWaitEvent.Close();
            }
            catch (Exception e)
            {
            }

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