Example #1
0
 private void OnDisconnect(BattlEyeLoginCredentials loginDetails, BattlEyeDisconnectionType?disconnectionType)
 {
     if (BattlEyeDisconnected != null)
     {
         BattlEyeDisconnected(new BattlEyeDisconnectEventArgs(loginDetails, disconnectionType));
     }
 }
Example #2
0
        private void Disconnect(BattlEyeDisconnectionType?disconnectionType)
        {
            if (disconnectionType == BattlEyeDisconnectionType.ConnectionLost)
            {
                this.disconnectionType = BattlEyeDisconnectionType.ConnectionLost;
            }

            keepRunning = false;

            if (socket.Connected)
            {
                socket.Shutdown(SocketShutdown.Both);
                socket.Close();
            }

            if (disconnectionType != null)
            {
                OnDisconnect(loginCredentials, disconnectionType);
            }
        }
        private void Disconnect(BattlEyeDisconnectionType?disconnectionType)
        {
            if (disconnectionType == BattlEyeDisconnectionType.ConnectionLost)
            {
                this.disconnectionType = BattlEyeDisconnectionType.ConnectionLost;
            }

            if (loginAccepted == false)
            {
                Disconnect();
                return;
            }

            if (threadKeepAlive != null)
            {
                threadKeepAlive.Abort();
            }
            if (threadReceive != null)
            {
                threadReceive.Abort();
            }

            threadKeepAlive = null;
            threadReceive   = null;

            if (socket.Connected)
            {
                socket.Shutdown(SocketShutdown.Both);
                socket.Close();
            }

            if (disconnectionType != null)
            {
                OnDisconnect(loginCredentials, disconnectionType);
            }
        }
Example #4
0
        private void Receive()
        {
            StateObject state = new StateObject();
            state.WorkSocket = socket;

            disconnectionType = null;

            socket.BeginReceive(state.Buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), state);

            new Thread(delegate() {
                while (socket.Connected && keepRunning)
                {
                    int timeoutClient = (int)(DateTime.Now - packetSent).TotalSeconds;
                    int timeoutServer = (int)(DateTime.Now - packetReceived).TotalSeconds;

                    if (timeoutClient >= 5)
                    {
                        if (timeoutServer >= 20)
                        {
                            Disconnect(BattlEyeDisconnectionType.ConnectionLost);
                            keepRunning = true;
                        }
                        else
                        {
                            if (packetQueue.Count == 0)
                            {
                                SendCommandPacket(null, false);
                            }
                        }
                    }

                    if (socket.Connected && packetQueue.Count > 0 && socket.Available == 0)
                    {
                        try
                        {
                            int key = packetQueue.First().Key;
                            string value = packetQueue[key][0];
                            DateTime date = DateTime.Parse(packetQueue[key][1]);
                            int timeDiff = (int)(DateTime.Now - date).TotalSeconds;

                            if (timeDiff > 5)
                            {
                                SendCommandPacket(value, false);
                                packetQueue.Remove(key);
                            }
                        }
                        catch
                        {
                            // Prevent possible crash when packet is received at the same moment it's trying to resend it.
                        }
                    }

                    Thread.Sleep(1000);
                }

                if (!socket.Connected)
                {
                    if (ReconnectOnPacketLoss && keepRunning)
                    {
                        Connect();
                    }
                    else if (!keepRunning)
                    {
                         //let the thread finish without further action
                    }
                    else
                    {
                        OnDisconnect(loginCredentials, BattlEyeDisconnectionType.ConnectionLost);
                    }
                }
            }).Start();
        }
Example #5
0
        private void Disconnect(BattlEyeDisconnectionType? disconnectionType)
        {
            if (disconnectionType == BattlEyeDisconnectionType.ConnectionLost)
                this.disconnectionType = BattlEyeDisconnectionType.ConnectionLost;

            keepRunning = false;

            if (socket.Connected)
            {
                socket.Shutdown(SocketShutdown.Both);
                socket.Close();
            }

            if (disconnectionType != null)
                OnDisconnect(loginCredentials, disconnectionType);
        }
Example #6
0
        private void Receive()
        {
            StateObject state = new StateObject();

            state.WorkSocket = socket;

            disconnectionType = null;

            socket.BeginReceive(state.Buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), state);

            new Thread(delegate() {
                while (socket.Connected && keepRunning)
                {
                    int timeoutClient = (int)(DateTime.Now - packetSent).TotalSeconds;
                    int timeoutServer = (int)(DateTime.Now - packetReceived).TotalSeconds;

                    if (timeoutClient >= 5)
                    {
                        if (timeoutServer >= 20)
                        {
                            Disconnect(BattlEyeDisconnectionType.ConnectionLost);
                            keepRunning = true;
                        }
                        else
                        {
                            if (packetQueue.Count == 0)
                            {
                                SendCommandPacket(null, false);
                            }
                        }
                    }

                    if (socket.Connected && packetQueue.Count > 0 && socket.Available == 0)
                    {
                        try
                        {
                            int key = packetQueue.First().Key;

                            if (currentPacket == -1 || !packetQueue.ContainsKey(currentPacket))
                            {
                                currentPacket = key;
                                string value  = packetQueue[key][0];
                                DateTime date = DateTime.Parse(packetQueue[key][1]);
                                int timeDiff  = (int)(DateTime.Now - date).TotalSeconds;

                                sendPacket(ConstructPacket(BattlEyePacketType.Command, key, value));
                            }
                        }
                        catch
                        {
                            // Prevent possible crash when packet is received at the same moment it's trying to resend it.
                        }
                    }

                    Thread.Sleep(250);
                }

                if (!socket.Connected)
                {
                    if (ReconnectOnPacketLoss && keepRunning)
                    {
                        Connect();
                    }
                    else if (!keepRunning)
                    {
                        //let the thread finish without further action
                    }
                    else
                    {
                        OnDisconnect(loginCredentials, BattlEyeDisconnectionType.ConnectionLost);
                    }
                }
            }).Start();
        }
Example #7
0
 private void OnDisconnect(BattlEyeLoginCredentials loginDetails, BattlEyeDisconnectionType?disconnectionType)
 {
     BattlEyeDisconnected?.Invoke(new BattlEyeDisconnectEventArgs(loginDetails, disconnectionType));
 }
Example #8
0
        private async void Receive()
        {
            var state = new StateObject {
                WorkSocket = _socket
            };

            _disconnectionType = null;

            _socket.BeginReceive(state.Buffer, 0, StateObject.BufferSize, 0, ReceiveCallback, state);

            while (_socket.Connected && _keepRunning)
            {
                int timeoutClient = (int)(DateTime.Now - _packetSent).TotalSeconds;
                int timeoutServer = (int)(DateTime.Now - _packetReceived).TotalSeconds;

                if (timeoutClient >= 5)
                {
                    if (timeoutServer >= 20)
                    {
                        Disconnect(BattlEyeDisconnectionType.ConnectionLost);
                        _keepRunning = true;
                    }
                    else
                    {
                        if (_packetQueue.Count == 0)
                        {
                            SendCommandPacket(null, false);
                        }
                    }
                }

                if (_socket.Connected && _packetQueue.Count > 0 && _socket.Available == 0)
                {
                    try
                    {
                        int key = _packetQueue.First().Key;

                        if (_currentPacket == -1 || !_packetQueue.ContainsKey(_currentPacket))
                        {
                            _currentPacket = key;
                            string value = _packetQueue[key][0];
                            SendPacket(ConstructPacket(BattlEyePacketType.Command, key, value));
                        }
                    }
                    catch
                    {
                        // Prevent possible crash when packet is received at the same moment it's trying to resend it.
                    }
                }

                await Task.Delay(250);
            }

            if (!_socket.Connected)
            {
                if (ReconnectOnPacketLoss && _keepRunning)
                {
                    Connect();
                }
                else if (!_keepRunning)
                {
                    //let the thread finish without further action
                }
                else
                {
                    OnDisconnect(_loginCredentials, BattlEyeDisconnectionType.ConnectionLost);
                }
            }
        }
 public BattlEyeDisconnectEventArgs(BattlEyeLoginCredentials loginDetails, BattlEyeDisconnectionType?disconnectionType)
 {
     LoginDetails      = loginDetails;
     DisconnectionType = disconnectionType;
     Message           = Helpers.StringValueOf(disconnectionType);
 }