import re from misc import repair_base64 from lz77 import lz77_decompress import xmltodict from urllib.parse import parse_qs from base64 import b64decode from flask import Blueprint, request # Import necessary functions from kbinxml import KBinXML from variables.protocols import IIDX_XML, IIDX_RESULT, EAC_XML, EAC_RESULT, IIDX_Protocol, Respond, EAC_PROTOCOL_1, EAC_PROTOCOL_2 from time import time from variables.strings.preLaunch import GenericOK from variables.strings.common import heartbeat from variables.strings.iidx import serverValues from variables.strings.games.iidx import clearList, clearListRegex, champInfo, champInfo2 bp = Blueprint( "needAuth", __name__, url_prefix="/iidx/needlessAuth" ) # Create a Blueprint for this route section @bp.route("/GetServerValues", methods=["POST"]) def GetServerValues(): if request.method == "POST": response = KBinXML(serverValues) binary_data = response.to_binary() if isinstance(binary_data, str): binary_data = binary_data.encode("utf-8") return Respond(binary_data,IIDX_Protocol) return "Invalid request method", 400 @bp.route("/GetClearRate", methods=["POST"]) def GetClearRate(): if request.method == "POST": # Access post data post_data = request.get_data().decode("UTF-8") variables = parse_qs(post_data) # Do something with post_data and headers kbinxml_data = "" playStyle = -1 # Example: Decoding and processing data try: decoded_data = b64decode(repair_base64(variables["request"][0])) decompressed_data = lz77_decompress(decoded_data) kbinxml_data = KBinXML(decompressed_data).to_text() data = xmltodict.parse(kbinxml_data) # Ensure to parse the XML correctly playStyle = data["p2d"]["params"]["play_style"]["#text"] # Process kbinxml_data except Exception as e: print(f"Error processing data: {e}") finally: print("playStyle:", playStyle) clearListReplace = f'{playStyle}' binary_data = KBinXML( re.sub( clearListRegex, clearListReplace.format(playStyle=playStyle), clearList, ).encode("utf-8") ) return Respond(binary_data,IIDX_Protocol) return "Invalid request method", 400 @bp.route("/GetChampionshipInfo", methods=["POST"]) def GetChampionshipInfo(): if request.method == "POST": response = KBinXML(champInfo) binary_data = response.to_binary() if isinstance(binary_data, str): binary_data = binary_data.encode("utf-8") return Respond(binary_data,IIDX_Protocol) return "Invalid request method", 400 @bp.route("/CheckChampionshipInfo", methods=["POST"]) def CheckChampionshipInfo(): if request.method == "POST": response = KBinXML(champInfo2) binary_data = response.to_binary() if isinstance(binary_data, str): binary_data = binary_data.encode("utf-8") return Respond(binary_data,IIDX_Protocol) return "Invalid request method", 400