2020-01-31 21:15:07 -05:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Commands;
|
|
|
|
|
using SharedLibraryCore.Configuration;
|
|
|
|
|
using SharedLibraryCore.Database.Models;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using System.Threading.Tasks;
|
2022-06-15 20:37:34 -04:00
|
|
|
|
using SharedLibraryCore.Helpers;
|
2020-01-31 21:15:07 -05:00
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin.Plugins.Login.Commands
|
|
|
|
|
{
|
|
|
|
|
public class LoginCommand : Command
|
|
|
|
|
{
|
|
|
|
|
public LoginCommand(CommandConfiguration config, ITranslationLookup translationLookup) : base(config, translationLookup)
|
|
|
|
|
{
|
|
|
|
|
Name = "login";
|
|
|
|
|
Description = _translationLookup["PLUGINS_LOGIN_COMMANDS_LOGIN_DESC"];
|
|
|
|
|
Alias = "li";
|
|
|
|
|
Permission = EFClient.Permission.Trusted;
|
|
|
|
|
RequiresTarget = false;
|
|
|
|
|
Arguments = new CommandArgument[]
|
|
|
|
|
{
|
2022-06-15 20:37:34 -04:00
|
|
|
|
new()
|
2020-01-31 21:15:07 -05:00
|
|
|
|
{
|
|
|
|
|
Name = Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_ARGS_PASSWORD"],
|
|
|
|
|
Required = true
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 20:37:34 -04:00
|
|
|
|
public override async Task ExecuteAsync(GameEvent gameEvent)
|
2020-01-31 21:15:07 -05:00
|
|
|
|
{
|
2022-06-15 20:37:34 -04:00
|
|
|
|
var success = gameEvent.Owner.Manager.TokenAuthenticator.AuthorizeToken(new TokenIdentifier
|
|
|
|
|
{
|
2022-06-16 11:07:03 -04:00
|
|
|
|
ClientId = gameEvent.Origin.ClientId,
|
2022-06-15 20:37:34 -04:00
|
|
|
|
Token = gameEvent.Data
|
|
|
|
|
});
|
2020-01-31 21:15:07 -05:00
|
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
|
{
|
2022-06-15 20:37:34 -04:00
|
|
|
|
var hashedPassword = await Task.FromResult(Hashing.Hash(gameEvent.Data, gameEvent.Origin.PasswordSalt));
|
|
|
|
|
success = hashedPassword[0] == gameEvent.Origin.Password;
|
2020-01-31 21:15:07 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
2022-06-15 20:37:34 -04:00
|
|
|
|
Plugin.AuthorizedClients[gameEvent.Origin.ClientId] = true;
|
2020-01-31 21:15:07 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_ = success ?
|
2022-06-15 20:37:34 -04:00
|
|
|
|
gameEvent.Origin.Tell(_translationLookup["PLUGINS_LOGIN_COMMANDS_LOGIN_SUCCESS"]) :
|
|
|
|
|
gameEvent.Origin.Tell(_translationLookup["PLUGINS_LOGIN_COMMANDS_LOGIN_FAIL"]);
|
2020-01-31 21:15:07 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|