Skip to content
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

Bump actions/checkout from 2 to 3 #2

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
SM_JSON_INC_PATH: get5/dependencies/sm-json/addons/sourcemod/scripting/include
STEAMWORKS_URL: https://raw.githubusercontent.com/PhlexPlexico/SteamWorks/master/Pawn/includes/SteamWorks.inc
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
path: 'get5'
submodules: true
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
if: github.ref == 'refs/heads/development'
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: ${{ needs.build.outputs.filename }}
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Generate changelog
id: changelog
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
SM_JSON_INC_PATH: get5/dependencies/sm-json/addons/sourcemod/scripting/include
STEAMWORKS_URL: https://raw.githubusercontent.com/PhlexPlexico/SteamWorks/master/Pawn/includes/SteamWorks.inc
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
path: 'get5'
submodules: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/generate_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v2
uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
Expand Down
8 changes: 8 additions & 0 deletions scripting/get5/natives.sp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
CreateNative("Get5_AddLiveCvar", Native_AddLiveCvar);
CreateNative("Get5_IncreasePlayerStat", Native_IncreasePlayerStat);
CreateNative("Get5_GetMatchStats", Native_GetMatchStats);
CreateNative("Get5_CreateGet5HTTPRequest", Native_CreateGet5HTTPRequest);
RegPluginLibrary("get5");
return APLRes_Success;
}
Expand Down Expand Up @@ -251,3 +252,10 @@ public int Native_GetMatchStats(Handle plugin, int numParams) {
return view_as<int>(true);
}
}

public int Native_CreateGet5HTTPRequest(Handle plugin, int numParams) {
EHTTPMethod method = view_as<EHTTPMethod>(GetNativeCell(1));
char url[1024];
GetNativeString(2, url, sizeof(url));
return view_as<int>(CreateGet5HTTPRequest(method, url));
}
76 changes: 53 additions & 23 deletions scripting/get5_apistats.sp
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,20 @@ void ApiInfoChanged(ConVar convar, const char[] oldValue, const char[] newValue)
}

static Handle CreateRequest(EHTTPMethod httpMethod, const char[] apiMethod, any:...) {
char url[1024];
FormatEx(url, sizeof(url), "%s%s", g_APIURL, apiMethod);

char formattedUrl[1024];
VFormat(formattedUrl, sizeof(formattedUrl), url, 3);

LogDebug("Trying to create request to url %s", formattedUrl);

Handle req = SteamWorks_CreateHTTPRequest(httpMethod, formattedUrl);
if (StrEqual(g_APIKey, "")) {
// Not using a web interface.
LogError("Failed to create request because get5_web_api_key was not provided");
return INVALID_HANDLE;
}

} else if (req == INVALID_HANDLE) {
LogError("Failed to create request to %s", formattedUrl);
char url[1024];
char formattedUrl[1024];
FormatEx(url, sizeof(url), "%s%s", g_APIURL, apiMethod);
VFormat(formattedUrl, sizeof(formattedUrl), url, 3);
LogDebug("Trying to create request to url %s", formattedUrl);
Handle req = Get5_CreateGet5HTTPRequest(httpMethod, formattedUrl);
if (req == INVALID_HANDLE) {
return INVALID_HANDLE;

} else {
Expand All @@ -136,15 +135,28 @@ static Handle CreateRequest(EHTTPMethod httpMethod, const char[] apiMethod, any:
}
}

int RequestCallback(Handle request, bool failure, bool requestSuccessful,
static int RequestCallback(Handle request, bool failure, bool requestSuccessful,
EHTTPStatusCode statusCode) {

if (failure || !requestSuccessful) {
LogError("API request failed, HTTP status code = %d", statusCode);
char response[1024];
SteamWorks_GetHTTPResponseBodyData(request, response, sizeof(response));
LogError(response);
LogError("Network connection failed for the API request");
delete request;
return;
}

int status = view_as<int>(statusCode);
if (status >= 300 || status < 200) {
LogError("API request failed with HTTP status code: %d.", statusCode);
int responseSize;
SteamWorks_GetHTTPResponseBodySize(request, responseSize);
char[] response = new char[responseSize];
if (SteamWorks_GetHTTPResponseBodyData(request, response, responseSize)) {
LogError("Response body: %s", response);
} else {
LogError("Failed to read response body.");
}
}
delete request;
}

public void Get5_OnSeriesInit(const Get5SeriesStartedEvent event) {
Expand Down Expand Up @@ -196,17 +208,31 @@ static void CheckForLogo(const char[] logo) {
}
}

static int LogoCallback(Handle request, bool failure, bool successful, EHTTPStatusCode status,
int data) {
static int LogoCallback(Handle request, bool failure, bool successful, EHTTPStatusCode statusCode,
DataPack data) {
if (failure || !successful) {
LogError("Logo request failed, status code = %d", status);
LogError("Network connection failed for the logo request");
delete request;
return;
}

DataPack pack = view_as<DataPack>(data);
pack.Reset();
int status = view_as<int>(statusCode);
if (status >= 300 || status < 200) {
LogError("Logo request failed with HTTP status code: %d.", statusCode);
int responseSize;
SteamWorks_GetHTTPResponseBodySize(request, responseSize);
char[] response = new char[responseSize];
if (SteamWorks_GetHTTPResponseBodyData(request, response, responseSize)) {
LogError("Response body: %s", response);
} else {
LogError("Failed to read response body.");
}
delete request;
}

data.Reset();
char logo[32];
pack.ReadString(logo, sizeof(logo));
data.ReadString(logo, sizeof(logo));

char logoPath[PLATFORM_MAX_PATH + 1];
if (g_UseSVGCvar.BoolValue) {
Expand All @@ -215,8 +241,12 @@ static int LogoCallback(Handle request, bool failure, bool successful, EHTTPStat
FormatEx(logoPath, sizeof(logoPath), "%s/%s.png", g_LogoBasePath, logo);
}

LogMessage("Saved logo for %s to %s", logo, logoPath);
SteamWorks_WriteHTTPResponseBodyToFile(request, logoPath);
if (SteamWorks_WriteHTTPResponseBodyToFile(request, logoPath)) {
LogMessage("Saved logo for %s to %s", logo, logoPath);
} else {
LogError("Failed to write logo %s to file %s.", logo, logoPath);
}
delete request;
}

public void Get5_OnGoingLive(const Get5GoingLiveEvent event) {
Expand Down
3 changes: 3 additions & 0 deletions scripting/include/get5.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <json> // github.com/clugg/sm-json
#include <cstrike>
#include <SteamWorks>

enum Get5Side {
Get5Side_None = CS_TEAM_NONE,
Expand Down Expand Up @@ -141,6 +142,8 @@ native bool Get5_GetMatchStats(KeyValues kv);
// Increases an (integer-typed) player statistic in the plugin's stats keyvalue structure.
native int Get5_IncreasePlayerStat(int client, const char[] statName, int amount = 1);

// Creates a Steamworks http(s) request with the get5 headers
native Handle Get5_CreateGet5HTTPRequest(const EHTTPMethod method, const char[] url);

methodmap Get5StatusTeam < JSON_Object {

Expand Down