Skip to content

Commit

Permalink
feature: adding player sanctions
Browse files Browse the repository at this point in the history
  • Loading branch information
lukepolo committed Nov 14, 2024
1 parent 816f350 commit 5164d82
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/FiveStack.Entities/MatchMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ public class MatchMember
public string? steam_id { get; set; } = "";
public bool captain { get; set; } = false;
public Guid match_lineup_id { get; set; } = Guid.Empty;
public bool is_banned { get; set; } = false;
public bool is_gagged { get; set; } = false;
public bool is_muted { get; set; } = false;
}
45 changes: 45 additions & 0 deletions src/FiveStack.Events/GagPlayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Utils;
using FiveStack.Entities;
using FiveStack.Utilities;

namespace FiveStack;

public partial class FiveStackPlugin
{
public HookResult GagPlayer(CCSPlayerController? player, CommandInfo info)
{
if (player == null || !player.IsValid)
{
return HookResult.Continue;
}

MatchManager? match = _matchService.GetCurrentMatch();

if (match == null)
{
return HookResult.Continue;
}

MatchData? matchData = match?.GetMatchData();

if (matchData == null)
{
return HookResult.Continue;
}

MatchMember? member = MatchUtility.GetMemberFromLineup(matchData, player);

if (member != null)
{
if (member.is_gagged)
{
player.PrintToChat($" {ChatColors.Red}You are gagged");
return HookResult.Stop;
}
}

return HookResult.Continue;
}
}
2 changes: 0 additions & 2 deletions src/FiveStack.Events/PlayerChat.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands;
using FiveStack.Entities;

namespace FiveStack;

Expand All @@ -14,7 +13,6 @@ public HookResult OnPlayerChat(CCSPlayerController? player, CommandInfo info)
}

MatchManager? match = _matchService.GetCurrentMatch();
MatchMap? currentMap = match?.GetCurrentMap();

if (match == null)
{
Expand Down
31 changes: 29 additions & 2 deletions src/FiveStack.Services/MatchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Utils;
using CounterStrikeSharp.API.ValveConstants.Protobuf;
using FiveStack.Entities;
using FiveStack.Enums;
using FiveStack.Utilities;
Expand Down Expand Up @@ -150,7 +151,12 @@ public void UpdateMapStatus(eMapStatus status)

var currentMap = GetCurrentMap();

if (_currentMapStatus == eMapStatus.Warmup && status != eMapStatus.Warmup && currentMap != null && currentMap.order == 1)
if (
_currentMapStatus == eMapStatus.Warmup
&& status != eMapStatus.Warmup
&& currentMap != null
&& currentMap.order == 1
)
{
SendUpdatedMatchLineups();
}
Expand All @@ -171,7 +177,6 @@ public void UpdateMapStatus(eMapStatus status)
return;
}


if (currentMap == null)
{
break;
Expand Down Expand Up @@ -433,6 +438,28 @@ public async void EnforceMemberTeam(CCSPlayerController player, CsTeam? currentT

Server.NextFrame(() =>
{
MatchMember? member = MatchUtility.GetMemberFromLineup(matchData, player);

if (member == null)
{
return;
}

if (member.is_banned)
{
player.Disconnect(NetworkDisconnectionReason.NETWORK_DISCONNECT_BANADDED);
return;
}

if (member.is_muted)
{
player.VoiceFlags = VoiceFlags.Muted;
}
else
{
player.VoiceFlags = VoiceFlags.Normal;
}

Guid? lineup_id = MatchUtility.GetPlayerLineup(matchData, player);

if (lineup_id == null)
Expand Down
3 changes: 3 additions & 0 deletions src/FiveStackPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public override void Load(bool hotReload)

AddCommandListener("say", OnPlayerChat, HookMode.Post);

AddCommandListener("say", GagPlayer, HookMode.Pre);
AddCommandListener("say_team", GagPlayer, HookMode.Pre);

Server.NextFrame(() =>
{
_gameServer.Message(HudDestination.Alert, "5Stack Loaded");
Expand Down

0 comments on commit 5164d82

Please sign in to comment.