コード例 #1
0
        /// <summary>
        /// Will close the current connection to TW2
        /// </summary>
        /// <returns>Was the connection closed successfully</returns>
        public async Task <bool> CloseConnection()
        {
            IsClosingConnection = true;

            if (_keepAlive)
            {
                LastMsgSendTimer.Stop();
            }

            if (IsConnected)
            {
                AddToConnectionLog("Closing connection");

                if (Client != null)
                {
                    var result = await Client?.Stop(WebSocketCloseStatus.NormalClosure, "Closed by command");
                }
            }
            else
            {
                return(false);
            }

            PingCount          = 0;
            ClientHasBeenSetup = false;

            DataEvents.InvokeConnectionStatus(false);

            IsClosingConnection = false;

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Will attempt to login with the account provided, if in test-mode then the connection will be closed immediately after.
        /// </summary>
        /// <param name="account">The account with which to login</param>
        /// <param name="testMode">Will close the connection immediately after if true</param>
        /// <returns>The connection result</returns>
        public async Task <ConnectResult> LoginWithAccount(Account account, bool testMode = false)
        {
            // Make sure to reset the connection and deleting it.
            await _socketManager.StopConnection(true);

            ConnectResult result = await _socketManager.StartConnection(account.ToConnectData());

            if (!result.IsConnected)
            {
                return(result);
            }

            result = await SendAccountAuthentication(account.ToConnectData());

            await SendSystemIdentify();

            result.IsConnected = await SendCharacterSelect(account.DefaultCharacter);

            if (testMode)
            {
                await _socketManager.StopConnection(true);
            }
            else
            {
                DataEvents.InvokeConnectionStatus(true);
            }

            return(result);
        }
        public void StopConnection()
        {
            DataEvents.InvokeConnectionStatus(false);

            StopConnectionEvent?.Invoke(this, EventArgs.Empty);
        }