MBMNET-App v2.8.2: Quellcode (GPLv3)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
// Entwickler-Werkzeuge nur für Admins: Die App fragt bei MBMNET, ob die verknüpfte NNID einem Admin
|
||||
// gehört (GET /mbmnet/app-info?pid=...). Die Antwort wird auf der SD gemerkt, damit die Werkzeuge
|
||||
// auch im Nintendo-Modus und ohne Verbindung da sind.
|
||||
#include <3ds.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "admin.h"
|
||||
|
||||
#define CACHE_FILE "sdmc:/3ds/mbmnet/admin"
|
||||
|
||||
static volatile bool isAdmin;
|
||||
static Thread thread;
|
||||
static char url[128];
|
||||
|
||||
static void remember(bool on)
|
||||
{
|
||||
FILE *f = fopen(CACHE_FILE, "w");
|
||||
if (f) { fputs(on ? "1" : "0", f); fclose(f); }
|
||||
}
|
||||
|
||||
static void worker(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
httpcContext ctx;
|
||||
if (R_FAILED(httpcOpenContext(&ctx, HTTPC_METHOD_GET, url, 1))) return;
|
||||
httpcAddRequestHeaderField(&ctx, "User-Agent", "MBMNET-Switcher/" APP_VERSION);
|
||||
u32 status = 0, got = 0;
|
||||
char body[32] = { 0 };
|
||||
Result rc = httpcBeginRequest(&ctx);
|
||||
if (R_SUCCEEDED(rc)) rc = httpcGetResponseStatusCodeTimeout(&ctx, &status, 8ULL * 1000 * 1000 * 1000);
|
||||
if (R_SUCCEEDED(rc) && status == 200) httpcDownloadData(&ctx, (u8 *)body, sizeof(body) - 1, &got);
|
||||
httpcCloseContext(&ctx);
|
||||
if (status != 200 || strncmp(body, "admin=", 6) != 0) return; // keine Antwort: gemerkte gilt weiter
|
||||
isAdmin = body[6] == '1';
|
||||
remember(isAdmin);
|
||||
}
|
||||
|
||||
void admin_start(const char *server, u32 pid)
|
||||
{
|
||||
FILE *f = fopen(CACHE_FILE, "r");
|
||||
if (f) { isAdmin = fgetc(f) == '1'; fclose(f); }
|
||||
if (!pid) return;
|
||||
snprintf(url, sizeof(url), "http://%s/mbmnet/app-info?pid=%lu", server, (unsigned long)pid);
|
||||
s32 prio = 0x30;
|
||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||
thread = threadCreate(worker, NULL, 16 * 1024, prio + 1, -2, false);
|
||||
}
|
||||
|
||||
bool admin_is(void) { return isAdmin; }
|
||||
|
||||
void admin_finish(void)
|
||||
{
|
||||
if (!thread) return;
|
||||
if (R_SUCCEEDED(threadJoin(thread, 3ULL * 1000 * 1000 * 1000))) threadFree(thread);
|
||||
thread = NULL;
|
||||
}
|
||||
Reference in New Issue
Block a user