diff --git a/src/events/messageCreateCs2RCON.ts b/src/events/messageCreateCs2RCON.ts index fd2b25a..bf5afa5 100644 --- a/src/events/messageCreateCs2RCON.ts +++ b/src/events/messageCreateCs2RCON.ts @@ -4,7 +4,6 @@ import { getGuildConfigsById } from "../tools/guildsConfigs"; import { textToLines, toSafeJsonString } from "../tools/myFunctions"; import { env } from "process"; - // https://www.ghostcap.com/cs2-commands/ // https://www.npmjs.com/package/@fabricio-191/valve-server-query export default new Event("messageCreate", async (message) => { @@ -22,8 +21,7 @@ export default new Event("messageCreate", async (message) => { } const prompt = message.content.toString(); - if (prompt.length >= 128) { - message.author.send("❌ An error occurred: Rcon prompt must be 128 characters long max."); + if (!handleSanityChecks(prompt, serverConf, message)) { return; } @@ -60,7 +58,6 @@ export default new Event("messageCreate", async (message) => { break; default: - // TODO: blacklist some prompts keywords connectionsParams.password = serverConf.password; const rcon = await RCON(connectionsParams); consoleOut = await rcon.exec(prompt); @@ -90,3 +87,32 @@ export default new Event("messageCreate", async (message) => { } }); + +function handleSanityChecks(serverConf, prompt: string, message) { + if (prompt?.length >= 128) { + message.author.send("❌ An error occurred: Rcon prompt must be 128 characters long max."); + return false; + } + + const filters = serverConf.cmdWhitelist; + if (!filters.length) { + return true; + } + + const split = prompt.split(" "); + const cmd = split[0]; + const singleCmdArgOnly = /^\w+\s+\w+$/; + + let isAllowed = filters.some((filter: any) => { + return cmd.startsWith(filter); + }); + + if (split.length === 1) { + return isAllowed; + } + + isAllowed = isAllowed && singleCmdArgOnly.test(prompt); + !isAllowed && message.author.send("❌ An error occurred: Your prompt includes a command that is not allowed."); + + return isAllowed; +} \ No newline at end of file diff --git a/src/tools/guildsConfigs.ts b/src/tools/guildsConfigs.ts index ddcc357..948dd4c 100644 --- a/src/tools/guildsConfigs.ts +++ b/src/tools/guildsConfigs.ts @@ -96,7 +96,7 @@ export const guildsConfigs = [ } }, { - //CS2-CustomMaps + //Smoking_Volcano guildId: "1166437263543128144", welcome: { channelId: "1166437265501847584", @@ -122,6 +122,13 @@ export const guildsConfigs = [ ip: "rvdprojects.synology.me", password: env["RCON_PASS_192_168_1_128_27016"], region: "US_EAST", + }, + "1202829534144237619": { + port: 27017, + ip: "rvdprojects.synology.me", + password: env["RCON_PASS_192_168_1_128_27016"], + region: "US_EAST", + cmdWhitelist: ['map', 'exec', 'sv_gravity', 'host_workshop_map'] } }, chatChannels: {