Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
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());
            }
        }
Ejemplo n.º 3
0
        public void Update()
        {
            SslSocket.Process();
            List <SslClientConnection.ConnectionEvent> connectionEvents = this.m_connectionEvents;

            lock (connectionEvents)
            {
                using (List <SslClientConnection.ConnectionEvent> .Enumerator enumerator = this.m_connectionEvents.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        SslClientConnection.ConnectionEvent current = enumerator.get_Current();
                        switch (current.Type)
                        {
                        case SslClientConnection.ConnectionEventTypes.OnConnected:
                        {
                            if (current.Error != BattleNetErrors.ERROR_OK)
                            {
                                this.Disconnect();
                                this.m_connectionState = SslClientConnection.ConnectionState.ConnectionFailed;
                            }
                            else
                            {
                                this.m_connectionState = SslClientConnection.ConnectionState.Connected;
                            }
                            ConnectHandler[] array = this.m_connectHandlers.ToArray();
                            for (int i = 0; i < array.Length; i++)
                            {
                                ConnectHandler connectHandler = array[i];
                                connectHandler(current.Error);
                            }
                            break;
                        }

                        case SslClientConnection.ConnectionEventTypes.OnDisconnected:
                        {
                            if (current.Error != BattleNetErrors.ERROR_OK)
                            {
                                this.Disconnect();
                            }
                            DisconnectHandler[] array2 = this.m_disconnectHandlers.ToArray();
                            for (int j = 0; j < array2.Length; j++)
                            {
                                DisconnectHandler disconnectHandler = array2[j];
                                disconnectHandler(current.Error);
                            }
                            break;
                        }

                        case SslClientConnection.ConnectionEventTypes.OnPacketCompleted:
                            for (int k = 0; k < this.m_listeners.get_Count(); k++)
                            {
                                IClientConnectionListener <BattleNetPacket> clientConnectionListener = this.m_listeners.get_Item(k);
                                object state = this.m_listenerStates.get_Item(k);
                                clientConnectionListener.PacketReceived(current.Packet, state);
                            }
                            break;
                        }
                    }
                }
                this.m_connectionEvents.Clear();
            }
            if (this.m_sslSocket == null || this.m_connectionState != SslClientConnection.ConnectionState.Connected)
            {
                return;
            }
            while (this.m_outQueue.get_Count() > 0)
            {
                if (this.OnlyOneSend && !this.m_sslSocket.m_canSend)
                {
                    return;
                }
                BattleNetPacket packet = this.m_outQueue.Dequeue();
                this.SendPacket(packet);
            }
        }