-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding Mute for IW4x
- Loading branch information
Showing
6 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Data.Models.Client; | ||
using SharedLibraryCore; | ||
using SharedLibraryCore.Commands; | ||
using SharedLibraryCore.Configuration; | ||
using SharedLibraryCore.Interfaces; | ||
|
||
namespace Mute.Commands; | ||
|
||
public class MuteCommand : Command | ||
{ | ||
public MuteCommand(CommandConfiguration config, ITranslationLookup translationLookup) : base(config, | ||
translationLookup) | ||
{ | ||
Name = "mute"; | ||
Description = translationLookup["PLUGINS_MUTE_COMMANDS_MUTE_DESC"]; | ||
Alias = "mu"; | ||
Permission = EFClient.Permission.Moderator; | ||
RequiresTarget = true; | ||
SupportedGames = Plugin.SupportedGames; | ||
Arguments = new[] | ||
{ | ||
new CommandArgument | ||
{ | ||
Name = translationLookup["COMMANDS_ARGS_PLAYER"], | ||
Required = true | ||
} | ||
}; | ||
} | ||
|
||
private readonly MuteManager _muteManager = new(); | ||
|
||
public override async Task ExecuteAsync(GameEvent gameEvent) | ||
{ | ||
if (await _muteManager.Mute(gameEvent)) | ||
{ | ||
gameEvent.Origin.Tell($"{_translationLookup["PLUGINS_MUTE_MUTED"]} {gameEvent.Target.Name}"); | ||
return; | ||
} | ||
|
||
gameEvent.Origin.Tell($"{_translationLookup["PLUGINS_MUTE_UNMUTED"]} {gameEvent.Target.Name}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Data.Models.Client; | ||
using SharedLibraryCore.Interfaces; | ||
using static System.Enum; | ||
|
||
namespace Mute; | ||
|
||
public class DataManager | ||
{ | ||
public DataManager(IMetaServiceV2 metaService) | ||
{ | ||
_metaService = metaService; | ||
} | ||
|
||
private readonly IMetaServiceV2 _metaService; | ||
|
||
public async Task<MuteState> ReadPersistentData(EFClient client) | ||
{ | ||
var clientMuteState = client.GetAdditionalProperty<MuteState?>(Plugin.MuteKey) ?? | ||
Parse<MuteState>((await _metaService.GetPersistentMeta(Plugin.MuteKey, client.ClientId))? | ||
.Value ?? nameof(MuteState.Unmuted)); | ||
|
||
client.SetAdditionalProperty(Plugin.MuteKey, clientMuteState); | ||
return clientMuteState; | ||
} | ||
|
||
public async Task WritePersistentData(EFClient client, MuteState state) | ||
{ | ||
await _metaService.SetPersistentMeta(Plugin.MuteKey, state.ToString(), client.ClientId); | ||
client.SetAdditionalProperty(Plugin.MuteKey, state); | ||
} | ||
} | ||
|
||
public enum MuteState | ||
{ | ||
Muted, | ||
Unmuting, | ||
Unmuted | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<Authors>MrAmos123</Authors> | ||
<OutputType>Library</OutputType> | ||
<Configurations>Debug;Release;Prerelease</Configurations> | ||
<Platforms>AnyCPU</Platforms> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.6.16.1"/> | ||
</ItemGroup> | ||
|
||
<Target Name="PostBuild" AfterTargets="PostBuildEvent"> | ||
<Exec Command="dotnet publish $(ProjectPath) -c $(ConfigurationName) -o $(ProjectDir)..\..\Build\Plugins --no-build --no-restore --no-dependencies"/> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using SharedLibraryCore; | ||
|
||
namespace Mute; | ||
|
||
public class MuteManager | ||
{ | ||
public async Task<bool> Mute(GameEvent gameEvent) | ||
{ | ||
if (await Plugin.DataManager.ReadPersistentData(gameEvent.Target) == MuteState.Muted) | ||
{ | ||
await gameEvent.Owner.ExecuteCommandAsync($"unmute {gameEvent.Target.ClientNumber}"); | ||
await Plugin.DataManager.WritePersistentData(gameEvent.Target, | ||
gameEvent.Target.IsIngame ? MuteState.Unmuted : MuteState.Unmuting); | ||
return false; | ||
} | ||
|
||
await gameEvent.Owner.ExecuteCommandAsync($"muteClient {gameEvent.Target.ClientNumber}"); | ||
await Plugin.DataManager.WritePersistentData(gameEvent.Target, MuteState.Muted); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using SharedLibraryCore; | ||
using SharedLibraryCore.Interfaces; | ||
|
||
namespace Mute; | ||
|
||
public class Plugin : IPlugin | ||
{ | ||
public Plugin(IMetaServiceV2 metaService) | ||
{ | ||
DataManager = new DataManager(metaService); | ||
} | ||
|
||
public string Name => "Mute"; | ||
public float Version => (float) Utilities.GetVersionAsDouble(); | ||
public string Author => "Amos"; | ||
|
||
public static string MuteKey = "IW4MMute"; | ||
|
||
public static DataManager DataManager; | ||
public static readonly Server.Game[] SupportedGames = {Server.Game.IW4}; | ||
|
||
public async Task OnEventAsync(GameEvent gameEvent, Server server) | ||
{ | ||
if (!SupportedGames.Contains(server.GameName)) return; | ||
|
||
switch (gameEvent.Type) | ||
{ | ||
case GameEvent.EventType.Join: | ||
switch (await DataManager.ReadPersistentData(gameEvent.Origin)) | ||
{ | ||
case MuteState.Muted: | ||
await server.ExecuteCommandAsync($"muteClient {gameEvent.Origin.ClientNumber}"); | ||
break; | ||
case MuteState.Unmuting: | ||
await server.ExecuteCommandAsync($"unmute {gameEvent.Origin.ClientNumber}"); | ||
await DataManager.WritePersistentData(gameEvent.Origin, MuteState.Unmuted); | ||
break; | ||
case MuteState.Unmuted: | ||
break; | ||
} | ||
|
||
break; | ||
} | ||
} | ||
|
||
public Task OnLoadAsync(IManager manager) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task OnUnloadAsync() | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task OnTickAsync(Server server) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} |