2012-05-12 16:03:14 +00:00
|
|
|
|
2012-12-27 17:01:04 +00:00
|
|
|
#include <string.h>
|
2012-01-21 20:57:41 +00:00
|
|
|
#include "gcard.h"
|
2019-10-24 23:26:17 +01:00
|
|
|
#include "https.h"
|
2012-08-05 13:48:15 +00:00
|
|
|
#include "loader/utils.h"
|
2012-12-08 16:17:35 +00:00
|
|
|
#include "gecko/gecko.hpp"
|
2012-12-27 17:01:04 +00:00
|
|
|
#include "memory/mem2.hpp"
|
2012-01-21 20:57:41 +00:00
|
|
|
|
2020-03-19 17:38:32 -05:00
|
|
|
#define MAX_URL_SIZE 263 // 128 + 129 + 6
|
2012-01-21 20:57:41 +00:00
|
|
|
|
|
|
|
struct provider
|
|
|
|
{
|
|
|
|
char url[128];
|
2020-03-19 17:38:32 -05:00
|
|
|
char key[129];
|
2012-01-21 20:57:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct provider *providers = NULL;
|
|
|
|
int amount_of_providers = 0;
|
|
|
|
|
|
|
|
u8 register_card_provider(const char *url, const char *key)
|
|
|
|
{
|
2012-12-27 20:22:40 +00:00
|
|
|
if(strlen(url) > 0 && strlen(key) > 0 && strstr(url, "{KEY}") != NULL && strstr(url, "{ID6}") != NULL)
|
2012-01-21 20:57:41 +00:00
|
|
|
{
|
2012-12-27 17:01:04 +00:00
|
|
|
providers = (struct provider*)MEM2_realloc(providers, (amount_of_providers + 1) * sizeof(struct provider));
|
2012-01-21 20:57:41 +00:00
|
|
|
memset(&providers[amount_of_providers], 0, sizeof(struct provider));
|
2020-03-19 17:38:32 -05:00
|
|
|
strncpy(providers[amount_of_providers].url, url, 127);
|
|
|
|
strncpy(providers[amount_of_providers].key, key, 128);
|
2012-01-21 20:57:41 +00:00
|
|
|
amount_of_providers++;
|
2012-02-18 13:51:55 +00:00
|
|
|
gprintf("Gamercard provider is valid!\n");
|
2012-01-21 20:57:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-02-18 13:51:55 +00:00
|
|
|
gprintf("Gamertag provider is NOT valid!\n");
|
2012-01-21 20:57:41 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 has_enabled_providers()
|
|
|
|
{
|
2012-02-24 21:08:24 +00:00
|
|
|
if (amount_of_providers != 0 && providers != NULL)
|
|
|
|
return 1;
|
2012-01-21 20:57:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_game_to_card(const char *gameid)
|
|
|
|
{
|
|
|
|
int i;
|
2012-02-23 19:08:34 +00:00
|
|
|
|
2012-12-27 17:01:04 +00:00
|
|
|
char *url = (char *)MEM2_alloc(MAX_URL_SIZE); // Too much memory, but only like 10 bytes
|
2014-05-25 20:54:39 +00:00
|
|
|
memset(url, 0, MAX_URL_SIZE);
|
2012-02-23 19:08:34 +00:00
|
|
|
|
2012-12-27 17:01:04 +00:00
|
|
|
for(i = 0; i < amount_of_providers && providers != NULL; i++)
|
2012-01-21 20:57:41 +00:00
|
|
|
{
|
2012-12-27 20:22:40 +00:00
|
|
|
strcpy(url, providers[i].url);
|
|
|
|
str_replace(url, "{KEY}", providers[i].key, MAX_URL_SIZE);
|
2012-12-27 17:01:04 +00:00
|
|
|
str_replace(url, "{ID6}", gameid, MAX_URL_SIZE);
|
2020-04-12 19:33:31 +01:00
|
|
|
gprintf("Gamertag URL: %s\n", url);
|
2019-10-24 23:26:17 +01:00
|
|
|
struct download file = {};
|
|
|
|
file.skip_response = 1;
|
|
|
|
downloadfile(url, &file);
|
2012-01-21 20:57:41 +00:00
|
|
|
}
|
2012-12-27 17:01:04 +00:00
|
|
|
MEM2_free(url);
|
2012-12-27 20:22:40 +00:00
|
|
|
}
|