Skip to content

Commit

Permalink
Move mappings and AES to Fortnite Central
Browse files Browse the repository at this point in the history
  • Loading branch information
GMatrixGames committed Jul 28, 2022
1 parent ffedb2b commit 88383c3
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 38 deletions.
4 changes: 2 additions & 2 deletions FModel/ViewModels/AesManagerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void AesKeysOnItemPropertyChanged(object sender, ItemPropertyChangedEven
new()
{
Key = key,
FileName = collection[e.CollectionIndex].Name,
Name = collection[e.CollectionIndex].Name,
Guid = collection[e.CollectionIndex].Guid.ToString()
}
};
Expand All @@ -97,7 +97,7 @@ private void AesKeysOnItemPropertyChanged(object sender, ItemPropertyChangedEven
_keysFromSettings.DynamicKeys.Add(new DynamicKey
{
Key = key,
FileName = collection[e.CollectionIndex].Name,
Name = collection[e.CollectionIndex].Name,
Guid = collection[e.CollectionIndex].Guid.ToString()
});
}
Expand Down
2 changes: 2 additions & 0 deletions FModel/ViewModels/ApiEndpointViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ApiEndpointViewModel

public FortniteApiEndpoint FortniteApi { get; }
public ValorantApiEndpoint ValorantApi { get; }
public FortniteCentralApiEndpoint CentralApi { get; }
public BenbotApiEndpoint BenbotApi { get; }
public EpicApiEndpoint EpicApi { get; }
public FModelApi FModelApi { get; }
Expand All @@ -25,6 +26,7 @@ public ApiEndpointViewModel()
{
FortniteApi = new FortniteApiEndpoint(_client);
ValorantApi = new ValorantApiEndpoint(_client);
CentralApi = new FortniteCentralApiEndpoint(_client);
BenbotApi = new BenbotApiEndpoint(_client);
EpicApi = new EpicApiEndpoint(_client);
FModelApi = new FModelApi(_client);
Expand Down
32 changes: 0 additions & 32 deletions FModel/ViewModels/ApiEndpoints/BenbotApiEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,6 @@ public BenbotApiEndpoint(RestClient client) : base(client)
{
}

public async Task<AesResponse> GetAesKeysAsync(CancellationToken token)
{
var request = new FRestRequest("https://benbot.app/api/v2/aes")
{
OnBeforeDeserialization = resp => { resp.ContentType = "application/json; charset=utf-8"; }
};
var response = await _client.ExecuteAsync<AesResponse>(request, token).ConfigureAwait(false);
Log.Information("[{Method}] [{Status}({StatusCode})] '{Resource}'", request.Method, response.StatusDescription, (int) response.StatusCode, response.ResponseUri?.OriginalString);
return response.Data;
}

public AesResponse GetAesKeys(CancellationToken token)
{
return GetAesKeysAsync(token).GetAwaiter().GetResult();
}

public async Task<MappingsResponse[]> GetMappingsAsync(CancellationToken token)
{
var request = new FRestRequest("https://benbot.app/api/v1/mappings")
{
OnBeforeDeserialization = resp => { resp.ContentType = "application/json; charset=utf-8"; }
};
var response = await _client.ExecuteAsync<MappingsResponse[]>(request, token).ConfigureAwait(false);
Log.Information("[{Method}] [{Status}({StatusCode})] '{Resource}'", request.Method, response.StatusDescription, (int) response.StatusCode, response.ResponseUri?.OriginalString);
return response.Data;
}

public MappingsResponse[] GetMappings(CancellationToken token)
{
return GetMappingsAsync(token).GetAwaiter().GetResult();
}

public async Task<Dictionary<string, Dictionary<string, string>>> GetHotfixesAsync(CancellationToken token, string language = "en-US")
{
var request = new FRestRequest("https://benbot.app/api/v1/hotfixes")
Expand Down
47 changes: 47 additions & 0 deletions FModel/ViewModels/ApiEndpoints/FortniteCentralApiEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Threading;
using System.Threading.Tasks;
using FModel.Framework;
using FModel.ViewModels.ApiEndpoints.Models;
using RestSharp;
using Serilog;

namespace FModel.ViewModels.ApiEndpoints;

public class FortniteCentralApiEndpoint : AbstractApiProvider
{
public FortniteCentralApiEndpoint(RestClient client) : base(client)
{
}

public async Task<AesResponse> GetAesKeysAsync(CancellationToken token)
{
var request = new FRestRequest("https://fortnitecentral.gmatrixgames.ga/api/v1/aes")
{
OnBeforeDeserialization = resp => { resp.ContentType = "application/json; charset=utf-8"; }
};
var response = await _client.ExecuteAsync<AesResponse>(request, token).ConfigureAwait(false);
Log.Information("[{Method}] [{Status}({StatusCode})] '{Resource}'", request.Method, response.StatusDescription, (int) response.StatusCode, response.ResponseUri?.OriginalString);
return response.Data;
}

public AesResponse GetAesKeys(CancellationToken token)
{
return GetAesKeysAsync(token).GetAwaiter().GetResult();
}

public async Task<MappingsResponse[]> GetMappingsAsync(CancellationToken token)
{
var request = new FRestRequest("https://fortnitecentral.gmatrixgames.ga/api/v1/mappings")
{
OnBeforeDeserialization = resp => { resp.ContentType = "application/json; charset=utf-8"; }
};
var response = await _client.ExecuteAsync<MappingsResponse[]>(request, token).ConfigureAwait(false);
Log.Information("[{Method}] [{Status}({StatusCode})] '{Resource}'", request.Method, response.StatusDescription, (int) response.StatusCode, response.ResponseUri?.OriginalString);
return response.Data;
}

public MappingsResponse[] GetMappings(CancellationToken token)
{
return GetMappingsAsync(token).GetAwaiter().GetResult();
}
}
4 changes: 2 additions & 2 deletions FModel/ViewModels/ApiEndpoints/Models/AesResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class AesResponse
[DebuggerDisplay("{" + nameof(Key) + "}")]
public class DynamicKey
{
[J("fileName")] public string FileName { get; set; }
[J("name")] public string Name { get; set; }
[J("guid")] public string Guid { get; set; }
[J("key")] public string Key { get; set; }
}
}
4 changes: 2 additions & 2 deletions FModel/ViewModels/CUE4ParseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public async Task RefreshAes()
{
await _threadWorkerView.Begin(cancellationToken =>
{
var aes = _apiEndpointView.BenbotApi.GetAesKeys(cancellationToken);
var aes = _apiEndpointView.CentralApi.GetAesKeys(cancellationToken);
if (aes?.MainKey == null && aes?.DynamicKeys == null && aes?.Version == null) return;
UserSettings.Default.AesKeys[Game] = aes;
Expand Down Expand Up @@ -333,7 +333,7 @@ await _threadWorkerView.Begin(cancellationToken =>
else
{
var mappingsFolder = Path.Combine(UserSettings.Default.OutputDirectory, ".data");
var mappings = _apiEndpointView.BenbotApi.GetMappings(cancellationToken);
var mappings = _apiEndpointView.CentralApi.GetMappings(cancellationToken);
if (mappings is { Length: > 0 })
{
foreach (var mapping in mappings)
Expand Down

0 comments on commit 88383c3

Please sign in to comment.