Skip to content

Commit

Permalink
Add TeamMode command
Browse files Browse the repository at this point in the history
  • Loading branch information
TheR00st3r committed Nov 28, 2023
1 parent 09f425b commit b4a10b7
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 5 deletions.
16 changes: 13 additions & 3 deletions Docs/source/admin/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Player Commands
Admin/Rcon Commands
-------------------

These commands are available through rcon or to users with the required permissions. See :ref:`admin/configuration:CounterstrikeSharp Configs`
These commands are available through rcon or to users with the required permissions. See :ref:`admin/configuration:CounterstrikeSharp Configs`

``<requiredParameter>`` marks parameters that are required for commands

Expand All @@ -48,9 +48,19 @@ These commands are available through rcon or to users with the required permissi
+----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| ``!ps_creatematch`` | Creates a new match without preloaded configuration. |
+----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| ``!ps_startmatch`` | After match configuration is done with ``!ps_creatematch`` the match can be started. |
+----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| ``!ps_addmap`` | Add a map to the map pool during match creation. |
+----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| ``!ps_removemap`` | Remove a map from the map pool during match creation. |
+----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| ``!ps_playersperteam <players>`` | Sets the number of players per team. |
+----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| ``!ps_maxrounds <rounds>`` | Sets the max number of rounds. |
+----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| ``!ps_maxovertimerounds <rounds>`` | Sets the max number of overtime rounds. |
+----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| ``!ps_teammode <teammode>`` | Sets the teammode. |
+----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| ``!ps_startmatch`` | After match configuration is done with ``!ps_creatematch`` the match can be started. |
+----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| ``!ps_matchinfo`` | Shows the match configuration for the current match or matchcreation. |
+----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
2 changes: 1 addition & 1 deletion PugSharp.Config/TeamMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public enum TeamMode
// Take Teams as they are
Default,

// Scramble Teams afte all players are joined
// Scramble Teams after all players are joined
Scramble,
}
36 changes: 36 additions & 0 deletions PugSharp.Translation/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions PugSharp.Translation/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<data name="PugSharp.Command.ChangedMaxRounds" xml:space="preserve">
<value>Changed max rounds from {0:oldMaxRounds} to {1:maxRounds}</value>
</data>
<data name="PugSharp.Command.ChangedTeamMode" xml:space="preserve">
<value>Changed Teammode from {0:oldTeamMode} to {1:newTeamMode}</value>
</data>
<data name="PugSharp.Command.ConfigLoaded" xml:space="preserve">
<value>Matchconfig loaded!</value>
</data>
Expand Down Expand Up @@ -150,6 +153,9 @@
<data name="PugSharp.Command.CreatingMatchStartMatch" xml:space="preserve">
<value>`!startmatch` to start the match!</value>
</data>
<data name="PugSharp.Command.CreatingMatchTeamMode" xml:space="preserve">
<value>`!teammode &lt;mode&gt;` to set the team mode!</value>
</data>
<data name="PugSharp.Command.Error.ArgumentRoundIndexNotNumeric" xml:space="preserve">
<value>The argument for round index has to be numeric.</value>
</data>
Expand Down Expand Up @@ -204,6 +210,12 @@
<data name="PugSharp.Command.Error.RoundBackupFileNotFound" xml:space="preserve">
<value>RoundBackupFile "{0:roundBackupFile}" not found!</value>
</data>
<data name="PugSharp.Command.Error.TeammodePossibleValues" xml:space="preserve">
<value>PossibleValues for TeamMode: {0:possibleValues}</value>
</data>
<data name="PugSharp.Command.Error.TeammodeRequired" xml:space="preserve">
<value>Teammode is required!</value>
</data>
<data name="PugSharp.Command.Error.UrlRequired" xml:space="preserve">
<value>Url is required as Argument!</value>
</data>
Expand Down
40 changes: 39 additions & 1 deletion PugSharp/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@ public void OnCommandCreateMatch(CCSPlayerController? player, CommandInfo comman
c.ReplyToCommand(_TextHelper, nameof(Resources.PugSharp_Command_CreatingMatchMaxRounds));
c.ReplyToCommand(_TextHelper, nameof(Resources.PugSharp_Command_CreatingMatchMaxOvertimeRounds));
c.ReplyToCommand(_TextHelper, nameof(Resources.PugSharp_Command_CreatingMatchPlayersPerTeam));
c.ReplyToCommand(_TextHelper, nameof(Resources.PugSharp_Command_CreatingMatchTeamMode));
c.ReplyToCommand(_TextHelper, nameof(Resources.PugSharp_Command_CreatingMatchMatchInfo));
},
command,
Expand Down Expand Up @@ -1295,6 +1296,44 @@ public void OnCommandPlayersPerTeam(CCSPlayerController? player, CommandInfo com
player);
}

[ConsoleCommand("css_teammode", "Sets the team mode for the match")]
[ConsoleCommand("ps_teammode", "Sets the team mode for the match")]
[RequiresPermissions("@pugsharp/matchadmin")]
public void OnCommandTeamMode(CCSPlayerController? player, CommandInfo command)
{
const int requiredArgCount = 2;
HandleCommand((p, c) =>
{
if (!IsConfigCreatorAvailable(c, p))
{
return;
}

if (c.ArgCount != requiredArgCount)
{
c.ReplyToCommand(_TextHelper, nameof(Resources.PugSharp_Command_Error_TeammodeRequired));
return;
}

if (!Enum.TryParse<TeamMode>(c.ArgByIndex(1), out var teamMode))
{
if (!int.TryParse(c.ArgByIndex(1), CultureInfo.InvariantCulture, out var teamModeNumber) || !Enum.GetValues<TeamMode>().Cast<int>().Contains(teamModeNumber))
{
c.ReplyToCommand(_TextHelper, nameof(Resources.PugSharp_Command_Error_TeammodePossibleValues), string.Join(", ", Enum.GetValues<TeamMode>()));
return;
}

teamMode = (TeamMode)teamModeNumber;
}

var oldTeamMode = _ConfigCreator.Config.TeamMode;
_ConfigCreator.Config.TeamMode = teamMode;
c.ReplyToCommand(_TextHelper, nameof(Resources.PugSharp_Command_ChangedTeamMode), oldTeamMode, teamMode);
},
command,
player);
}

private bool IsConfigCreatorAvailable(CommandInfo command, CCSPlayerController? playerController)
{
if (_Match != null)
Expand Down Expand Up @@ -1670,6 +1709,5 @@ public void Dispose()
GC.SuppressFinalize(this);
}


#endregion
}

0 comments on commit b4a10b7

Please sign in to comment.