mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-07 21:58:06 -05:00
Add mute/unmute functionality and update related components
Added mute and unmute commands in ParserIW6x.js, including necessary updates in MuteManager.cs and Plugin.cs files. Refactored the query for mute penalties. Also added RootNamespace in Mute.csproj.
This commit is contained in:
parent
82d89b9dd0
commit
a9dd4e66b6
@ -8,6 +8,7 @@
|
|||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<Configurations>Debug;Release;Prerelease</Configurations>
|
<Configurations>Debug;Release;Prerelease</Configurations>
|
||||||
<Platforms>AnyCPU</Platforms>
|
<Platforms>AnyCPU</Platforms>
|
||||||
|
<RootNamespace>IW4MAdmin.Plugins.Mute</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -131,8 +131,11 @@ public class MuteManager
|
|||||||
{
|
{
|
||||||
var newPenalty = new EFPenalty
|
var newPenalty = new EFPenalty
|
||||||
{
|
{
|
||||||
Type = muteState is MuteState.Unmuted ? EFPenalty.PenaltyType.Unmute :
|
Type = muteState is MuteState.Unmuted
|
||||||
dateTime is null ? EFPenalty.PenaltyType.Mute : EFPenalty.PenaltyType.TempMute,
|
? EFPenalty.PenaltyType.Unmute
|
||||||
|
: dateTime is null
|
||||||
|
? EFPenalty.PenaltyType.Mute
|
||||||
|
: EFPenalty.PenaltyType.TempMute,
|
||||||
Expires = muteState is MuteState.Unmuted ? DateTime.UtcNow : dateTime,
|
Expires = muteState is MuteState.Unmuted ? DateTime.UtcNow : dateTime,
|
||||||
Offender = target,
|
Offender = target,
|
||||||
Offense = reason,
|
Offense = reason,
|
||||||
@ -148,10 +151,9 @@ public class MuteManager
|
|||||||
{
|
{
|
||||||
await using var context = _databaseContextFactory.CreateContext();
|
await using var context = _databaseContextFactory.CreateContext();
|
||||||
var mutePenalties = await context.Penalties
|
var mutePenalties = await context.Penalties
|
||||||
.Where(penalty => penalty.OffenderId == client.ClientId &&
|
.Where(penalty => penalty.OffenderId == client.ClientId)
|
||||||
(penalty.Type == EFPenalty.PenaltyType.Mute ||
|
.Where(penalty => penalty.Type == EFPenalty.PenaltyType.Mute || penalty.Type == EFPenalty.PenaltyType.TempMute)
|
||||||
penalty.Type == EFPenalty.PenaltyType.TempMute) &&
|
.Where(penalty => penalty.Expires == null || penalty.Expires > DateTime.UtcNow)
|
||||||
(penalty.Expires == null || penalty.Expires > DateTime.UtcNow))
|
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
foreach (var mutePenalty in mutePenalties)
|
foreach (var mutePenalty in mutePenalties)
|
||||||
@ -169,19 +171,20 @@ public class MuteManager
|
|||||||
switch (muteStateMeta.MuteState)
|
switch (muteStateMeta.MuteState)
|
||||||
{
|
{
|
||||||
case MuteState.Muted:
|
case MuteState.Muted:
|
||||||
await server.ExecuteCommandAsync($"muteClient {client.ClientNumber}");
|
var muteCommand = string.Format(server.RconParser.Configuration.CommandPrefixes.Mute, client.ClientNumber);
|
||||||
|
await server.ExecuteCommandAsync(muteCommand);
|
||||||
muteStateMeta.CommandExecuted = true;
|
muteStateMeta.CommandExecuted = true;
|
||||||
break;
|
break;
|
||||||
case MuteState.Unmuted:
|
case MuteState.Unmuted:
|
||||||
await server.ExecuteCommandAsync($"unmute {client.ClientNumber}");
|
var unMuteCommand = string.Format(server.RconParser.Configuration.CommandPrefixes.Unmute, client.ClientNumber);
|
||||||
|
await server.ExecuteCommandAsync(unMuteCommand);
|
||||||
muteStateMeta.CommandExecuted = true;
|
muteStateMeta.CommandExecuted = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<MuteState?> ReadPersistentDataV1(EFClient client) => TryParse<MuteState>(
|
private async Task<MuteState?> ReadPersistentDataV1(EFClient client) => TryParse<MuteState>(
|
||||||
(await _metaService.GetPersistentMeta(Plugin.MuteKey, client.ClientId))?.Value,
|
(await _metaService.GetPersistentMeta(Plugin.MuteKey, client.ClientId))?.Value, out var muteState)
|
||||||
out var muteState)
|
|
||||||
? muteState
|
? muteState
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ public class Plugin : IPluginV2
|
|||||||
|
|
||||||
public const string MuteKey = "IW4MMute";
|
public const string MuteKey = "IW4MMute";
|
||||||
public static IManager Manager { get; private set; } = null!;
|
public static IManager Manager { get; private set; } = null!;
|
||||||
public static readonly Server.Game[] SupportedGames = {Server.Game.IW4};
|
public static Server.Game[] SupportedGames { get; private set; } = Array.Empty<Server.Game>();
|
||||||
private static readonly string[] DisabledCommands = {nameof(PrivateMessageAdminsCommand), "PrivateMessageCommand"};
|
private static readonly string[] DisabledCommands = {nameof(PrivateMessageAdminsCommand), "PrivateMessageCommand"};
|
||||||
private readonly IInteractionRegistration _interactionRegistration;
|
private readonly IInteractionRegistration _interactionRegistration;
|
||||||
private readonly IRemoteCommandService _remoteCommandService;
|
private readonly IRemoteCommandService _remoteCommandService;
|
||||||
@ -37,9 +37,11 @@ public class Plugin : IPluginV2
|
|||||||
|
|
||||||
IManagementEventSubscriptions.Load += OnLoad;
|
IManagementEventSubscriptions.Load += OnLoad;
|
||||||
IManagementEventSubscriptions.Unload += OnUnload;
|
IManagementEventSubscriptions.Unload += OnUnload;
|
||||||
|
|
||||||
IManagementEventSubscriptions.ClientStateInitialized += OnClientStateInitialized;
|
IManagementEventSubscriptions.ClientStateInitialized += OnClientStateInitialized;
|
||||||
|
|
||||||
IGameServerEventSubscriptions.ClientDataUpdated += OnClientDataUpdated;
|
IGameServerEventSubscriptions.ClientDataUpdated += OnClientDataUpdated;
|
||||||
|
IGameServerEventSubscriptions.MonitoringStarted += OnServerMonitoredStarted;
|
||||||
|
|
||||||
IGameEventSubscriptions.ClientMessaged += OnClientMessaged;
|
IGameEventSubscriptions.ClientMessaged += OnClientMessaged;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,16 +159,16 @@ public class Plugin : IPluginV2
|
|||||||
|
|
||||||
switch (muteMetaJoin)
|
switch (muteMetaJoin)
|
||||||
{
|
{
|
||||||
case { MuteState: MuteState.Muted }:
|
case {MuteState: MuteState.Muted}:
|
||||||
// Let the client know when their mute expires.
|
// Let the client know when their mute expires.
|
||||||
state.Client.Tell(Utilities.CurrentLocalization
|
state.Client.Tell(Utilities.CurrentLocalization
|
||||||
.LocalizationIndex["PLUGINS_MUTE_REMAINING_TIME"].FormatExt(
|
.LocalizationIndex["PLUGINS_MUTE_REMAINING_TIME"].FormatExt(
|
||||||
muteMetaJoin is { Expiration: not null }
|
muteMetaJoin is {Expiration: not null}
|
||||||
? muteMetaJoin.Expiration.Value.HumanizeForCurrentCulture()
|
? muteMetaJoin.Expiration.Value.HumanizeForCurrentCulture()
|
||||||
: Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_MUTE_NEVER"],
|
: Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_MUTE_NEVER"],
|
||||||
muteMetaJoin.Reason));
|
muteMetaJoin.Reason));
|
||||||
break;
|
break;
|
||||||
case { MuteState: MuteState.Unmuting }:
|
case {MuteState: MuteState.Unmuting}:
|
||||||
// Handle unmute of unmuted players.
|
// Handle unmute of unmuted players.
|
||||||
await _muteManager.Unmute(state.Client.CurrentServer, Utilities.IW4MAdminClient(), state.Client,
|
await _muteManager.Unmute(state.Client.CurrentServer, Utilities.IW4MAdminClient(), state.Client,
|
||||||
muteMetaJoin.Reason ?? string.Empty);
|
muteMetaJoin.Reason ?? string.Empty);
|
||||||
@ -319,4 +321,29 @@ public class Plugin : IPluginV2
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Task OnServerMonitoredStarted(MonitorStartEvent serverEvent, CancellationToken token)
|
||||||
|
{
|
||||||
|
var game = (Server.Game)serverEvent.Server.GameCode;
|
||||||
|
|
||||||
|
lock (SupportedGames)
|
||||||
|
{
|
||||||
|
if (SupportedGames.Contains(game))
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
var server = Manager.GetServers().FirstOrDefault(x => x == serverEvent.Server);
|
||||||
|
var commandIsEmpty = string.IsNullOrWhiteSpace(server?.RconParser.Configuration.CommandPrefixes.Mute);
|
||||||
|
|
||||||
|
if (commandIsEmpty)
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
SupportedGames = SupportedGames.Append(game).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@ var plugin = {
|
|||||||
rconParser.Configuration.CommandPrefixes.Kick = 'clientkick {0} "{1}"';
|
rconParser.Configuration.CommandPrefixes.Kick = 'clientkick {0} "{1}"';
|
||||||
rconParser.Configuration.CommandPrefixes.Ban = 'clientkick {0} "{1}"';
|
rconParser.Configuration.CommandPrefixes.Ban = 'clientkick {0} "{1}"';
|
||||||
rconParser.Configuration.CommandPrefixes.TempBan = 'tempbanclient {0} "{1}"';
|
rconParser.Configuration.CommandPrefixes.TempBan = 'tempbanclient {0} "{1}"';
|
||||||
|
rconParser.Configuration.CommandPrefixes.Mute = 'muteClient {0}';
|
||||||
|
rconParser.Configuration.CommandPrefixes.Unmute = 'unmute {0}';
|
||||||
|
|
||||||
rconParser.Configuration.DefaultRConPort = 28960;
|
rconParser.Configuration.DefaultRConPort = 28960;
|
||||||
rconParser.Configuration.DefaultInstallationDirectoryHint = 'HKEY_CURRENT_USER\\Software\\Classes\\iw4x\\shell\\open\\command';
|
rconParser.Configuration.DefaultInstallationDirectoryHint = 'HKEY_CURRENT_USER\\Software\\Classes\\iw4x\\shell\\open\\command';
|
||||||
|
@ -20,6 +20,8 @@ var plugin = {
|
|||||||
rconParser.Configuration.CommandPrefixes.Ban = 'clientkick {0} "{1}"';
|
rconParser.Configuration.CommandPrefixes.Ban = 'clientkick {0} "{1}"';
|
||||||
rconParser.Configuration.CommandPrefixes.TempBan = 'clientkick {0} "{1}"';
|
rconParser.Configuration.CommandPrefixes.TempBan = 'clientkick {0} "{1}"';
|
||||||
rconParser.Configuration.CommandPrefixes.RConResponse = '\xff\xff\xff\xffprint\n';
|
rconParser.Configuration.CommandPrefixes.RConResponse = '\xff\xff\xff\xffprint\n';
|
||||||
|
rconParser.Configuration.CommandPrefixes.Mute = 'muteClient {0}';
|
||||||
|
rconParser.Configuration.CommandPrefixes.Unmute = 'unmuteClient {0}';
|
||||||
rconParser.Configuration.Dvar.Pattern = '^ *\\"(.+)\\" is: \\"(.+)?\\" default: \\"(.+)?\\"\\n?(?:latched: \\"(.+)?\\"\\n?)?(.*)$';
|
rconParser.Configuration.Dvar.Pattern = '^ *\\"(.+)\\" is: \\"(.+)?\\" default: \\"(.+)?\\"\\n?(?:latched: \\"(.+)?\\"\\n?)?(.*)$';
|
||||||
rconParser.Configuration.Status.Pattern = '^ *([0-9]+) +-?([0-9]+) +(Yes|No) +((?:[A-Z]+|[0-9]+)) +((?:[a-z]|[0-9]){8,32}|(?:[a-z]|[0-9]){8,32}|bot[0-9]+|(?:[0-9]+)) *(.{0,32}) +(\\d+\\.\\d+\\.\\d+.\\d+\\:-*\\d{1,5}|0+.0+:-*\\d{1,5}|loopback|unknown|bot) +(-*[0-9]+) *$';
|
rconParser.Configuration.Status.Pattern = '^ *([0-9]+) +-?([0-9]+) +(Yes|No) +((?:[A-Z]+|[0-9]+)) +((?:[a-z]|[0-9]){8,32}|(?:[a-z]|[0-9]){8,32}|bot[0-9]+|(?:[0-9]+)) *(.{0,32}) +(\\d+\\.\\d+\\.\\d+.\\d+\\:-*\\d{1,5}|0+.0+:-*\\d{1,5}|loopback|unknown|bot) +(-*[0-9]+) *$';
|
||||||
rconParser.Configuration.StatusHeader.Pattern = 'num +score +bot +ping +guid +name +address +qport *';
|
rconParser.Configuration.StatusHeader.Pattern = 'num +score +bot +ping +guid +name +address +qport *';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user