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)); } }