accelerator/extension/natives.cpp
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

55 lines
1.4 KiB
C++

#include <algorithm>
#include <amtl/am-string.h>
#include "extension.h"
#include "natives.h"
static cell_t Native_GetUploadedCrashCount(IPluginContext* context, const cell_t* params)
{
return g_accelerator.GetUploadedCrashCount();
}
static cell_t Native_IsDoneUploadingCrashes(IPluginContext* context, const cell_t* params)
{
if (g_accelerator.IsDoneUploading()) {
return 1;
}
return 0;
}
static cell_t Native_GetCrashHTTPResponse(IPluginContext* context, const cell_t* params)
{
if (!g_accelerator.IsDoneUploading()) {
context->ReportError("Wait until accelerator is done uploading crashes before accessing crash information!");
return 0;
}
int element = static_cast<int>(params[1]);
const UploadedCrash* crash = g_accelerator.GetUploadedCrash(element);
if (!crash) {
context->ReportError("Crash index %i is invalid!", element);
return 0;
}
char* buffer;
context->LocalToString(params[2], &buffer);
size_t maxsize = static_cast<size_t>(params[3]);
ke::SafeStrcpy(buffer, maxsize, crash->GetHTTPResponse().c_str());
return 0;
}
void natives::Setup(std::vector<sp_nativeinfo_t>& vec)
{
sp_nativeinfo_t list[] = {
{"Accelerator_GetUploadedCrashCount", Native_GetUploadedCrashCount},
{"Accelerator_IsDoneUploadingCrashes", Native_IsDoneUploadingCrashes},
{"Accelerator_GetCrashHTTPResponse", Native_GetCrashHTTPResponse},
};
vec.insert(vec.end(), std::begin(list), std::end(list));
}