Internals rewritten. PHoton config can now be fetched from the server, and if it fails, fallback to the local configuration.
This commit is contained in:
50
Core/Content/CustomRecNet/CustomRecNet.cs
Normal file
50
Core/Content/CustomRecNet/CustomRecNet.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using BestHTTP;
|
||||
using Il2CppInterop.Runtime;
|
||||
using RecNet;
|
||||
|
||||
namespace undead_universal_patch_il2cpp.Core.Content.CustomRecNet;
|
||||
|
||||
public class RecNetInteractions
|
||||
{
|
||||
public static int AccountId { get; set; }
|
||||
public static string AccessToken { get; set; }
|
||||
|
||||
public static List<Action> postNameServerActions = [];
|
||||
public static List<Action> postAuthenticationActions = [];
|
||||
public static List<Action> postLocalAccountActions = [];
|
||||
|
||||
public static Il2CppSystem.Uri CreateServiceUri(Service service, string pathAndQuery)
|
||||
{
|
||||
Il2CppSystem.Uri uri = RecNet.Core.GetServiceUri(service) ?? throw new Exception("Service is not available");
|
||||
var newUri = new Il2CppSystem.Uri(uri, pathAndQuery);
|
||||
|
||||
return newUri;
|
||||
}
|
||||
|
||||
public static bool HasNameserverConnected()
|
||||
{
|
||||
return RecNet.Core.ServiceUris.Count > 1;
|
||||
}
|
||||
|
||||
public static void SendRequest<T>(HTTPMethods method, Service service, string requestUri, Action<HTTPResponse, T> reqFinished, Action<HTTPResponse>? reqFailed = null)
|
||||
{
|
||||
var res = RecNet.Core.SendRequest(method, service, requestUri);
|
||||
|
||||
res.Then(DelegateSupport.ConvertDelegate<Il2CppSystem.Action<HTTPResponse>>((HTTPResponse res) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = JsonSerializer.Deserialize<T>(res.DataAsText);
|
||||
reqFinished(res, data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UniversalPatchPlugin.Log.LogError($"'{requestUri}' failed\n{ex}");
|
||||
if (reqFailed != null) reqFailed(res);
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user