update schema to support unique guid + game combinations

This commit is contained in:
RaidMax
2022-06-15 19:37:34 -05:00
parent deeb1dea87
commit 8ae6561f4e
46 changed files with 5449 additions and 181 deletions

View File

@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.Extensions.Logging;
using SharedLibraryCore;
using SharedLibraryCore.Helpers;
using SharedLibraryCore.Services;
using WebfrontCore.Controllers.API.Dtos;
using ILogger = Microsoft.Extensions.Logging.ILogger;
@ -100,9 +101,16 @@ namespace WebfrontCore.Controllers.API
if (!Authorized)
{
var tokenData = new TokenIdentifier
{
Game = privilegedClient.GameName,
Token = request.Password,
NetworkId = privilegedClient.NetworkId
};
loginSuccess =
Manager.TokenAuthenticator.AuthorizeToken(privilegedClient.NetworkId, request.Password) ||
(await Task.FromResult(SharedLibraryCore.Helpers.Hashing.Hash(request.Password,
Manager.TokenAuthenticator.AuthorizeToken(tokenData) ||
(await Task.FromResult(Hashing.Hash(request.Password,
privilegedClient.PasswordSalt)))[0] == privilegedClient.Password;
}
@ -120,7 +128,7 @@ namespace WebfrontCore.Controllers.API
var claimsPrinciple = new ClaimsPrincipal(claimsIdentity);
await SignInAsync(claimsPrinciple);
Manager.AddEvent(new GameEvent()
Manager.AddEvent(new GameEvent
{
Origin = privilegedClient,
Type = GameEvent.EventType.Login,
@ -149,7 +157,7 @@ namespace WebfrontCore.Controllers.API
{
if (Authorized)
{
Manager.AddEvent(new GameEvent()
Manager.AddEvent(new GameEvent
{
Origin = Client,
Type = GameEvent.EventType.Logout,

View File

@ -7,7 +7,7 @@ using System;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using SharedLibraryCore.Helpers;
namespace WebfrontCore.Controllers
{
@ -19,6 +19,7 @@ namespace WebfrontCore.Controllers
}
[HttpGet]
[Obsolete]
public async Task<IActionResult> Login(int clientId, string password)
{
if (clientId == 0 || string.IsNullOrEmpty(password))
@ -29,14 +30,23 @@ namespace WebfrontCore.Controllers
try
{
var privilegedClient = await Manager.GetClientService().GetClientForLogin(clientId);
bool loginSuccess = false;
#if DEBUG
loginSuccess = clientId == 1;
#endif
var loginSuccess = false;
if (Utilities.IsDevelopment)
{
loginSuccess = clientId == 1;
}
if (!Authorized && !loginSuccess)
{
loginSuccess = Manager.TokenAuthenticator.AuthorizeToken(privilegedClient.NetworkId, password) ||
(await Task.FromResult(SharedLibraryCore.Helpers.Hashing.Hash(password, privilegedClient.PasswordSalt)))[0] == privilegedClient.Password;
loginSuccess = Manager.TokenAuthenticator.AuthorizeToken(new TokenIdentifier
{
NetworkId = privilegedClient.NetworkId,
Game = privilegedClient.GameName,
Token = password
}) ||
(await Task.FromResult(Hashing.Hash(password, privilegedClient.PasswordSalt)))[0] ==
privilegedClient.Password;
}
if (loginSuccess)
@ -46,21 +56,22 @@ namespace WebfrontCore.Controllers
new Claim(ClaimTypes.NameIdentifier, privilegedClient.Name),
new Claim(ClaimTypes.Role, privilegedClient.Level.ToString()),
new Claim(ClaimTypes.Sid, privilegedClient.ClientId.ToString()),
new Claim(ClaimTypes.PrimarySid, privilegedClient.NetworkId.ToString("X"))
new Claim(ClaimTypes.PrimarySid, privilegedClient.NetworkId.ToString("X")),
new Claim(ClaimTypes.PrimaryGroupSid, privilegedClient.GameName.ToString())
};
var claimsIdentity = new ClaimsIdentity(claims, "login");
var claimsPrinciple = new ClaimsPrincipal(claimsIdentity);
await SignInAsync(claimsPrinciple);
Manager.AddEvent(new GameEvent()
Manager.AddEvent(new GameEvent
{
Origin = privilegedClient,
Type = GameEvent.EventType.Login,
Owner = Manager.GetServers().First(),
Data = HttpContext.Request.Headers.ContainsKey("X-Forwarded-For")
? HttpContext.Request.Headers["X-Forwarded-For"].ToString()
: HttpContext.Connection.RemoteIpAddress.ToString()
: HttpContext.Connection.RemoteIpAddress?.ToString()
});
return Ok($"Welcome {privilegedClient.Name}. You are now logged in");
@ -80,14 +91,14 @@ namespace WebfrontCore.Controllers
{
if (Authorized)
{
Manager.AddEvent(new GameEvent()
Manager.AddEvent(new GameEvent
{
Origin = Client,
Type = GameEvent.EventType.Logout,
Owner = Manager.GetServers().First(),
Data = HttpContext.Request.Headers.ContainsKey("X-Forwarded-For")
? HttpContext.Request.Headers["X-Forwarded-For"].ToString()
: HttpContext.Connection.RemoteIpAddress.ToString()
: HttpContext.Connection.RemoteIpAddress?.ToString()
});
}

View File

@ -10,6 +10,7 @@ using SharedLibraryCore;
using SharedLibraryCore.Commands;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Dtos;
using SharedLibraryCore.Helpers;
using SharedLibraryCore.Interfaces;
using WebfrontCore.Permissions;
using WebfrontCore.ViewModels;
@ -274,7 +275,12 @@ namespace WebfrontCore.Controllers
[Authorize]
public string GenerateLoginTokenAsync()
{
var state = Manager.TokenAuthenticator.GenerateNextToken(Client.NetworkId);
var state = Manager.TokenAuthenticator.GenerateNextToken(new TokenIdentifier
{
NetworkId = Client.NetworkId,
Game = Client.GameName
});
return string.Format(Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_GENERATETOKEN_SUCCESS"],
state.Token,
$"{state.RemainingTime} {Utilities.CurrentLocalization.LocalizationIndex["GLOBAL_MINUTES"]}",

View File

@ -47,7 +47,7 @@ namespace WebfrontCore.Controllers
}
var activePenalties = await Manager.GetPenaltyService().GetActivePenaltiesAsync(client.AliasLinkId,
client.CurrentAliasId, client.NetworkId, client.IPAddress);
client.CurrentAliasId, client.NetworkId, client.GameName, client.IPAddress);
var persistentMetaTask = new[]
{
@ -88,7 +88,7 @@ namespace WebfrontCore.Controllers
var clientDto = new PlayerInfo
{
Name = client.Name,
Game = client.GameName ?? Reference.Game.UKN,
Game = client.GameName,
Level = displayLevel,
LevelInt = displayLevelInt,
ClientId = client.ClientId,
@ -183,7 +183,7 @@ namespace WebfrontCore.Controllers
ClientId = admin.ClientId,
LastConnection = admin.LastConnection,
IsMasked = admin.Masked,
Game = admin.GameName ?? Reference.Game.UKN
Game = admin.GameName
});
}

View File

@ -34,7 +34,12 @@ namespace WebfrontCore.Controllers
{
ClientId = id,
ServerEndpoint = serverId
})).Results.First();
}))?.Results?.First();
if (hitInfo is null)
{
return NotFound();
}
var server = Manager.GetServers().FirstOrDefault(server => server.ToString() == serverId);
long? matchedServerId = null;