Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into update-libs
Browse files Browse the repository at this point in the history
  • Loading branch information
aspriddell authored Dec 17, 2021
2 parents 004833c + 29ea6b3 commit 904adca
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 28 deletions.
18 changes: 18 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": 1,
"isRoot": true,
"tools": {
"nvika": {
"version": "2.2.0",
"commands": [
"nvika"
]
},
"jetbrains.resharper.globaltools": {
"version": "2021.2.2",
"commands": [
"jb"
]
}
}
}
31 changes: 19 additions & 12 deletions .github/workflows/codequality.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
name: Code Quality

on: [ pull_request, push ]

jobs:
quality:
runs-on: windows-latest
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install CodeCutter
run: powershell Invoke-WebRequest -Uri "https://github.com/dragonfruitnetwork/CodeCutter/releases/latest/download/DragonFruit.CodeCutter.exe" -OutFile ".\DragonFruit.CodeCutter.exe"
- name: Install .NET 3.1.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: "3.1.x"

- name: Install .NET 6.0.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: "6.0.x"

- name: Restore Tools
run: dotnet tool restore

- name: "Setup MSBuild"
uses: microsoft/setup-msbuild@v1.0.2
- name: Restore Packages
run: dotnet restore

- name: NuGet Restore
run: |
nuget locals all -clear
nuget restore
- name: InspectCode
run: dotnet jb inspectcode ${{github.workspace}}/DragonFruit.Six.Api.sln --output=${{github.workspace}}/inspectcodereport.xml --cachesDir=${{github.workspace}}/inspectcode --verbosity=WARN --no-build

- name: Code Quality Check
run: ".\\DragonFruit.CodeCutter.exe"
- name: NVika
run: dotnet nvika parsereport "${{github.workspace}}/inspectcodereport.xml"
2 changes: 1 addition & 1 deletion DragonFruit.Six.Api.Tests/DragonFruit.Six.Api.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
</ItemGroup>

Expand Down
8 changes: 4 additions & 4 deletions DragonFruit.Six.Api/Dragon6Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
using DragonFruit.Six.Api.Enums;
using DragonFruit.Six.Api.Exceptions;
using DragonFruit.Six.Api.Utils;
using Nito.AsyncEx;

namespace DragonFruit.Six.Api
{
public abstract class Dragon6Client : ApiClient<ApiJsonSerializer>
{
private readonly object _lock = new();
private readonly AsyncLock _lock = new();
public static readonly CultureInfo Culture = new("en-US", false);

protected Dragon6Client(string userAgent = null, UbisoftService app = UbisoftService.RainbowSix)
Expand Down Expand Up @@ -72,13 +73,12 @@ protected virtual void ApplyToken(TokenBase token)

internal void ValidateToken()
{
lock (_lock)
using (_lock.Lock())
{
if (Token is null || Token.Expired)
if (Token?.Expired is not false)
{
// todo throw something if this is majorly expired or null
Token = GetToken();

ApplyToken(Token);
}
}
Expand Down
16 changes: 10 additions & 6 deletions DragonFruit.Six.Api/Tokens/TokenBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,31 @@ namespace DragonFruit.Six.Api.Tokens
/// </summary>
public abstract class TokenBase
{
private DateTimeOffset? _safeExpiry;
private DateTimeOffset? _skewedExpiry;

public virtual string SessionId { get; set; }

public abstract string Token { get; set; }
public abstract DateTimeOffset Expiry { get; set; }

[JsonIgnore]
public DateTimeOffset ExpiryOffset => GetSkewedExpiry();

[JsonIgnore]
public bool Expired => GetSkewedExpiry() <= DateTimeOffset.Now;

private DateTimeOffset GetSkewedExpiry()
{
if (!_safeExpiry.HasValue)
if (!_skewedExpiry.HasValue)
{
// if the ticks equals zero timespan is set to +8hrs, asking for the UtcTicks will cause an ArgumentOutOfRangeException
// 3000000000 ticks = 5 mins
// we knock off 5 mins (3000000000 ticks) to allow clock skew.
// if the ticks equals zero when the timespan is positive (UTC)
// asking for the UtcTicks will cause an ArgumentOutOfRangeException
var skewedTimeTicks = Math.Max(Expiry.UtcTicks - 3000000000, 0);
_safeExpiry = new DateTimeOffset(skewedTimeTicks, TimeSpan.Zero);
_skewedExpiry = new DateTimeOffset(skewedTimeTicks, TimeSpan.Zero);
}

return _safeExpiry.Value;
return _skewedExpiry.Value;
}
}
}
11 changes: 11 additions & 0 deletions DragonFruit.Six.Api/Utils/OperatorData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under Apache-2. Please refer to the LICENSE file for more info

using System.Collections.Generic;
using System.Threading.Tasks;
using DragonFruit.Data;
using DragonFruit.Data.Serializers.Newtonsoft;
using DragonFruit.Six.Api.Entities;
Expand All @@ -28,5 +29,15 @@ public static IEnumerable<OperatorStats> GetOperatorInfo(this ApiClient client)
var request = new OperatorDataRequest(null);
return client.Perform<IEnumerable<OperatorStats>>(request);
}

/// <summary>
/// Gets the <see cref="IEnumerable{T}"/> needed to use the <see cref="OperatorStatsRequest"/>
/// </summary>
/// <param name="client">The <see cref="ApiClient"/> to use</param>
public static Task<IEnumerable<OperatorStats>> GetOperatorInfoAsync(this ApiClient client)
{
var request = new OperatorDataRequest(null);
return client.PerformAsync<IEnumerable<OperatorStats>>(request);
}
}
}
5 changes: 0 additions & 5 deletions codecutter.json

This file was deleted.

0 comments on commit 904adca

Please sign in to comment.