Now able to enter the lobby

This commit is contained in:
AeonLucid
2021-11-04 06:29:58 +01:00
parent 667d19e9f2
commit e0010e1d31
19 changed files with 593 additions and 10 deletions
@@ -38,12 +38,12 @@ namespace Prospect.Server.Api.Services.Auth
return _tokenHandler.WriteToken(token);
}
public string GenerateUser(PlayFabEntity user)
public string GenerateUser(PlayFabEntity entity)
{
return CreateToken(new[]
{
new Claim(AuthClaimTypes.UserId, user.UserId),
new Claim(AuthClaimTypes.EntityId, user.Id),
new Claim(AuthClaimTypes.UserId, entity.UserId),
new Claim(AuthClaimTypes.EntityId, entity.Id),
new Claim(AuthClaimTypes.Type, AuthType.User),
});
}
@@ -52,6 +52,7 @@ namespace Prospect.Server.Api.Services.Auth
{
return CreateToken(new[]
{
new Claim(AuthClaimTypes.UserId, entity.UserId),
new Claim(AuthClaimTypes.EntityId, entity.Id),
new Claim(AuthClaimTypes.Type, AuthType.Entity),
});
@@ -47,5 +47,14 @@ namespace Prospect.Server.Api.Services.Database
return await query.ToCursorAsync();
}
public async Task UpdateValueAsync(string dataId, string value)
{
var update = Builders<PlayFabUserData>.Update
.Set(data => data.Value, value)
.Set(data => data.LastUpdated, DateTime.UtcNow);
await Collection.UpdateOneAsync(data => data.Id == dataId, update);
}
}
}
@@ -117,5 +117,66 @@ namespace Prospect.Server.Api.Services.UserData
return result;
}
/// <summary>
///
/// </summary>
/// <param name="currentUserId">
/// The authenticated user id.
/// </param>
/// <param name="requestUserId">
/// The requested user id.
/// </param>
/// <param name="changes"></param>
/// <returns></returns>
public async Task UpdateAsync(
string currentUserId,
string requestUserId,
Dictionary<string, string> changes)
{
if (changes.Count == 0)
{
return;
}
if (string.IsNullOrEmpty(currentUserId))
{
throw new ArgumentNullException(nameof(currentUserId));
}
if (requestUserId == null)
{
requestUserId = currentUserId;
}
// Whether we are updating someone else.
var other = currentUserId != requestUserId;
foreach (var (key, value) in changes)
{
var data = await _dbUserDataService.FindAsync(currentUserId, key);
if (data == null)
{
if (other)
{
_logger.LogWarning("User {PlayFabId} attempted to update non-existing key {Key} of another user {PlayFabIdOther}", currentUserId, key, requestUserId);
}
else
{
await _dbUserDataService.InsertAsync(currentUserId, key, value, false);
}
continue;
}
if (!data.Public && other)
{
_logger.LogWarning("User {PlayFabId} attempted to update non-public key {Key} of another user {PlayFabIdOther}", currentUserId, key, data.PlayFabId);
continue;
}
await _dbUserDataService.UpdateValueAsync(data.Id, value);
}
}
}
}