示例#1
0
        public async Task HandleAsync(ChannelReader <byte> reader, ChannelWriter <byte> writer, Client clientModel)
        {
            Requests.RS_LOGON_PROOF request = await RS_LOGON_PROOF_Reader.ReadAsync(reader);

            // Calculate U and M1
            clientModel.AuthEngine.CalculateU(request.A);
            clientModel.AuthEngine.CalculateM1();
            // AuthEngine.CalculateCRCHash()

            if (!clientModel.AuthEngine.M1.SequenceEqual(request.M1))
            {
                // Wrong pass
                logger.Debug("Wrong password for user {0}.", clientModel.AccountName);

                await AUTH_LOGON_PROOF_Writer.WriteAsync(writer, new AUTH_LOGON_PROOF(AccountState.LOGIN_BAD_PASS));
            }
            else
            {
                clientModel.AuthEngine.CalculateM2(request.M1);

                await AUTH_LOGON_PROOF_Writer.WriteAsync(writer, new AUTH_LOGON_PROOF(
                                                             AccountState.LOGIN_OK,
                                                             clientModel.AuthEngine.M2));

                // Set SSHash in DB
                string sshash = string.Concat(clientModel.AuthEngine.SsHash.Select(x => x.ToString("X2")));

                await accountStorage.UpdateAccountAsync(sshash,
                                                        clientModel.RemoteEnpoint.Address.ToString(),
                                                        Strings.Format(DateAndTime.Now, "yyyy-MM-dd"),
                                                        clientModel.AccountName);

                logger.Debug("Auth success for user {0} [{1}]", clientModel.AccountName, sshash);
            }
        }
示例#2
0
        public async Task HandleAsync(ChannelReader <byte> reader, ChannelWriter <byte> writer, Client clientModel)
        {
            var request = await RS_LOGON_CHALLENGE_Reader.ReadAsync(reader);

            clientModel.AccountName = request.AccountName;

            // DONE: Check if our build can join the server
            if (request.Build == mangosGlobalConstants.Required_Build_1_12_1
                | request.Build == mangosGlobalConstants.Required_Build_1_12_2
                | request.Build == mangosGlobalConstants.Required_Build_1_12_3)
            {
                // TODO: in the far future should check if the account is expired too
                var accountInfo = await accountStorage.GetAccountInfoAsync(clientModel.AccountName);

                var accountState = await GetAccountStateAsync(accountInfo);

                // DONE: Send results to client
                switch (accountState)
                {
                case AccountState.LOGIN_OK:
                    await HandleLoginOkStateAsync(request, writer, clientModel, accountInfo);

                    return;

                case AccountState.LOGIN_UNKNOWN_ACCOUNT:
                    await AUTH_LOGON_PROOF_Writer.WriteAsync(writer, new AUTH_LOGON_PROOF(AccountState.LOGIN_UNKNOWN_ACCOUNT));

                    return;

                case AccountState.LOGIN_BANNED:
                    await AUTH_LOGON_PROOF_Writer.WriteAsync(writer, new AUTH_LOGON_PROOF(AccountState.LOGIN_BANNED));

                    return;

                case AccountState.LOGIN_NOTIME:
                    await AUTH_LOGON_PROOF_Writer.WriteAsync(writer, new AUTH_LOGON_PROOF(AccountState.LOGIN_NOTIME));

                    return;

                case AccountState.LOGIN_ALREADYONLINE:
                    await AUTH_LOGON_PROOF_Writer.WriteAsync(writer, new AUTH_LOGON_PROOF(AccountState.LOGIN_ALREADYONLINE));

                    return;

                case AccountState.LOGIN_FAILED:
                case AccountState.LOGIN_BAD_PASS:
                case AccountState.LOGIN_DBBUSY:
                case AccountState.LOGIN_BADVERSION:
                case AccountState.LOGIN_DOWNLOADFILE:
                case AccountState.LOGIN_SUSPENDED:
                case AccountState.LOGIN_PARENTALCONTROL:
                    break;

                default:
                    await AUTH_LOGON_PROOF_Writer.WriteAsync(writer, new AUTH_LOGON_PROOF(AccountState.LOGIN_FAILED));

                    return;
                }
            }
            else
            {
                // Send BAD_VERSION
                logger.Warning($"WRONG_VERSION {request.Build}");
                await AUTH_LOGON_PROOF_Writer.WriteAsync(writer, new AUTH_LOGON_PROOF(AccountState.LOGIN_BADVERSION));
            }
        }