-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
css_peace / first warden mute #69
Changes from 2 commits
01d159a
decf532
f666467
b2fc6bd
2fa50af
4c5d809
1981bfa
b048cf4
535ccdf
fa4c17d
a523859
e9b9fad
fffe439
bf043bd
eff7b35
2dda935
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using CounterStrikeSharp.API.Core.Attributes.Registration; | ||
using CounterStrikeSharp.API.Core; | ||
using CounterStrikeSharp.API.Modules.Commands; | ||
using Jailbreak.Public.Behaviors; | ||
using Jailbreak.Public.Mod.Warden; | ||
using Jailbreak.Public.Generic; | ||
|
||
namespace Jailbreak.Warden.Commands; | ||
|
||
public class WardenPeaceCommandsBehavior : IPluginBehavior | ||
{ | ||
|
||
private readonly IWardenPeaceService _peaceService; | ||
private readonly ICoroutines _coroutines; | ||
|
||
private static readonly float _muteTime = 10.0f; | ||
|
||
public WardenPeaceCommandsBehavior(IWardenPeaceService peaceService, ICoroutines coroutines) | ||
{ | ||
_peaceService = peaceService; | ||
_coroutines = coroutines; | ||
} | ||
|
||
[ConsoleCommand("css_peace", "Gives everybody some peace of mind by muting Prisoners/Guards for x seconds (warden is exempt from this).")] | ||
[CommandHelper(0, "", CommandUsage.CLIENT_ONLY)] | ||
public void Command_Peace(CCSPlayerController? invoker, CommandInfo command) | ||
{ | ||
|
||
if (invoker == null) return; | ||
|
||
CCSPlayerController? warden = _peaceService.GetWarden(); | ||
|
||
if (warden == null) return; | ||
|
||
// we only want the warden to be able to run this! | ||
if (!invoker.Equals(warden)) return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a fan of wrapping around already written logic for checking if activator is warden. Please use https://github.com/edgegamers/Jailbreak/blob/main/public/Jailbreak.Public/Mod/Warden/IWardenService.cs#L15 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also done |
||
|
||
_peaceService.PeaceMute(_muteTime, true); | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,28 +7,32 @@ | |
using Jailbreak.Formatting.Views; | ||
using Jailbreak.Public.Behaviors; | ||
using Jailbreak.Public.Extensions; | ||
using Jailbreak.Public.Mod.Logs; | ||
using Jailbreak.Public.Mod.Plugin; | ||
using Jailbreak.Public.Mod.Warden; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Jailbreak.Warden.Global; | ||
|
||
public class WardenBehavior : IPluginBehavior, IWardenService | ||
{ | ||
private ILogger<WardenBehavior> _logger; | ||
private IRichLogService _logs; | ||
|
||
private IWardenNotifications _notifications; | ||
private readonly ILogger<WardenBehavior> _logger; | ||
private readonly IRichLogService _logs; | ||
private readonly IWardenNotifications _notifications; | ||
private readonly IEventsService _eventsService; | ||
|
||
private bool _firstWarden = false; | ||
private bool _currentWardenIsFirst = false; | ||
private bool _hasWarden; | ||
private CCSPlayerController? _warden; | ||
|
||
public WardenBehavior(ILogger<WardenBehavior> logger, IWardenNotifications notifications, IRichLogService logs) | ||
public WardenBehavior(ILogger<WardenBehavior> logger, IWardenNotifications notifications, IRichLogService logs, IEventsService eventsService) | ||
{ | ||
_logger = logger; | ||
_notifications = notifications; | ||
_logs = logs; | ||
} | ||
_eventsService = eventsService; | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Get the current warden, if there is one. | ||
|
@@ -66,7 +70,23 @@ public bool TrySetWarden(CCSPlayerController controller) | |
.ToAllCenter(); | ||
|
||
_logs.Append( _logs.Player(_warden), "is now the warden."); | ||
|
||
// makes sure the second person (and people thereafter) who claim warden are not labelled as "first warden" | ||
if (_currentWardenIsFirst && _firstWarden) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confusing variable / if check here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed entirely :P idk why it's there! |
||
{ | ||
_currentWardenIsFirst = false; | ||
return true; | ||
} | ||
|
||
if (!_firstWarden) | ||
{ | ||
_firstWarden = true; | ||
_currentWardenIsFirst = true; | ||
_eventsService.FireEvent("first_warden_event"); | ||
} | ||
|
||
return true; | ||
|
||
} | ||
|
||
public bool TryRemoveWarden() | ||
|
@@ -89,6 +109,16 @@ public bool TryRemoveWarden() | |
return true; | ||
} | ||
|
||
public bool HasBeenFirstWarden() | ||
{ | ||
return _firstWarden; | ||
} | ||
|
||
public bool CurrentWardenIsFirst() | ||
{ | ||
return _currentWardenIsFirst; | ||
} | ||
|
||
[GameEventHandler] | ||
public HookResult OnDeath(EventPlayerDeath ev, GameEventInfo info) | ||
{ | ||
|
@@ -127,6 +157,8 @@ private void ProcessWardenDeath() | |
public HookResult OnRoundEnd(EventRoundEnd ev, GameEventInfo info) | ||
{ | ||
this.TryRemoveWarden(); | ||
_firstWarden = false; | ||
_currentWardenIsFirst = false; | ||
|
||
return HookResult.Continue; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using CounterStrikeSharp.API; | ||
using CounterStrikeSharp.API.Core; | ||
using Jailbreak.Public.Behaviors; | ||
using Jailbreak.Public.Generic; | ||
using Jailbreak.Public.Mod.Plugin; | ||
using Jailbreak.Public.Mod.Warden; | ||
|
||
namespace Jailbreak.Warden.Global; | ||
|
||
public class WardenPeaceBehaviour : IPluginBehavior, IWardenPeaceService | ||
{ | ||
|
||
private readonly IWardenService _wardenService; | ||
private readonly ICoroutines _coroutines; | ||
private readonly IEventsService _eventsService; | ||
|
||
private readonly float _muteTime = 10.0f; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If possible distinguish this variable from https://github.com/edgegamers/Jailbreak/pull/69/files#diff-e81c196d0b0e42fe347b9e3ee80c463e42c9aa74b8baec3127ed11383c01feaeR16 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
public WardenPeaceBehaviour(IWardenService wardenService, ICoroutines coroutines, IEventsService eventsService) | ||
{ | ||
_wardenService = wardenService; | ||
_coroutines = coroutines; | ||
_eventsService = eventsService; | ||
|
||
Func<bool> firstWardenPeaceMuteCallback = () => | ||
{ | ||
PeaceMute(_muteTime, true); | ||
return true; | ||
}; | ||
|
||
_eventsService.RegisterEventListener("first_warden_event", firstWardenPeaceMuteCallback); | ||
|
||
} | ||
|
||
public CCSPlayerController? GetWarden() | ||
{ | ||
return _wardenService.Warden; | ||
} | ||
|
||
public void PeaceMute(float time, bool exemptWarden = false) | ||
{ | ||
|
||
List<CCSPlayerController> alreadyMuted = new List<CCSPlayerController>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why keep track of already muted players? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point 😆 |
||
List<CCSPlayerController> prevUnmutedPlayers = new List<CCSPlayerController>(); | ||
|
||
foreach (CCSPlayerController player in Utilities.GetPlayers()) | ||
{ | ||
|
||
if (player.Equals(_wardenService.Warden) && exemptWarden) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue here, use the interface instead of lower level logic. |
||
continue; | ||
|
||
if (player.VoiceFlags == VoiceFlags.Muted) | ||
{ | ||
player.PrintToChat("bro you already muted"); | ||
alreadyMuted.Add(player); | ||
} | ||
else | ||
{ | ||
player.VoiceFlags |= VoiceFlags.Muted; | ||
prevUnmutedPlayers.Add(player); | ||
player.PrintToChat("we muted you"); | ||
} | ||
|
||
} | ||
|
||
// then unmute the people who weren't already muted after _muteTime seconds | ||
_coroutines.Round(() => | ||
{ | ||
|
||
foreach (CCSPlayerController player in prevUnmutedPlayers) | ||
{ | ||
player.VoiceFlags &= ~VoiceFlags.Muted; | ||
player.PrintToChat("we've unmuted you"); | ||
} | ||
|
||
}, time); | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Diagnostics.Tracing; | ||
|
||
namespace Jailbreak.Public.Mod.Plugin; | ||
|
||
public class EventsService : IEventsService | ||
{ | ||
// key: event name, value: callback | ||
private readonly Dictionary<string, Func<bool>> _eventListeners; | ||
|
||
public EventsService() | ||
{ | ||
_eventListeners = new Dictionary<string, Func<bool>>(); | ||
} | ||
|
||
public void RegisterEventListener(string eventName, Func<bool> eventListener) | ||
{ | ||
_eventListeners.Add(eventName, eventListener); | ||
} | ||
|
||
public void FireEvent(string eventName) | ||
{ | ||
foreach (var listener in _eventListeners) | ||
{ | ||
if (listener.Key.Equals(eventName)) | ||
{ | ||
listener.Value.Invoke(); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
| ||
namespace Jailbreak.Public.Mod.Plugin; | ||
|
||
// Ideally very simple event driven callback service... | ||
// Allows parts of the plugin to tell each other it's done things. | ||
// this must be registered before any other service... | ||
public interface IEventsService | ||
{ | ||
|
||
// usage: CreateEventListener( bool (eventName) => { callback here } ) | ||
// returns true if successful | ||
void RegisterEventListener(string eventName, Func<bool> eventListener); | ||
|
||
void FireEvent(string eventName); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
| ||
using CounterStrikeSharp.API.Core; | ||
|
||
namespace Jailbreak.Public.Mod.Warden; | ||
|
||
public interface IWardenPeaceService | ||
{ | ||
|
||
public CCSPlayerController? GetWarden(); | ||
|
||
// todo document saying that by default all admins SHOULD bypass this mute | ||
// not implemented bypass yet | ||
public void PeaceMute(float time, bool exemptWarden = false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warden should always be exempt. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a cooldown to the command?
Also, please add a message broadcasted to players that the warden issued peace.