Phil25 / RTD

Roll The Dice SourceMod plugin for Team Fortress 2
GNU General Public License v3.0
55 stars 20 forks source link

Add generic `call` function which uses the command interface #77

Open Phil25 opened 10 months ago

Phil25 commented 10 months ago

Perk config is very versatile, but it can be even more so.

Example

There could be an unused-by-default call function which is able to execture commands provided via perk's settings, for example:

"myslapperk"
{
    "name"          "My Slap Perk"
    "good"          "0"
    (...)
    "settings"
    {
        "command"   "sm_slap"
        "arg1"      "%target%" // %target% gets replaced with user ID player who rolled the perk
        "arg2"      "100" // slap damage
    }
    "call"          "CustomCommand_Call"
    "init"          "CustomCommand_Init"
}

Overview

The command can be provided via the command setting and its arguments through consecutive argN settings. The function called CustomCommand_Call will parse and build a command that is run on the server, targeting the player who rolled this particular perk.

%target% will be replaced with the user ID of a player by RTD, to make sure addressing is unique and not name-dependent. Furthermore, %target% can be specified in any argument, since it's up to the command to define which argument is the target.

CustomCommand_Init will verify whether the command is valid and is safe (see section below) to run while the config is parsed. This is helpful for debugging because you can see a message in the server logs whether you configured something incorrectly.

Security

Running server commands in an unsolicited way is bad. CustomCommand_Call will always check flags of the provided command. Commands will the following flags should error out without being executed:

  1. kick
  2. ban
  3. unban
  4. changemap
  5. cvar
  6. config
  7. password
  8. rcon
  9. root