add unlink command
fix parsing names with colors codes enabled
This commit is contained in:
parent
6b27beb355
commit
b992f4d910
@ -420,6 +420,7 @@ namespace IW4MAdmin.Application
|
|||||||
Commands.Add(new CSetGravatar());
|
Commands.Add(new CSetGravatar());
|
||||||
Commands.Add(new CNextMap());
|
Commands.Add(new CNextMap());
|
||||||
Commands.Add(new RequestTokenCommand());
|
Commands.Add(new RequestTokenCommand());
|
||||||
|
Commands.Add(new UnlinkClientCommand());
|
||||||
|
|
||||||
foreach (Command C in SharedLibraryCore.Plugins.PluginImporter.ActiveCommands)
|
foreach (Command C in SharedLibraryCore.Plugins.PluginImporter.ActiveCommands)
|
||||||
{
|
{
|
||||||
|
@ -86,12 +86,13 @@ namespace SharedLibraryCore.Commands
|
|||||||
|
|
||||||
if (E.Target == null && C.RequiresTarget) // Find active player including quotes (multiple words)
|
if (E.Target == null && C.RequiresTarget) // Find active player including quotes (multiple words)
|
||||||
{
|
{
|
||||||
matchingPlayers = E.Owner.GetClientByName(E.Data.Trim());
|
matchingPlayers = E.Owner.GetClientByName(E.Data);
|
||||||
if (matchingPlayers.Count > 1)
|
if (matchingPlayers.Count > 1)
|
||||||
{
|
{
|
||||||
E.Origin.Tell(loc["COMMAND_TARGET_MULTI"]);
|
E.Origin.Tell(loc["COMMAND_TARGET_MULTI"]);
|
||||||
throw new CommandException($"{E.Origin} had multiple players found for {C.Name}");
|
throw new CommandException($"{E.Origin} had multiple players found for {C.Name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (matchingPlayers.Count == 1)
|
else if (matchingPlayers.Count == 1)
|
||||||
{
|
{
|
||||||
E.Target = matchingPlayers.First();
|
E.Target = matchingPlayers.First();
|
||||||
|
18
SharedLibraryCore/Commands/UnlinkClientCommand.cs
Normal file
18
SharedLibraryCore/Commands/UnlinkClientCommand.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using SharedLibraryCore.Database.Models;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SharedLibraryCore.Commands
|
||||||
|
{
|
||||||
|
public class UnlinkClientCommand : Command
|
||||||
|
{
|
||||||
|
public UnlinkClientCommand() :
|
||||||
|
base("unlinkclient", Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_UNLINK_CLIENT_DESC"], "uc", EFClient.Permission.Administrator, true)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public override async Task ExecuteAsync(GameEvent E)
|
||||||
|
{
|
||||||
|
await E.Owner.Manager.GetClientService().UnlinkClient(E.Target.ClientId);
|
||||||
|
E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_UNLINK_CLIENT_SUCCESS"].FormatExt(E.Target));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -89,6 +89,8 @@ namespace SharedLibraryCore
|
|||||||
return new List<EFClient>();
|
return new List<EFClient>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pName = pName.Trim().StripColors();
|
||||||
|
|
||||||
string[] QuoteSplit = pName.Split('"');
|
string[] QuoteSplit = pName.Split('"');
|
||||||
bool literal = false;
|
bool literal = false;
|
||||||
if (QuoteSplit.Length > 1)
|
if (QuoteSplit.Length > 1)
|
||||||
|
@ -638,5 +638,30 @@ namespace SharedLibraryCore.Services
|
|||||||
.AnyAsync();
|
.AnyAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unlinks shared GUID account into its own separate account
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="clientId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task UnlinkClient(int clientId)
|
||||||
|
{
|
||||||
|
using (var ctx = new DatabaseContext())
|
||||||
|
{
|
||||||
|
var newLink = new EFAliasLink() { Active = true };
|
||||||
|
ctx.AliasLinks.Add(newLink);
|
||||||
|
await ctx.SaveChangesAsync();
|
||||||
|
|
||||||
|
var client = await ctx.Clients.Include(_client => _client.CurrentAlias)
|
||||||
|
.FirstAsync(_client => _client.ClientId == clientId);
|
||||||
|
client.AliasLinkId = newLink.AliasLinkId;
|
||||||
|
client.Level = Permission.User;
|
||||||
|
|
||||||
|
await ctx.Aliases.Where(_alias => _alias.IPAddress == client.IPAddress)
|
||||||
|
.ForEachAsync(_alias => _alias.LinkId = newLink.AliasLinkId);
|
||||||
|
|
||||||
|
await ctx.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user