{
  "name": "VACChecker",
  "author": "limon",
  "supportedGames": [
    "all"
  ],
  "takaroVersion": "main",
  "versions": [
    {
      "tag": "latest",
      "description": "Automatically checks players for VAC bans upon connection and applies configurable punishments (kick or ban) based on the ban's age.\n\n  ## Key Functionality\n\n  * **VAC Ban Detection:** The module retrieves player VAC ban information (number of bans, days since last ban) from the game server.\n  * **Configurable Threshold:** Administrators can set a threshold for the number of days since the last VAC ban. Players with bans within this threshold are subject to punishment.\n  * **Punishment Options:** The module supports two punishment types:\n        * `Kick`: Removes the player from the server.\n        * `Ban`: Temporarily bans the player.\n  * **Customizable Messages:** Kick and ban messages can be customized to inform players of the reason for the action.\n  * **Immunity Permission:** A permission can be granted to exempt specific players from VAC ban checks and punishments.\n\n  ## How to Use\n\n  1.  **Configuration:**\n      * `PunishmentType`: Choose the punishment to apply (`kick` or `ban`). Default: `kick`.\n      * `Ban Duration`: If `PunishmentType` is `ban`, set the duration of the ban (in milliseconds).\n      * `PunishmentMessage`: Customize the message shown to the player when they are kicked or banned. Use `{days}` as a placeholder for the number of days since the player's last VAC ban and `{threshold}` for the configured `DaysThreshold`.\n      * `DaysThreshold`: Set the number of days. Players with a VAC ban within this many days will be punished.\n  2.  **Permissions:**\n      * Grant the `VAC_BAN_IMMUNITY` permission to players who should be exempt from VAC ban checks.\n  3.  **Module Operation:**\n      * The module automatically checks players when they connect to the server. No manual commands are required.\n\n  ## Important Considerations\n\n  * **Game Server Compatibility:** Ensure that your game server provides the necessary player VAC ban information for this module to function correctly.\n  * **Threshold Setting:** Carefully consider the `DaysThreshold` to balance enforcement with player leniency.\n  * **Immunity Usage:** Use the `VAC_BAN_IMMUNITY` permission judiciously.\n  * **Message Clarity:** Customize the `PunishmentMessage` to provide clear and informative reasons for kicks or bans.\n",
      "configSchema": "{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"type\":\"object\",\"required\":[],\"additionalProperties\":false,\"properties\":{\"PunishmentType\":{\"title\":\"PunishmentType\",\"description\":\"PunishmentType\",\"default\":\"kick\",\"type\":\"string\",\"enum\":[\"kick\",\"ban\"]},\"Ban Duration\":{\"title\":\"Ban Duration\",\"description\":\"Ban Duration\",\"default\":3600000,\"x-component\":\"duration\",\"type\":\"number\"},\"PunishmentMessage\":{\"title\":\"PunishmentMessage\",\"description\":\"Punishment Message\",\"default\":\"VAC ban detected {days} days ago\",\"type\":\"string\"},\"DaysThreshold\":{\"title\":\"DaysThreshold\",\"description\":\"Days Threshold\",\"type\":\"string\"}}}",
      "uiSchema": "{}",
      "commands": [],
      "hooks": [
        {
          "name": "vac-checker",
          "eventType": "player-connected",
          "description": "Hook for player-connected events",
          "regex": null,
          "function": "import { takaro, data, checkPermission } from '@takaro/helpers';\n\nasync function main() {\n    const { gameServerId, player, pog } = data;\n    console.log(`VACBanChecker: Checking player ${player.name}`);\n\n    // Check for immunity permission\n    if (checkPermission(pog, 'VAC_BAN_IMMUNITY')) {\n        console.log(`VACBanChecker: Player ${player.name} has immunity, skipping check`);\n        return;\n    }\n\n    // Get the player data from their ID\n    const playerData = (await takaro.player.playerControllerGetOne(player.id)).data.data;\n    console.log(`VACBanChecker: Player Steam data loaded for ${player.name}`, {\n        vacBans: playerData.steamNumberOfVACBans,\n        daysSinceLastBan: playerData.steamsDaysSinceLastBan\n    });\n\n    // Check for VAC bans\n    if (playerData.steamNumberOfVACBans > 0 &&\n        parseInt(playerData.steamsDaysSinceLastBan) < data.module.userConfig.daysThreshold) {\n\n        const formattedMessage = data.module.userConfig.PunishmentMessage\n            .replace('{days}', playerData.steamsDaysSinceLastBan)\n            .replace('{threshold}', data.module.userConfig.daysThreshold);\n\n        if (data.module.userConfig.PunishmentType === 'kick') {\n            await takaro.gameserver.gameServerControllerKickPlayer(gameServerId, player.id, {\n                reason: formattedMessage\n            });\n\n            await takaro.gameserver.gameServerControllerSendMessage(gameServerId, {\n                message: `${player.name} was kicked (VAC ban ${playerData.steamsDaysSinceLastBan} days ago)`\n            });\n        } else if (data.module.userConfig.PunishmentType === 'ban') {\n            const now = new Date();\n            const expiresAt = new Date(now.getTime() + (data.module.userConfig['Ban Duration']));\n\n            await takaro.player.banControllerCreate({\n                gameServerId,\n                playerId: player.id,\n                until: expiresAt,\n                reason: formattedMessage\n            });\n\n            await takaro.gameserver.gameServerControllerSendMessage(gameServerId, {\n                message: `${player.name} was banned (VAC ban ${playerData.steamsDaysSinceLastBan} days ago)`\n            });\n        }\n    }\n}\n\nawait main();"
        }
      ],
      "cronJobs": [],
      "functions": [],
      "permissions": [
        {
          "permission": "VAC_BAN_IMMUNITY",
          "friendlyName": "VAC_BAN_IMMUNITY",
          "description": "VAC_BAN_IMMUNITY",
          "canHaveCount": false
        }
      ]
    }
  ]
}