Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

show detailed libcurl errors #11

Open
wants to merge 2 commits into
base: master
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
98 changes: 51 additions & 47 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@
static void* xfb = NULL;
static GXRModeObj* rmode = NULL;

char version_major = 1;
char version_minor = 4;
char version_patch = 0;

// sorry had to make this a subroutine
static void printContactInfo(s64 friendCode) {
printf(
"Contact info:\n"
"- Discord: https://discord.gg/rc24\n"
" Wait time: Short, send a Direct Message to a developer.\n"
"- E-Mail: support@riiconnect24.net\n"
" Wait time: up to 24 hours, sometimes longer\n\n"
);

if (friendCode)
printf(
"When contacting, please provide a brief explanation of the issue, and\n"
"include your Wii Number: w%016lli\n\n", friendCode);
}

int main(void) {
VIDEO_Init();

Expand All @@ -22,89 +42,73 @@ int main(void) {
VIDEO_WaitVSync();
if (rmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();

// Init network
wiisocket_init();

char version_major = 1;
char version_minor = 4;
char version_patch = 0;

printf("\n:---------------------------------------------------------:\n");
printf(" RiiConnect24 Mail Patcher - (C) RiiConnect24 ");
#ifdef COMMITHASH
printf("v%u.%u.%u-%s\n", version_major, version_minor, version_patch, COMMITHASH);
#else
printf("v%u.%u.%u\n", version_major, version_minor, version_patch);
#endif
printf(" Compiled on %s at %s\n", __DATE__ , __TIME__);
#ifdef COMMITHASH
printf("v%u.%u.%u-%s\n", version_major, version_minor, version_patch, COMMITHASH);
#else
printf("v%u.%u.%u\n", version_major, version_minor, version_patch);
#endif
printf(" Compiled on %s at %s\n", __DATE__ , __TIME__);
printf(":---------------------------------------------------------:\n\n");

printf("Initializing... ");
WPAD_Init();
NAND_Init();
printf("OK!\n");
wiisocket_init();
printf("OK!\n\n");


if (isDolphin()) {
printf("\n:---------------------------------------------------------------:\n"
printf(":---------------------------------------------------------------:\n"
": Dolphin is not supported! :\n"
": This tool can only run on a real Wii Console. :\n"
": :\n"
": Exiting in 10 seconds... :\n"
": Exiting in 10 seconds... :\n"
":---------------------------------------------------------------:\n");
sleep(10);
exit(0);
} else if (CheckvWii()){
printf("\n:---------------------------------------------------------------:\n"
": vWii Detected :\n"
": This tool will still patch your nwc24msg.cfg, but you will be :\n"
": unable to fully utilize Wii Mail. :\n"
":---------------------------------------------------------------:\n");
}
printf("\nPatching...\n\n");

printf("Patching...\n\n");

s64 friendCode = getFriendCode();
s32 error = patchMail();

switch (error) {
case RESPONSE_AREGISTERED:
printf("You have already patched your Wii to use Wii Mail.\n");
printf("In most cases, there is no need to run this patcher again.\n");
printf("If you're having any sorts of problems, reinstalling RiiConnect24 is unnecessary\n");
printf("and unlikely to fix issues.\n");
printf("If you still need to have your Wii Number removed, please contact us.\n");
printf("\nContact info:\n- Discord: https://discord.gg/rc24\n Wait time: Short, send a Direct Message to a developer.\n- E-Mail: support@riiconnect24.net\n Wait time: up to 24 hours, sometimes longer\n");
printf("\nWhen contacting, please provide a brief explanation of the issue, and");
printf("\ninclude your Wii Number: w");
printf("%016llu\n", friendCode);
printf("\nPress the HOME Button to exit.\n");
printf(
"You have already patched your Wii to use Wii Mail.\n"
"In most cases, there is no need to run this patcher again.\n"
"If you're having any sorts of problems, reinstalling RiiConnect24\n"
"is unnecessary and unlikely to fix issues.\n"
"If you still need to have your Wii Number removed, please contact us.\n\n");
printContactInfo(friendCode);
break;
case 22:
// cURL's error code 6 covers all the HTTP error codes higher or equal to 400
printf("We're probably performing maintenance or having some issues. Hang tight!\n\nMake sure to check https://status.rc24.xyz/ for more info.\n\n");
printf("\nContact info:\n- Discord: https://discord.gg/rc24\n Wait time: Short, send a Direct Message to a developer.\n- E-Mail: support@riiconnect24.net\n Wait time: up to 24 hours, sometimes longer\n");
printf("\nPress the HOME Button to exit.\n");
case 22: // You needed CURLOPT_FAILONERROR for this to actually happen
// cURL's error code 22 covers all the HTTP error codes higher or equal to 400
printf(
"We're probably performing maintenance or having some issues. Hang tight!\n"
"Make sure to check https://status.rc24.xyz/ for more info.\n\n");
printContactInfo(0);
break;
case 0:
// Success
printf("All done, all done! Thank you for installing RiiConnect24.\n");
printf("\nPress the HOME Button to exit.\n");
break;
default:
printf("There was an error while patching.\nPlease make a screenshot of this error message and contact us.\n");
printf("\nPlease contact us using:\n- Discord: https://discord.gg/rc24\n Wait time: Short, send a Direct Message to a developer.\n- E-Mail: support@riiconnect24.net\n Wait time: up to 24 hours, sometimes longer\n");
printf("\nWhen contacting, please provide a brief explanation of the issue, and");
printf("\ninclude your Wii Number: w");
printf("%016llu\n", friendCode);
printf("\nPress the HOME Button to exit.\n");
printf(
"There was an error while patching.\n"
"Please make a screenshot of this error message and contact us.\n\n");
printContactInfo(friendCode);
break;
}

printf("\nPress the HOME Button to exit.\n");
while (1) {
WPAD_ScanPads();
u32 pressed = WPAD_ButtonsDown(0);

if (pressed & WPAD_BUTTON_HOME) exit(0);
if (pressed & WPAD_BUTTON_HOME) break;

VIDEO_WaitVSync();
}
Expand Down
16 changes: 12 additions & 4 deletions source/nand.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
static bool isNANDInitialised = false;

bool isDolphin(void) {
s32 checkDolphin;
checkDolphin = IOS_Open("/dev/dolphin", IPC_OPEN_NONE);
if (checkDolphin >= 0)
s32 ret;

s32 fd = ret = IOS_Open("/dev/sha", 0);
if (ret < 0)
return true;
else

IOS_Close(fd);

fd = ret = IOS_Open("/dev/dolphin", 0);
if (ret < 0)
return false;

IOS_Close(fd);
return true;
}


Expand Down
12 changes: 12 additions & 0 deletions source/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <mbedtls/x509.h>
#include "patcher.h"

static char curl_errorbuffer[CURL_ERROR_SIZE];

// Override CA certificate with those bundled from cacert.pem.
// A message from Spotlight: TODO: This is very broken.
static CURLcode ssl_ctx_callback(CURL *curl, void *ssl_ctx, void *userptr) {
Expand Down Expand Up @@ -55,6 +57,8 @@ s32 post_request(char *url, char *post_arguments, char **response) {
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");

curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorbuffer);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "WiiPatcher/1.0 (Nintendo Wii)");
Expand All @@ -77,8 +81,12 @@ s32 post_request(char *url, char *post_arguments, char **response) {
curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, ssl_ctx_callback);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);

curl_errorbuffer[0] = 0;
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
if (!curl_errorbuffer[0])
sprintf(curl_errorbuffer, "%s", curl_easy_strerror(res));

return (s32)res;
}

Expand All @@ -90,3 +98,7 @@ s32 post_request(char *url, char *post_arguments, char **response) {
*response = chunk.memory;
return 0;
}

const char *cURL_GetLastError(void) {
return curl_errorbuffer;
}
1 change: 1 addition & 0 deletions source/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
#include <gccore.h>

s32 post_request(char *url, char *post_arguments, char **response);
const char *cURL_GetLastError(void);

#endif
52 changes: 18 additions & 34 deletions source/patcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,10 @@ void patchNWC24MSG(unionNWC24MSG* unionFile, char passwd[0x20], char mlchkid[0x2
strcpy(unionFile->structNWC24MSG.mlchkid, mlchkid);

// Patch the URLs
const char engines[0x5][0x80] = { "account", "check", "receive", "delete", "send" };
const char *engines[] = { "account", "check", "receive", "delete", "send" };
for (int i = 0; i < 5; i++) {
char formattedLink[0x80];
for (int i = 0; i < sizeof(formattedLink); i++)
{
formattedLink[i] = '\0';
}
strncpy(unionFile->structNWC24MSG.urls[i], formattedLink, sizeof(formattedLink));
}
for (int i = 0; i < 5; i++) {
char formattedLink[0x80];
sprintf(formattedLink, "http://%s/cgi-bin/%s.cgi", BASE_HTTP_URL, engines[i]);
strcpy(unionFile->structNWC24MSG.urls[i], formattedLink);
memset(unionFile->structNWC24MSG.urls[i], 0, sizeof(unionFile->structNWC24MSG.urls[i]));
sprintf(unionFile->structNWC24MSG.urls[i], "http://%s/cgi-bin/%s.cgi", BASE_HTTP_URL, engines[i]);
}

// Patch the title booting
Expand All @@ -65,25 +56,24 @@ void patchNWC24MSG(unionNWC24MSG* unionFile, char passwd[0x20], char mlchkid[0x2

s32 patchMail() {
// Read the nwc24msg.cfg file
static char fileBufferNWC24MSG[0x400];
unionNWC24MSG fileUnionNWC24MSG;

s32 error = NAND_ReadFile("/shared2/wc24/nwc24msg.cfg", fileBufferNWC24MSG, 0x400);
s32 error = NAND_ReadFile("/shared2/wc24/nwc24msg.cfg", fileUnionNWC24MSG.charNWC24MSG, sizeof(fileUnionNWC24MSG));
if (error < 0) {
printf(":-----------------------------------------:\n");
printf(": The nwc24msg.cfg file couldn't be read. :\n");
printf(":-----------------------------------------:\n\n");
return error;
}
memcpy(&fileUnionNWC24MSG, fileBufferNWC24MSG, 0x400);

// Separate the file magic and checksum
unsigned int oldChecksum = fileUnionNWC24MSG.structNWC24MSG.checksum;
unsigned int calculatedChecksum = calcChecksum(fileUnionNWC24MSG.charNWC24MSG, 0x3FC);

// Check the file magic and checksum
if (strcmp(fileUnionNWC24MSG.structNWC24MSG.magic, "WcCf") != 0) {
printf("The file couldn't be verified\n");
if (memcmp(fileUnionNWC24MSG.structNWC24MSG.magic, "WcCf", 4) != 0) {
printf(":-----------------------------------------:\n");
printf(": Invalid nwc24msg.cfg file. :\n");
printf(":-----------------------------------------:\n\n");
return -1;
}
if (oldChecksum != calculatedChecksum) {
Expand Down Expand Up @@ -111,25 +101,19 @@ s32 patchMail() {
char *response = (char *)malloc(2048);
error = post_request(url, arg, &response);

// cURL error code 6 could also mean the host doesn't exists, but we know for a fact it does.
if (error == 6) {
printf(":--------------------------------------------------------:");
printf("\n: There is no Internet connection. :");
printf("\n: Please check if your Wii is connected to the Internet. :");
printf("\n: :");
printf("\n: Could not reach remote host. :");
printf("\n:--------------------------------------------------------:\n\n");
if (error > 0) {
printf(":-------------------------------------------------------------:\n");
printf(": Failed to send request to the server. :\n");
printf(": Please check if your Wii is connected to the Internet. :\n");
printf(": :\n");
printf(": %-60s" ":\n", cURL_GetLastError());
printf(":-------------------------------------------------------------:\n\n");

return error;
}
if (error < 0) {
else if (error < 0) {
return error;
}
if (error < 0 && error != 6) {
printf(":-----------------------------------------:\n");
printf(" Couldn't request the data: %i\n", error);
printf(":-----------------------------------------:\n\n");
return error;
}

// Parse the response
struct phr_header headers[10];
Expand Down