Beispiel #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());
            }
        }
Beispiel #2
0
 public void AddListener(IClientConnectionListener <BattleNetPacket> listener, object state)
 {
     this.m_listeners.Add(listener);
     this.m_listenerStates.Add(state);
 }
        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);
            }
        }
Beispiel #4
0
 public void RemoveListener(IClientConnectionListener <BattleNetPacket> listener)
 {
     while (this.m_listeners.Remove(listener))
     {
     }
 }
Beispiel #5
0
        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;
                            }
                            ConnectHandler[] array = this.m_connectHandlers.ToArray();
                            for (int i = 0; i < array.Length; i++)
                            {
                                ConnectHandler connectHandler = array[i];
                                connectHandler(current.Error);
                            }
                            break;
                        }

                        case ClientConnection <PacketType> .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 ClientConnection <PacketType> .ConnectionEventTypes.OnPacketCompleted:
                            for (int k = 0; k < this.m_listeners.get_Count(); k++)
                            {
                                IClientConnectionListener <PacketType> 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_socket == null || this.m_connectionState != ClientConnection <PacketType> .ConnectionState.Connected)
            {
                return;
            }
            this.SendQueuedPackets();
        }
Beispiel #6
0
 public void RemoveListener(IClientConnectionListener <PacketType> listener)
 {
     while (this.m_listeners.Remove(listener))
     {
     }
 }
Beispiel #7
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);
            }
        }
Beispiel #8
0
        public void Update()
        {
            object mMutex = this.m_mutex;

            Monitor.Enter(mMutex);
            try
            {
                foreach (ClientConnection <PacketType> .ConnectionEvent mConnectionEvent in this.m_connectionEvents)
                {
                    this.PrintConnectionException(mConnectionEvent);
                    ClientConnection <PacketType> .ConnectionEventTypes type = mConnectionEvent.Type;
                    if (type == ClientConnection <PacketType> .ConnectionEventTypes.OnConnected)
                    {
                        if (mConnectionEvent.Error == BattleNetErrors.ERROR_OK)
                        {
                            this.m_connectionState = ClientConnection <PacketType> .ConnectionState.Connected;
                        }
                        else
                        {
                            this.DisconnectSocket();
                            this.m_connectionState = ClientConnection <PacketType> .ConnectionState.ConnectionFailed;
                        }
                        ConnectHandler[] array = this.m_connectHandlers.ToArray();
                        for (int i = 0; i < (int)array.Length; i++)
                        {
                            array[i](mConnectionEvent.Error);
                        }
                    }
                    else if (type == ClientConnection <PacketType> .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 == ClientConnection <PacketType> .ConnectionEventTypes.OnPacketCompleted)
                    {
                        for (int k = 0; k < this.m_listeners.Count; k++)
                        {
                            IClientConnectionListener <PacketType> item = this.m_listeners[k];
                            object obj = this.m_listenerStates[k];
                            item.PacketReceived(mConnectionEvent.Packet, obj);
                        }
                    }
                }
                this.m_connectionEvents.Clear();
            }
            finally
            {
                Monitor.Exit(mMutex);
            }
            if (this.m_socket == null || this.m_connectionState != ClientConnection <PacketType> .ConnectionState.Connected)
            {
                return;
            }
            this.SendQueuedPackets();
        }
Beispiel #9
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++)
                                {
                                    IClientConnectionListener <PacketType> 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.DisconnectSocket();
                            this.m_connectionState = ClientConnection <PacketType> .ConnectionState.ConnectionFailed;
                        }
                        else
                        {
                            this.m_connectionState = ClientConnection <PacketType> .ConnectionState.Connected;
                        }
                        foreach (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();
        }