Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Allow arbitrary RCon commands in chat commands #678

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

FlorianSW
Copy link
Collaborator

@FlorianSW FlorianSW commented Sep 4, 2024

There are communities that would like to use chat commands with a more powerful set of actions that can be triggered when a player uses a chat command. Two real-worl example from the "event server for prepping" use case:

Switching player side

Changing a side without needing to redeploy for themself, a command "!switch" is useful. Issuing this command will forward a switch_player_now RCon command with the player_name of the issuing player.

Redeploying with 10 instead of 20 seconds

Redeploying with the punish command might be useful when needing to redeploy for multiple times. A command "!redeploy", which issues a punish command for the issuing player, might be useful here.

This feature is implemented with this PR. A chat command can either have a message key or a command key (message takes precendence). The command config is an object that has the same signature and functinality as auto-settings commands.
This allows for a powerful set of tools, while it also has some risks, as everything can now be executed with a player issuing a specific chat command.

The parameters of the command will replace message parameters same as the message itself, however, only context keys are populated. No other variables are available in commands params.

Example config

{
  "enabled": true,
  "command_words": [
    {
      "words": [
        "!switch"
      ],
      "message": null,
      "commands": {
        "switch_player_now": {
          "player_name": "{player_name}"
        }
      },
      "conditions": {
        "player_id": {
          "player_ids": [
            "765611..."
          ]
        },
        "online_mods": {
          "max": 10,
          "min": 0
        },
        "player_flag": {
          "flags": [
            "👍"
          ]
        },
        "player_count": {
          "max": 10,
          "min": 0
        }
      }
      "enabled": true,
      "description": "Switch yourself in side"
    },
    {
      "words": [
        "!admin"
      ],
      "message": null,
      "commands": {
        "add_admin": {
          "role": "junior",
          "player_id": "{player_id}",
          "description": "{player_name}"
        }
      },
      "enabled": true,
      "description": "Add yourself to admin cam list"
    }
  ],
  "describe_words": []
}

Conditions

As seen in the above example, conditions are available for these commands. This allows an admin to define commands which are only executed when the execution context matches certain conditions. These conditions are the same as in AutoSettings.
The PR adds two new conditions, which are only available when the metric source player_id is available. This metric source is currently only available in chat commands, not in auto settings. In auto settings, if one of these conditions is configured, it will always default to "condition is met".

  • Player Flags: The player flags condition is met, when the executing player has at least one of the flags configured in the condition. Otherwise, the condition is not met.
  • Player ID: The condition is met, when the player's ID (Steam ID or Windows ID hash) is one of the configured ones

Automatic enablement and disablement

To make commands only available under certain conditions, a new api is available for auto settings, an example::

{
  "always_allow_defaults": true,
  "defaults": {
    "set_chat_command_enabled": {
      "word": "!switch",
      "enabled": true
    }
  },
  "rules": []
}

This api can be used with all the available conditions in the rules section as known for the other stuff..

Signed-off-by: Florian <[email protected]>
These conditions work in a very same way as conditions in Auto Settings
(they are shared between them both).
All conditions are available in chat rcon commands, conditions that rely
on the player_id metric are only available in chat commands. Using these
conditions in auto settings will implicitly default to "condition is
met".

Two new conditions are available for chat commands (requiring the
player_id metric source):
- player_flags: A condition that is met, when the player has at least
  one of the provided flags. A list of flags can be provided, which are
  combined with OR, meaning that the player requires only one of these
  flags to  meet the condition.
- player_id: A condition thgat is met, when the player's ID is in the
  provided list of static IDs. This ID can either be the player's Steam
  ID or Windows ID, depending on whatever the player's platform is

Allowing the use of the auto settings conditions is a bit redundant, as
a single chat command can still be enabled and disabled using the set_chat_command_enabled
api, which is also available in auto settings. However, this gives the
user freedom to enable/disable the command using auto settings, or by a
condition in the command itself, whatever they prefer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant