Merge branch 'master' of github.com:OriolBonjoch/RockPaperScissorsLizardSpock
This commit is contained in:
Коммит
108937b969
|
@ -10,5 +10,6 @@
|
|||
public TokenSettings Token { get; set; } = new TokenSettings();
|
||||
public int GameStatusUpdateDelay { get; set; } = 1000;
|
||||
public int GameStatusMaxWait { get; set; } = 60;
|
||||
public int EntityTokenExpirationMinutes { get; set; } = 60;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
|
||||
namespace RPSLS.Game.Multiplayer.Models
|
||||
{
|
||||
public class Token
|
||||
{
|
||||
private readonly int _maxTokenLifeMinutes;
|
||||
private readonly DateTime _creationTimeStamp;
|
||||
|
||||
public Token(string value, int maxTokenLifeMinutes)
|
||||
{
|
||||
Value = value;
|
||||
_maxTokenLifeMinutes = maxTokenLifeMinutes;
|
||||
_creationTimeStamp = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public string Value { get; private set; }
|
||||
|
||||
public bool IsExpired
|
||||
{
|
||||
get
|
||||
{
|
||||
var tokenLife = DateTime.UtcNow.Subtract(_creationTimeStamp);
|
||||
return tokenLife.Minutes > _maxTokenLifeMinutes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,6 +22,8 @@ namespace RPSLS.Game.Multiplayer.Services
|
|||
private readonly ILogger<PlayFabService> _logger;
|
||||
private readonly MultiplayerSettings _settings;
|
||||
|
||||
private Token _entityToken = null;
|
||||
|
||||
public bool HasCredentials { get => !string.IsNullOrWhiteSpace(_settings.Title) && !string.IsNullOrWhiteSpace(_settings.SecretKey); }
|
||||
|
||||
public PlayFabService(ILogger<PlayFabService> logger, IOptions<MultiplayerSettings> settings)
|
||||
|
@ -43,6 +45,13 @@ namespace RPSLS.Game.Multiplayer.Services
|
|||
|
||||
public async Task<string> GetEntityToken(string userTitleId = null)
|
||||
{
|
||||
if (_entityToken?.Value != null && !_entityToken.IsExpired)
|
||||
{
|
||||
return _entityToken.Value;
|
||||
}
|
||||
|
||||
PlayFabAuthenticationAPI.ForgetAllCredentials();
|
||||
|
||||
var tokenRequestBuilder = new GetEntityTokenRequestBuilder();
|
||||
if (!string.IsNullOrWhiteSpace(userTitleId))
|
||||
{
|
||||
|
@ -52,7 +61,10 @@ namespace RPSLS.Game.Multiplayer.Services
|
|||
var entityTokenResult = await Call(
|
||||
PlayFabAuthenticationAPI.GetEntityTokenAsync,
|
||||
tokenRequestBuilder);
|
||||
return entityTokenResult.EntityToken;
|
||||
|
||||
_entityToken = new Token(entityTokenResult.EntityToken, _settings.EntityTokenExpirationMinutes);
|
||||
|
||||
return _entityToken.Value;
|
||||
}
|
||||
|
||||
public async Task<string> CreateTicket(string username, string token)
|
||||
|
@ -154,7 +166,7 @@ namespace RPSLS.Game.Multiplayer.Services
|
|||
.WithStats(WinsStat)
|
||||
.WithLimits(0, _settings.Leaderboard.Top));
|
||||
|
||||
var players = new List<LeaderboardEntry>();
|
||||
var players = new List<LeaderboardEntry>();
|
||||
foreach (var entry in leaderboardResult.Leaderboard)
|
||||
{
|
||||
var isTwitterUser = !(entry.DisplayName?.StartsWith("$") ?? false);
|
||||
|
|
Загрузка…
Ссылка в новой задаче