Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion buildbot/PackageScript
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ builder.SetBuildFolder('package')
folder_list = [
'addons/sourcemod/extensions',
'addons/sourcemod/gamedata',
'addons/sourcemod/configs'
'addons/sourcemod/configs',
'addons/sourcemod/scripting/include',
]

# Are we build a x86_64 extension ?
Expand Down Expand Up @@ -42,6 +43,13 @@ def CopyDirContent(src, dest):
if item.is_file():
builder.AddCopy(item.path, dest_entry)

# Include files
CopyFiles('scripting', 'addons/sourcemod/scripting/include',
[
'accelerator.inc',
]
)

# Copy binaries.
for task in Accelerator.extension:
if task.target.arch == 'x86_64':
Expand Down
1 change: 1 addition & 0 deletions extension/AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ project = builder.LibraryProject('accelerator.ext')
project.sources = [
'extension.cpp',
'MemoryDownloader.cpp',
'forwards.cpp',
os.path.join(Accelerator.sm_root, 'public', 'smsdk_ext.cpp')
]

Expand Down
9 changes: 9 additions & 0 deletions extension/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <IWebternet.h>
#include "MemoryDownloader.h"
#include "forwards.h"

#if defined _LINUX
#include "client/linux/handler/exception_handler.h"
Expand Down Expand Up @@ -464,6 +465,7 @@ class UploadThread: public IThread
count++;
g_pSM->LogError(myself, "Accelerator uploaded crash dump: %s", response);
if (log) fprintf(log, "Uploaded crash dump: %s\n", response);
extforwards::CallForward(count, response);
} else {
failed++;
g_pSM->LogError(myself, "Accelerator failed to upload crash dump: %s", response);
Expand Down Expand Up @@ -1321,6 +1323,7 @@ bool Accelerator::SDK_OnLoad(char *error, size_t maxlength, bool late)

void Accelerator::SDK_OnUnload()
{
extforwards::Shutdown();
plsys->RemovePluginsListener(this);

#if defined _LINUX
Expand All @@ -1336,6 +1339,12 @@ void Accelerator::SDK_OnUnload()
delete handler;
}

void Accelerator::SDK_OnAllLoaded()
{
extforwards::Init();
sharesys->RegisterLibrary(myself, "accelerator");
}

void Accelerator::OnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax)
{
strncpy(crashMap, gamehelpers->GetCurrentMap(), sizeof(crashMap) - 1);
Expand Down
5 changes: 5 additions & 0 deletions extension/extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class Accelerator : public SDKExtension, IPluginsListener
*/
virtual void SDK_OnUnload();

/**
* @brief This is called once all known extensions have been loaded.
*/
virtual void SDK_OnAllLoaded();

/**
* @brief Called on server activation before plugins receive the OnServerLoad forward.
*
Expand Down
59 changes: 59 additions & 0 deletions extension/forwards.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <array>
#include <string>
#include "extension.h"
#include "forwards.h"

static SourceMod::IForward* s_postuploadfoward = nullptr;

struct CrashPawnData
{
int index;
std::string response;
};

static void OnCrashUploadedCallback(void* data)
{
CrashPawnData* crashdata = reinterpret_cast<CrashPawnData*>(data);

Comment thread
caxanga334 marked this conversation as resolved.
Outdated
if (s_postuploadfoward)
{
s_postuploadfoward->PushCell(crashdata->index);
s_postuploadfoward->PushString(crashdata->response.c_str());
Comment thread
Kenzzer marked this conversation as resolved.
Outdated
s_postuploadfoward->PushCell(static_cast<cell_t>(crashdata->response.size()));
s_postuploadfoward->Execute(nullptr);
}

delete crashdata;
}

void extforwards::Init()
{
std::array types = {
SourceMod::ParamType::Param_Cell,
SourceMod::ParamType::Param_String,
SourceMod::ParamType::Param_Cell,
};

s_postuploadfoward = forwards->CreateForward("Accelerator_OnCrashUploaded", SourceMod::ExecType::ET_Ignore, 3, types.data());
}

void extforwards::Shutdown()
{
if (s_postuploadfoward)
{
forwards->ReleaseForward(s_postuploadfoward);
s_postuploadfoward = nullptr;
}
}

void extforwards::CallForward(int crashIndex, const char* response)
{
CrashPawnData* data = new CrashPawnData;

data->index = crashIndex;
data->response.assign(response);

// Accelerator uploads from a secondary thread, calling a forward directly will crash
// this will call the forward from the main thread.
smutils->AddFrameAction(OnCrashUploadedCallback, reinterpret_cast<void*>(data));
}
11 changes: 11 additions & 0 deletions extension/forwards.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef _INCLUDE_FORWARDS_H_
#define _INCLUDE_FORWARDS_H_

namespace extforwards
{
void Init();
void Shutdown();
void CallForward(int crashIndex, const char* response);
}

#endif // !_INCLUDE_FORWARDS_H_
2 changes: 1 addition & 1 deletion extension/smsdk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
//#define SMEXT_CONF_METAMOD

/** Enable interfaces you want to use here by uncommenting lines */
//#define SMEXT_ENABLE_FORWARDSYS
#define SMEXT_ENABLE_FORWARDSYS
//#define SMEXT_ENABLE_HANDLESYS
//#define SMEXT_ENABLE_PLAYERHELPERS
//#define SMEXT_ENABLE_DBMANAGER
Expand Down
37 changes: 37 additions & 0 deletions scripting/accelerator.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Accelerator's SourcePawn include file
*/

#if defined _accelerator_included
#endinput
#endif
#define _accelerator_included


/**
* Called when a crash dump is uploaded.
*
* @param index Index of the crash.
* @param response HTTP response in plain text.
* @param responsesize HTTP response char buffer size.
*/
forward void Accelerator_OnCrashUploaded(int index, const char[] response, int responsesize);
Comment thread
Kenzzer marked this conversation as resolved.
Outdated

/**
* Do not edit below this line!
*/
public Extension __ext_accelerator =
{
name = "accelerator",
file = "accelerator.ext",
#if defined AUTOLOAD_EXTENSIONS
autoload = 1,
#else
autoload = 0,
#endif
#if defined REQUIRE_EXTENSIONS
required = 1,
#else
required = 0,
#endif
};