예제 #1
0
    public void Update()
    {
        object mutex = this.m_mutex;

        lock (mutex)
        {
            foreach (ClientConnection <PacketType> .ConnectionEvent connectionEvent in this.m_connectionEvents)
            {
                this.PrintConnectionException(connectionEvent);
                ClientConnection <PacketType> .ConnectionEventTypes type = connectionEvent.Type;
                if (type != ClientConnection <PacketType> .ConnectionEventTypes.OnConnected)
                {
                    if (type != ClientConnection <PacketType> .ConnectionEventTypes.OnDisconnected)
                    {
                        if (type == ClientConnection <PacketType> .ConnectionEventTypes.OnPacketCompleted)
                        {
                            for (int i = 0; i < this.m_listeners.Count; i++)
                            {
                                IConnectionListener <PacketType> connectionListener = this.m_listeners[i];
                                object state = this.m_listenerStates[i];
                                connectionListener.PacketReceived(connectionEvent.Packet, state);
                            }
                        }
                    }
                    else
                    {
                        if (connectionEvent.Error != BattleNetErrors.ERROR_OK)
                        {
                            this.Disconnect();
                        }
                        foreach (ClientConnection <PacketType> .DisconnectHandler disconnectHandler in this.m_disconnectHandlers.ToArray())
                        {
                            disconnectHandler(connectionEvent.Error);
                        }
                    }
                }
                else
                {
                    if (connectionEvent.Error != BattleNetErrors.ERROR_OK)
                    {
                        this.DisconnectSocket();
                        this.m_connectionState = ClientConnection <PacketType> .ConnectionState.ConnectionFailed;
                    }
                    else
                    {
                        this.m_connectionState = ClientConnection <PacketType> .ConnectionState.Connected;
                    }
                    foreach (ClientConnection <PacketType> .ConnectHandler connectHandler in this.m_connectHandlers.ToArray())
                    {
                        connectHandler(connectionEvent.Error);
                    }
                }
            }
            this.m_connectionEvents.Clear();
        }
        if (this.m_socket == null || this.m_connectionState != ClientConnection <PacketType> .ConnectionState.Connected)
        {
            return;
        }
        this.SendQueuedPackets();
    }
    public void Update()
    {
        object mutex = this.m_mutex;

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

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

                    case ClientConnection <PacketType> .ConnectionEventTypes.OnPacketCompleted:
                        for (int k = 0; k < this.m_listeners.get_Count(); k++)
                        {
                            IConnectionListener <PacketType> connectionListener = this.m_listeners.get_Item(k);
                            object state = this.m_listenerStates.get_Item(k);
                            connectionListener.PacketReceived(current.Packet, state);
                        }
                        break;
                    }
                }
            }
            this.m_connectionEvents.Clear();
        }
        if (this.m_socket == null || this.m_connectionState != ClientConnection <PacketType> .ConnectionState.Connected)
        {
            return;
        }
        this.SendQueuedPackets();
    }