2018-04-14 00:51:38 -04:00
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Configuration;
|
|
|
|
|
using SharedLibraryCore.Exceptions;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-04-25 02:38:59 -04:00
|
|
|
|
using SharedLibraryCore.Objects;
|
2018-04-14 00:51:38 -04:00
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin.Plugins.Login
|
|
|
|
|
{
|
|
|
|
|
public class Plugin : IPlugin
|
|
|
|
|
{
|
|
|
|
|
public string Name => "Login";
|
|
|
|
|
|
|
|
|
|
public float Version => Assembly.GetExecutingAssembly().GetName().Version.Major + Assembly.GetExecutingAssembly().GetName().Version.Minor / 10.0f;
|
|
|
|
|
|
|
|
|
|
public string Author => "RaidMax";
|
|
|
|
|
|
|
|
|
|
public static ConcurrentDictionary<int, bool> AuthorizedClients { get; private set; }
|
|
|
|
|
private Configuration Config;
|
|
|
|
|
|
|
|
|
|
public Task OnEventAsync(GameEvent E, Server S)
|
|
|
|
|
{
|
|
|
|
|
if (E.Remote || Config.RequirePrivilegedClientLogin == false)
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
|
|
|
|
if (E.Type == GameEvent.EventType.Connect)
|
|
|
|
|
{
|
|
|
|
|
AuthorizedClients.TryAdd(E.Origin.ClientId, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (E.Type == GameEvent.EventType.Disconnect)
|
|
|
|
|
{
|
|
|
|
|
AuthorizedClients.TryRemove(E.Origin.ClientId, out bool value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (E.Type == GameEvent.EventType.Command)
|
|
|
|
|
{
|
2018-04-26 16:26:03 -04:00
|
|
|
|
if (E.Origin.Level < Player.Permission.Moderator ||
|
|
|
|
|
E.Origin.Level == Player.Permission.Console)
|
2018-04-15 21:27:43 -04:00
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
2018-04-25 02:38:59 -04:00
|
|
|
|
E.Owner.Manager.GetPrivilegedClients().TryGetValue(E.Origin.ClientId, out Player client);
|
|
|
|
|
|
2018-04-14 00:51:38 -04:00
|
|
|
|
if (((Command)E.Extra).Name == new SharedLibraryCore.Commands.CSetPassword().Name &&
|
2018-04-25 02:38:59 -04:00
|
|
|
|
client?.Password == null)
|
2018-04-14 00:51:38 -04:00
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
|
|
|
|
if (((Command)E.Extra).Name == new Commands.CLogin().Name)
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
|
|
|
|
if (!AuthorizedClients[E.Origin.ClientId])
|
2018-05-08 00:58:46 -04:00
|
|
|
|
throw new AuthorizationException(Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_LOGIN_AUTH"]);
|
2018-04-14 00:51:38 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task OnLoadAsync(IManager manager)
|
|
|
|
|
{
|
|
|
|
|
AuthorizedClients = new ConcurrentDictionary<int, bool>();
|
|
|
|
|
|
|
|
|
|
var cfg = new BaseConfigurationHandler<Configuration>("LoginPluginSettings");
|
|
|
|
|
if (cfg.Configuration() == null)
|
|
|
|
|
{
|
|
|
|
|
cfg.Set((Configuration)new Configuration().Generate());
|
|
|
|
|
await cfg.Save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Config = cfg.Configuration();
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 02:13:04 -04:00
|
|
|
|
public Task OnTickAsync(Server S) => Task.CompletedTask;
|
2018-04-14 00:51:38 -04:00
|
|
|
|
|
2018-04-26 02:13:04 -04:00
|
|
|
|
public Task OnUnloadAsync() => Task.CompletedTask;
|
2018-04-14 00:51:38 -04:00
|
|
|
|
}
|
|
|
|
|
}
|