Skip to content

Commit

Permalink
added panorama logo dir (splewis#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoritzLoewenstein authored Apr 15, 2020
1 parent ed23e8a commit 5282ee9
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions scripting/get5_apistats.sp
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,24 @@
#include "get5/version.sp"

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

#include "get5/jsonhelpers.sp"

#pragma semicolon 1
#pragma newdecls required

int g_MatchID = -1;

ConVar g_UseSVGCvar;
char g_LogoBasePath[128];
ConVar g_APIKeyCvar;
char g_APIKey[128];

ConVar g_APIURLCvar;
char g_APIURL[128];

#define LOGO_DIR "resource/flash/econ/tournaments/teams"
#define LOGO_DIR "materials/panorama/images/tournaments/teams"
#define LEGACY_LOGO_DIR "resource/flash/econ/tournaments/teams"

// clang-format off
public Plugin myinfo = {
Expand All @@ -57,7 +59,8 @@ public Plugin myinfo = {
public void OnPluginStart() {
InitDebugLog("get5_debug", "get5_api");
LogDebug("OnPluginStart version=%s", PLUGIN_VERSION);

g_UseSVGCvar = CreateConVar("get5_use_svg", "1", "support svg team logos");
HookConVarChange(g_UseSVGCvar, LogoBasePathChanged);
g_APIKeyCvar =
CreateConVar("get5_web_api_key", "", "Match API key, this is automatically set through rcon");
HookConVarChange(g_APIKeyCvar, ApiInfoChanged);
Expand Down Expand Up @@ -94,6 +97,10 @@ public Action Command_Avaliable(int client, int args) {
return Plugin_Handled;
}

public void LogoBasePathChanged(ConVar convar, const char[] oldValue, const char[] newValue) {
g_LogoBasePath = g_UseSVGCvar.BoolValue ? LOGO_DIR : LEGACY_LOGO_DIR;
}

public void ApiInfoChanged(ConVar convar, const char[] oldValue, const char[] newValue) {
g_APIKeyCvar.GetString(g_APIKey, sizeof(g_APIKey));
g_APIURLCvar.GetString(g_APIURL, sizeof(g_APIURL));
Expand Down Expand Up @@ -155,9 +162,9 @@ public void Get5_OnSeriesInit() {
g_MatchID = StringToInt(matchid);

// Handle new logos.
if (!DirExists(LOGO_DIR)) {
if (!CreateDirectory(LOGO_DIR, 755)) {
LogError("Failed to create logo directory: %s", LOGO_DIR);
if (!DirExists(g_LogoBasePath)) {
if (!CreateDirectory(g_LogoBasePath, 755)) {
LogError("Failed to create logo directory: %s", g_LogoBasePath);
}
}

Expand All @@ -173,17 +180,22 @@ public void CheckForLogo(const char[] logo) {
if (StrEqual(logo, "")) {
return;
}

char logoPath[PLATFORM_MAX_PATH + 1];
Format(logoPath, sizeof(logoPath), "%s/%s.png", LOGO_DIR, logo);
//change png to svg because it's better supported
if (g_UseSVGCvar.BoolValue)
Format(logoPath, sizeof(logoPath), "%s/%s.svg", g_LogoBasePath, logo);
else
Format(logoPath, sizeof(logoPath), "%s/%s.png", g_LogoBasePath, logo);

// Try to fetch the file if we don't have it.
if (!FileExists(logoPath)) {
LogDebug("Fetching logo for %s", logo);
Handle req = CreateRequest(k_EHTTPMethodGET, "/static/img/logos/%s.png", logo);
if (req == INVALID_HANDLE) {
return;
}
Handle req = g_UseSVGCvar.BoolValue ?
CreateRequest(k_EHTTPMethodGET, "/static/img/logos/%s.svg", logo) :
CreateRequest(k_EHTTPMethodGET, "/static/img/logos/%s.png", logo);

if (req == INVALID_HANDLE) return;

Handle pack = CreateDataPack();
WritePackString(pack, logo);
Expand All @@ -206,7 +218,11 @@ public int LogoCallback(Handle request, bool failure, bool successful, EHTTPStat
pack.ReadString(logo, sizeof(logo));

char logoPath[PLATFORM_MAX_PATH + 1];
Format(logoPath, sizeof(logoPath), "%s/%s.png", LOGO_DIR, logo);
//change to svg
if (g_UseSVGCvar.BoolValue)
Format(logoPath, sizeof(logoPath), "%s/%s.svg", g_LogoBasePath, logo);
else
Format(logoPath, sizeof(logoPath), "%s/%s.png", g_LogoBasePath, logo);

LogMessage("Saved logo for %s to %s", logo, logoPath);
SteamWorks_WriteHTTPResponseBodyToFile(request, logoPath);
Expand Down

0 comments on commit 5282ee9

Please sign in to comment.