WiiFlow_Lite/source/network/gcard.c

62 lines
1.6 KiB
C
Raw Normal View History

#include <string.h>
2012-01-21 21:57:41 +01:00
#include "gcard.h"
2019-10-25 00:26:17 +02:00
#include "https.h"
#include "loader/utils.h"
#include "gecko/gecko.hpp"
#include "memory/mem2.hpp"
2012-01-21 21:57:41 +01:00
#define MAX_URL_SIZE 263 // 128 + 129 + 6
2012-01-21 21:57:41 +01:00
struct provider
{
char url[128];
char key[129];
2012-01-21 21:57:41 +01:00
};
struct provider *providers = NULL;
int amount_of_providers = 0;
u8 register_card_provider(const char *url, const char *key)
{
if(strlen(url) > 0 && strlen(key) > 0 && strstr(url, "{KEY}") != NULL && strstr(url, "{ID6}") != NULL)
2012-01-21 21:57:41 +01:00
{
providers = (struct provider*)MEM2_realloc(providers, (amount_of_providers + 1) * sizeof(struct provider));
2012-01-21 21:57:41 +01:00
memset(&providers[amount_of_providers], 0, sizeof(struct provider));
strncpy(providers[amount_of_providers].url, url, 127);
strncpy(providers[amount_of_providers].key, key, 128);
2012-01-21 21:57:41 +01:00
amount_of_providers++;
gprintf("Gamercard provider is valid!\n");
2012-01-21 21:57:41 +01:00
return 0;
}
gprintf("Gamertag provider is NOT valid!\n");
2012-01-21 21:57:41 +01:00
return -1;
}
u8 has_enabled_providers()
{
if (amount_of_providers != 0 && providers != NULL)
return 1;
2012-01-21 21:57:41 +01:00
return 0;
}
void add_game_to_card(const char *gameid)
{
int i;
char *url = (char *)MEM2_alloc(MAX_URL_SIZE); // Too much memory, but only like 10 bytes
memset(url, 0, MAX_URL_SIZE);
for(i = 0; i < amount_of_providers && providers != NULL; i++)
2012-01-21 21:57:41 +01:00
{
strcpy(url, providers[i].url);
str_replace(url, "{KEY}", providers[i].key, MAX_URL_SIZE);
str_replace(url, "{ID6}", gameid, MAX_URL_SIZE);
gprintf("Gamertag URL: %s\n", url);
2019-10-25 00:26:17 +02:00
struct download file = {};
file.skip_response = 1;
downloadfile(url, &file);
2012-01-21 21:57:41 +01:00
}
MEM2_free(url);
}