コード例 #1
0
        public async Task SyncFriends()
        {
            using (AccountsDatabaseContext context = new AccountsDatabaseContext()) {
                var accounts = from a in context.Accounts where a.Id == Account.Id select a;
                if (!accounts.Any())
                {
                    Logger.Warn($"No such account Id={Account.Id}!");
                    await SendAsync(new FriendListMessage()).ConfigureAwait(false);

                    return;
                }

                AccountInfo account = accounts.First();
                Logger.Debug($"Read {account.Friends.Count} friends...");

                List <Account> friends = new List <Account>();
                foreach (AccountFriend friend in account.Friends)
                {
                    Account friendAccount = friend.FriendAccount.ToAccount();
                    if (null != friend.Group)
                    {
                        friendAccount.GroupName = friend.Group.GroupName;
                    }

                    friends.Add(friendAccount);
                }

                await SendAsync(new FriendListMessage()
                {
                    Friends = friends,
                }).ConfigureAwait(false);
            }
        }
コード例 #2
0
        private async Task AuthenticateAsync(AuthSession session, string accountName, string nonce, string cnonce, string nc, string qop, string digestUri, string response)
        {
            using (AccountsDatabaseContext context = new AccountsDatabaseContext()) {
                var accounts = from a in context.Accounts where a.AccountName == accountName select a;
                if (!accounts.Any())
                {
                    await session.FailureAsync("Bad Username or Password").ConfigureAwait(false);

                    return;
                }

                AccountInfo account = accounts.First();
                if (!account.IsActive)
                {
                    await session.FailureAsync("Account Inactive").ConfigureAwait(false);

                    return;
                }

                string expected, rspauth;
                switch (session.AuthType)
                {
                case AuthType.DigestMD5:
                    /*Logger.Debug("Handling MD5 response...");
                     * ////Logger.Debug($"passwordHash={account.PasswordMD5}");
                     * expected = await AuthUtil.DigestClientResponse(new MD5(), account.PasswordMD5, nonce, nc, qop, cnonce, digestURI).ConfigureAwait(false);
                     * rspauth = await AuthUtil.DigestServerResponse(new MD5(), account.PasswordMD5, nonce, nc, qop, cnonce, digestURI).ConfigureAwait(false);
                     * break;*/
                    await session.FailureAsync("MD5 auth type not supported!").ConfigureAwait(false);

                    return;

                case AuthType.DigestSHA512:
                    Logger.Debug("Handling SHA512 response...");
                    ////Logger.Debug($"passwordHash={account.PasswordSHA512}");
                    expected = await AuthUtil.DigestClientResponseAsync(new SHA512(), account.PasswordSHA512, nonce, nc, qop, cnonce, digestUri).ConfigureAwait(false);

                    rspauth = await AuthUtil.DigestServerResponseAsync(new SHA512(), account.PasswordSHA512, nonce, nc, qop, cnonce, digestUri).ConfigureAwait(false);

                    break;

                default:
                    await session.FailureAsync("Unsupported auth type!").ConfigureAwait(false);

                    return;
                }

                if (!expected.Equals(response))
                {
                    await session.FailureAsync("Bad Username or Password").ConfigureAwait(false);

                    return;
                }

                Logger.Info($"Session {session.Id} authenticated account '{accountName}', sending response: {rspauth}");
                await session.ChallengeAsync($"rspauth={rspauth}", account).ConfigureAwait(false);
            }
        }
コード例 #3
0
        protected async override Task <Account> LookupAccountAsync(string accountName)
        {
            Logger.Debug($"Looking up account for accountName={accountName}");
            using (AccountsDatabaseContext context = new AccountsDatabaseContext()) {
                var accounts = from a in context.Accounts where a.AccountName == accountName select a;
                if (!accounts.Any())
                {
                    return(null);
                }

                await Task.Delay(0).ConfigureAwait(false);

                return(accounts.First().ToAccount());
            }
        }
コード例 #4
0
        public async Task SuccessAsync(string sessionid)
        {
            await InstanceNotifier.Instance.AuthenticatedAsync(AccountInfo.AccountName, sessionid, RemoteEndPoint).ConfigureAwait(false);

            await EventLogger.Instance.SuccessEventAsync(RemoteEndPoint, AccountInfo.AccountName).ConfigureAwait(false);

            using (AccountsDatabaseContext context = new AccountsDatabaseContext()) {
                context.Accounts.Attach(AccountInfo);

                AccountInfo.SessionId = sessionid;
                AccountInfo.EndPoint  = RemoteEndPoint.ToString();

                await context.SaveChangesAsync().ConfigureAwait(false);
            }

            await SendAsync(new SuccessMessage()
            {
                SessionId = sessionid,
            }).ConfigureAwait(false);

            await DisconnectAsync().ConfigureAwait(false);
        }