mirror of
https://codeberg.org/demostf/plugin.git
synced 2026-06-04 00:54:08 +02:00
New syntax
This commit is contained in:
parent
5310aa9e3b
commit
3b5f93bf6e
2 changed files with 59 additions and 63 deletions
BIN
demostf.smx
BIN
demostf.smx
Binary file not shown.
120
demostf.sp
120
demostf.sp
|
|
@ -1,25 +1,25 @@
|
||||||
#pragma semicolon 1
|
#pragma semicolon 1
|
||||||
#include <sourcemod>
|
#pragma newdecls required
|
||||||
#include <cURL>
|
#include <cURL>
|
||||||
|
|
||||||
public Plugin:myinfo =
|
public Plugin myinfo =
|
||||||
{
|
{
|
||||||
name = "demos.tf uploader",
|
name = "demos.tf uploader",
|
||||||
author = "Icewind",
|
author = "Icewind",
|
||||||
description = "Auto-upload match stv to demos.tf",
|
description = "Auto-upload match stv to demos.tf",
|
||||||
version = "0.3.1",
|
version = "0.3.1",
|
||||||
url = "https://demos.tf"
|
url = "https://demos.tf"
|
||||||
};
|
}
|
||||||
|
|
||||||
new CURL_Default_opt[][2] = {
|
int CURL_Default_opt[][2] = {
|
||||||
{_:CURLOPT_NOSIGNAL,1},
|
{view_as<int>(CURLOPT_NOSIGNAL),1},
|
||||||
{_:CURLOPT_NOPROGRESS,1},
|
{view_as<int>(CURLOPT_NOPROGRESS),1},
|
||||||
{_:CURLOPT_TIMEOUT,600},
|
{view_as<int>(CURLOPT_TIMEOUT),600},
|
||||||
{_:CURLOPT_CONNECTTIMEOUT,600},
|
{view_as<int>(CURLOPT_CONNECTTIMEOUT),600},
|
||||||
{_:CURLOPT_USE_SSL,CURLUSESSL_TRY},
|
{view_as<int>(CURLOPT_USE_SSL),CURLUSESSL_TRY},
|
||||||
{_:CURLOPT_SSL_VERIFYPEER,0},
|
{view_as<int>(CURLOPT_SSL_VERIFYPEER),0},
|
||||||
{_:CURLOPT_SSL_VERIFYHOST,0},
|
{view_as<int>(CURLOPT_SSL_VERIFYHOST),0},
|
||||||
{_:CURLOPT_VERBOSE,0}
|
{view_as<int>(CURLOPT_VERBOSE),0}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -28,46 +28,47 @@ new CURL_Default_opt[][2] = {
|
||||||
* @param buffer String to convert
|
* @param buffer String to convert
|
||||||
* @noreturn
|
* @noreturn
|
||||||
*/
|
*/
|
||||||
public CStrToLower(String:buffer[]) {
|
public void CStrToLower(char[] buffer) {
|
||||||
new len = strlen(buffer);
|
int len = strlen(buffer);
|
||||||
for(new i = 0; i < len; i++) {
|
for(int i = 0; i < len; i++) {
|
||||||
buffer[i] = CharToLower(buffer[i]);
|
buffer[i] = CharToLower(buffer[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CURL_DEFAULT_OPT(%1) curl_easy_setopt_int_array(%1, CURL_Default_opt, sizeof(CURL_Default_opt))
|
#define CURL_DEFAULT_OPT(%1) curl_easy_setopt_int_array(%1, CURL_Default_opt, sizeof(CURL_Default_opt))
|
||||||
|
|
||||||
new String:g_sDemoName[256] = "";
|
char g_sDemoName[256];
|
||||||
new String:g_sLastDemoName[256] = "";
|
char g_sLastDemoName[256];
|
||||||
|
|
||||||
new Handle:g_hCvarAPIKey = INVALID_HANDLE;
|
ConVar g_hCvarAPIKey = null;
|
||||||
new Handle:g_hCvarUrl = INVALID_HANDLE;
|
ConVar g_hCvarUrl = null;
|
||||||
new Handle:output_file = INVALID_HANDLE;
|
ConVar g_hCvarRedTeamName = null;
|
||||||
new Handle:postForm = INVALID_HANDLE;
|
ConVar g_hCvarBlueTeamName = null;
|
||||||
new Handle:g_hCvarRedTeamName = INVALID_HANDLE;
|
|
||||||
new Handle:g_hCvarBlueTeamName = INVALID_HANDLE;
|
|
||||||
|
|
||||||
new Handle:g_hDemoUploaded = INVALID_HANDLE;
|
Handle output_file = null;
|
||||||
|
Handle postForm = null;
|
||||||
|
|
||||||
public OnPluginStart()
|
GlobalForward g_hDemoUploaded = null;
|
||||||
|
|
||||||
|
public void 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);
|
||||||
g_hCvarUrl = CreateConVar("sm_demostf_url", "https://demos.tf", "demos.tf url", FCVAR_PROTECTED);
|
g_hCvarUrl = CreateConVar("sm_demostf_url", "https://demos.tf", "demos.tf url", FCVAR_PROTECTED);
|
||||||
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);
|
g_hDemoUploaded = new GlobalForward("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()
|
public void OnPluginEnd()
|
||||||
{
|
{
|
||||||
CloseHandle(g_hDemoUploaded);
|
delete g_hDemoUploaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Action:Command_StartRecord(args)
|
Action Command_StartRecord(int args)
|
||||||
{
|
{
|
||||||
if (strlen(g_sDemoName) == 0) {
|
if (strlen(g_sDemoName) == 0) {
|
||||||
GetCmdArgString(g_sDemoName, sizeof(g_sDemoName));
|
GetCmdArgString(g_sDemoName, sizeof(g_sDemoName));
|
||||||
|
|
@ -77,7 +78,7 @@ public Action:Command_StartRecord(args)
|
||||||
return Plugin_Continue;
|
return Plugin_Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Action:Command_StopRecord(args)
|
Action Command_StopRecord(int args)
|
||||||
{
|
{
|
||||||
TrimString(g_sDemoName);
|
TrimString(g_sDemoName);
|
||||||
if (strlen(g_sDemoName) != 0) {
|
if (strlen(g_sDemoName) != 0) {
|
||||||
|
|
@ -89,29 +90,28 @@ public Action:Command_StopRecord(args)
|
||||||
return Plugin_Continue;
|
return Plugin_Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Action:StartDemoUpload(Handle:timer)
|
Action StartDemoUpload(Handle timer)
|
||||||
{
|
{
|
||||||
decl String:fullPath[128];
|
char fullPath[128];
|
||||||
Format(fullPath, sizeof(fullPath), "%s.dem", g_sLastDemoName);
|
Format(fullPath, sizeof(fullPath), "%s.dem", g_sLastDemoName);
|
||||||
UploadDemo(fullPath);
|
UploadDemo(fullPath);
|
||||||
|
|
||||||
|
return Plugin_Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
UploadDemo(const String:fullPath[])
|
void UploadDemo(const char[] fullPath)
|
||||||
{
|
{
|
||||||
decl String:APIKey[128];
|
char APIKey[128], BaseUrl[64], bluname[128], redname[128], Map[64];
|
||||||
GetConVarString(g_hCvarAPIKey, APIKey, sizeof(APIKey));
|
g_hCvarAPIKey.GetString(APIKey, sizeof(APIKey));
|
||||||
decl String:BaseUrl[64];
|
g_hCvarUrl.GetString(BaseUrl, sizeof(BaseUrl));
|
||||||
GetConVarString(g_hCvarUrl, BaseUrl, sizeof(BaseUrl));
|
g_hCvarRedTeamName.GetString(redname, sizeof(redname));
|
||||||
new String:Map[64];
|
g_hCvarBlueTeamName.GetString(bluname, sizeof(bluname));
|
||||||
GetCurrentMap(Map, sizeof(Map));
|
GetCurrentMap(Map, sizeof(Map));
|
||||||
PrintToChatAll("[demos.tf]: Uploading demo %s", fullPath);
|
|
||||||
new Handle:curl = curl_easy_init();
|
|
||||||
CURL_DEFAULT_OPT(curl);
|
|
||||||
decl String:bluname[128];
|
|
||||||
decl String:redname[128];
|
|
||||||
GetConVarString(g_hCvarRedTeamName, redname, sizeof(redname));
|
|
||||||
GetConVarString(g_hCvarBlueTeamName, bluname, sizeof(bluname));
|
|
||||||
|
|
||||||
|
PrintToChatAll("[demos.tf]: Uploading demo %s", fullPath);
|
||||||
|
|
||||||
|
Handle curl = curl_easy_init();
|
||||||
|
CURL_DEFAULT_OPT(curl);
|
||||||
postForm = curl_httppost();
|
postForm = curl_httppost();
|
||||||
curl_formadd(postForm, CURLFORM_COPYNAME, "demo", CURLFORM_FILE, fullPath, CURLFORM_END);
|
curl_formadd(postForm, CURLFORM_COPYNAME, "demo", CURLFORM_FILE, fullPath, CURLFORM_END);
|
||||||
curl_formadd(postForm, CURLFORM_COPYNAME, "name", CURLFORM_COPYCONTENTS, fullPath, CURLFORM_END);
|
curl_formadd(postForm, CURLFORM_COPYNAME, "name", CURLFORM_COPYCONTENTS, fullPath, CURLFORM_END);
|
||||||
|
|
@ -122,46 +122,42 @@ UploadDemo(const String:fullPath[])
|
||||||
|
|
||||||
output_file = curl_OpenFile("output_demo.json", "w");
|
output_file = curl_OpenFile("output_demo.json", "w");
|
||||||
curl_easy_setopt_handle(curl, CURLOPT_WRITEDATA, output_file);
|
curl_easy_setopt_handle(curl, CURLOPT_WRITEDATA, output_file);
|
||||||
decl String:fullUrl[128];
|
char fullUrl[128];
|
||||||
Format(fullUrl, sizeof(fullUrl), "%s/upload", BaseUrl);
|
Format(fullUrl, sizeof(fullUrl), "%s/upload", BaseUrl);
|
||||||
curl_easy_setopt_string(curl, CURLOPT_URL, fullUrl);
|
curl_easy_setopt_string(curl, CURLOPT_URL, fullUrl);
|
||||||
curl_easy_perform_thread(curl, onComplete);
|
curl_easy_perform_thread(curl, onComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
public onComplete(Handle:hndl, CURLcode:code)
|
void onComplete(Handle hndl, CURLcode code)
|
||||||
{
|
{
|
||||||
if(code != CURLE_OK)
|
if(code != CURLE_OK)
|
||||||
{
|
{
|
||||||
new String:error_buffer[256];
|
char error_buffer[256];
|
||||||
curl_easy_strerror(code, error_buffer, sizeof(error_buffer));
|
curl_easy_strerror(code, error_buffer, sizeof(error_buffer));
|
||||||
CloseHandle(output_file);
|
delete output_file;
|
||||||
CloseHandle(hndl);
|
delete hndl;
|
||||||
PrintToChatAll("cURLCode error: %d", code);
|
PrintToChatAll("cURLCode error: %d", code);
|
||||||
CallDemoUploaded(false, "", "");
|
CallDemoUploaded(false, "", "");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CloseHandle(output_file);
|
delete output_file;
|
||||||
CloseHandle(hndl);
|
delete hndl;
|
||||||
ShowResponse();
|
ShowResponse();
|
||||||
}
|
}
|
||||||
CloseHandle(postForm);
|
delete postForm;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShowResponse()
|
void ShowResponse()
|
||||||
{
|
{
|
||||||
new Handle:resultFile = OpenFile("output_demo.json", "r");
|
File resultFile = OpenFile("output_demo.json", "r");
|
||||||
new String:output[512];
|
char output[512];
|
||||||
ReadFileString(resultFile, output, sizeof(output));
|
resultFile.ReadString(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];
|
char demoid[16], url[256], url_parts[4][16];
|
||||||
new String:url[256];
|
|
||||||
|
|
||||||
char url_parts[4][16];
|
|
||||||
|
|
||||||
strcopy(url, sizeof(url), output);
|
strcopy(url, sizeof(url), output);
|
||||||
|
|
||||||
if (StrContains(url, "STV available at: ") != -1)
|
if (StrContains(url, "STV available at: ") != -1)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue