6
6
#pragma newdecls required
7
7
#pragma semicolon 1
8
8
9
- #define VERSION " 1.0.1 "
9
+ #define VERSION " 1.1.0 "
10
10
11
11
char g_sWebhookToken [128 ];
12
12
@@ -25,20 +25,48 @@ public Plugin myinfo =
25
25
26
26
public void OnPluginStart ()
27
27
{
28
- g_hCvarWebhookToken = CreateConVar (" payload_webhook_token " , " " , " Channel to post rendered logs to" , FCVAR_PROTECTED );
29
- g_hCvarApiUrl = CreateConVar (" payload_apiurl " , " https://api.payload.tf/api" , " Payload API url" , FCVAR_PROTECTED );
28
+ g_hCvarWebhookToken = CreateConVar (" sm_payload_token " , " " , " Channel to post rendered logs to" , FCVAR_PROTECTED );
29
+ g_hCvarApiUrl = CreateConVar (" sm_payload_apiurl " , " https://api.payload.tf/api" , " Payload API url" , FCVAR_PROTECTED );
30
30
31
- g_hCvarSendLogs = CreateConVar (" payload_send " , " 1" , " Send the logs or not" , FCVAR_NOTIFY );
31
+ g_hCvarSendLogs = CreateConVar (" sm_payload_send " , " 1" , " Send the logs or not" , FCVAR_NOTIFY );
32
32
33
- RegConsoleCmd (" payload_testupload " , testUpload , " Debug function to simulate an uploaded log" );
33
+ RegConsoleCmd (" sm_payload_test " , TestUpload , " Debug function to simulate an uploaded log" );
34
34
35
35
PrintToChatAll (" [Payload] Plugin loaded." );
36
36
PrintToServer (" [Payload] Plugin loaded." );
37
37
}
38
38
39
- public Action testUpload (int client , int args )
39
+ public Action TestUpload (int client , int args )
40
40
{
41
- LogUploaded (true , " 2961236" , " https://logs.tf/2961236" );
41
+ bool sendRequest = GetConVarBool (g_hCvarSendLogs );
42
+ if (sendRequest == false )
43
+ {
44
+ PrintToChatAll (" [Payload] sm_payload_send is 0, not sending requests." );
45
+ PrintToServer (" [Payload] sm_payload_send is 0, not sending requests." );
46
+
47
+ return Plugin_Handled ;
48
+ }
49
+
50
+ // Make sure we update the string value of the token
51
+ GetConVarString (g_hCvarWebhookToken , g_sWebhookToken , sizeof (g_sWebhookToken ));
52
+
53
+ if (strlen (g_sWebhookToken ) == 0 )
54
+ return Plugin_Handled ;
55
+
56
+ char BaseUrl [64 ];
57
+ char FullUrl [128 ];
58
+
59
+ // Store convar for the api Url in BaseUrl
60
+ GetConVarString (g_hCvarApiUrl , BaseUrl , sizeof (BaseUrl ));
61
+
62
+ // Complete the baseUrl
63
+ Format (FullUrl , sizeof (FullUrl ), " %s /webhooks/v1/internal/test" , BaseUrl );
64
+
65
+ PrintToServer (" [Payload] Testing webhook..." );
66
+ PrintToChatAll (" [Payload] Testing webhook..." );
67
+
68
+ SendTestRequest (FullUrl );
69
+
42
70
return Plugin_Handled ;
43
71
}
44
72
@@ -88,18 +116,47 @@ public void SendRequest(const char[] logid, const char[] fullApiUrl)
88
116
SteamWorks_SendHTTPRequest (hRequest );
89
117
}
90
118
119
+ public void SendTestRequest (const char [] fullApiUrl )
120
+ {
121
+ Handle hRequest = SteamWorks_CreateHTTPRequest (k_EHTTPMethodPOST , fullApiUrl );
122
+
123
+ // Headers
124
+ SteamWorks_SetHTTPRequestHeaderValue (hRequest , " Content-Type" , " x-www-form-urlencoded" );
125
+ SteamWorks_SetHTTPRequestHeaderValue (hRequest , " Authorization" , g_sWebhookToken );
126
+
127
+ SteamWorks_SetHTTPCallbacks (hRequest , TestWebhookComplete );
128
+ SteamWorks_SendHTTPRequest (hRequest );
129
+ }
130
+
91
131
public int OnSteamWorksHTTPComplete (Handle hRequest , bool bFailure , bool bRequestSuccessful , EHTTPStatusCode eStatusCode , any data )
92
132
{
93
133
if (bFailure )
94
134
{
95
- PrintToChatAll (" [Payload] Unable to post logs preview" );
96
- PrintToServer (" [Payload] Unable to post logs preview" );
135
+ PrintToChatAll (" [Payload] Unable to post logs preview." );
136
+ PrintToServer (" [Payload] Unable to post logs preview." );
137
+ PrintToServer (" Status Code: %i " , eStatusCode );
138
+ }
139
+ else
140
+ {
141
+ PrintToChatAll (" [Payload] Log preview uploaded." );
142
+ PrintToServer (" [Payload] Log preview uploaded." );
143
+ }
144
+
145
+ delete hRequest ;
146
+ }
147
+
148
+ public int TestWebhookComplete (Handle hRequest , bool bFailure , bool bRequestSuccessful , EHTTPStatusCode eStatusCode , any data )
149
+ {
150
+ if (bFailure )
151
+ {
152
+ PrintToChatAll (" [Payload] Unable to test webhook." );
153
+ PrintToServer (" [Payload] Unable to test preview." );
97
154
PrintToServer (" Status Code: %i " , eStatusCode );
98
155
}
99
156
else
100
157
{
101
- PrintToChatAll (" [Payload] Log preview uploaded " );
102
- PrintToServer (" [Payload] Log preview uploaded " );
158
+ PrintToChatAll (" [Payload] Webhook test successful. " );
159
+ PrintToServer (" [Payload] Webhook test successful. " );
103
160
}
104
161
105
162
delete hRequest ;
0 commit comments