Skip to content

Commit

Permalink
Add team logo download support.
Browse files Browse the repository at this point in the history
  • Loading branch information
splewis committed Sep 6, 2016
1 parent 518303c commit f63d5a6
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
4 changes: 1 addition & 3 deletions scripting/get5/matchconfig.sp
Original file line number Diff line number Diff line change
Expand Up @@ -950,9 +950,7 @@ static void AddTeamLogoToDownloadTable(const char[] logoName) {
"resource/flash/econ/tournaments/teams/%s.png",
logoName);

if (FileExists(logoPath)) {
AddFileToDownloadsTable(logoPath);
}
AddFileToDownloadsTable(logoPath);
}

public void CheckTeamNameStatus(MatchTeam team) {
Expand Down
9 changes: 9 additions & 0 deletions scripting/get5/util.sp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,15 @@ stock void SetConVarStringSafe(const char[] name, const char[] value) {
}
}

stock void GetConVarStringSafe(const char[] name, char[] value, int len) {
Handle cvar = FindConVar(name);
if (cvar == INVALID_HANDLE) {
LogError("Failed to find cvar: \"%s\"", name);
} else {
GetConVarString(cvar, value, len);
}
}

stock bool OnActiveTeam(int client) {
if (!IsPlayer(client))
return false;
Expand Down
62 changes: 61 additions & 1 deletion scripting/get5_apistats.sp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* =============================================================================
* Get5 API stats
* Get5 web API integration
* Copyright (C) 2016. Sean Lewis. All rights reserved.
* =============================================================================
*
Expand Down Expand Up @@ -143,8 +143,68 @@ public void Get5_OnSeriesInit() {
char matchid[64];
Get5_GetMatchID(matchid, sizeof(matchid));
g_MatchID = StringToInt(matchid);


// Handle new logos.
if (!DirExists("resource/flash/econ/tournaments/teams")) {
if (!CreateDirectory("resource/flash/econ/tournaments/teams", 755)) {
LogError("Failed to create logo directory");
}
}

char logo1[32];
char logo2[32];
GetConVarStringSafe("mp_teamlogo_1", logo1, sizeof(logo1));
GetConVarStringSafe("mp_teamlogo_2", logo2, sizeof(logo2));
CheckForLogo(logo1);
CheckForLogo(logo2);
}

public void CheckForLogo(const char[] logo) {
char logoPath[PLATFORM_MAX_PATH + 1];
Format(logoPath, sizeof(logoPath),
"resource/flash/econ/tournaments/teams/%s.png",
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 pack = CreateDataPack();
WritePackString(pack, logo);

SteamWorks_SetHTTPRequestContextValue(req, view_as<int>(pack));
SteamWorks_SetHTTPCallbacks(req, LogoCallback);
SteamWorks_SendHTTPRequest(req);
}
}


public int LogoCallback(Handle request, bool failure, bool successful, EHTTPStatusCode status, int data) {
if (failure || !successful) {
LogError("Logo request failed, status code = %d", status);
return;
}

DataPack pack = view_as<DataPack>(data);
pack.Reset();
char logo[32];
pack.ReadString(logo, sizeof(logo));

char logoPath[PLATFORM_MAX_PATH + 1];
Format(logoPath, sizeof(logoPath),
"resource/flash/econ/tournaments/teams/%s.png",
logo);

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


public void Get5_OnGoingLive(int mapNumber) {
char mapName[64];
GetCurrentMap(mapName, sizeof(mapName));
Expand Down

0 comments on commit f63d5a6

Please sign in to comment.