Skip to content

Commit 6002dea

Browse files
authored
feat(logic): Improve 3rd party checks
1 parent 473210f commit 6002dea

1 file changed

Lines changed: 53 additions & 14 deletions

File tree

addons/sourcemod/scripting/AdminLogging.sp

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ char g_sMap[PLATFORM_MAX_PATH];
2020
bool g_bLate = false;
2121
bool g_Plugin_ExtDiscord = false;
2222
bool g_Plugin_AutoRecorder = false;
23+
bool g_bNative_IsDemoRecording = false;
24+
bool g_bNative_GetDemoRecordCount = false;
25+
bool g_bNative_GetDemoRecordingTick = false;
26+
bool g_bNative_GetDemoRecordingTime = false;
27+
bool g_bNative_ExtendedDiscord_LogError = false;
2328

2429
public Plugin myinfo =
2530
{
2631
name = PLUGIN_NAME,
2732
author = "inGame, maxime1907, .Rushaway",
2833
description = "Admin logs saved to Discord",
29-
version = "1.3.8",
34+
version = "1.3.9",
3035
url = "https://github.com/srcdslab/sm-plugin-AdminLogging"
3136
};
3237

@@ -57,22 +62,51 @@ public void OnAllPluginsLoaded()
5762
{
5863
g_Plugin_AutoRecorder = LibraryExists("AutoRecorder");
5964
g_Plugin_ExtDiscord = LibraryExists("ExtendedDiscord");
65+
66+
VerifyNatives();
6067
}
6168

6269
public void OnLibraryAdded(const char[] sName)
6370
{
64-
if (strcmp(sName, "AutoRecorder", false) == 0)
65-
g_Plugin_AutoRecorder = true;
66-
else if (strcmp(sName, "ExtendedDiscord", false) == 0)
67-
g_Plugin_ExtDiscord = true;
71+
HandleLibraryChange(sName, true);
6872
}
6973

7074
public void OnLibraryRemoved(const char[] sName)
7175
{
72-
if (strcmp(sName, "AutoRecorder", false) == 0)
73-
g_Plugin_AutoRecorder = false;
74-
else if (strcmp(sName, "ExtendedDiscord", false) == 0)
75-
g_Plugin_ExtDiscord = false;
76+
HandleLibraryChange(sName, false);
77+
}
78+
79+
void HandleLibraryChange(const char[] name, bool isAdded = false)
80+
{
81+
if (strcmp(name, "AutoRecorder", false) == 0)
82+
{
83+
g_Plugin_AutoRecorder = isAdded;
84+
VerifyNative_AutoRecorder();
85+
}
86+
else if (strcmp(name, "ExtendedDiscord", false) == 0)
87+
{
88+
g_Plugin_ExtDiscord = isAdded;
89+
VerifyNative_ExtendedDiscord();
90+
}
91+
}
92+
93+
stock void VerifyNatives()
94+
{
95+
VerifyNative_AutoRecorder();
96+
VerifyNative_ExtendedDiscord();
97+
}
98+
99+
stock void VerifyNative_AutoRecorder()
100+
{
101+
g_bNative_GetDemoRecordCount = g_Plugin_AutoRecorder && GetFeatureStatus(FeatureType_Native, "AutoRecorder_GetDemoRecordCount") == FeatureStatus_Available;
102+
g_bNative_IsDemoRecording = g_Plugin_AutoRecorder && GetFeatureStatus(FeatureType_Native, "AutoRecorder_IsDemoRecording") == FeatureStatus_Available;
103+
g_bNative_GetDemoRecordingTick = g_Plugin_AutoRecorder && GetFeatureStatus(FeatureType_Native, "AutoRecorder_GetDemoRecordingTick") == FeatureStatus_Available;
104+
g_bNative_GetDemoRecordingTime = g_Plugin_AutoRecorder && GetFeatureStatus(FeatureType_Native, "AutoRecorder_GetDemoRecordingTime") == FeatureStatus_Available;
105+
}
106+
107+
stock void VerifyNative_ExtendedDiscord()
108+
{
109+
g_bNative_ExtendedDiscord_LogError = g_Plugin_ExtDiscord && GetFeatureStatus(FeatureType_Native, "ExtendedDiscord_LogError") == FeatureStatus_Available;
76110
}
77111

78112
public void OnMapInit(const char[] mapName)
@@ -125,11 +159,16 @@ public Action OnLogAction(Handle source, Identity ident, int client, int target,
125159
int iTick = -1;
126160
int retValTime = -1;
127161
#if defined _autorecorder_included
128-
if (AutoRecorder_IsDemoRecording())
162+
if (g_bNative_IsDemoRecording && AutoRecorder_IsDemoRecording())
129163
{
130-
iCount = AutoRecorder_GetDemoRecordCount();
131-
iTick = AutoRecorder_GetDemoRecordingTick();
132-
retValTime = AutoRecorder_GetDemoRecordingTime();
164+
if (g_bNative_GetDemoRecordCount)
165+
iCount = AutoRecorder_GetDemoRecordCount();
166+
167+
if (g_bNative_GetDemoRecordingTick)
168+
iTick = AutoRecorder_GetDemoRecordingTick();
169+
170+
if (g_bNative_GetDemoRecordingTime)
171+
retValTime = AutoRecorder_GetDemoRecordingTime();
133172
}
134173
if (retValTime == -1)
135174
sDate = "N/A";
@@ -231,7 +270,7 @@ public void OnWebHookExecuted(HTTPResponse response, DataPack pack)
231270
PrintToServer("[%s] Failed to send the webhook (ID: %d). Resending it in %0.1f seconds.. (%d/%d)", PLUGIN_NAME, iMsgIndex, fTimer, retries[iMsgIndex], g_cvWebhookRetry.IntValue);
232271
return;
233272
} else {
234-
if (!g_Plugin_ExtDiscord)
273+
if (!g_bNative_ExtendedDiscord_LogError)
235274
{
236275
LogError("[%s] Failed to send the webhook after %d retries, aborting.", PLUGIN_NAME, retries[iMsgIndex]);
237276
LogError("[%s] Failed message : %s", PLUGIN_NAME, sMessage);

0 commit comments

Comments
 (0)