1
0
Fork 0
mirror of https://codeberg.org/demostf/plugin.git synced 2026-06-04 09:04:07 +02:00

Merge pull request #7 from TheBv/master

Added a forward for successfully uploaded demos
This commit is contained in:
Robin Appelman 2022-12-07 17:12:15 +01:00 committed by GitHub
commit 7d3730511a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 1 deletions

Binary file not shown.

View file

@ -47,6 +47,8 @@ new Handle:postForm = INVALID_HANDLE;
new Handle:g_hCvarRedTeamName = INVALID_HANDLE; new Handle:g_hCvarRedTeamName = INVALID_HANDLE;
new Handle:g_hCvarBlueTeamName = INVALID_HANDLE; new Handle:g_hCvarBlueTeamName = INVALID_HANDLE;
new Handle:g_hDemoUploaded = INVALID_HANDLE;
public OnPluginStart() public OnPluginStart()
{ {
g_hCvarAPIKey = CreateConVar("sm_demostf_apikey", "", "API key for demos.tf", FCVAR_PROTECTED); g_hCvarAPIKey = CreateConVar("sm_demostf_apikey", "", "API key for demos.tf", FCVAR_PROTECTED);
@ -54,10 +56,17 @@ public OnPluginStart()
g_hCvarRedTeamName = FindConVar("mp_tournament_redteamname"); g_hCvarRedTeamName = FindConVar("mp_tournament_redteamname");
g_hCvarBlueTeamName = FindConVar("mp_tournament_blueteamname"); g_hCvarBlueTeamName = FindConVar("mp_tournament_blueteamname");
g_hDemoUploaded = CreateGlobalForward("DemoUploaded", ET_Ignore, Param_Cell, Param_String, Param_String);
RegServerCmd("tv_record", Command_StartRecord); RegServerCmd("tv_record", Command_StartRecord);
RegServerCmd("tv_stoprecord", Command_StopRecord); RegServerCmd("tv_stoprecord", Command_StopRecord);
} }
public OnPluginEnd()
{
CloseHandle(g_hDemoUploaded);
}
public Action:Command_StartRecord(args) public Action:Command_StartRecord(args)
{ {
if (strlen(g_sDemoName) == 0) { if (strlen(g_sDemoName) == 0) {
@ -128,6 +137,7 @@ public onComplete(Handle:hndl, CURLcode:code)
CloseHandle(output_file); CloseHandle(output_file);
CloseHandle(hndl); CloseHandle(hndl);
PrintToChatAll("cURLCode error: %d", code); PrintToChatAll("cURLCode error: %d", code);
CallDemoUploaded(false, "", "");
} }
else else
{ {
@ -146,5 +156,41 @@ public ShowResponse()
ReadFileString(resultFile, output, sizeof(output)); ReadFileString(resultFile, output, sizeof(output));
PrintToChatAll("[demos.tf]: %s", output); PrintToChatAll("[demos.tf]: %s", output);
LogToGame("[demos.tf]: %s", output); LogToGame("[demos.tf]: %s", output);
new String:demoid[16];
new String:url[256];
new bool:success;
char url_parts[16][4];
strcopy(url, sizeof(url), output);
// Get the url part
ReplaceString(url, sizeof(url), "STV available at: ", "");
// Split the string on '/'
ExplodeString(url, "/", url_parts, sizeof(url_parts[]), sizeof(url_parts));
// Find the last part of the url
for (int i = sizeof(url_parts[]) - 1; i >= 0; i--)
{
if (!StrEqual(url_parts[i], "")){
demoid = url_parts[i];
break;
}
}
CallDemoUploaded(success, demoid, url);
return; return;
} }
void CallDemoUploaded(bool success, const char[] demoid, const char[] url) {
Call_StartForward(g_hDemoUploaded);
// Push parameters one at a time
Call_PushCell(success);
Call_PushString(demoid);
Call_PushString(url);
// Finish the call
Call_Finish();
}

6
include/demostf.inc Normal file
View file

@ -0,0 +1,6 @@
#if defined _demostf_included
#endinput
#endif
#define _demostf_included
forward DemoUploaded(bool success, const char[] demoid, const char[] url);