mirror of
https://github.com/asherkin/accelerator.git
synced 2025-12-07 10:28:29 +00:00
117 lines
2.5 KiB
SourcePawn
117 lines
2.5 KiB
SourcePawn
#include <sourcemod>
|
|
#include <accelerator>
|
|
|
|
#pragma newdecls required
|
|
#pragma semicolon 1
|
|
|
|
bool g_bLoggedCrashes = false;
|
|
Handle g_Timer = null;
|
|
|
|
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.");
|
|
}
|
|
|
|
public void OnMapStart()
|
|
{
|
|
// Example of how to fetch crashes automatically. This doesn't have to be on a OnMapStart callback.
|
|
if (!g_bLoggedCrashes) // only log crashes once
|
|
{
|
|
if (g_Timer == null) // avoid creating multiple timers since this is OnMapStart
|
|
{
|
|
// Create a repeating timer that will query Accelerator and log crashes when it's done uploading.
|
|
g_Timer = CreateTimer(0.1, Timer_LogCrashes, .flags = TIMER_REPEAT);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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;
|
|
}
|
|
|
|
Action Timer_LogCrashes(Handle timer)
|
|
{
|
|
// Wait until accelerator is done.
|
|
if (!Accelerator_IsDoneUploadingCrashes())
|
|
{
|
|
return Plugin_Continue;
|
|
}
|
|
|
|
int max = Accelerator_GetUploadedCrashCount();
|
|
|
|
if (max == 0)
|
|
{
|
|
LogMessage("No crashes were uploaded!");
|
|
g_Timer = null;
|
|
g_bLoggedCrashes = true;
|
|
return Plugin_Stop;
|
|
}
|
|
|
|
char buffer[512];
|
|
|
|
for (int i = 0; i < max; i++)
|
|
{
|
|
Accelerator_GetCrashHTTPResponse(i, buffer, sizeof(buffer));
|
|
LogMessage("Crash #%i: HTTP reponse: \"%s\".", i, buffer);
|
|
}
|
|
|
|
g_Timer = null;
|
|
g_bLoggedCrashes = true;
|
|
return Plugin_Stop;
|
|
} |