Skip to content

Commit

Permalink
feature: voting system (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukepolo authored Nov 7, 2024
1 parent 9385d60 commit 8e4a195
Show file tree
Hide file tree
Showing 20 changed files with 606 additions and 362 deletions.
5 changes: 4 additions & 1 deletion scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ if $INSTALL_5STACK_PLUGIN = true ; then
fi
fi

cp "/opt/server-cfg/core.json" "$INSTANCE_SERVER_DIR/game/csgo/addons/counterstrikesharp/configs"
if [ ! -e "$INSTANCE_SERVER_DIR/game/csgo/addons/counterstrikesharp/configs/core.json" ]; then
cp "/opt/server-cfg/core.json" "$INSTANCE_SERVER_DIR/game/csgo/addons/counterstrikesharp/configs"
fi


echo "---Check Metamod Install---"
gameinfo_path="${INSTANCE_SERVER_DIR}/game/csgo/gameinfo.gi"
Expand Down
20 changes: 14 additions & 6 deletions src/FiveStack.Commands/BackupRounds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public void OnResetRound(CCSPlayerController? player, CommandInfo command)
"Should only be called by the API, this is so we know the api regonized the restore"
)]
[CommandHelper(whoCanExecute: CommandUsage.SERVER_ONLY)]
public void OnApiResetRound(CCSPlayerController? player, CommandInfo command)
public async void OnApiResetRound(CCSPlayerController? player, CommandInfo command)
{
_logger.LogInformation("API Restoring Round");
string _round = command.ArgByIndex(1);

if (_round == null)
Expand Down Expand Up @@ -62,12 +63,18 @@ public void OnApiResetRound(CCSPlayerController? player, CommandInfo command)

_gameServer.SendCommands(new[] { $"mp_backup_restore_load_file {backupRoundFile}" });

_gameBackupRounds.ResetRestoreBackupRound();
_logger.LogInformation($"LETS GO Round {round}");

_gameServer.Message(
HudDestination.Alert,
$" {ChatColors.Red}Round {round} has been restored ({CommandUtility.PublicChatTrigger}resume to continue)"
);
await Task.Delay(10 * 1000);

Server.NextFrame(() =>
{
_logger.LogInformation($"Sending Message for Round {round}");
_gameServer.Message(
HudDestination.Alert,
$" {ChatColors.Red}Round {round} has been restored ({CommandUtility.PublicChatTrigger}resume to continue)"
);
});
}

[ConsoleCommand("css_reset", "Restores to a previous round")]
Expand All @@ -77,6 +84,7 @@ public void OnRestoreRound(CCSPlayerController? player, CommandInfo command)

if (_round == null || _gameBackupRounds.IsResettingRound())
{
_logger.LogWarning("Already restoring round, skipping");
return;
}

Expand Down
3 changes: 3 additions & 0 deletions src/FiveStack.Commands/Help.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public void OnHelp(CCSPlayerController? player, CommandInfo command)
command.ReplyToCommand(
$" {ChatColors.BlueGrey}Rules: {ChatColors.Default}{CommandUtility.PublicChatTrigger}rules"
);
command.ReplyToCommand(
$" {ChatColors.BlueGrey}Restore Round: {ChatColors.Default}{CommandUtility.PublicChatTrigger}reset <round>"
);
}

[ConsoleCommand("css_rules", "Shows Rules for Match")]
Expand Down
9 changes: 1 addition & 8 deletions src/FiveStack.Commands/Surrender.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Utils;
using FiveStack.Utilities;

namespace FiveStack;

Expand All @@ -16,11 +14,6 @@ public void Surrender(CCSPlayerController? player, CommandInfo? command)
return;
}

_gameServer.Message(
HudDestination.Notify,
$"{player.PlayerName} has asked to surrender the match, type in {CommandUtility.PublicChatTrigger}y or {CommandUtility.PublicChatTrigger}n to vote"
);

_surrender.SetupSurrender(player.Team);
_surrenderSystem.SetupSurrender(player.Team, player);
}
}
6 changes: 3 additions & 3 deletions src/FiveStack.Commands/Timeout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ public partial class FiveStackPlugin
[ConsoleCommand("css_pause", "Pauses the match")]
public void OnPause(CCSPlayerController? player, CommandInfo? command)
{
_matchTimeouts.Pause(player);
_timeoutSystem.RequestPause(player);
}

[ConsoleCommand("css_resume", "Resumes the match")]
public void OnResume(CCSPlayerController? player, CommandInfo? command)
{
_matchTimeouts.Resume(player);
_timeoutSystem.RequestResume(player);
}

[ConsoleCommand("css_tac", "Tactical Timeout")]
public void OnTimeout(CCSPlayerController? player, CommandInfo? command)
{
_matchTimeouts.CallTacTimeout(player);
_timeoutSystem.CallTacTimeout(player);
}
}
18 changes: 15 additions & 3 deletions src/FiveStack.Commands/Vote.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
using Microsoft.Extensions.Logging;

namespace FiveStack;

Expand All @@ -17,12 +18,23 @@ public void OnResetAnswer(CCSPlayerController? player, CommandInfo command)

if (_gameBackupRounds.IsResettingRound())
{
_gameBackupRounds.CastVote(player, command.GetCommandString == "css_y");
_gameBackupRounds.restoreRoundVote?.CastVote(
player,
command.GetCommandString == "css_y"
);
}

if (_surrender.IsSurrendering())
if (_surrenderSystem.IsSurrendering())
{
_surrender.CastVote(player, command.GetCommandString == "css_y");
_surrenderSystem.surrenderingVote?.CastVote(
player,
command.GetCommandString == "css_y"
);
}

if (_timeoutSystem.resumeVote != null)
{
_timeoutSystem.resumeVote?.CastVote(player, command.GetCommandString == "css_y");
}
}
}
1 change: 1 addition & 0 deletions src/FiveStack.Events/GameEnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public partial class FiveStackPlugin
[GameEventHandler]
public HookResult OnGameEnd(EventCsWinPanelMatch @event, GameEventInfo info)
{
_surrenderSystem.ResetDisconnectTimers();
_gameDemos.Stop();

MatchManager? match = _matchService.GetCurrentMatch();
Expand Down
2 changes: 1 addition & 1 deletion src/FiveStack.Events/PlayerConnected.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public HookResult OnPlayerConnect(EventPlayerConnectFull @event, GameEventInfo i
return HookResult.Continue;
}

_surrender.CancelDisconnectTimer(@event.Userid.SteamID);
_surrenderSystem.CancelDisconnectTimer(@event.Userid.SteamID);

CCSPlayerController player = @event.Userid;

Expand Down
5 changes: 1 addition & 4 deletions src/FiveStack.Events/PlayerDisconnected.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Utils;
using FiveStack.Entities;

namespace FiveStack;
Expand Down Expand Up @@ -38,9 +37,7 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo

if (match.IsLive())
{
_gameServer.Message(HudDestination.Center, $" {ChatColors.Red}Match Paused");
match.PauseMatch();
_surrender.SetupDisconnectTimer(@event.Userid.Team, @event.Userid.SteamID);
_surrenderSystem.SetupDisconnectTimer(@event.Userid.Team, @event.Userid.SteamID);
}

return HookResult.Continue;
Expand Down
4 changes: 2 additions & 2 deletions src/FiveStack.Events/RoundEnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ public HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
MatchMap? currentMap = match?.GetCurrentMap();
MatchData? matchData = match?.GetMatchData();

this.roundWinner = TeamUtility.TeamNumToCSTeam(@event.Winner);

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

this.roundWinner = TeamUtility.TeamNumToCSTeam(@event.Winner);

if (match.IsKnife())
{
match.knifeSystem.SetWinningTeam(TeamUtility.TeamNumToCSTeam(@event.Winner));
Expand Down
40 changes: 40 additions & 0 deletions src/FiveStack.Events/RoundStart.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using FiveStack.Utilities;
using Microsoft.Extensions.Logging;

namespace FiveStack;

public partial class FiveStackPlugin
{
[GameEventHandler]
public HookResult OnRoundStart(EventRoundPrestart @event, GameEventInfo info)
{
MatchManager? matchManager = _matchService.GetCurrentMatch();
if (matchManager == null)
{
return HookResult.Continue;
}

if (!matchManager.IsLive())
{
return HookResult.Continue;
}

int currentPlayers = MatchUtility.Players().Count;

int expectedPlayers = _matchService.GetCurrentMatch()?.GetExpectedPlayerCount() ?? 10;

_logger.LogInformation(
"expectedPlayers: {expectedPlayers}, currentPlayers: {currentPlayers}",
expectedPlayers,
currentPlayers
);
if (currentPlayers < expectedPlayers)
{
matchManager.PauseMatch("Waiting for players to reconnect");
}

return HookResult.Continue;
}
}
Loading

0 comments on commit 8e4a195

Please sign in to comment.