-
-
Notifications
You must be signed in to change notification settings - Fork 38
[Feature]: Add on crash uploaded SourceMod forward #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
99b3cad
Squashed commit of the following:
caxanga334 f4d60b3
Update accelerator.inc
caxanga334 d0cb652
Fix: Missing forwards.cpp in AMBuilder
caxanga334 1a6223a
Refactor API
caxanga334 d06a0fd
Implement Requested Changes
caxanga334 68ba00f
Fix Error
caxanga334 e567441
Update Example Plugin
caxanga334 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #include <array> | ||
| #include <string> | ||
| #include "extension.h" | ||
| #include "forwards.h" | ||
|
|
||
|
|
||
| static SourceMod::IForward* s_ondoneuploadingforward = nullptr; | ||
|
|
||
| static void OnDoneUploadingCallback(void* data) | ||
| { | ||
| if (s_ondoneuploadingforward) { | ||
| s_ondoneuploadingforward->Execute(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| void extforwards::Init() | ||
| { | ||
| s_ondoneuploadingforward = forwards->CreateForward("Accelerator_OnDoneUploadingCrashes", SourceMod::ExecType::ET_Ignore, 0, nullptr); | ||
| } | ||
|
|
||
| void extforwards::Shutdown() | ||
| { | ||
| if (s_ondoneuploadingforward) { | ||
| forwards->ReleaseForward(s_ondoneuploadingforward); | ||
| s_ondoneuploadingforward = nullptr; | ||
| } | ||
| } | ||
|
|
||
| void extforwards::CallOnDoneUploadingForward() | ||
| { | ||
| // It's obligatory to use AddFrameAction here because SourcePawn forwards can only be called from the server's main thread. | ||
| // AddFrameAction will do this for us and is also thread safe. | ||
| smutils->AddFrameAction(OnDoneUploadingCallback, nullptr); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #ifndef _INCLUDE_FORWARDS_H_ | ||
| #define _INCLUDE_FORWARDS_H_ | ||
|
|
||
| namespace extforwards | ||
| { | ||
| // Initialize the sourcepawn forwards. | ||
| void Init(); | ||
| // Shutdown the sourcepawn forwards. | ||
| void Shutdown(); | ||
| // Calls the on done uploadind forward. (thread safe) | ||
| void CallOnDoneUploadingForward(); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| #endif // !_INCLUDE_FORWARDS_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #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)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #ifndef _INCLUDE_NATIVES_H_ | ||
| #define _INCLUDE_NATIVES_H_ | ||
|
|
||
|
|
||
| namespace natives | ||
| { | ||
| // Called during the load process to setup the extension natives | ||
| void Setup(std::vector<sp_nativeinfo_t>& vec); | ||
| } | ||
|
|
||
| #endif // !_INCLUDE_NATIVES_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.