Skip to content

Commit

Permalink
fix a bug introduced before
Browse files Browse the repository at this point in the history
  • Loading branch information
moonheart committed Sep 24, 2023
1 parent 7754ffe commit 0c81dce
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
10 changes: 6 additions & 4 deletions MementoMori/MementoMoriFuncs.Ops.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public partial class MementoMoriFuncs : ReactiveObject

public ObservableCollection<string> MesssageList { get; } = new();

private const int Max_Err_Count = 20;

public async Task Login()
{
Logining = true;
Expand Down Expand Up @@ -930,9 +932,9 @@ public async Task AutoBossRequest()
catch (Exception e)
{
errCount++;
if (errCount > 10)
if (errCount > Max_Err_Count)
{
log("错误达到了 10 次, 中断");
log($"错误达到了 {Max_Err_Count} 次, 中断");
return;
}
Expand Down Expand Up @@ -981,9 +983,9 @@ public async Task AutoInfiniteTowerRequest()
catch (Exception e)
{
errCount++;
if (errCount > 10)
if (errCount > Max_Err_Count)
{
log("错误达到了 10 次, 中断");
log($"错误达到了 {Max_Err_Count} 次, 中断");
return;
}
Expand Down
3 changes: 2 additions & 1 deletion MementoMori/MementoMoriFuncs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ public async Task AuthLogin()
AdverisementId = Guid.NewGuid().ToString("D"),
UserId = _authOption.UserId
};
UserSyncData = await _networkManager.Login(reqBody, AddLog);
await _networkManager.Login(reqBody, AddLog);
await UserGetUserData();
}

public async Task AutoDungeonBattle(Action<string> log, CancellationToken cancellationToken)
Expand Down
18 changes: 12 additions & 6 deletions MementoMori/MementoNetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using MessagePack;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Reflection;
Expand Down Expand Up @@ -58,7 +59,8 @@ public MementoNetworkManager(ILogger<MementoNetworkManager> logger)
_logger = logger;

_meMoriHttpClientHandler = new MeMoriHttpClientHandler();
_httpClient = new HttpClient(_meMoriHttpClientHandler) {Timeout = TimeSpan.FromSeconds(10)};
_httpClient = new HttpClient(_meMoriHttpClientHandler);
if (!Debugger.IsAttached) _httpClient.Timeout = TimeSpan.FromSeconds(10);

var response = GetResponse<GetDataUriRequest, GetDataUriResponse>(new GetDataUriRequest() {CountryCode = "CN"}).ConfigureAwait(false).GetAwaiter().GetResult();
AssetCatalogUriFormat = response.AssetCatalogUriFormat;
Expand All @@ -68,7 +70,8 @@ public MementoNetworkManager(ILogger<MementoNetworkManager> logger)
AppAssetVersionInfo = response.AppAssetVersionInfo;
_meMoriHttpClientHandler.AppVersion = AppAssetVersionInfo.Version;

_unityHttpClient = new HttpClient() {Timeout = TimeSpan.FromSeconds(30)};
_unityHttpClient = new HttpClient();
if (!Debugger.IsAttached) _unityHttpClient.Timeout = TimeSpan.FromSeconds(30);
_unityHttpClient.DefaultRequestHeaders.Add("User-Agent", "UnityPlayer/2021.3.10f1 (UnityWebRequest/1.0, libcurl/7.80.0-DEV)");
_unityHttpClient.DefaultRequestHeaders.Add("X-Unity-Version", "2021.3.10f1");
}
Expand Down Expand Up @@ -168,7 +171,7 @@ private async Task<string> CalcFileMd5(string path)
return sb.ToString();
}

public async Task<UserSyncData> Login(LoginRequest loginRequest, Action<string> log = null)
public async Task Login(LoginRequest loginRequest, Action<string> log = null)
{
_lastLoginRequest = loginRequest;
var authLoginResp = await GetResponse<LoginRequest, LoginResponse>(loginRequest, log);
Expand All @@ -184,7 +187,6 @@ public async Task<UserSyncData> Login(LoginRequest loginRequest, Action<string>
{
PlayerId = playerDataInfo.PlayerId, Password = playerDataInfo.Password
}, log);
return loginPlayerResp.UserSyncData;
}


Expand Down Expand Up @@ -217,15 +219,19 @@ public async Task<UserSyncData> Login(LoginRequest loginRequest, Action<string>

if (apiErrResponse.ErrorCode == ErrorCode.InvalidRequestHeader)
{
log("登录失效, 正在重新登录");
await Login(_lastLoginRequest);
log("登录失效, 请重新登录");
}

if (apiErrResponse.ErrorCode == ErrorCode.AuthLoginInvalidRequest)
{
log("登录失败, 请检查帐号配置");
}

if (apiErrResponse.ErrorCode == ErrorCode.CommonNoSession)
{
log("工作階段已過期, 请重新登錄");
}

var errorCodeMessage = Masters.TextResourceTable.GetErrorCodeMessage(apiErrResponse.ErrorCode);
log(uri.ToString());
log($"{errorCodeMessage}");
Expand Down

0 comments on commit 0c81dce

Please sign in to comment.