2
2
#include <sdktools>
3
3
#include <sdkhooks>
4
4
#include <logstf>
5
+ #include <demostf>
5
6
#include <SteamWorks>
6
7
#pragma newdecls required
7
8
#pragma semicolon 1
8
9
9
- #define VERSION " 1.3 .0"
10
+ #define VERSION " 1.4 .0"
10
11
11
12
char g_sWebhookToken [128 ];
13
+ bool g_bDemostfLoaded ;
14
+ char g_sLogId [128 ];
15
+ char g_sDemoId [128 ];
12
16
13
17
ConVar g_hCvarWebhookToken ;
14
18
ConVar g_hCvarSendLogs ;
@@ -36,6 +40,33 @@ public void OnPluginStart()
36
40
PrintToServer (" [Payload] Plugin loaded." );
37
41
}
38
42
43
+ public void OnAllPluginsLoaded ()
44
+ {
45
+ IsDemosTfPresent ();
46
+ }
47
+
48
+ public bool IsDemosTfPresent ()
49
+ {
50
+ Handle h_demostf = FindPluginByFile (" demostf.smx" );
51
+ if (h_demostf != null && GetPluginStatus (h_demostf ) == Plugin_Running )
52
+ {
53
+ char version [64 ];
54
+ GetPluginInfo (h_demostf , PlInfo_Version , version , sizeof (version ));
55
+
56
+ // Crude way of making sure we're running a version newer than 0.2
57
+ if (strcmp (version , " 0.2" ) > 0 ) {
58
+ g_bDemostfLoaded = true ;
59
+ PrintToServer (" [Payload] Demos.tf plugin detected." );
60
+ return true ;
61
+ }
62
+ }
63
+ else
64
+ {
65
+ g_bDemostfLoaded = false ;
66
+ return false ;
67
+ }
68
+ }
69
+
39
70
public Action TestUpload (int client , int args )
40
71
{
41
72
bool sendRequest = GetConVarBool (g_hCvarSendLogs );
@@ -74,34 +105,53 @@ public int LogUploaded(bool success, const char[] logid, const char[] url)
74
105
{
75
106
if (success )
76
107
{
77
- bool sendRequest = GetConVarBool (g_hCvarSendLogs );
78
- if (sendRequest == false )
79
- return ;
108
+ strcopy (g_sLogId , sizeof (g_sLogId ), logid );
109
+ // Prepare the request if we have received the demoid or if the plugin isn't loaded
110
+ if (! StrEqual (g_sDemoId , " " ) || ! g_bDemostfLoaded )
111
+ PrepareRequest ();
112
+ }
113
+ }
114
+
115
+ public int DemoUploaded (bool success , const char [] demoid , const char [] url )
116
+ {
117
+ if (success )
118
+ {
119
+ strcopy (g_sDemoId , sizeof (g_sDemoId ), demoid );
120
+ }
121
+ // Prepare the request if we have received the logid
122
+ if (! StrEqual (g_sLogId , " " ))
123
+ PrepareRequest ();
124
+ }
80
125
81
- // Make sure we update the string value of the token
82
- GetConVarString (g_hCvarWebhookToken , g_sWebhookToken , sizeof (g_sWebhookToken ));
83
- if (strlen (g_sWebhookToken ) == 0 )
84
- return ;
126
+ public void PrepareRequest ()
127
+ {
128
+ bool sendRequest = GetConVarBool (g_hCvarSendLogs );
129
+ if (sendRequest == false )
130
+ return ;
85
131
86
- char BaseUrl [64 ];
87
- char FullUrl [128 ];
132
+ // Make sure we update the string value of the token
133
+ GetConVarString (g_hCvarWebhookToken , g_sWebhookToken , sizeof (g_sWebhookToken ));
134
+ if (strlen (g_sWebhookToken ) == 0 )
135
+ return ;
136
+
137
+ char BaseUrl [64 ];
138
+ char FullUrl [128 ];
88
139
89
- // Store convar for the api Url in BaseUrl
90
- GetConVarString (g_hCvarApiUrl , BaseUrl , sizeof (BaseUrl ));
140
+ // Store convar for the api Url in BaseUrl
141
+ GetConVarString (g_hCvarApiUrl , BaseUrl , sizeof (BaseUrl ));
91
142
92
- // Complete the baseUrl
93
- Format (FullUrl , sizeof (FullUrl ), " %s /webhooks/logs" , BaseUrl );
143
+ // Complete the baseUrl
144
+ Format (FullUrl , sizeof (FullUrl ), " %s /webhooks/logs" , BaseUrl );
94
145
95
- // For debug purposes:
96
- PrintToServer (" FullURL: %s " , FullUrl );
97
- PrintToServer (" [Payload] Rendering logs preview..." );
98
- PrintToChatAll (" [Payload] Rendering logs preview..." );
146
+ // For debug purposes:
147
+ PrintToServer (" FullURL: %s " , FullUrl );
148
+ PrintToServer (" [Payload] Rendering logs preview..." );
149
+ PrintToChatAll (" [Payload] Rendering logs preview..." );
99
150
100
- SendRequest (logid , FullUrl );
101
- }
151
+ SendRequest (FullUrl );
102
152
}
103
153
104
- public void SendRequest (const char [] logid , const char [] fullApiUrl )
154
+ public void SendRequest (const char [] fullApiUrl )
105
155
{
106
156
Handle hRequest = SteamWorks_CreateHTTPRequest (k_EHTTPMethodPOST , fullApiUrl );
107
157
@@ -110,8 +160,12 @@ public void SendRequest(const char[] logid, const char[] fullApiUrl)
110
160
SteamWorks_SetHTTPRequestHeaderValue (hRequest , " Authorization" , g_sWebhookToken );
111
161
112
162
// Body
113
- SteamWorks_SetHTTPRequestGetOrPostParameter (hRequest , " logsId" , logid );
114
-
163
+ SteamWorks_SetHTTPRequestGetOrPostParameter (hRequest , " logsId" , g_sLogId );
164
+
165
+ // Only add parameter if the demos.tf plugin was loaded and returned an id
166
+ if (g_bDemostfLoaded && ! StrEqual (g_sDemoId , " " ))
167
+ SteamWorks_SetHTTPRequestGetOrPostParameter (hRequest , " demosId" , g_sDemoId );
168
+
115
169
SteamWorks_SetHTTPCallbacks (hRequest , OnSteamWorksHTTPComplete );
116
170
SteamWorks_SendHTTPRequest (hRequest );
117
171
}
@@ -141,7 +195,10 @@ public int OnSteamWorksHTTPComplete(Handle hRequest, bool bFailure, bool bReques
141
195
PrintToChatAll (" [Payload] Log preview uploaded." );
142
196
PrintToServer (" [Payload] Log preview uploaded." );
143
197
}
144
-
198
+ // Clear the ids
199
+ g_sDemoId = " " ;
200
+ g_sLogId = " " ;
201
+
145
202
delete hRequest ;
146
203
}
147
204
0 commit comments