highPingKicker

  • builtin
  • by Takaro
  • Takaro >=0.0.1
  • 7 days to die
  • rust
  • minecraft
Version

Built-in modules ship with Takaro — no import needed.

View export JSON

Automatically kick players with high ping, with warnings and configurable thresholds.

Configuration 2

Settings you fill in when installing the module on a server.

SettingTypeDefaultDescription
pingThreshold Ping threshold number 200 A ping value that is deemed too high and prompts a warning.
warningsBeforeKick Kick warnings number 3 Number of warnings before a player is kicked.
Raw config schema
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "pingThreshold": {
      "type": "number",
      "title": "Ping threshold",
      "description": "A ping value that is deemed too high and prompts a warning.",
      "default": 200,
      "minimum": 0
    },
    "warningsBeforeKick": {
      "type": "number",
      "title": "Kick warnings",
      "description": "Number of warnings before a player is kicked.",
      "default": 3,
      "minimum": 0
    }
  },
  "required": []
}
Raw UI schema
{}

Cron jobs 1

Work the module runs on a schedule.

  • Ping check

    Cron job source
    import { takaro, data } from '@takaro/helpers';
    const VARIABLE_KEY = 'highPingKicker:warnings';
    async function main() {
        const currentPlayers = await takaro.gameserver.gameServerControllerGetPlayers(data.gameServerId);
        await Promise.all(currentPlayers.data.data.map(async (player) => {
            if (player.ping > data.module.userConfig.pingThreshold) {
                const takaroPlayerRes = await takaro.player.playerControllerSearch({
                    filters: {
                        steamId: [player.steamId],
                    },
                });
                const takaroPlayer = takaroPlayerRes.data.data[0];
                const currentWarningsRes = await takaro.variable.variableControllerSearch({
                    filters: {
                        playerId: [takaroPlayer.id],
                        key: [VARIABLE_KEY],
                    },
                });
                const currentWarningsRecords = currentWarningsRes.data.data;
                let currentWarnings = 1;
                if (currentWarningsRecords.length) {
                    currentWarnings = parseInt(currentWarningsRecords[0].value, 10) + 1;
                    await takaro.variable.variableControllerUpdate(currentWarningsRecords[0].id, {
                        value: currentWarnings.toString(),
                    });
                }
                else {
                    await takaro.variable.variableControllerCreate({
                        playerId: takaroPlayer.id,
                        key: VARIABLE_KEY,
                        value: '1',
                    });
                }
                // Check if player should be kicked before sending warning
                if (currentWarnings >= data.module.userConfig.warningsBeforeKick) {
                    await takaro.gameserver.gameServerControllerKickPlayer(data.gameServerId, takaroPlayer.id, {
                        reason: `Your ping (${player.ping}) is too high, please try again later.`,
                    });
                    // Delete the warning record after kicking
                    if (currentWarningsRecords.length > 0) {
                        await takaro.variable.variableControllerDelete(currentWarningsRecords[0].id);
                    }
                }
                else {
                    // Only send warning if player won't be kicked
                    await takaro.gameserver.gameServerControllerSendMessage(data.gameServerId, {
                        message: `Your ping (${player.ping}) is too high. Warning ${currentWarnings}/${data.module.userConfig.warningsBeforeKick}`,
                        opts: {
                            recipient: {
                                gameId: player.gameId,
                            },
                        },
                    });
                }
            }
        }));
    }
    await main();
    //# sourceMappingURL=Ping%20check.js.map