From fc37baafbff882acd21da793425d305a38c47871 Mon Sep 17 00:00:00 2001 From: ApfelTeeSaft <91074565+ApfelTeeSaft@users.noreply.github.com> Date: Sat, 2 Nov 2024 16:05:24 +0100 Subject: [PATCH] i don't know if this works, too drunk to test --- Backend.HC | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Parser.py | 42 ++++++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 Backend.HC create mode 100644 Parser.py diff --git a/Backend.HC b/Backend.HC new file mode 100644 index 0000000..4862a4f --- /dev/null +++ b/Backend.HC @@ -0,0 +1,94 @@ +// TempleOS Account API Simulation + +char username[32] := "apfelteesaft"; +char email[64] := "apfelteesaft@example.com"; + +void DatarouterResponse() { + Print("204 No Content\n"); +} + +void Token() { + // simulate token response lol + Print("Token Granted\nAccess Token: eg1~h1e35h4tr5h456r4h75r4h8r4h5r45h4r5\n"); + Print("Expires In: 28800\n"); +} + +void ExternalAuths() { + Print("External Auths Data\nProvider: example_provider\n"); +} + +void Account() { + Print("Account Info\n"); + Print("ID: 1234567890\nDisplayName: %s\nEmail: %s\n", username, email); +} + +void EnabledFeatures() { + Print("Enabled Features:\nFeature1, Feature2, Feature3\n"); +} + +void CloudStorage() { + Print("Cloud Storage Data:\nStorage Item 1\nStorage Item 2\n"); +} + +void Receipts() { + Print("Receipts Data:\nReceipt ID: 001\nReceipt ID: 002\n"); +} + +void Friends() { + Print("Friends List:\nFriend1\nFriend2\n"); +} + +void BlockList() { + Print("Block List:\nBlockedUser1\nBlockedUser2\n"); +} + +void VerifyAccount() { + Print("Account Verification Status: Verified\n"); +} + +void SetMtx() { + Print("Set Mtx Transaction Successful\n"); +} + +void QueryProfile() { + Print("Profile Data:\nID: 001\nName: Sample Profile\n"); +} + +void APIHandler() { + ClrScr(); + Print("TempleOS Account API Backend\nListening for Routes...\n"); + + while (TRUE) { + int key = KeyPeek(); + + if (key == '/') { + KeyGet(); // Consume '/' + int a = KeyGet(); + int p = KeyGet(); + int i = KeyGet(); + int slash = KeyGet(); + int r = KeyGet(); + int e = KeyGet(); + int s = KeyGet(); + int p2 = KeyGet(); + int o = KeyGet(); + int n = KeyGet(); + int s2 = KeyGet(); + int e2 = KeyGet(); + + if (a == 'a' && p == 'p' && i == 'i' && slash == '/' && + r == 'r' && e == 'e' && s == 's' && p2 == 'p' && + o == 'o' && n == 'n' && s2 == 's' && e2 == 'e') { + + // This would call DatarouterResponse if "/api/response" is typed + DatarouterResponse(); + Wait(100); + return; + } + // other stuff, won't implement + } + Wait(1); + } +} + +APIHandler(); \ No newline at end of file diff --git a/Parser.py b/Parser.py new file mode 100644 index 0000000..d1f278a --- /dev/null +++ b/Parser.py @@ -0,0 +1,42 @@ +from flask import Flask, jsonify +import pyautogui +import time + +app = Flask(__name__) + +def send_route_to_templeos(route): + for char in route: + pyautogui.press(char) + pyautogui.press('enter') + +def capture_response(): + response = [] + for _ in range(10): + response.append(pyautogui.read_key()) + time.sleep(0.5) + return ''.join(response) + + +@app.route('/api/datarouter', methods=['GET']) +def datarouter(): + route = "/api/response" + send_route_to_templeos(route) + result = capture_response() + return jsonify({"result": result}) + +@app.route('/api/token', methods=['POST']) +def token(): + route = "/api/token" + send_route_to_templeos(route) + result = capture_response() + return jsonify({"result": result}) + +@app.route('/api/account', methods=['GET']) +def account(): + route = "/api/account" + send_route_to_templeos(route) + result = capture_response() + return jsonify({"result": result}) + +if __name__ == "__main__": + app.run(port=5000) \ No newline at end of file