Skip to content

Commit

Permalink
allowedCmds for new server
Browse files Browse the repository at this point in the history
  • Loading branch information
Izocel committed Feb 2, 2024
1 parent 0378a16 commit 56a5629
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
34 changes: 30 additions & 4 deletions src/events/messageCreateCs2RCON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
9 changes: 8 additions & 1 deletion src/tools/guildsConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const guildsConfigs = [
}
},
{
//CS2-CustomMaps
//Smoking_Volcano
guildId: "1166437263543128144",
welcome: {
channelId: "1166437265501847584",
Expand All @@ -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: {
Expand Down

0 comments on commit 56a5629

Please sign in to comment.