Skip to content

Commit

Permalink
feat: add invalid webhook name checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarrus1 committed Jan 25, 2023
1 parent 4078abd commit ccbd331
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Release Notes

## [2.5.3]

### Added

- Added a check for invalid webhook names.

## [2.5.2]

### Fixed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ The stage record feature will only work with the version `1.0.5` or above of the
- You can modify the phrases in addons/sourcemod/translations/SurfTimer-discord.phrases.txt.
- Once the plugin has been loaded, you can modify the cvars in cfg/sourcemod/SurfTimer-discord.cfg.
- To use Discord mentions, follow [this tutorial](https://discordhelp.net/role-id) to get the role's ID and use `<@&role_id>` in the .cfg file. You can use `@here` and `@everyone` normally.
- **WARNING** Discord no longer allows "everyone" and "here" as webhook names, nor the following substrings: "@", "#", ":", "```", "discord".

## Usage

Expand Down
22 changes: 21 additions & 1 deletion scripting/SurfTimer-discord.sp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public Plugin myinfo =
name = "SurfTimer-Discord",
author = "Sarrus",
description = "A module for SurfTimer-Official to send Discord Notifications when a new record is set.",
version = "2.5.2",
version = "2.5.3",
url = "https://github.com/Sarrus1/SurfTimer-discord"
};

Expand Down Expand Up @@ -142,6 +142,26 @@ public void OnConfigsExecuted()
{
strcopy(g_szProfileUrl, sizeof g_szProfileUrl, "https://steamcommunity.com/profiles");
}

checkIfValidName();
}

void checkIfValidName()
{
char szWebhookName[64];
GetConVarString(g_cvBotUsername, szWebhookName, sizeof szWebhookName);
char szForbiddenSubStrings[5][32] = {"@", "#", ":", "```", "discord"};
char szForbiddenStrings[2][32] = {"everyone", "here"};
for(int i; i<sizeof(szForbiddenStrings); i++){
if (StrEqual(szForbiddenStrings[i], szWebhookName)){
SetFailState("\"%s\" is not allowed in a webhook name.");
}
}
for(int i; i<sizeof(szForbiddenSubStrings); i++){
if (StrContains(szWebhookName, szForbiddenSubStrings[i])){
SetFailState("Webhook name contains an invalid substring: %s", szForbiddenSubStrings[i]);
}
}
}

public void OnAllPluginsLoaded()
Expand Down

0 comments on commit ccbd331

Please sign in to comment.