Beispiel #1
0
        public async Task <AuthenticationResult> Authenticate(string userName, string password = null)
        {
            if (!Connected)
            {
                throw new InvalidOperationException("Not yet connected to a server.");
            }
            if (_authenticationPending || _authenticated)
            {
                throw new InvalidOperationException("Already or currently authenticating.");
            }

            _userName = userName;
            _authenticationPending        = true;
            _authenticationReceivedSignal = new TaskSignal();

            try
            {
                SendAuth(userName, password);
                await _authenticationReceivedSignal.Wait(PacketWaitTimeout);

                return(_authenticationResult);
            }
            finally
            {
                _authenticationPending        = false;
                _authenticationReceivedSignal = null;
            }
        }
Beispiel #2
0
        public async Task <string> RequestServerInfo()
        {
            if (!Connected)
            {
                throw new InvalidOperationException("Not yet connected to a server.");
            }
            if (_serverInfoReceivedSignal != null)
            {
                throw new InvalidOperationException("Already requesting server info.");
            }

            _serverInfoReceivedSignal = new TaskSignal();
            try
            {
                SendServerInfoRequest();
                await _serverInfoReceivedSignal.Wait(PacketWaitTimeout);

                return(_serverInfoJson);
            }
            finally
            {
                _serverInfoReceivedSignal = null;
            }
        }