update version, and add support for renaming default rank names through ClanTagCommands.json

This commit is contained in:
INSANEMODE 2020-11-20 04:05:14 -06:00
parent eed006b0fe
commit 50a6c83913
6 changed files with 99 additions and 33 deletions

View File

@ -1,54 +1,63 @@

using SharedLibraryCore.Database.Models;
using SharedLibraryCore;
using SharedLibraryCore.Interfaces;
namespace ClanTagRankApi
{
public static class ExtensionMethods
static class ExtensionMethods
{
public static string ClanTag(this EFClient.Permission level)
public static string Truncate(this string input, int strLength)
{
if (string.IsNullOrEmpty(input)) return input;
return input.Length <= strLength ? input : input.Substring(0, strLength);
}
public static string ClanTag(this EFClient.Permission level, Configuration Config)
{
string rankName;
switch ((int)level)
{
case -1:
rankName = "Banned"; //this typically won't be seen.
break;
case 0:
rankName = "User";
rankName = Config.User;
break;
case 1:
rankName = "User"; //1 = flagged, but don't want to show this in game.
rankName = Config.User; //1 = flagged, but don't want to show this in game.
break;
case 2:
rankName = "Trusted";
rankName = Config.Trusted;
break;
case 3:
rankName = "Mod";
rankName = Config.Moderator;
break;
case 4:
rankName = "Admin";
rankName = Config.Admin;
break;
case 5:
rankName = "SrAdmin";
rankName = Config.SeniorAdmin;
break;
case 6:
rankName = "Owner";
rankName = Config.Owner;
break;
case 7:
rankName = "Creator";
rankName = Config.Creator;
break;
case 8:
rankName = "Console";
rankName = Config.Console;
break;
default:
rankName = "User";
rankName = Config.User;
break;
}
return rankName;
return rankName.Truncate(8);
}
}
}

View File

@ -3,6 +3,7 @@ using SharedLibraryCore.Commands;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces;
using System;
using System.Threading.Tasks;
@ -17,10 +18,20 @@ namespace ClanTagRankApi.Commands
readonly string rank = "rank";
string rank_string;
private readonly IMetaService _metaService;
private readonly IConfigurationHandler<Configuration> _configurationHandler;
private Configuration Config;
public ResetRankCommand(CommandConfiguration config, ITranslationLookup lookup, IMetaService metaService) : base(config, lookup)
public ResetRankCommand(CommandConfiguration config, ITranslationLookup lookup, IMetaService metaService, IConfigurationHandlerFactory configurationHandlerFactory) : base(config, lookup)
{
_metaService = metaService;
_configurationHandler = configurationHandlerFactory.GetConfigurationHandler<Configuration>("ClanTagRankCommands");
if (_configurationHandler.Configuration() == null)
{
_configurationHandler.Set((Configuration)new Configuration().Generate());
_configurationHandler.Save();
}
Config = _configurationHandler.Configuration();
Name = "ResetRank";
Description = "set a user's clan tag Rank (does not give permissions)";
Alias = "rr";
@ -41,7 +52,7 @@ namespace ClanTagRankApi.Commands
//var S = E.Owner;
rank_string = "none";
await _metaService.AddPersistentMeta(rank, rank_string, E.Target);
rank_string = E.Target.Level.ClanTag();
rank_string = E.Target.Level.ClanTag(Config);
E.Origin.Tell(E.Target.Name + "'s rank has been reset to: " + rank_string);
await E.Owner.ExecuteCommandAsync("setrank" + " " + E.Target.ClientNumber + " " + rank_string);
}

View File

@ -6,21 +6,34 @@ using SharedLibraryCore.Interfaces;
using System.Threading.Tasks;
namespace ClanTagRankApi.Commands
{
/// <summary>
/// Example script command
/// </summary>
///
public class SetRankCommand : Command
{
readonly string rank = "rank";
string rank_string;
private readonly IMetaService _metaService;
private readonly IConfigurationHandler<Configuration> _configurationHandler;
private Configuration Config;
public SetRankCommand(CommandConfiguration config, ITranslationLookup lookup, IMetaService metaService) : base(config, lookup)
public SetRankCommand(CommandConfiguration config, ITranslationLookup lookup, IMetaService metaService, IConfigurationHandlerFactory configurationHandlerFactory) : base(config, lookup)
{
_metaService = metaService;
_configurationHandler = configurationHandlerFactory.GetConfigurationHandler<Configuration>("ClanTagRankCommands");
if (_configurationHandler.Configuration() == null)
{
_configurationHandler.Set((Configuration)new Configuration().Generate());
_configurationHandler.Save();
}
Config = _configurationHandler.Configuration();
Name = "SetRank";
Description = "set a user's clan tag Rank (does not give permissions)";
Alias = "sr";
@ -56,8 +69,9 @@ namespace ClanTagRankApi.Commands
rank_player_var = await _metaService.GetPersistentMeta(rank, E.Target);
if(rank_player_var.Value == "none" || rank_player_var.Value == "None" || rank_player_var.Value == "NONE")
{
//E.Origin.Tell(E.Target.Name + "'s rank has been reset");
rank_string = E.Target.Level.ClanTag();
rank_string = E.Target.Level.ClanTag(Config);
E.Origin.Tell(E.Target.Name + "'s rank has been reset to: " + rank_string);
}

View File

@ -3,18 +3,36 @@ using SharedLibraryCore.Interfaces;
namespace ClanTagRankApi
{
internal class Configuration : IBaseConfiguration
public class Configuration : IBaseConfiguration
{
internal const string _name = "IW4MAdmin";
public int RestartTimerLength { get; set; }
public string WARNING { get; set; }
public string User { get; set; }
public string Trusted { get; set; }
public string Moderator { get; set; }
public string Admin { get; set; }
public string SeniorAdmin { get; set; }
public string Owner { get; set; }
public string Creator { get; set; }
public string Console { get; set; }
public IBaseConfiguration Generate()
{
//this.RestartTimerLength = Utilities.PromptInt("How long in seconds until a server is killed after it is empty?", (string)null, 60, 86400, new int?(43200));
this.WARNING = "Do Not Exceed 8 characters, names will be truncated.";
this.User = "User";
this.Trusted = "Trusted";
this.Moderator = "Mod";
this.Admin = "Admin";
this.SeniorAdmin = "SrAdmin";
this.Owner = "Owner";
this.Creator = "Creator";
this.Console = "Console";
return (IBaseConfiguration)this;
}
string IBaseConfiguration.Name() => "ClanTagRankApi";
string IBaseConfiguration.Name() => "ClanTagRankCommands";
}
}

View File

@ -6,6 +6,7 @@ using SharedLibraryCore.Interfaces;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Xsl;
namespace WebfrontCore.Controllers.API
{
@ -16,9 +17,19 @@ namespace WebfrontCore.Controllers.API
string rankName;
EFMeta customRankName;
private readonly IMetaService _metaService;
public GscApiController(IManager manager, IMetaService metaService) : base(manager)
private readonly IConfigurationHandler<Configuration> _configurationHandler;
private Configuration Config;
public GscApiController(IManager manager, IMetaService metaService, IConfigurationHandlerFactory configurationHandlerFactory) : base(manager)
{
_metaService = metaService;
_configurationHandler = configurationHandlerFactory.GetConfigurationHandler<Configuration>("ClanTagRankCommands");
if (_configurationHandler.Configuration() == null)
{
_configurationHandler.Set((Configuration)new Configuration().Generate());
_configurationHandler.Save();
}
Config = _configurationHandler.Configuration();
}
/// <summary>
@ -36,7 +47,7 @@ namespace WebfrontCore.Controllers.API
if (clientInfo != null)
{
rankName = clientInfo.Level.ClanTag();
rankName = clientInfo.Level.ClanTag(Config);
customRankName = await _metaService.GetPersistentMeta("rank", clientInfo);
if (customRankName == null)
@ -70,7 +81,7 @@ namespace WebfrontCore.Controllers.API
if (clientInfo != null)
{
rankName = clientInfo.Level.ClanTag();
rankName = clientInfo.Level.ClanTag(Config);
customRankName = await _metaService.GetPersistentMeta("rank", clientInfo);
if (customRankName == null)

View File

@ -4,6 +4,8 @@ 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;
namespace ClanTagRankApi
@ -12,24 +14,26 @@ namespace ClanTagRankApi
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 => "ClanTagRankApi";
public string Name => "ClanTagRankCommands";
public float Version => 1.3f;
public float Version => 1.31f;
public string Author => "INSANEMODE";
private readonly IMetaService _metaService;
public Plugin(IMetaService metaService, IConfigurationHandlerFactory configurationHandlerFactory)
public Plugin(IMetaService metaService, IConfigurationHandlerFactory configurationHandlerFactory, ILogger<Plugin> logger)
{
_logger = logger;
_metaService = metaService;
_configurationHandler = (IConfigurationHandler<Configuration>)configurationHandlerFactory.GetConfigurationHandler<Configuration>("ClanTagRankApi");
_configurationHandler = (IConfigurationHandler<Configuration>)configurationHandlerFactory.GetConfigurationHandler<Configuration>("ClanTagRankCommands");
}
public Task OnLoadAsync(IManager manager)// => Task.CompletedTask;
{
@ -41,7 +45,7 @@ namespace ClanTagRankApi
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);
manager.GetLogger(0L).WriteVerbose(str);
_logger.LogInformation(str);
return Task.CompletedTask;
}
@ -51,7 +55,7 @@ namespace ClanTagRankApi
{
Thread.Sleep(10000);
var rank_player_var = await _metaService.GetPersistentMeta(rank, E.Origin);
rankName = E.Origin.Level.ClanTag();
rankName = E.Origin.Level.ClanTag(Config);
rank_player_var = await _metaService.GetPersistentMeta("rank", E.Origin);
if (rank_player_var == null)
@ -75,7 +79,7 @@ namespace ClanTagRankApi
foreach(EFClient client in currentclients)
{
var rank_player_var = await _metaService.GetPersistentMeta(rank, client);
rankName = client.Level.ClanTag();
rankName = client.Level.ClanTag(Config);
rank_player_var = await _metaService.GetPersistentMeta("rank", client);
if (rank_player_var == null)
@ -107,6 +111,5 @@ namespace ClanTagRankApi
public Task OnUnloadAsync() => Task.CompletedTask;
}
}