refactor(core): improve code readability - #36
Merged
Conversation
Rushaway
commented
Aug 7, 2026
Member
- Also remove un-needed code
There was a problem hiding this comment.
Pull request overview
This PR refactors the AdminLogging SourcePawn plugin to simplify webhook handling and queue cleanup, aiming to improve readability while removing some previously duplicated/temporary webhook URL plumbing.
Changes:
- Cache
sm_adminlogging_webhookinto a globalg_sWebhookURLvia a ConVar change hook, and use it for webhook execution/retries. - Simplify plugin shutdown cleanup by directly deleting the send queue.
- Refactor queue dispatch and
SendWebHook()to no longer pass the webhook URL around as a parameter.
Suppressed comments (6)
addons/sourcemod/scripting/AdminLogging.sp:322
- This error message also omits the plugin prefix, making it harder to trace back to this plugin in aggregated logs.
if (g_hSendQueue == null)
{
LogError("Send queue is not initialized.");
return Plugin_Handled;
}
addons/sourcemod/scripting/AdminLogging.sp:363
- SendWebHook() now always uses the global g_sWebhookURL. If the ConVar is changed/cleared after messages are queued (or while retries are pending), webhook.Execute() will run with an empty/changed URL. Add a defensive check inside SendWebHook() so retries/queued sends can’t execute with an empty URL.
This issue also appears on line 401 of the same file.
stock void SendWebHook(char sMessage[WEBHOOK_MSG_MAX_SIZE + 1], int iMsgIndex = -1, int iRetries = 0)
{
/* Webhook UserName */
char sName[128];
g_cvUsername.GetString(sName, sizeof(sName));
addons/sourcemod/scripting/AdminLogging.sp:380
- This ThreadID error message also dropped the plugin prefix, which reduces context in server logs.
if (IsThread && !sThreadID[0])
{
LogError("ThreadID not found or specified.");
delete webhook;
return;
addons/sourcemod/scripting/AdminLogging.sp:404
- Queue dispatch + retry logic no longer snapshots the webhook URL per message/dispatch. If sm_adminlogging_webhook changes while a queue is in flight (or between a failed send and its retry timer), subsequent sends/retries may go to a different webhook than the one that was configured when the message was enqueued.
pack.WriteString(sMessage);
webhook.Execute(g_sWebhookURL, OnWebHookExecuted, pack, sThreadID);
delete webhook;
addons/sourcemod/scripting/AdminLogging.sp:441
- These failure logs dropped the plugin prefix and have inconsistent punctuation ("Failed message :"). Including PLUGIN_NAME and a consistent label makes ops triage easier.
LogError("Failed to send the webhook after %d retries, aborting.", retries[iMsgIndex]);
LogError("Failed message : %s", sMessage);
addons/sourcemod/scripting/AdminLogging.sp:447
- Same as the LogError branch: ExtendedDiscord_LogError messages should include the plugin prefix and consistent punctuation for easier correlation with other logs.
ExtendedDiscord_LogError("Failed to send the webhook after %d retries, aborting.", retries[iMsgIndex]);
ExtendedDiscord_LogError("Failed message : %s", sMessage);
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.