Skip to content

Commit

Permalink
Merge branch 'dev' into chore/logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooshua authored Jan 24, 2024
2 parents f0fda6a + 729e15b commit d7fc330
Show file tree
Hide file tree
Showing 32 changed files with 735 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

- uses: actions/[email protected]
with:
name: jailbreak-nightly-${{ github.run_id }}
name: jailbreak-nightly
path: build
# If build didn't put any artifacts in the build folder, consider it an error
if-no-files-found: error
16 changes: 16 additions & 0 deletions Jailbreak.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.Generic", "src\Ja
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.Teams", "mod\Jailbreak.Teams\Jailbreak.Teams.csproj", "{28EE05E4-8FE3-4CC6-AA03-0C533EFBFBF2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.Formatting", "public\Jailbreak.Formatting\Jailbreak.Formatting.csproj", "{446E0B6F-E4FE-45E6-BD9B-BD943698327A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lang", "lang", "{CDCDE44E-01D2-4B76-99DA-A57E1E956038}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.English", "lang\Jailbreak.English\Jailbreak.English.csproj", "{FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -42,12 +48,22 @@ Global
{28EE05E4-8FE3-4CC6-AA03-0C533EFBFBF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28EE05E4-8FE3-4CC6-AA03-0C533EFBFBF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28EE05E4-8FE3-4CC6-AA03-0C533EFBFBF2}.Release|Any CPU.Build.0 = Release|Any CPU
{446E0B6F-E4FE-45E6-BD9B-BD943698327A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{446E0B6F-E4FE-45E6-BD9B-BD943698327A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{446E0B6F-E4FE-45E6-BD9B-BD943698327A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{446E0B6F-E4FE-45E6-BD9B-BD943698327A}.Release|Any CPU.Build.0 = Release|Any CPU
{FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{9135CCC9-66C5-4A9C-AE3C-91475B5F0437} = {177DA48D-8306-4102-918D-992569878581}
{51AF228F-27F2-4225-A387-FDEAD123FAC2} = {59311734-3648-43C2-B43C-385718B0D103}
{E73417E7-D397-415B-B96F-BF43DAC511B8} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7}
{1D9CC1AC-4ABC-41A3-8CC7-6FB17E864C3F} = {177DA48D-8306-4102-918D-992569878581}
{28EE05E4-8FE3-4CC6-AA03-0C533EFBFBF2} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7}
{446E0B6F-E4FE-45E6-BD9B-BD943698327A} = {59311734-3648-43C2-B43C-385718B0D103}
{FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF} = {CDCDE44E-01D2-4B76-99DA-A57E1E956038}
EndGlobalSection
EndGlobal
13 changes: 13 additions & 0 deletions lang/Jailbreak.English/Jailbreak.English.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

</Project>
46 changes: 46 additions & 0 deletions lang/Jailbreak.English/Teams/RatioNotifications.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using CounterStrikeSharp.API.Modules.Utils;

using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Core;
using Jailbreak.Formatting.Logistics;
using Jailbreak.Formatting.Objects;
using Jailbreak.Formatting.Views;

namespace Jailbreak.English.Teams;

public class RatioNotifications : IRatioNotifications, ILanguage<Formatting.Languages.English>
{
public static FormatObject PREFIX = new HiddenFormatObject( $" {ChatColors.LightRed}[{ChatColors.Red}JB{ChatColors.LightRed}]" )
{
// Hide in panorama and center text
Plain = false,
Panorama = false,
Chat = true,
};

public IView NOT_ENOUGH_GUARDS => new SimpleView(writer =>
writer
.Line(PREFIX, "There's not enough guards in the queue!"));

public IView JOIN_GUARD_QUEUE => new SimpleView(writer =>
writer
.Line(PREFIX, "Type !guard to become a guard!"));

public IView YOU_WERE_AUTOBALANCED_PRISONER => new SimpleView(writer =>
writer
.Line(PREFIX, "You were autobalanced to the prisoner team!"));

public IView ATTEMPT_TO_JOIN_FROM_TEAM_MENU => new SimpleView(writer =>
writer
.Line(PREFIX, "You were swapped back to the prisoner team!")
.Line(PREFIX, "Please use !guard to join the guard team."));

public IView LEFT_GUARD => new SimpleView(writer =>
writer
.Line(PREFIX, "You are no longer a guard.")
.Line(PREFIX, "Please use !guard if you want to re-join the guard team."));

public IView YOU_WERE_AUTOBALANCED_GUARD => new SimpleView(writer =>
writer
.Line(PREFIX, "You are now a guard!"));
}
67 changes: 67 additions & 0 deletions lang/Jailbreak.English/Warden/WardenNotifications.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;

using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Core;
using Jailbreak.Formatting.Logistics;
using Jailbreak.Formatting.Objects;
using Jailbreak.Formatting.Views;

namespace Jailbreak.English.Warden;

public class WardenNotifications : IWardenNotifications, ILanguage<Formatting.Languages.English>
{
public static FormatObject PREFIX = new HiddenFormatObject( $" {ChatColors.Lime}[{ChatColors.Green}WARDEN{ChatColors.Lime}]" )
{
// Hide in panorama and center text
Plain = false,
Panorama = false,
Chat = true,
};

public IView PICKING_SHORTLY => new SimpleView(writer =>
writer
.Line(PREFIX, "Picking a warden shortly")
.Line(PREFIX, "To enter the warden queue, type !warden in chat."));

public IView NO_WARDENS => new SimpleView(writer =>
writer
.Line(PREFIX, "No wardens in queue! The next player to run !warden will become a warden."));

public IView WARDEN_LEFT => new SimpleView(writer =>
writer.Line(PREFIX, "The warden has left the game!"));

public IView WARDEN_DIED => new SimpleView(writer =>
writer.Line(PREFIX, "The warden has died!"));

public IView BECOME_NEXT_WARDEN => new SimpleView(writer =>
writer.Line(PREFIX, "Type !warden to become the next warden"));

public IView JOIN_RAFFLE => new SimpleView(writer =>
writer.Line(PREFIX, "You've joined the warden raffle!"));

public IView LEAVE_RAFFLE => new SimpleView(writer =>
writer.Line(PREFIX, "You've left the warden raffle!"));

public IView PASS_WARDEN(CCSPlayerController player)
{
return new SimpleView(writer =>
writer.Line(PREFIX, player, "has resigned from being warden!"));
}

public IView NEW_WARDEN(CCSPlayerController player)
{
return new SimpleView(writer =>
writer.Line(PREFIX, player, "is now the warden!"));
}

public IView CURRENT_WARDEN(CCSPlayerController? player)
{
if (player is not null)
return new SimpleView(writer =>
writer.Line(PREFIX, "The current warden is", player));
else
return new SimpleView(writer =>
writer.Line(PREFIX, "There is currently no warden!"));
}
}
5 changes: 3 additions & 2 deletions mod/Jailbreak.Teams/Jailbreak.Teams.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
</PropertyGroup>

<ItemGroup>
<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>
91 changes: 76 additions & 15 deletions mod/Jailbreak.Teams/Queue/QueueBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Utils;

using Jailbreak.Formatting.Extensions;
using Jailbreak.Formatting.Views;
using Jailbreak.Public.Behaviors;
using Jailbreak.Public.Extensions;
using Jailbreak.Public.Generic;
Expand All @@ -18,9 +21,12 @@ public class QueueBehavior : IGuardQueue, IPluginBehavior
private readonly ILogger<QueueBehavior> _logger;
private readonly IPlayerState<QueueState> _state;

public QueueBehavior(IPlayerStateFactory factory, ILogger<QueueBehavior> logger)
private IRatioNotifications _notifications;

public QueueBehavior(IPlayerStateFactory factory, ILogger<QueueBehavior> logger, IRatioNotifications notifications)
{
_logger = logger;
_logger = logger;
_notifications = notifications;
_counter = 0;
_state = factory.Global<QueueState>();
}
Expand Down Expand Up @@ -48,14 +54,12 @@ public bool TryExitQueue(CCSPlayerController player)

public bool TryPop(int count)
{
Server.PrintToChatAll($"[Jail] Autobalancing is adding {count} guards.");
var queue = Queue.ToList();

if (queue.Count <= count)
{
Server.PrintToChatAll("[Jail] Not enough guards are in the queue!");
Server.PrintToChatAll("[Jail] Type !guard in chat to join the queue");
ServerExtensions.PrintToCenterAll("Not enough players in guard queue!\nType !guard to become a guard.");
_notifications.NOT_ENOUGH_GUARDS.ToAllChat();
_notifications.JOIN_GUARD_QUEUE.ToAllChat().ToAllCenter();
}

_logger.LogInformation("[Queue] Pop requested {@Count} out of {@InQueue}", count, queue.Count);
Expand All @@ -72,8 +76,6 @@ public bool TryPop(int count)

public bool TryPush(int count)
{
Server.PrintToChatAll($"[Jail] Autobalancing is removing {count} guards.");

var players = Utilities.GetPlayers()
.Where(player => player.GetTeam() == CsTeam.CounterTerrorist)
.Shuffle(Random.Shared)
Expand All @@ -91,7 +93,7 @@ public bool TryPush(int count)

TryEnterQueue(toSwap);

toSwap.PrintToCenter("You were autobalanced to the prisoner team!");
_notifications.YOU_WERE_AUTOBALANCED_PRISONER.ToPlayerCenter(toSwap);
}

return true;
Expand All @@ -102,7 +104,10 @@ public void ForceGuard(CCSPlayerController player)
// Set IsGuard so they won't be swapped back.
_state.Get(player).IsGuard = true;

player.PrintToCenter("You are now a guard!");
_notifications.YOU_WERE_AUTOBALANCED_GUARD
.ToPlayerChat(player)
.ToPlayerCenter(player);

player.ChangeTeam(CsTeam.CounterTerrorist);
}

Expand All @@ -129,16 +134,72 @@ public HookResult OnPlayerTeam(EventPlayerTeam ev, GameEventInfo info)

if (ev.Team == (int)CsTeam.CounterTerrorist && !state.IsGuard)
{
player.SwitchTeam(CsTeam.Terrorist);
player.PrintToCenter("You were swapped to T!\nUse !guard to join the queue.");

return HookResult.Handled;
}

if (player.GetTeam() == CsTeam.Terrorist && state.IsGuard)
if (TryExitQueue(player))
player.PrintToCenter("You were removed from the guard queue for switching to T.\nUse !guard to rejoin the queue!");
{
if (this.TryExitQueue(player))
_notifications.LEFT_GUARD
.ToPlayerCenter(player)
.ToPlayerChat(player);
}

return HookResult.Continue;
}

private void HandleQueueRequest(CCSPlayerController player)
{
if (TryEnterQueue(player))
_notifications.JOIN_GUARD_QUEUE
.ToPlayerCenter(player)
.ToPlayerChat(player);
else
player.PrintToCenter("An error occured adding you to the queue.");

}

private void HandleLeaveRequest(CCSPlayerController player)
{
if (TryExitQueue(player))
_notifications.LEFT_GUARD
.ToPlayerCenter(player)
.ToPlayerChat(player);
else
player.PrintToCenter("An error occured removing you from the queue.");
}

public int GetQueuePosition(CCSPlayerController player)

Check failure on line 172 in mod/Jailbreak.Teams/Queue/QueueBehavior.cs

View workflow job for this annotation

GitHub Actions / build

Type 'QueueBehavior' already defines a member called 'GetQueuePosition' with the same parameter types

Check failure on line 172 in mod/Jailbreak.Teams/Queue/QueueBehavior.cs

View workflow job for this annotation

GitHub Actions / build

Type 'QueueBehavior' already defines a member called 'GetQueuePosition' with the same parameter types

Check failure on line 172 in mod/Jailbreak.Teams/Queue/QueueBehavior.cs

View workflow job for this annotation

GitHub Actions / build

Type 'QueueBehavior' already defines a member called 'GetQueuePosition' with the same parameter types

Check failure on line 172 in mod/Jailbreak.Teams/Queue/QueueBehavior.cs

View workflow job for this annotation

GitHub Actions / build

Type 'QueueBehavior' already defines a member called 'GetQueuePosition' with the same parameter types
{
return Queue.ToList()
.FindIndex(controller => controller.Slot == player.Slot);
}

[ConsoleCommand("css_guard", "Joins the guard queue")]
[ConsoleCommand("css_g", "Joins the guard queue")]
[CommandHelper(0, "", CommandUsage.CLIENT_ONLY)]
public void Command_Guard(CCSPlayerController? player, CommandInfo command)
{
if (player == null)
return;
HandleQueueRequest(player);
}

[ConsoleCommand("css_leave", "Leaves the guard queue")]
[CommandHelper(0, "", CommandUsage.CLIENT_ONLY)]
public void Command_Leave(CCSPlayerController? player, CommandInfo command)
{
if (player == null)
return;
HandleLeaveRequest(player);
}


public IEnumerable<CCSPlayerController> Queue

Check failure on line 198 in mod/Jailbreak.Teams/Queue/QueueBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The type 'QueueBehavior' already contains a definition for 'Queue'

Check failure on line 198 in mod/Jailbreak.Teams/Queue/QueueBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The type 'QueueBehavior' already contains a definition for 'Queue'

Check failure on line 198 in mod/Jailbreak.Teams/Queue/QueueBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The type 'QueueBehavior' already contains a definition for 'Queue'

Check failure on line 198 in mod/Jailbreak.Teams/Queue/QueueBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The type 'QueueBehavior' already contains a definition for 'Queue'
=> Utilities.GetPlayers()
.Select(player => (Player: player, State: _state.Get(player)))
.Where(tuple => tuple.State.InQueue) // Exclude not in queue
.Where(tuple => !tuple.State.IsGuard) // Exclude current guards
.OrderBy(tuple => tuple.State.Position) // Order by counter value when joined queue
.Select(tuple => tuple.Player);
}
Loading

0 comments on commit d7fc330

Please sign in to comment.