diff --git a/Application/Misc/TokenAuthentication.cs b/Application/Misc/TokenAuthentication.cs index d87887d2..f88a3e42 100644 --- a/Application/Misc/TokenAuthentication.cs +++ b/Application/Misc/TokenAuthentication.cs @@ -9,25 +9,25 @@ namespace IW4MAdmin.Application.Misc { internal class TokenAuthentication : ITokenAuthentication { - private readonly ConcurrentDictionary _tokens; + private readonly ConcurrentDictionary _tokens; private readonly RandomNumberGenerator _random; private static readonly TimeSpan TimeoutPeriod = new(0, 0, 120); private const short TokenLength = 4; public TokenAuthentication() { - _tokens = new ConcurrentDictionary(); + _tokens = new ConcurrentDictionary(); _random = RandomNumberGenerator.Create(); } public bool AuthorizeToken(ITokenIdentifier authInfo) { - var key = BuildKey(authInfo); - var authorizeSuccessful = _tokens.ContainsKey(key) && _tokens[key].Token == key; + var authorizeSuccessful = _tokens.ContainsKey(authInfo.ClientId) && + _tokens[authInfo.ClientId].Token == authInfo.Token; if (authorizeSuccessful) { - _tokens.TryRemove(key, out _); + _tokens.TryRemove(authInfo.ClientId, out _); } return authorizeSuccessful; @@ -36,15 +36,14 @@ namespace IW4MAdmin.Application.Misc public TokenState GenerateNextToken(ITokenIdentifier authInfo) { TokenState state; - var genKey = BuildKey(authInfo); - if (_tokens.ContainsKey(genKey)) + if (_tokens.ContainsKey(authInfo.ClientId)) { - state = _tokens[genKey]; + state = _tokens[authInfo.ClientId]; if (DateTime.Now - state.RequestTime > TimeoutPeriod) { - _tokens.TryRemove(genKey, out _); + _tokens.TryRemove(authInfo.ClientId, out _); } else @@ -59,12 +58,12 @@ namespace IW4MAdmin.Application.Misc TokenDuration = TimeoutPeriod }; - _tokens.TryAdd(genKey, state); + _tokens.TryAdd(authInfo.ClientId, state); // perform some housekeeping so we don't have built up tokens if they're not ever used foreach (var (key, value) in _tokens) { - if ((DateTime.Now - value.RequestTime) > TimeoutPeriod) + if (DateTime.Now - value.RequestTime > TimeoutPeriod) { _tokens.TryRemove(key, out _); } @@ -97,7 +96,5 @@ namespace IW4MAdmin.Application.Misc _random.Dispose(); return token.ToString(); } - - private string BuildKey(ITokenIdentifier authInfo) => $"{authInfo.NetworkId}_${authInfo.Game}"; } } diff --git a/Plugins/AutomessageFeed/AutomessageFeed.csproj b/Plugins/AutomessageFeed/AutomessageFeed.csproj index 67c07f89..7f279a2a 100644 --- a/Plugins/AutomessageFeed/AutomessageFeed.csproj +++ b/Plugins/AutomessageFeed/AutomessageFeed.csproj @@ -10,7 +10,7 @@ - + diff --git a/Plugins/LiveRadar/LiveRadar.csproj b/Plugins/LiveRadar/LiveRadar.csproj index 110d4ca4..5c9bb5df 100644 --- a/Plugins/LiveRadar/LiveRadar.csproj +++ b/Plugins/LiveRadar/LiveRadar.csproj @@ -16,7 +16,7 @@ - + diff --git a/Plugins/Login/Commands/LoginCommand.cs b/Plugins/Login/Commands/LoginCommand.cs index 64ce6abb..61392068 100644 --- a/Plugins/Login/Commands/LoginCommand.cs +++ b/Plugins/Login/Commands/LoginCommand.cs @@ -31,8 +31,7 @@ namespace IW4MAdmin.Plugins.Login.Commands { var success = gameEvent.Owner.Manager.TokenAuthenticator.AuthorizeToken(new TokenIdentifier { - NetworkId = gameEvent.Origin.NetworkId, - Game = gameEvent.Origin.GameName, + ClientId = gameEvent.Origin.ClientId, Token = gameEvent.Data }); diff --git a/Plugins/Login/Login.csproj b/Plugins/Login/Login.csproj index ba07b94f..d412e524 100644 --- a/Plugins/Login/Login.csproj +++ b/Plugins/Login/Login.csproj @@ -19,7 +19,7 @@ - + diff --git a/Plugins/ProfanityDeterment/ProfanityDeterment.csproj b/Plugins/ProfanityDeterment/ProfanityDeterment.csproj index 7cb9202c..b52745c3 100644 --- a/Plugins/ProfanityDeterment/ProfanityDeterment.csproj +++ b/Plugins/ProfanityDeterment/ProfanityDeterment.csproj @@ -16,7 +16,7 @@ - + diff --git a/Plugins/Stats/Stats.csproj b/Plugins/Stats/Stats.csproj index d466aba9..b355f5b6 100644 --- a/Plugins/Stats/Stats.csproj +++ b/Plugins/Stats/Stats.csproj @@ -17,7 +17,7 @@ - + diff --git a/Plugins/Welcome/Welcome.csproj b/Plugins/Welcome/Welcome.csproj index 29d82435..30b841bf 100644 --- a/Plugins/Welcome/Welcome.csproj +++ b/Plugins/Welcome/Welcome.csproj @@ -20,7 +20,7 @@ - + diff --git a/SharedLibraryCore/Commands/RequestTokenCommand.cs b/SharedLibraryCore/Commands/RequestTokenCommand.cs index 9988b52a..a4be2470 100644 --- a/SharedLibraryCore/Commands/RequestTokenCommand.cs +++ b/SharedLibraryCore/Commands/RequestTokenCommand.cs @@ -24,8 +24,7 @@ namespace SharedLibraryCore.Commands { var state = gameEvent.Owner.Manager.TokenAuthenticator.GenerateNextToken(new TokenIdentifier { - Game = gameEvent.Origin.GameName, - NetworkId = gameEvent.Origin.NetworkId + ClientId = gameEvent.Origin.ClientId }); gameEvent.Origin.Tell(string.Format(_translationLookup["COMMANDS_GENERATETOKEN_SUCCESS"], state.Token, $"{state.RemainingTime} {_translationLookup["GLOBAL_MINUTES"]}", gameEvent.Origin.ClientId)); diff --git a/SharedLibraryCore/Helpers/TokenIdentifier.cs b/SharedLibraryCore/Helpers/TokenIdentifier.cs index b03eb933..da99aa34 100644 --- a/SharedLibraryCore/Helpers/TokenIdentifier.cs +++ b/SharedLibraryCore/Helpers/TokenIdentifier.cs @@ -1,11 +1,9 @@ -using Data.Models; -using SharedLibraryCore.Interfaces; +using SharedLibraryCore.Interfaces; namespace SharedLibraryCore.Helpers; public class TokenIdentifier : ITokenIdentifier { - public long NetworkId { get; set; } - public Reference.Game Game { get; set; } + public int ClientId { get; set; } public string Token { get; set; } } diff --git a/SharedLibraryCore/Interfaces/ITokenIdentifier.cs b/SharedLibraryCore/Interfaces/ITokenIdentifier.cs index 0e2e0a0e..a42e014f 100644 --- a/SharedLibraryCore/Interfaces/ITokenIdentifier.cs +++ b/SharedLibraryCore/Interfaces/ITokenIdentifier.cs @@ -1,11 +1,7 @@ - -using Data.Models; - -namespace SharedLibraryCore.Interfaces; +namespace SharedLibraryCore.Interfaces; public interface ITokenIdentifier { - long NetworkId { get; } - Reference.Game Game { get; set; } - string Token { get; set; } + int ClientId { get; } + string Token { get; } } diff --git a/WebfrontCore/Controllers/API/ClientController.cs b/WebfrontCore/Controllers/API/ClientController.cs index 9c980e77..50372502 100644 --- a/WebfrontCore/Controllers/API/ClientController.cs +++ b/WebfrontCore/Controllers/API/ClientController.cs @@ -103,9 +103,8 @@ namespace WebfrontCore.Controllers.API { var tokenData = new TokenIdentifier { - Game = privilegedClient.GameName, - Token = request.Password, - NetworkId = privilegedClient.NetworkId + ClientId = clientId, + Token = request.Password }; loginSuccess = diff --git a/WebfrontCore/Controllers/AccountController.cs b/WebfrontCore/Controllers/AccountController.cs index e2302dbe..d90d3cc0 100644 --- a/WebfrontCore/Controllers/AccountController.cs +++ b/WebfrontCore/Controllers/AccountController.cs @@ -41,8 +41,7 @@ namespace WebfrontCore.Controllers { loginSuccess = Manager.TokenAuthenticator.AuthorizeToken(new TokenIdentifier { - NetworkId = privilegedClient.NetworkId, - Game = privilegedClient.GameName, + ClientId = clientId, Token = password }) || (await Task.FromResult(Hashing.Hash(password, privilegedClient.PasswordSalt)))[0] == diff --git a/WebfrontCore/Controllers/ActionController.cs b/WebfrontCore/Controllers/ActionController.cs index bfd872b3..552e5993 100644 --- a/WebfrontCore/Controllers/ActionController.cs +++ b/WebfrontCore/Controllers/ActionController.cs @@ -277,8 +277,7 @@ namespace WebfrontCore.Controllers { var state = Manager.TokenAuthenticator.GenerateNextToken(new TokenIdentifier { - NetworkId = Client.NetworkId, - Game = Client.GameName + ClientId = Client.ClientId }); return string.Format(Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_GENERATETOKEN_SUCCESS"], diff --git a/WebfrontCore/wwwroot/css/src/main.scss b/WebfrontCore/wwwroot/css/src/main.scss index 62a03560..1bf08eda 100644 --- a/WebfrontCore/wwwroot/css/src/main.scss +++ b/WebfrontCore/wwwroot/css/src/main.scss @@ -454,6 +454,6 @@ img.social-icon { margin-top: 3px; } -.sidebar-link .oi { - min-width: 16px; +.sidebar-link .oi, .sidebar-link img { + min-width: 1.2rem; }