Skip to content

Commit

Permalink
Add perm check and autobalance bypass
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Mar 5, 2024
1 parent 01d159a commit 977fbb7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lang/Jailbreak.English/Teams/RatioNotifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class RatioNotifications : IRatioNotifications, ILanguage<Formatting.Lang

public IView ATTEMPT_TO_JOIN_FROM_TEAM_MENU =>
new SimpleView { PREFIX, "You were swapped back to the prisoner team!" };

public IView LEFT_GUARD =>
new SimpleView
{
Expand Down
34 changes: 31 additions & 3 deletions mod/Jailbreak.Teams/Queue/QueueBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.Formatting.Extensions;
Expand All @@ -20,7 +21,7 @@ public class QueueBehavior : IGuardQueue, IPluginBehavior

private readonly IRatioNotifications _notifications;
private readonly IPlayerState<QueueState> _state;

private BasePlugin _parent;

public QueueBehavior(IPlayerStateFactory factory, IRatioNotifications notifications, ILogger<QueueBehavior> logger)

Check warning on line 26 in mod/Jailbreak.Teams/Queue/QueueBehavior.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_parent' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 26 in mod/Jailbreak.Teams/Queue/QueueBehavior.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_parent' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 26 in mod/Jailbreak.Teams/Queue/QueueBehavior.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_parent' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 26 in mod/Jailbreak.Teams/Queue/QueueBehavior.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_parent' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
{
Expand Down Expand Up @@ -60,7 +61,7 @@ public bool TryExitQueue(CCSPlayerController player)

public bool TryPop(int count)
{
var queue = Queue.Where(p=>p.IsReal()).ToList();
var queue = Queue.Where(p => p.IsReal()).ToList();

if (queue.Count <= count)
{
Expand Down Expand Up @@ -136,6 +137,7 @@ public IEnumerable<CCSPlayerController> Queue

public void Start(BasePlugin parent)
{
_parent = parent;
// Listen for the player requesting to join a team.
// Thanks, destoer!
parent.AddCommandListener("jointeam", OnRequestToJoinTeam);
Expand All @@ -158,6 +160,18 @@ public HookResult OnRequestToJoinTeam(CCSPlayerController? invoked, CommandInfo
if (command.ArgCount < 2)
return HookResult.Stop;

if (!state.IsGuard)
_parent.AddTimer(0.1f, () =>
{
if (!invoked.IsReal())
return;
if (invoked.GetTeam() != CsTeam.CounterTerrorist)
return;
_notifications.ATTEMPT_TO_JOIN_FROM_TEAM_MENU
.ToPlayerChat(invoked)
.ToPlayerCenter(invoked);
invoked.ChangeTeam(CsTeam.Terrorist);
});
if (!int.TryParse(command.ArgByIndex(1), out var team))
return HookResult.Stop;

Expand Down Expand Up @@ -255,6 +269,20 @@ public void Command_Guard(CCSPlayerController? player, CommandInfo command)
{
if (player == null)
return;
if (player.AuthorizedSteamID == null)
{
player.PrintToCenter("Steam has not yet authorized you. Please try again later.");
return;
}

AdminData? data = AdminManager.GetPlayerAdminData(player.AuthorizedSteamID!);

if (data == null || !data.Groups.Contains("#ego/e"))
{
player.PrintToCenter("You must be an =(e)= to join the guard queue.");
return;
}

HandleQueueRequest(player);
}

Expand All @@ -266,4 +294,4 @@ public void Command_Leave(CCSPlayerController? player, CommandInfo command)
return;
HandleLeaveRequest(player);
}
}
}

0 comments on commit 977fbb7

Please sign in to comment.