accelerator/scripting/accelerator_example.sp
caxanga334 87704dc53b
Some checks failed
Release / main-ci (push) Has been cancelled
Release / release (push) Has been cancelled
[Feature]: Add on crash uploaded SourceMod forward (#42)
* Squashed commit of the following:

commit c7efce2d6722b08e2ea719ce1a39f80747502f77
Author: caxanga334 <10157643+caxanga334@users.noreply.github.com>
Date:   Sat Nov 22 22:35:24 2025 -0300

    Fix Error

commit e8acf9f505aa26b007c5837d4075f649099f43c3
Author: caxanga334 <10157643+caxanga334@users.noreply.github.com>
Date:   Sat Nov 22 22:23:57 2025 -0300

    Fix Possible Memory Leak

commit 51e718922726c074c0e7a45f9d13c6a51e4b97eb
Author: caxanga334 <10157643+caxanga334@users.noreply.github.com>
Date:   Sat Nov 22 22:13:55 2025 -0300

    Add Upload Forward

* Update accelerator.inc

* Fix: Missing forwards.cpp in AMBuilder

* Refactor API

Forward notifies plugins when the extension is done uploading.
Plugins can fetch data from uploaded crashes via natives.
Added example plugin.

* Implement Requested Changes

* Fix Error

* Update Example Plugin

Removed timer example.
Added example of how to handle plugin late loads.
2025-12-02 16:32:12 -05:00

77 lines
1.6 KiB
SourcePawn

#include <sourcemod>
#include <accelerator>
#pragma newdecls required
#pragma semicolon 1
public Plugin myinfo =
{
name = "Accelerator Example",
author = "caxanga334",
description = "Example Accelerator natives plugin.",
version = "1.0.0",
url = "https://github.com/asherkin/accelerator"
};
public void OnPluginStart()
{
RegAdminCmd("sm_listcrashes", Command_ListCrashes, ADMFLAG_RCON, "List all uploaded crash dumps.");
// Call the forward manually. (For late loading plugins)
if (Accelerator_IsDoneUploadingCrashes())
{
Accelerator_OnDoneUploadingCrashes();
}
}
// This is called when the extension is done uploading crashes
public void Accelerator_OnDoneUploadingCrashes()
{
LogMessage("Accelerator is done uploading crashes!");
int max = Accelerator_GetUploadedCrashCount();
if (max == 0)
{
LogMessage("No crashes were uploaded!");
return;
}
char buffer[512];
for (int i = 0; i < max; i++)
{
Accelerator_GetCrashHTTPResponse(i, buffer, sizeof(buffer));
LogMessage("Crash #%i: HTTP reponse: \"%s\".", i, buffer);
}
}
// Admin command to list crashes
Action Command_ListCrashes(int client, int args)
{
if (!Accelerator_IsDoneUploadingCrashes())
{
ReplyToCommand(client, "Accelerator is still uploading crashes, please wait!");
return Plugin_Handled;
}
int max = Accelerator_GetUploadedCrashCount();
if (max == 0)
{
ReplyToCommand(client, "No crashes were uploaded!");
return Plugin_Handled;
}
char buffer[512];
for (int i = 0; i < max; i++)
{
Accelerator_GetCrashHTTPResponse(i, buffer, sizeof(buffer));
ReplyToCommand(client, "Crash #%i: HTTP reponse: \"%s\".", i, buffer);
}
return Plugin_Handled;
}