Skip to content

refactor(core): improve code readability - #36

Merged
Rushaway merged 2 commits into
masterfrom
Rushaway-patch-1
Aug 7, 2026
Merged

refactor(core): improve code readability#36
Rushaway merged 2 commits into
masterfrom
Rushaway-patch-1

Conversation

@Rushaway

@Rushaway Rushaway commented Aug 7, 2026

Copy link
Copy Markdown
Member
  • Also remove un-needed code

Copilot AI lite review requested due to automatic review settings August 7, 2026 13:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_webhook into a global g_sWebhookURL via 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);

Comment thread addons/sourcemod/scripting/AdminLogging.sp
Comment thread addons/sourcemod/scripting/AdminLogging.sp
@Rushaway
Rushaway merged commit 52e16b6 into master Aug 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants