From 3db39c096fc700f056a273f4240bf51a448a5377 Mon Sep 17 00:00:00 2001 From: Rushaway Date: Sat, 5 Apr 2025 14:00:41 +0200 Subject: [PATCH 1/2] feat: Steamid 3 cvar, reduce errors log spam --- client/Source-Chat-Relay.sp | 46 ++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/client/Source-Chat-Relay.sp b/client/Source-Chat-Relay.sp index 522be7d..4021471 100644 --- a/client/Source-Chat-Relay.sp +++ b/client/Source-Chat-Relay.sp @@ -22,6 +22,7 @@ int g_iPort = 57452; int g_iFlag; bool g_bFlag; +bool g_bSocketErrorLogged; // Core convars ConVar g_cHost; @@ -30,6 +31,7 @@ ConVar g_cPrefix; ConVar g_cFlag; ConVar g_cHostname; ConVar g_cTimeStamp; +ConVar g_cSteamID3; ConVar g_cDebug; // Event convars @@ -323,7 +325,7 @@ public Plugin myinfo = name = "Source Chat Relay", author = "Fishy, maxime1907, .Rushaway, Koen", description = "Communicate between Discord & In-Game, monitor server without being in-game, control the flow of messages and user base engagement!", - version = "2.3.0", + version = "2.3.1", url = "https://keybase.io/RumbleFrog" }; @@ -351,6 +353,8 @@ public void OnPluginStart() g_cTimeStamp = CreateConVar("rf_scr_timestamp", "1", "Enable timestamp on messages", FCVAR_NONE, true, 0.0, true, 1.0); + g_cSteamID3 = CreateConVar("rf_scr_steamid3", "0", "Enable SteamID3 format for messages", FCVAR_NONE, true, 0.0, true, 1.0); + g_cDebug = CreateConVar("rf_scr_debug", "0", "Enable debug mode", FCVAR_NONE, true, 0.0, true, 1.0); // Start basic event convars @@ -514,7 +518,15 @@ public void OnSocketError(Handle socket, int errorType, int errorNum, any ary) { StartReconnectTimer(); - LogError("Source Chat Relay socket error %i (errno %i)", errorType, errorNum); + if (!g_bSocketErrorLogged) + { + g_bSocketErrorLogged = true; + LogError("Source Chat Relay socket error %i (errno %i)", errorType, errorNum); + } + else + { + PrintToServer("Source Chat Relay: Socket error %i (errno %i)", errorType, errorNum); + } } public void OnSocketConnected(Handle socket, any arg) @@ -687,6 +699,11 @@ public void ePlayerJoinLeave(Handle event, const char[] name, bool dontBroadcast } } +public void OnMapStart() +{ + g_bSocketErrorLogged = false; +} + public void OnMapEnd() { if (!g_cMapEvent.BoolValue) @@ -728,7 +745,7 @@ public void OnClientSayCommand_Post(int client, const char[] command, const char void DispatchMessage(int iClient, const char[] sMessage) { - char sID[64], sName[MAX_NAME_LENGTH], tMessage[MAX_COMMAND_LENGTH], sFinalMessage[MAX_COMMAND_LENGTH]; + char sID[64], sID3[64], sName[MAX_NAME_LENGTH], tMessage[MAX_COMMAND_LENGTH], sFinalMessage[MAX_COMMAND_LENGTH]; Action aResult; @@ -744,6 +761,11 @@ void DispatchMessage(int iClient, const char[] sMessage) return; } + if (g_cSteamID3.BoolValue && !GetClientAuthId(iClient, AuthId_Steam3, sID3, sizeof sID3)) + { + return; + } + if (!GetClientName(iClient, sName, sizeof sName)) { return; @@ -761,13 +783,19 @@ void DispatchMessage(int iClient, const char[] sMessage) ReplaceString(sFinalMessage, sizeof(sFinalMessage), ".", "¸"); ReplaceString(sFinalMessage, sizeof(sFinalMessage), "@", "ⓐ"); // Because it is a webhook, it bypasses the permission + char sNameFormatted[MAX_NAME_LENGTH]; + if (g_cSteamID3.BoolValue) + FormatEx(sNameFormatted, sizeof(sNameFormatted), "%s | %s", sID3, sName); + else + FormatEx(sNameFormatted, sizeof(sNameFormatted), "%s", sName); + // Format the final message to include timestamp before the name // Note: We open the code block before the timestamp/name and close it after the message to only have one code block - char sNameFormatted[MAX_NAME_LENGTH]; + char sFinalFormat[MAX_NAME_LENGTH]; if (g_cTimeStamp.BoolValue) - FormatEx(sNameFormatted, sizeof(sNameFormatted), " | `%s", GetTime(), sName); + FormatEx(sFinalFormat, sizeof(sFinalFormat), " | `%s", GetTime(), sNameFormatted); else - FormatEx(sNameFormatted, sizeof(sNameFormatted), "`%s", sName); + FormatEx(sFinalFormat, sizeof(sFinalFormat), "`%s", sNameFormatted); // Format message to prevent mardown formatting on Discord FormatEx(sFinalMessage, sizeof(sFinalMessage), "%s`", tMessage); @@ -776,6 +804,8 @@ void DispatchMessage(int iClient, const char[] sMessage) { PrintToConsoleAll("====== DispatchMessage ====="); PrintToConsoleAll("sID: %s", sID); + if (g_cSteamID3.BoolValue) + PrintToConsoleAll("sID3: %s", sID3); PrintToConsoleAll("sName: %s", sName); PrintToConsoleAll("sNameFormatted: %s", sNameFormatted); PrintToConsoleAll("sMessage: %s", sMessage); @@ -785,14 +815,14 @@ void DispatchMessage(int iClient, const char[] sMessage) Call_StartForward(g_hMessageSendForward); Call_PushCell(iClient); - Call_PushStringEx(sNameFormatted, sizeof(sNameFormatted), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + Call_PushStringEx(sFinalFormat, sizeof(sFinalFormat), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); Call_PushStringEx(sFinalMessage, sizeof(sFinalMessage), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); Call_Finish(aResult); if (aResult >= Plugin_Handled) return; - ChatMessage(IdentificationSteam, sID, sNameFormatted, sFinalMessage).Dispatch(); + ChatMessage(IdentificationSteam, sID, sFinalFormat, sFinalMessage).Dispatch(); } public int Native_SendMessage(Handle plugin, int numParams) From d0210b6314e79dfda796d5c4c8ef966adee9f522 Mon Sep 17 00:00:00 2001 From: Rushaway Date: Wed, 21 May 2025 15:36:44 +0200 Subject: [PATCH 2/2] Update Source-Chat-Relay.sp --- client/Source-Chat-Relay.sp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/client/Source-Chat-Relay.sp b/client/Source-Chat-Relay.sp index 4021471..23d1a1b 100644 --- a/client/Source-Chat-Relay.sp +++ b/client/Source-Chat-Relay.sp @@ -31,7 +31,7 @@ ConVar g_cPrefix; ConVar g_cFlag; ConVar g_cHostname; ConVar g_cTimeStamp; -ConVar g_cSteamID3; +ConVar g_cAuthIdType; ConVar g_cDebug; // Event convars @@ -353,7 +353,7 @@ public void OnPluginStart() g_cTimeStamp = CreateConVar("rf_scr_timestamp", "1", "Enable timestamp on messages", FCVAR_NONE, true, 0.0, true, 1.0); - g_cSteamID3 = CreateConVar("rf_scr_steamid3", "0", "Enable SteamID3 format for messages", FCVAR_NONE, true, 0.0, true, 1.0); + g_cAuthIdType = CreateConVar("rf_scr_authid_type", "2", "AuthID type used for display [0 = Engine, 1 = Steam2, 2 = Steam3, 3 = Steam64]", FCVAR_NONE, true, 0.0, true, 3.0); g_cDebug = CreateConVar("rf_scr_debug", "0", "Enable debug mode", FCVAR_NONE, true, 0.0, true, 1.0); @@ -745,7 +745,7 @@ public void OnClientSayCommand_Post(int client, const char[] command, const char void DispatchMessage(int iClient, const char[] sMessage) { - char sID[64], sID3[64], sName[MAX_NAME_LENGTH], tMessage[MAX_COMMAND_LENGTH], sFinalMessage[MAX_COMMAND_LENGTH]; + char sID[64], sDisplayID[64], sName[MAX_NAME_LENGTH], tMessage[MAX_COMMAND_LENGTH], sFinalMessage[MAX_COMMAND_LENGTH]; Action aResult; @@ -756,12 +756,18 @@ void DispatchMessage(int iClient, const char[] sMessage) if (tMessage[0] == '/' || tMessage[0] == '@' || strlen(tMessage) == 0 || IsChatTrigger()) return; + AuthIdType authType = view_as(g_cAuthIdType.IntValue); if (!GetClientAuthId(iClient, AuthId_SteamID64, sID, sizeof sID)) { return; } - if (g_cSteamID3.BoolValue && !GetClientAuthId(iClient, AuthId_Steam3, sID3, sizeof sID3)) + // Get the display ID based on the selected auth type + if (authType == AuthId_SteamID64) + { + strcopy(sDisplayID, sizeof(sDisplayID), sID); + } + else if (!GetClientAuthId(iClient, authType, sDisplayID, sizeof sDisplayID)) { return; } @@ -784,10 +790,7 @@ void DispatchMessage(int iClient, const char[] sMessage) ReplaceString(sFinalMessage, sizeof(sFinalMessage), "@", "ⓐ"); // Because it is a webhook, it bypasses the permission char sNameFormatted[MAX_NAME_LENGTH]; - if (g_cSteamID3.BoolValue) - FormatEx(sNameFormatted, sizeof(sNameFormatted), "%s | %s", sID3, sName); - else - FormatEx(sNameFormatted, sizeof(sNameFormatted), "%s", sName); + FormatEx(sNameFormatted, sizeof(sNameFormatted), "%s | %s", sDisplayID, sName); // Format the final message to include timestamp before the name // Note: We open the code block before the timestamp/name and close it after the message to only have one code block @@ -804,8 +807,7 @@ void DispatchMessage(int iClient, const char[] sMessage) { PrintToConsoleAll("====== DispatchMessage ====="); PrintToConsoleAll("sID: %s", sID); - if (g_cSteamID3.BoolValue) - PrintToConsoleAll("sID3: %s", sID3); + PrintToConsoleAll("sDisplayID: %s", sDisplayID); PrintToConsoleAll("sName: %s", sName); PrintToConsoleAll("sNameFormatted: %s", sNameFormatted); PrintToConsoleAll("sMessage: %s", sMessage);