Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ When modifying the plugin, test integration with:

## Common Pitfalls to Avoid
- **Never use synchronous SQL queries** - all must be async
- **Don't forget to escape SQL strings** - always use `g_hDB.Escape()`
- **Don't forget to escape SQL strings** - build queries with `g_hDB.Format()`, which escapes `%s` string arguments directly, instead of manually calling `g_hDB.Escape()` into a separate buffer
- **Avoid memory leaks** - use `delete` instead of `.Clear()`
- **Don't hardcode values** - use configuration where appropriate
- **Handle client disconnections** - always validate client indices
Expand Down
31 changes: 13 additions & 18 deletions addons/sourcemod/scripting/SelfMute.sp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public Plugin myinfo = {
name = "SelfMute V2",
author = "Dolly",
description = "Ignore other players in text and voicechat.",
version = "2.2.1",
version = "2.2.2",
url = ""
};

Expand Down Expand Up @@ -1804,13 +1804,10 @@ void DeleteMuteFromDatabase(int client, int target = -1, const char[] groupFilte
FormatEx(query, sizeof(query), "DELETE FROM `clients_mute` WHERE `client_steamid`=%d AND `target_steamid`=%d",
clientSteamID, targetSteamID);
} else {
char escapedGroupFilter[42];
if (!g_hDB.Escape(groupFilterC, escapedGroupFilter, sizeof(escapedGroupFilter))) {
if (!g_hDB.Format(query, sizeof(query), "DELETE FROM `groups_mute` WHERE `client_steamid`=%d AND `group_filter`='%s'",
clientSteamID, groupFilterC)) {
return;
}

FormatEx(query, sizeof(query), "DELETE FROM `groups_mute` WHERE `client_steamid`=%d AND `group_filter`='%s'",
clientSteamID, escapedGroupFilter);
}

g_hDB.Query(DB_OnRemove, query, _, DBPrio_Normal);
Expand Down Expand Up @@ -1884,34 +1881,32 @@ void SaveSelfMuteClient(int client, int target) {
}

void SaveSelfMuteGroup(int client, GroupFilter groupFilter) {
char groupFilterC[20 * 2 + 1];

if (!g_hDB.Escape(g_sGroupsFilters[view_as<int>(groupFilter)], groupFilterC, sizeof(groupFilterC))) {
return;
}

int clientSteamID = g_PlayerData[client].steamID;
if (!clientSteamID) {
return;
}

char query[512];
if (!g_bSQLLite) {
FormatEx(query, sizeof(query), "INSERT INTO `groups_mute` (`client_steamid`, `group_filter`,"
if (!g_hDB.Format(query, sizeof(query), "INSERT INTO `groups_mute` (`client_steamid`, `group_filter`,"
... "`text_chat`, `voice_chat`) VALUES (%d, '%s', %d, %d)"
... "ON DUPLICATE KEY UPDATE "
... "`text_chat`=VALUES(`text_chat`), `voice_chat`=VALUES(`voice_chat`)",
clientSteamID,
groupFilterC, view_as<int>(g_bClientGroupText[client][view_as<int>(groupFilter)]),
view_as<int>(g_bClientGroupVoice[client][view_as<int>(groupFilter)]));
g_sGroupsFilters[view_as<int>(groupFilter)], view_as<int>(g_bClientGroupText[client][view_as<int>(groupFilter)]),
view_as<int>(g_bClientGroupVoice[client][view_as<int>(groupFilter)]))) {
return;
}
} else {
FormatEx(query, sizeof(query), "INSERT INTO groups_mute (client_steamid, group_filter,"
if (!g_hDB.Format(query, sizeof(query), "INSERT INTO groups_mute (client_steamid, group_filter,"
... "text_chat, voice_chat) VALUES (%d, '%s', %d, %d)"
... " ON CONFLICT(client_steamid, group_filter) DO UPDATE SET "
... "text_chat=excluded.text_chat, voice_chat=excluded.voice_chat",
clientSteamID,
groupFilterC, view_as<int>(g_bClientGroupText[client][view_as<int>(groupFilter)]),
view_as<int>(g_bClientGroupVoice[client][view_as<int>(groupFilter)]));
g_sGroupsFilters[view_as<int>(groupFilter)], view_as<int>(g_bClientGroupText[client][view_as<int>(groupFilter)]),
view_as<int>(g_bClientGroupVoice[client][view_as<int>(groupFilter)]))) {
return;
}
}

g_hDB.Query(DB_OnInsertData, query, _, DBPrio_High);
Expand Down