implement custom tag (descriptor) feature
allow override of level names through configuration few small fixes/improvements
This commit is contained in:
37
SharedLibraryCore/Commands/AddClientTagCommand.cs
Normal file
37
SharedLibraryCore/Commands/AddClientTagCommand.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using SharedLibraryCore.Configuration;
|
||||
using SharedLibraryCore.Database.Models;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibraryCore.Commands
|
||||
{
|
||||
public class AddClientTagCommand : Command
|
||||
{
|
||||
private readonly IMetaService _metaService;
|
||||
|
||||
public AddClientTagCommand(CommandConfiguration config, ITranslationLookup layout, IMetaService metaService) : base(config, layout)
|
||||
{
|
||||
Name = "addclienttag";
|
||||
Description = layout["COMMANDS_ADD_CLIENT_TAG_DESC"];
|
||||
Alias = "act";
|
||||
Permission = EFClient.Permission.Owner;
|
||||
RequiresTarget = false;
|
||||
Arguments = new[]
|
||||
{
|
||||
new CommandArgument()
|
||||
{
|
||||
Name = _translationLookup["COMMANDS_ARGUMENT_TAG"],
|
||||
Required = true
|
||||
}
|
||||
};
|
||||
|
||||
_metaService = metaService;
|
||||
}
|
||||
|
||||
public override async Task ExecuteAsync(GameEvent gameEvent)
|
||||
{
|
||||
await _metaService.AddPersistentMeta(EFMeta.ClientTagName, gameEvent.Data);
|
||||
gameEvent.Origin.Tell(_translationLookup["COMMANDS_ADD_CLIENT_TAG_SUCCESS"].FormatExt(gameEvent.Data));
|
||||
}
|
||||
}
|
||||
}
|
33
SharedLibraryCore/Commands/ListClientTags.cs
Normal file
33
SharedLibraryCore/Commands/ListClientTags.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using SharedLibraryCore.Configuration;
|
||||
using SharedLibraryCore.Database.Models;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibraryCore.Commands
|
||||
{
|
||||
|
||||
public class ListClientTags : Command
|
||||
{
|
||||
private readonly IMetaService _metaService;
|
||||
|
||||
public ListClientTags(CommandConfiguration config, ITranslationLookup layout, IMetaService metaService) : base(config, layout)
|
||||
{
|
||||
Name = "listclienttags";
|
||||
Description = layout["COMMANDS_LIST_CLIENT_TAGS_DESC"];
|
||||
Alias = "lct";
|
||||
Permission = EFClient.Permission.Owner;
|
||||
RequiresTarget = false;
|
||||
|
||||
_metaService = metaService;
|
||||
}
|
||||
|
||||
public override async Task ExecuteAsync(GameEvent gameEvent)
|
||||
{
|
||||
var tags = await _metaService.GetPersistentMeta(EFMeta.ClientTagName);
|
||||
gameEvent.Origin.Tell(tags.Select(tag => tag.Value));
|
||||
}
|
||||
}
|
||||
}
|
@ -465,10 +465,11 @@ namespace SharedLibraryCore.Commands
|
||||
RequiresTarget = false;
|
||||
}
|
||||
|
||||
public override Task ExecuteAsync(GameEvent E)
|
||||
public override Task ExecuteAsync(GameEvent gameEvent)
|
||||
{
|
||||
string you = string.Format("{0} [^3#{1}^7] {2} ^7[^3@{3}^7] ^7[{4}^7] IP: {5}", E.Origin.Name, E.Origin.ClientNumber, E.Origin.NetworkId, E.Origin.ClientId, Utilities.ConvertLevelToColor(E.Origin.Level, E.Origin.ClientPermission.Name), E.Origin.IPAddressString);
|
||||
E.Origin.Tell(you);
|
||||
var you = _translationLookup["COMMANDS_WHOAMI_FORMAT"].FormatExt(gameEvent.Origin.ClientNumber, gameEvent.Origin.ClientId, gameEvent.Origin.GuidString,
|
||||
gameEvent.Origin.IPAddressString, gameEvent.Origin.ClientPermission.Name, string.IsNullOrEmpty(gameEvent.Origin.Tag) ? "" : $" {gameEvent.Origin.Tag}^7", gameEvent.Origin.Name);
|
||||
gameEvent.Origin.Tell(you);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
@ -488,46 +489,14 @@ namespace SharedLibraryCore.Commands
|
||||
RequiresTarget = false;
|
||||
}
|
||||
|
||||
public override Task ExecuteAsync(GameEvent E)
|
||||
public override Task ExecuteAsync(GameEvent gameEvent)
|
||||
{
|
||||
StringBuilder playerList = new StringBuilder();
|
||||
int count = 0;
|
||||
for (int i = 0; i < E.Owner.Clients.Count; i++)
|
||||
{
|
||||
var P = E.Owner.Clients[i];
|
||||
var clientList = gameEvent.Owner.GetClientsAsList()
|
||||
.Select(client => _translationLookup["COMMANDS_LIST_FORMAT"]
|
||||
.FormatExt(client.ClientPermission.Name, string.IsNullOrEmpty(client.Tag) ? "" : $" {client.Tag}^7", client.ClientNumber, client.Name))
|
||||
.ToArray();
|
||||
|
||||
if (P == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// todo: fix spacing
|
||||
// todo: make this better :)
|
||||
if (P.Masked)
|
||||
{
|
||||
playerList.AppendFormat("[^3{0}^7]{3}[^3{1}^7] {2}", Utilities.ConvertLevelToColor(EFClient.Permission.User, P.ClientPermission.Name), P.ClientNumber, P.Name, Utilities.GetSpaces(EFClient.Permission.SeniorAdmin.ToString().Length - EFClient.Permission.User.ToString().Length));
|
||||
}
|
||||
else
|
||||
{
|
||||
playerList.AppendFormat("[^3{0}^7]{3}[^3{1}^7] {2}", Utilities.ConvertLevelToColor(P.Level, P.ClientPermission.Name), P.ClientNumber, P.Name, Utilities.GetSpaces(EFClient.Permission.SeniorAdmin.ToString().Length - P.Level.ToString().Length));
|
||||
}
|
||||
|
||||
if (count == 2 || E.Owner.GetClientsAsList().Count == 1)
|
||||
{
|
||||
E.Origin.Tell(playerList.ToString());
|
||||
count = 0;
|
||||
playerList = new StringBuilder();
|
||||
continue;
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
if (playerList.Length > 0)
|
||||
{
|
||||
E.Origin.Tell(playerList.ToString());
|
||||
}
|
||||
|
||||
// todo: make no players response for webfront
|
||||
gameEvent.Origin.Tell(clientList);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
@ -737,7 +706,7 @@ namespace SharedLibraryCore.Commands
|
||||
{
|
||||
// can't promote a client to higher than your current perms
|
||||
// or your peer
|
||||
gameEvent.Origin.Tell(string.Format(_translationLookup["COMMANDS_SETLEVEL_LEVELTOOHIGH"], gameEvent.Target.Name, (gameEvent.Origin.Level - 1).ToString()));
|
||||
gameEvent.Origin.Tell(string.Format(_translationLookup["COMMANDS_SETLEVEL_LEVELTOOHIGH"], gameEvent.Target.Name, (gameEvent.Origin.Level - 1).ToLocalizedLevelName()));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -991,9 +960,14 @@ namespace SharedLibraryCore.Commands
|
||||
rules.AddRange(E.Owner.ServerConfig.Rules);
|
||||
}
|
||||
|
||||
foreach (string r in rules)
|
||||
var ruleFomat = rules.Select(r => $"- {r}");
|
||||
if (E.Message.IsBroadcastCommand(_config.BroadcastCommandPrefix))
|
||||
{
|
||||
var _ = E.Message.IsBroadcastCommand(_config.BroadcastCommandPrefix) ? E.Owner.Broadcast($"- {r}") : E.Origin.Tell($"- {r}");
|
||||
E.Owner.Broadcast(ruleFomat);
|
||||
}
|
||||
else
|
||||
{
|
||||
E.Origin.Tell(ruleFomat);
|
||||
}
|
||||
}
|
||||
|
||||
|
37
SharedLibraryCore/Commands/RemoveClientTagCommand.cs
Normal file
37
SharedLibraryCore/Commands/RemoveClientTagCommand.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using SharedLibraryCore.Configuration;
|
||||
using SharedLibraryCore.Database.Models;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibraryCore.Commands
|
||||
{
|
||||
public class RemoveClientTag : Command
|
||||
{
|
||||
private readonly IMetaService _metaService;
|
||||
|
||||
public RemoveClientTag(CommandConfiguration config, ITranslationLookup layout, IMetaService metaService) : base(config, layout)
|
||||
{
|
||||
Name = "removeclienttag";
|
||||
Description = layout["COMMANDS_REMOVE_CLIENT_TAG_DESC"];
|
||||
Alias = "rct";
|
||||
Permission = EFClient.Permission.Owner;
|
||||
RequiresTarget = false;
|
||||
Arguments = new[]
|
||||
{
|
||||
new CommandArgument()
|
||||
{
|
||||
Name = _translationLookup["COMMANDS_ARGUMENT_TAG"],
|
||||
Required = true
|
||||
}
|
||||
};
|
||||
|
||||
_metaService = metaService;
|
||||
}
|
||||
|
||||
public override async Task ExecuteAsync(GameEvent gameEvent)
|
||||
{
|
||||
await _metaService.RemovePersistentMeta(EFMeta.ClientTagName, gameEvent.Data);
|
||||
gameEvent.Origin.Tell(_translationLookup["COMMANDS_REMOVE_CLIENT_TAG_SUCCESS"].FormatExt(gameEvent.Data));
|
||||
}
|
||||
}
|
||||
}
|
49
SharedLibraryCore/Commands/SetClientTagCommand.cs
Normal file
49
SharedLibraryCore/Commands/SetClientTagCommand.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using SharedLibraryCore.Configuration;
|
||||
using SharedLibraryCore.Database.Models;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibraryCore.Commands
|
||||
{
|
||||
public class SetClientTagCommand : Command
|
||||
{
|
||||
private readonly IMetaService _metaService;
|
||||
|
||||
|
||||
public SetClientTagCommand(CommandConfiguration config, ITranslationLookup layout, IMetaService metaService) : base(config, layout)
|
||||
{
|
||||
Name = "setclienttag";
|
||||
Description = layout["COMMANDS_SET_CLIENT_TAG_DESC"];
|
||||
Alias = "sct";
|
||||
Permission = EFClient.Permission.Owner;
|
||||
RequiresTarget = true;
|
||||
Arguments = new[]
|
||||
{
|
||||
new CommandArgument()
|
||||
{
|
||||
Name = _translationLookup["COMMANDS_ARGUMENT_TAG"],
|
||||
Required = true
|
||||
}
|
||||
};
|
||||
|
||||
_metaService = metaService;
|
||||
}
|
||||
|
||||
public override async Task ExecuteAsync(GameEvent gameEvent)
|
||||
{
|
||||
var availableTags = await _metaService.GetPersistentMeta(EFMeta.ClientTagName);
|
||||
var matchingTag = availableTags.FirstOrDefault(tag => tag.Value == gameEvent.Data);
|
||||
|
||||
if (matchingTag == null)
|
||||
{
|
||||
gameEvent.Origin.Tell(_translationLookup["COMMANDS_SET_CLIENT_TAG_FAIL"].FormatExt(gameEvent.Data));
|
||||
return;
|
||||
}
|
||||
|
||||
gameEvent.Target.Tag = matchingTag.Value;
|
||||
await _metaService.AddPersistentMeta(EFMeta.ClientTag, string.Empty, gameEvent.Target, matchingTag);
|
||||
gameEvent.Origin.Tell(_translationLookup["COMMANDS_SET_CLIENT_TAG_SUCCESS"].FormatExt(matchingTag.Value));
|
||||
}
|
||||
}
|
||||
}
|
40
SharedLibraryCore/Commands/UnsetClientTagCommand.cs
Normal file
40
SharedLibraryCore/Commands/UnsetClientTagCommand.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using SharedLibraryCore.Configuration;
|
||||
using SharedLibraryCore.Database.Models;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibraryCore.Commands
|
||||
{
|
||||
public class UnsetClientTagCommand : Command
|
||||
{
|
||||
private readonly IMetaService _metaService;
|
||||
|
||||
|
||||
public UnsetClientTagCommand(CommandConfiguration config, ITranslationLookup layout, IMetaService metaService) : base(config, layout)
|
||||
{
|
||||
Name = "unsetclienttag";
|
||||
Description = layout["COMMANDS_UNSET_CLIENT_TAG_DESC"];
|
||||
Alias = "uct";
|
||||
Permission = EFClient.Permission.Owner;
|
||||
RequiresTarget = true;
|
||||
Arguments = new[]
|
||||
{
|
||||
new CommandArgument()
|
||||
{
|
||||
Name = _translationLookup["COMMANDS_ARGUMENT_TAG"],
|
||||
Required = true
|
||||
}
|
||||
};
|
||||
|
||||
_metaService = metaService;
|
||||
}
|
||||
|
||||
public override async Task ExecuteAsync(GameEvent gameEvent)
|
||||
{
|
||||
gameEvent.Target.Tag = null;
|
||||
await _metaService.RemovePersistentMeta(EFMeta.ClientTag, gameEvent.Target);
|
||||
gameEvent.Origin.Tell(_translationLookup["COMMANDS_UNSET_CLIENT_TAG_SUCCESS"]);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user