118 lines
3.9 KiB
C#
118 lines
3.9 KiB
C#
using SharedLibraryCore;
|
|
using SharedLibraryCore.Interfaces;
|
|
using System.Threading.Tasks;
|
|
using System.Threading;
|
|
using SharedLibraryCore.Database.Models;
|
|
using System.Collections.Generic;
|
|
using Microsoft.Extensions.Logging;
|
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
|
using Data.Models;
|
|
using System;
|
|
|
|
|
|
namespace ClanTagRankCommands
|
|
{
|
|
|
|
public class Plugin : IPlugin
|
|
{
|
|
private readonly IConfigurationHandler<Configuration> _configurationHandler;
|
|
private readonly ILogger _logger;
|
|
private Configuration Config;
|
|
//readonly string rank = "rank";
|
|
//string rankName = "none";
|
|
|
|
|
|
|
|
public string Name => "ClanTagRankCommands";
|
|
|
|
public float Version => 1.42f;
|
|
|
|
public string Author => "INSANEMODE";
|
|
|
|
private readonly IMetaServiceV2 _metaService;
|
|
|
|
public Plugin(IMetaServiceV2 metaService, IConfigurationHandlerFactory configurationHandlerFactory, ILogger<Plugin> logger)
|
|
{
|
|
_logger = logger;
|
|
_metaService = metaService;
|
|
_configurationHandler = (IConfigurationHandler<Configuration>)configurationHandlerFactory.GetConfigurationHandler<Configuration>("ClanTagRankCommands");
|
|
}
|
|
public Task OnLoadAsync(IManager manager)// => Task.CompletedTask;
|
|
{
|
|
if (_configurationHandler.Configuration() == null)
|
|
{
|
|
_configurationHandler.Set((Configuration)new Configuration().Generate());
|
|
_configurationHandler.Save();
|
|
}
|
|
Config = _configurationHandler.Configuration();
|
|
string version = manager.Version;
|
|
string str = string.Format("Loaded {0} ({1}) by {2} in {3} ({4})!", (object)((IPlugin)this).Name, (object)((IPlugin)this).Version, (object)((IPlugin)this).Author, (object)"IW4MAdmin", (object)version);
|
|
_logger.LogInformation(str);
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
public async Task OnEventAsync(GameEvent E, Server S)// => Task.CompletedTask;
|
|
{
|
|
if (E.Type == GameEvent.EventType.Disconnect && E.Origin.Tag == "Guest")
|
|
{
|
|
E.Origin.Tag = null;
|
|
await _metaService.RemovePersistentMeta(EFMeta.ClientTagV2, E.Origin.ClientId,
|
|
E.Owner.Manager.CancellationToken);
|
|
}
|
|
|
|
}
|
|
public Task OnTickAsync(Server S)// =>
|
|
{
|
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
|
|
|
public Task OnUnloadAsync() => Task.CompletedTask;
|
|
|
|
|
|
}
|
|
public static class yadb
|
|
{
|
|
public static Task notifyYADB(string message, string title, string reason, string icon, Server S, EFClient OriginClient, EFClient TargetClient)
|
|
{
|
|
string json = "";
|
|
using (var stream = new System.IO.MemoryStream())
|
|
{
|
|
using (var writer = new System.Text.Json.Utf8JsonWriter(stream))
|
|
{
|
|
writer.WriteStartObject();
|
|
writer.WriteString("title", title);
|
|
writer.WriteString("message", message);
|
|
writer.WriteString("reason", reason);
|
|
writer.WriteString("icon", icon);
|
|
writer.WriteEndObject();
|
|
}
|
|
|
|
json = System.Text.Encoding.UTF8.GetString(stream.ToArray());
|
|
}
|
|
var e = new GameEvent()
|
|
{
|
|
Origin = OriginClient,
|
|
Target = TargetClient,
|
|
Owner = S,
|
|
Type = GameEvent.EventType.Other,
|
|
Subtype = "YADB-Embed",
|
|
Extra = json
|
|
};
|
|
|
|
S.ExecuteEvent(e);
|
|
Console.WriteLine("event triggered!" + message);
|
|
return Task.CompletedTask;
|
|
|
|
|
|
|
|
//notifyYADB("Kicked player @{target} after a successful vote started from @{origin}", $"Vote kicked {target.Name}", gameEvent.Data,":pencil:", Server, origin, target);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|