libreshop_client/source/main.c

111 lines
2.3 KiB
C
Raw Normal View History

2023-07-20 18:59:22 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <gccore.h>
#include <network.h>
#include <wiiuse/wpad.h>
2023-07-20 19:10:01 +00:00
#include "sandia/sandia.h"
// Uncomment if this is a development build
//#include "debug.h"
2023-07-20 18:59:22 +00:00
static void *xfb = NULL;
static GXRModeObj *rmode = NULL;
static char version[] = { "0.0dev\0" };
void printheader() {
printf("\x1b[44m");
printf(" \n");
printf(" LibreShop v%s \n", version);
printf(" \n");
printf("\x1b[40m\n");
}
void logprint(int type, char *message) {
switch(type) {
case 1:
printf("\x1b[34m[\x1b[32mOK\x1b[34m]");
break;
case 2:
printf("\x1b[34m[\x1b[31m--\x1b[34m]");
break;
2023-07-20 18:59:22 +00:00
case 3:
printf("\x1b[31m!!\x1b[34m]");
break;
2023-07-20 18:59:22 +00:00
default:
printf(" ");
}
printf(" \x1b[37m%s", message);
}
int main(int argc, char **argv) {
s32 ret;
char localip[16] = {0};
char gateway[16] = {0};
char netmask[16] = {0};
VIDEO_Init();
WPAD_Init();
rmode = VIDEO_GetPreferredMode(NULL);
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
VIDEO_Configure(rmode);
VIDEO_SetNextFramebuffer(xfb);
VIDEO_SetBlack(FALSE);
VIDEO_Flush();
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
printf("\x1b[1;0H");
printheader();
logprint(0, "Welcome to LibreShop!\n");
#ifdef DEBUG_H
logprint(2, "Warning! You are running a DEBUG build.\n");
#endif
2023-07-20 18:59:22 +00:00
logprint(0, "Initializing network.\n");
ret = if_config(localip, netmask, gateway, TRUE, 20);
if (ret>=0) {
logprint(1, "Initialized successfully!\n");
logprint(0, "Your Wii's IP address is ");
printf("%s.\n", localip);
2023-07-20 19:10:01 +00:00
sandia req = sandia_create("libreshop.donut.eu.org", 80);
sandia_response res = sandia_get_request(&req, "/");
printf("\n%s\n", res.body);
sandia_close(&req);
2023-07-20 19:10:01 +00:00
} else {
2023-07-20 18:59:22 +00:00
logprint(0, "Network configuration failed :(\n");
}
while(1) {
WPAD_ScanPads();
u32 pressed = WPAD_ButtonsDown(0);
if ( pressed & WPAD_BUTTON_HOME ) {
logprint(0, "HOME pressed, quitting!");
exit(0);
}
VIDEO_WaitVSync();
}
return 0;
}