예제 #1
0
        public void Update()
        {
            SslSocket.Process();
            object mConnectionEvents = this.m_connectionEvents;

            Monitor.Enter(mConnectionEvents);
            try
            {
                foreach (SslClientConnection.ConnectionEvent mConnectionEvent in this.m_connectionEvents)
                {
                    SslClientConnection.ConnectionEventTypes type = mConnectionEvent.Type;
                    if (type == SslClientConnection.ConnectionEventTypes.OnConnected)
                    {
                        if (mConnectionEvent.Error == BattleNetErrors.ERROR_OK)
                        {
                            this.m_connectionState = SslClientConnection.ConnectionState.Connected;
                        }
                        else
                        {
                            this.Disconnect();
                            this.m_connectionState = SslClientConnection.ConnectionState.ConnectionFailed;
                        }
                        ConnectHandler[] array = this.m_connectHandlers.ToArray();
                        for (int i = 0; i < (int)array.Length; i++)
                        {
                            array[i](mConnectionEvent.Error);
                        }
                    }
                    else if (type == SslClientConnection.ConnectionEventTypes.OnDisconnected)
                    {
                        if (mConnectionEvent.Error != BattleNetErrors.ERROR_OK)
                        {
                            this.Disconnect();
                        }
                        DisconnectHandler[] disconnectHandlerArray = this.m_disconnectHandlers.ToArray();
                        for (int j = 0; j < (int)disconnectHandlerArray.Length; j++)
                        {
                            disconnectHandlerArray[j](mConnectionEvent.Error);
                        }
                    }
                    else if (type == SslClientConnection.ConnectionEventTypes.OnPacketCompleted)
                    {
                        for (int k = 0; k < this.m_listeners.Count; k++)
                        {
                            IClientConnectionListener <BattleNetPacket> item = this.m_listeners[k];
                            object obj = this.m_listenerStates[k];
                            item.PacketReceived(mConnectionEvent.Packet, obj);
                        }
                    }
                }
                this.m_connectionEvents.Clear();
            }
            finally
            {
                Monitor.Exit(mConnectionEvents);
            }
            if (this.m_sslSocket == null || this.m_connectionState != SslClientConnection.ConnectionState.Connected)
            {
                return;
            }
            while (this.m_outQueue.Count > 0)
            {
                if (this.OnlyOneSend && !this.m_sslSocket.m_canSend)
                {
                    return;
                }
                this.SendPacket(this.m_outQueue.Dequeue());
            }
        }
        public void Update()
        {
            SslSocket.Process();
            object connectionEvents = this.m_connectionEvents;

            lock (connectionEvents)
            {
                foreach (SslClientConnection.ConnectionEvent connectionEvent in this.m_connectionEvents)
                {
                    SslClientConnection.ConnectionEventTypes type = connectionEvent.Type;
                    if (type != SslClientConnection.ConnectionEventTypes.OnConnected)
                    {
                        if (type != SslClientConnection.ConnectionEventTypes.OnDisconnected)
                        {
                            if (type == SslClientConnection.ConnectionEventTypes.OnPacketCompleted)
                            {
                                for (int i = 0; i < this.m_listeners.Count; i++)
                                {
                                    IClientConnectionListener <BattleNetPacket> clientConnectionListener = this.m_listeners[i];
                                    object state = this.m_listenerStates[i];
                                    clientConnectionListener.PacketReceived(connectionEvent.Packet, state);
                                }
                            }
                        }
                        else
                        {
                            if (connectionEvent.Error != BattleNetErrors.ERROR_OK)
                            {
                                this.Disconnect();
                            }
                            foreach (DisconnectHandler disconnectHandler in this.m_disconnectHandlers.ToArray())
                            {
                                disconnectHandler(connectionEvent.Error);
                            }
                        }
                    }
                    else
                    {
                        if (connectionEvent.Error != BattleNetErrors.ERROR_OK)
                        {
                            this.Disconnect();
                            this.m_connectionState = SslClientConnection.ConnectionState.ConnectionFailed;
                        }
                        else
                        {
                            this.m_connectionState = SslClientConnection.ConnectionState.Connected;
                        }
                        foreach (ConnectHandler connectHandler in this.m_connectHandlers.ToArray())
                        {
                            connectHandler(connectionEvent.Error);
                        }
                    }
                }
                this.m_connectionEvents.Clear();
            }
            if (this.m_sslSocket == null || this.m_connectionState != SslClientConnection.ConnectionState.Connected)
            {
                return;
            }
            while (this.m_outQueue.Count > 0)
            {
                if (this.OnlyOneSend && !this.m_sslSocket.m_canSend)
                {
                    return;
                }
                BattleNetPacket packet = this.m_outQueue.Dequeue();
                this.SendPacket(packet);
            }
        }