Beispiel #1
0
        internal DatagramSender(DatagramDispatcher dispatcher)
        {
            if (dispatcher == null)
            {
                throw new ArgumentNullException("dispatcher");
            }

            this.lastCommandSequenceNumber = -1;
            this.LastCommandSentTime = DateTime.Now.Subtract(dispatcher.KeepAlivePeriod).AddSeconds(5);
            this.Metrics = dispatcher.Metrics;
            this.responseDispatcher = dispatcher.ResponseDispatcher;
            this.udpClient = dispatcher.UdpClient;
            this.Log = LogManager.GetLogger(this.GetType());
        }
Beispiel #2
0
        /// <summary>
        ///   Handles the event of the dispatcher closing (and disposing)
        ///   because of a disconnect or a user request.
        /// </summary>
        /// <param name="reason"> The reason why the dispatcher closed. </param>
        internal void HandleDispatcherClosed(ShutdownReason reason)
        {
            this.ShutdownReason = reason;
            this.dispatcher = null;

#if DEBUG
            this.runningLock.Set();
#endif

            this.OnDisconnected(new DisconnectedEventArgs(reason));
        }
Beispiel #3
0
        /// <summary>
        ///   Registers with the established remote Battleye RCon server
        ///   using the provided password and starts listening for messages
        ///   from it.
        /// </summary>
        /// <returns> True if connection and login are successful, false otherwise. </returns>
        /// <exception cref="InvalidCredentialException"> 
        ///     The server rejected the connection with the specified credentials. 
        /// </exception>
        /// <exception cref="TimeoutException"> 
        ///     The server did not respond to the login request.
        /// </exception>
        public async Task<bool> ConnectAsync()
        {
            if (this.closed)
            {
                throw new ObjectDisposedException(
                        "RConClient", "This RConClient has been disposed.");
            }

            // Start listening for messages from the server
            this.dispatcher = new DatagramDispatcher(this);

            bool loggedIn = false;
            try
            {
                this.Log.Trace("BEFORE LOGIN await Login()");
                loggedIn = await this.Login();
                this.Log.Trace("AFTER LOGIN await Login()");
            }
            finally
            {
                this.Log.Trace("FINALLY LOGIN await Login()");
                if (!loggedIn)
                {
                    if (this.dispatcher != null)
                    {
                        this.dispatcher.Close(); // disposes
                    }
                }
            }

            return loggedIn;
        }