IW4M-Admin/Plugins/Login/Commands/CLogin.cs

41 lines
1.5 KiB
C#
Raw Normal View History

2018-04-14 00:51:38 -04:00
using SharedLibraryCore;
using SharedLibraryCore.Database.Models;
2018-04-14 00:51:38 -04:00
using System.Threading.Tasks;
namespace IW4MAdmin.Plugins.Login.Commands
{
public class CLogin : Command
{
public CLogin() : base("login", Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_LOGIN_COMMANDS_LOGIN_DESC"], "li", EFClient.Permission.Trusted, false, new CommandArgument[]
2018-04-14 00:51:38 -04:00
{
new CommandArgument()
{
Name = Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_ARGS_PASSWORD"],
2018-04-14 00:51:38 -04:00
Required = true
}
})
{ }
2018-04-14 00:51:38 -04:00
public override async Task ExecuteAsync(GameEvent E)
{
var client = E.Owner.Manager.GetPrivilegedClients()[E.Origin.ClientId];
bool success = E.Owner.Manager.TokenAuthenticator.AuthorizeToken(E.Origin.NetworkId, E.Data);
2018-04-14 00:51:38 -04:00
if (!success)
2018-04-14 00:51:38 -04:00
{
string[] hashedPassword = await Task.FromResult(SharedLibraryCore.Helpers.Hashing.Hash(E.Data, client.PasswordSalt));
success = hashedPassword[0] == client.Password;
}
if (success)
{
Plugin.AuthorizedClients[E.Origin.ClientId] = true;
2018-04-14 00:51:38 -04:00
}
_ = success ?
E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_LOGIN_COMMANDS_LOGIN_SUCCESS"]) :
E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_LOGIN_COMMANDS_LOGIN_FAIL"]);
2018-04-14 00:51:38 -04:00
}
}
}