Skip to content

Commit

Permalink
Merge branch 'dev' into feat/logging
Browse files Browse the repository at this point in the history
# Conflicts:
#	lang/Jailbreak.English/Generic/GenericCommandNotifications.cs
#	lang/Jailbreak.English/Rebel/RebelNotifications.cs
#	lang/Jailbreak.English/Teams/RatioNotifications.cs
#	lang/Jailbreak.English/Warden/WardenNotifications.cs
#	mod/Jailbreak.Logs/LogsListeners.cs
#	mod/Jailbreak.Logs/LogsManager.cs
#	mod/Jailbreak.Logs/LogsServiceExtension.cs
#	mod/Jailbreak.Rebel/RebelManager.cs
#	mod/Jailbreak.Teams/Ratio/RatioBehavior.cs
#	mod/Jailbreak.Warden/Global/WardenBehavior.cs
#	public/Jailbreak.Formatting/Base/SimpleView.cs
#	public/Jailbreak.Formatting/Extensions/ViewExtensions.cs
#	public/Jailbreak.Formatting/Logistics/LanguageConfig.cs
#	public/Jailbreak.Public/Extensions/ServerExtensions.cs
#	src/Jailbreak/JailbreakServiceCollection.cs
  • Loading branch information
Mooshua committed Feb 6, 2024
2 parents 53fab1a + be71265 commit 423ccbb
Show file tree
Hide file tree
Showing 81 changed files with 1,438 additions and 1,484 deletions.
15 changes: 6 additions & 9 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,18 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Insert Job Version
run: sed -i "s/{GIT_VERSION}/${{github.run_number}}/g" src/Jailbreak/Jailbreak.cs

- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build src/Jailbreak/Jailbreak.csproj --no-restore
- name: Publish
run: dotnet publish src/Jailbreak/Jailbreak.csproj --no-build --no-restore
- run: |
dotnet restore
dotnet build src/Jailbreak/Jailbreak.csproj --no-restore
dotnet publish src/Jailbreak/Jailbreak.csproj --no-build --no-restore
- uses: actions/[email protected]
with:
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ The classic Jail gamemode, ported to Counter-Strike 2.
- [ ] Error reporting
- [x] Configuration system
- Note: Passable, but in a terrible state. Needs TLC.
- [x] Logging
- **👮 Guards**
- [x] Warden Selection
- [x] Warden Laser and Paint
- [ ] Special Days
- [x] Ratio Enforcement
- [ ] Bans/Punishments
- **🎃 Prisoners**
- [ ] Last Request
- [x] Rebel System
- **🛕 Maps**
- [ ] Custom Entities
- [ ] Custom I/O
Expand Down
28 changes: 11 additions & 17 deletions mod/Jailbreak.Debug/DebugCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,41 @@
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Commands;
using Jailbreak.Debug.Subcommands;
using Jailbreak.Formatting.Views;
using Jailbreak.Public.Behaviors;

namespace Jailbreak.Debug;

// css_debug [subcommand] [args] -> subcommand [args]
public class DebugCommand : IPluginBehavior
{
private readonly Dictionary<string, Subcommands.AbstractCommand> commands = new();
private readonly Dictionary<string, AbstractCommand> _commands = new();

public DebugCommand(IServiceProvider serviceProvider)
{
commands.Add("markrebel", new MarkRebel(serviceProvider));
commands.Add("pardon", new Pardon(serviceProvider));
_commands.Add("markrebel", new MarkRebel(serviceProvider));
_commands.Add("pardon", new Pardon(serviceProvider));
}



[RequiresPermissions("@css/root")]
[ConsoleCommand("css_debug", "Debug command for Jailbreak.")]
public void Command_Debug(CCSPlayerController? executor, CommandInfo info)
{
if (executor == null)
{
return;
}
if (executor == null) return;

if (info.ArgCount == 1)
{
foreach (var command in commands)
{
info.ReplyToCommand(command.Key);
}
foreach (var command in _commands) info.ReplyToCommand(command.Key);

return;
}
if (!commands.TryGetValue(info.GetArg(1), out var subcommand))

if (!_commands.TryGetValue(info.GetArg(1), out var subcommand))
{
info.ReplyToCommand("Invalid subcommand");
return;
}

subcommand.OnCommand(executor, new WrappedInfo(info));
}
}
8 changes: 4 additions & 4 deletions mod/Jailbreak.Debug/DebugServiceExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Jailbreak.Debug;

public static class DebugServiceExtension
{
public static void AddJailbreakDebug(this IServiceCollection services)
{
services.AddPluginBehavior<DebugCommand>();
}
public static void AddJailbreakDebug(this IServiceCollection services)
{
services.AddPluginBehavior<DebugCommand>();
}
}
4 changes: 2 additions & 2 deletions mod/Jailbreak.Debug/Jailbreak.Debug.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\public\Jailbreak.Formatting\Jailbreak.Formatting.csproj" />
<ProjectReference Include="..\..\public\Jailbreak.Public\Jailbreak.Public.csproj" />
<ProjectReference Include="..\..\public\Jailbreak.Formatting\Jailbreak.Formatting.csproj"/>
<ProjectReference Include="..\..\public\Jailbreak.Public\Jailbreak.Public.csproj"/>
</ItemGroup>

</Project>
38 changes: 20 additions & 18 deletions mod/Jailbreak.Debug/Subcommands/AbstractCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ namespace Jailbreak.Debug.Subcommands;

public abstract class AbstractCommand
{
protected IServiceProvider services;
private IGenericCommandNotifications lang;
private readonly IGenericCommandNotifications _lang;
protected IServiceProvider Services;

protected AbstractCommand(IServiceProvider services)
{
this.services = services;
lang = services.GetRequiredService<IGenericCommandNotifications>();
Services = services;
_lang = services.GetRequiredService<IGenericCommandNotifications>();
}

public abstract void OnCommand(CCSPlayerController? executor, WrappedInfo info);

protected TargetResult? GetTarget(WrappedInfo command, int argIndex = 1,
Func<CCSPlayerController, bool>? predicate = null)
{
return GetTarget(command.info, argIndex + 1, predicate);
return GetTarget(command.Info, argIndex + 1, predicate);
}

protected TargetResult? GetVulnerableTarget(WrappedInfo command, int argIndex = 1,
Func<CCSPlayerController, bool>? predicate = null)
{
return GetVulnerableTarget(command.info, argIndex + 1, predicate);
return GetVulnerableTarget(command.Info, argIndex + 1, predicate);
}

protected TargetResult? GetTarget(CommandInfo command, int argIndex = 1,
Expand All @@ -46,7 +46,7 @@ protected AbstractCommand(IServiceProvider services)
if (!matches.Any())
{
if (command.CallingPlayer != null)
lang.PlayerNotFound(command.GetArg(argIndex)).ToPlayerChat(command.CallingPlayer);
_lang.PlayerNotFound(command.GetArg(argIndex)).ToPlayerChat(command.CallingPlayer);
return null;
}

Expand All @@ -57,16 +57,16 @@ protected AbstractCommand(IServiceProvider services)
return matches;

if (command.CallingPlayer != null)
lang.PlayerFoundMultiple(command.GetArg(argIndex)).ToPlayerChat(command.CallingPlayer);
_lang.PlayerFoundMultiple(command.GetArg(argIndex)).ToPlayerChat(command.CallingPlayer);
return null;
}

internal TargetResult? GetVulnerableTarget(CommandInfo command, int argIndex = 1,
Func<CCSPlayerController, bool>? predicate = null)
{
return GetTarget(command, argIndex,
(p) => command.CallingPlayer == null ||
command.CallingPlayer.CanTarget(p) && (predicate == null || predicate(p)));
p => command.CallingPlayer == null ||
(command.CallingPlayer.CanTarget(p) && (predicate == null || predicate(p))));
}

protected TargetResult? GetSingleTarget(CommandInfo command, int argIndex = 1)
Expand All @@ -76,14 +76,14 @@ protected AbstractCommand(IServiceProvider services)
if (!matches.Any())
{
if (command.CallingPlayer != null)
lang.PlayerNotFound(command.GetArg(argIndex)).ToPlayerChat(command.CallingPlayer);
_lang.PlayerNotFound(command.GetArg(argIndex)).ToPlayerChat(command.CallingPlayer);
return null;
}

if (matches.Count() > 1)
{
if (command.CallingPlayer != null)
lang.PlayerFoundMultiple(command.GetArg(argIndex)).ToPlayerChat(command.CallingPlayer);
_lang.PlayerFoundMultiple(command.GetArg(argIndex)).ToPlayerChat(command.CallingPlayer);
return null;
}

Expand All @@ -92,8 +92,9 @@ protected AbstractCommand(IServiceProvider services)

protected string GetTargetLabel(WrappedInfo info, int argIndex = 1)
{
return GetTargetLabel(info.info, argIndex + 1);
return GetTargetLabel(info.Info, argIndex + 1);
}

protected string GetTargetLabel(CommandInfo info, int argIndex = 1)
{
switch (info.GetArg(argIndex))
Expand Down Expand Up @@ -128,11 +129,12 @@ protected string GetTargetLabel(CommandInfo info, int argIndex = 1)

protected string GetTargetLabels(WrappedInfo info, int argIndex = 1)
{
return GetTargetLabels(info.info, argIndex + 1);
return GetTargetLabels(info.Info, argIndex + 1);
}

protected string GetTargetLabels(CommandInfo info, int argIndex = 1)
{
string label = GetTargetLabel(info, argIndex);
var label = GetTargetLabel(info, argIndex);
if (label.ToLower().EndsWith("s"))
return label + "'";
return label + "'s";
Expand Down
14 changes: 3 additions & 11 deletions mod/Jailbreak.Debug/Subcommands/MarkRebel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands;
using Jailbreak.Formatting.Views;
using Jailbreak.Public.Mod.Rebel;
using Microsoft.Extensions.DependencyInjection;

Expand All @@ -27,19 +24,14 @@ public override void OnCommand(CCSPlayerController? executor, WrappedInfo info)
return;

var duration = 120;
if(info.ArgCount == 3)
{
if (info.ArgCount == 3)
if (!int.TryParse(info.GetArg(2), out duration))
{
info.ReplyToCommand("Invalid duration");
return;
}
}

foreach (var player in target.Players)
{
services.GetRequiredService<IRebelService>().MarkRebel(player, duration);
}

foreach (var player in target.Players) Services.GetRequiredService<IRebelService>().MarkRebel(player, duration);
info.ReplyToCommand($"Marked {GetTargetLabel(info)} as rebels for {duration} seconds.");
}
}
10 changes: 2 additions & 8 deletions mod/Jailbreak.Debug/Subcommands/Pardon.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands;
using Jailbreak.Formatting.Views;
using Jailbreak.Public.Mod.Rebel;
using Microsoft.Extensions.DependencyInjection;

Expand All @@ -25,11 +22,8 @@ public override void OnCommand(CCSPlayerController? executor, WrappedInfo info)
var target = GetVulnerableTarget(info);
if (target == null)
return;

foreach (var player in target.Players)
{
services.GetRequiredService<IRebelService>().UnmarkRebel(player);
}

foreach (var player in target.Players) Services.GetRequiredService<IRebelService>().UnmarkRebel(player);

info.ReplyToCommand($"Pardoned {GetTargetLabel(info)}");
}
Expand Down
48 changes: 29 additions & 19 deletions mod/Jailbreak.Debug/Subcommands/WrappedInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,37 @@

namespace Jailbreak.Debug.Subcommands;

public class WrappedInfo
public class WrappedInfo
{
public readonly CommandInfo info;
public readonly CommandInfo Info;

public WrappedInfo(CommandInfo info)
{
this.info = info;
Info = info;
}

public CCSPlayerController? CallingPlayer => Info.CallingPlayer;

public IntPtr Handle => Info.Handle;

public int ArgCount => Info.ArgCount - 1;

public string ArgString => Info.ArgString[(Info.ArgString.IndexOf(' ') + 1)..];

public string GetCommandString => Info.GetCommandString[(Info.GetCommandString.IndexOf(' ') + 1)..];

public string ArgByIndex(int index)
{
return Info.ArgByIndex(index + 1);
}

public string GetArg(int index)
{
return Info.GetArg(index + 1);
}

public void ReplyToCommand(string message, bool console = false)
{
Info.ReplyToCommand(message, console);
}

public CCSPlayerController? CallingPlayer => info.CallingPlayer;

public IntPtr Handle => info.Handle;

public int ArgCount => info.ArgCount - 1;

public string ArgString => info.ArgString[(info.ArgString.IndexOf(' ') + 1)..];

public string GetCommandString => info.GetCommandString[(info.GetCommandString.IndexOf(' ') + 1)..];

public string ArgByIndex(int index) => info.ArgByIndex(index + 1);
public string GetArg(int index) => info.GetArg(index + 1);

public void ReplyToCommand(string message, bool console = false) => info.ReplyToCommand(message, console);
}
4 changes: 2 additions & 2 deletions mod/Jailbreak.Logs/Jailbreak.Logs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\public\Jailbreak.Formatting\Jailbreak.Formatting.csproj" />
<ProjectReference Include="..\..\public\Jailbreak.Public\Jailbreak.Public.csproj" />
<ProjectReference Include="..\..\public\Jailbreak.Formatting\Jailbreak.Formatting.csproj"/>
<ProjectReference Include="..\..\public\Jailbreak.Public\Jailbreak.Public.csproj"/>
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions mod/Jailbreak.Logs/LogsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ namespace Jailbreak.Logs;

public class LogsCommand : IPluginBehavior
{
private ILogService logs;
private readonly ILogService _logs;

public LogsCommand(ILogService logs)
{
this.logs = logs;
_logs = logs;
}

[ConsoleCommand("css_logs")]
[RequiresPermissionsOr("@css/ban", "@css/generic", "@css/kick")]
public void Command_Logs(CCSPlayerController? executor, CommandInfo info)
{
logs.PrintLogs(executor);
_logs.PrintLogs(executor);
}
}
6 changes: 3 additions & 3 deletions mod/Jailbreak.Rebel/Jailbreak.Rebel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\public\Jailbreak.Formatting\Jailbreak.Formatting.csproj" />
<ProjectReference Include="..\..\public\Jailbreak.Public\Jailbreak.Public.csproj" />
<ProjectReference Include="..\..\public\Jailbreak.Formatting\Jailbreak.Formatting.csproj"/>
<ProjectReference Include="..\..\public\Jailbreak.Public\Jailbreak.Public.csproj"/>
</ItemGroup>

</Project>
Loading

0 comments on commit 423ccbb

Please sign in to comment.