import http.server import json import os import re import socketserver import ssl import threading from pathlib import Path from urllib.parse import urlsplit, parse_qs HTTP_PORT = 80 HTTPS_PORT = 443 ALT_PORT = 8444 IP_ADDRESS = "192.168.1.135" SERVER_DIR = Path(__file__).resolve().parent WEB_ROOT = SERVER_DIR DOWNLOADED_DLC_DIR = ( SERVER_DIR.parent / "com.gameloft.minionrushmod" / "files" / "dlcs" ) GAME_HOST_RE = re.compile( r"^(?:[a-z0-9-]+\.)*(?:gameloft\.com|gameloft\.com\.cn|mrur\.duckdns\.org|mrurdns\.duckdns\.org)$", re.IGNORECASE, ) DATACENTERS_JSON = [ { "name": "mdc", "status": "active", "preferred": True, "country_code": "CA", "_datacenter_id": "bob~gold", } ] MDC_URLS_JSON = { "ads_agency": "https://mrur.duckdns.org/un/index.hhh", "apple_iap": "https://iap.gameloft.com/partners/igcontents", "china_regulation": "https://ecomapis.gameloft.com.cn", "crm_iap": "https://iap-gen.gameloft.com/inapp_crm/index.php", "customer_care": "https://helpshift-api.tools.gameloft.com/bob~gold", "ecomm_api_root": "https://iap-gen.gameloft.com", "ets": "https://bob-ets-wsg.gameloft.com", "etsv2": "https://etsv2.datalake.gameloft.com", "ets_gs": "https://bob-ets-wsg.gameloft.com/index_gs.php", "federation": "https://federation-bob.gameloft.com", "federation-internal": "https://federation-bob-int.gameloft.com", "game_portal": "https://mrur.duckdns.org", "gdid": "https://gdid.datalake.gameloft.com", "glid": "https://id.gameloft.com", "gllive-asa": "https://gllive-asa.gameloft.com/ope", "gllive-bdc": "https://gllive-bdc.gameloft.com/ope", "gllive-ope": "https://gllive.gameloft.com/ope", "livewebapp": "https://livewebapp.gameloft.com/glive", "marketing_site": "https://mrur.duckdns.org", "master_federation": "https://fed-master.xsilo-gold.gameloft.com", "offline_apple_iap": "https://confirmation.gameloft.com/partners/offline_ingame/item_list.php", "offline_items": "https://confirmation.gameloft.com/partners/offline_ingame/item_list.php", "online_connectivity": "https://oct.tools.gameloft.com", "pandora": "https://v.mrur.duckdns.org/1677:53646:5.7.0h:android:googleplay", "standalone_iap": "https://iap-gen.gameloft.com/inapp_crm/standalone/index.php", "statetrackers": "https://state.gameloft.com", "tapjoy": "https://gllive.gameloft.com/ope/tapjoy_log.php", } WHITELISTED_SERVICES_JSON = {"service": "com.android.vending"} BANNED_SERVICES_JSON = [ "ea6dd65af18b4b22081e32bf1ac79202fd2c00e81938c7511f74dabecbdafc35", "55cc3f0a2d4c5d990a5e4977252354b9e8366dd00d99ce4b0678ae9ef2396068", "1664a6aa87ef53d7e9d02bb030595688c083fa90a3410a4efcb4c78420b94a42", "35cf93335b719a45563228f99e6236147a012d6583ecfd71ff58afd616755fce", "4c82e2b20d658730ae684012d524918f5c9611bd978e808302065a6ceed46de6", "a4a387cae50415b530b55d3adb7b049c0f6acb4749ba99f15ae1a77fda0724b0", "065a8b2102191d6759de20f998f9cee10bbf41860b3502defd254b03c486f2ed", "f8974b0157c0e1c960fd066191566f85b1d959f7a1a9ad42b0c6429e21d172d3", "fafc98fabade1f34d2fbf3058870372d92950dbe4bcc3d31614d855ee97a2e27", "738d686ddd2878a7976ec25bc84f2d481de957cc659bb738368257d85ffe0b4a", "677185e85caa0684d628d8c67b197856608ce746275cb581800ca5f8619dbf9f", "aeeaae74b491facceddd6c13a932cb8e43c87b8328de90c82bad2c1fb5555f1d", "b10ae0c5ccf7fd0e37e82022dc25b31ee986d1ae9058d3e86f78231a0c89680a", "dd46666b8249a6db30d9539803be982c1befa46b47ad18888edd9a5cbf6a33ec", "8e8f10cc772526f8527771558d585c54e2fc5f86f6a6ab9bd958badb9918e1eb", "679ffb737ad96acc255d6d560876dbb45c70701167c2ed2467e2487eeaf1f05c", "59f956e457e3000da5d3ab6c57d743a999936348d2a284bfe3b644e3c2ffb998", "b7e2f33339d96fde818016ce96ca688eaa27eb3749a70bd8fc4a516c7d299186", "7abb0c957faa4d62b3bce4b240fe09502332860c0886f505147cfca321115e9b", "998b06939b6fe26673f6a3f6ad253c947fed0978af4a26a9fe4d15f1593f3374", "574c362e643e04194b621a19b3e0727dadbb74b013e0d41cfcc98cc2c5d9289f", "f5a6f17c502d3721776a061cdaba9259a28f92123dd3371a6c03c605650e7247", "5b5f3c2b23a483fffc8e1c51b602a9b1502e40d350d59e799dd844a12c9dfd9b", "29cc057ecd905495a052c6ea2fa8f10ba73175d1b64fc90d34b341e91ab90ef8", "b699f6aee89199130c69055f8e85411dc176fcffb8b0f79c0f6b02eccd4a16d9", "2e679126f653ce9531e2ac6d4cee685c333d6a29ba425a62e32cb23768c10d27", "d88eb8432687c325147000aec8a5078b410a8f1ea72d893f970abaa7342a5121", "342a867edb1ec3c892a049c40837d4bf65ee600eafac9b92642a337f5934d910", "69c96a447f0999a41a4ee610215717076435f0f8531a0abd1064f8893c5e5305", "cc3d09e9ba51e348df4d2d8102ae08ff46d9e2b820e0e80269ce43058c53fdc2", "6fd579f0188c744a996e007f823721101c831e3707d72f3867e1796d25c62e59", "3e396a55df7ae61ad8d5bc55e45d6e6a286eca7025d15035779946502495c99a", ] class LoggingTLSServer(socketserver.ThreadingMixIn, http.server.HTTPServer): allow_reuse_address = True daemon_threads = True def __init__(self, server_address, RequestHandlerClass, ssl_context=None): super().__init__(server_address, RequestHandlerClass) self.ssl_context = ssl_context def get_request(self): newsocket, fromaddr = self.socket.accept() port = self.server_address[1] if self.ssl_context: try: newsocket = self.ssl_context.wrap_socket(newsocket, server_side=True) except Exception as e: print(f"[TLS ERROR on port {port} from {fromaddr[0]}] {e}") newsocket.close() raise return newsocket, fromaddr class MinionRushHandler(http.server.SimpleHTTPRequestHandler): def __init__(self, *args, **kwargs): super().__init__(*args, directory=str(WEB_ROOT), **kwargs) def _request_host_and_path(self): parsed = urlsplit(self.path) host = parsed.netloc or self.headers.get("Host", "") host = host.rsplit("@", 1)[-1].partition(":")[0].lower() return host, parsed.path, parsed.query def _send_json(self, payload, status=200): raw = json.dumps(payload).encode("utf-8") self.send_response(status) self.send_header("Content-Type", "application/json") self.send_header("Content-Length", str(len(raw))) self.end_headers() self.wfile.write(raw) def _send_text(self, text, status=200): raw = text.encode("utf-8") self.send_response(status) self.send_header("Content-Type", "text/plain; charset=utf-8") self.send_header("Content-Length", str(len(raw))) self.end_headers() self.wfile.write(raw) def translate_path(self, path): host, _, _ = self._request_host_and_path() translated = super().translate_path(urlsplit(path).path) if GAME_HOST_RE.fullmatch(host): relative_path = os.path.relpath(translated, WEB_ROOT) safe_relative = relative_path.replace(":", "_") base_target = WEB_ROOT / host / safe_relative if base_target.is_file(): return str(base_target) for ext in (".jpk", ".json"): candidate = Path(str(base_target) + ext) if candidate.is_file(): return str(candidate) downloaded_jpk = DOWNLOADED_DLC_DIR / (Path(safe_relative).name + ".jpk") if downloaded_jpk.is_file(): return str(downloaded_jpk) return str(base_target) return translated def guess_type(self, path): if Path(path).name.startswith(("mnhtn_metadata", "mnhtn_indeb")): return "application/json" return super().guess_type(path) def _handle_game_request(self, method): host, request_path, query_string = self._request_host_and_path() query_params = parse_qs(query_string) port = self.server.server_address[1] proto = "https" if port in (HTTPS_PORT, ALT_PORT) else "http" content_length = int(self.headers.get("Content-Length", 0)) body = self.rfile.read(content_length) if content_length > 0 else b"" print(f"\n[{method} :{port}] {proto}://{host}{self.path}") if body and not request_path.endswith("/connectionstatus"): print(f"[BODY] {body[:500]}") # 1. Datacenters if request_path.endswith("/datacenters"): self._send_json(DATACENTERS_JSON) return True # 2. MDC service URLs if request_path.endswith("/mdc/urls"): self._send_json(MDC_URLS_JSON) return True # 3. Gaia Global ID assignment if "/assign_global_id" in request_path: self._send_text("4550315047147196380") return True # 4. Connection status if request_path.endswith("/connectionstatus"): self._send_text("OK\n") return True # 5. Whitelisted / Banned services if "/whitelisted_services" in request_path: self._send_json(WHITELISTED_SERVICES_JSON) return True if "/banned_services" in request_path: self._send_json(BANNED_SERVICES_JSON) return True # 6. Pandora service locator (/locate/asset or ?service=asset vs others) if "/locate/asset" in request_path or query_params.get("service") == ["asset"]: self._send_text("v.mrur.duckdns.org:443") return True if "/locate" in request_path: self._send_text("mrur.duckdns.org:443") return True # 6b. Pandora OAuth /authorize if request_path.endswith("/authorize"): self._send_json( { "access_token": "local_mrur_access_token_1234567890", "token_type": "bearer", "expires_in": 86400, "scope": "auth config leaderboard_ro message social storage storage_ro", } ) return True # 6c. Profile / Device endpoints if request_path.endswith("/profiles/me/myprofile"): self._send_json({"id": "4550315047147196380", "alias": "Player"}) return True if request_path.endswith("/devices/mydevice"): self._send_json({"status": "ok"}) return True # 7. Ads agency if request_path.endswith("/un/index.hhh"): if query_params.get("op") == ["get_cache_ids"]: self._send_json({"action": "exit", "error": "There is no content available1"}) return True self._send_json( { "location_capping_reached": 0, "ad_type_available": "", "currency": "", "ts": 1795468958, } ) return True # 8. In-game news if request_path.endswith("/ingamenews.php"): self._send_json({"success": True, "current-id": 6536, "unread": 0}) return True # 9. Ad rewards claim if request_path.endswith("/ad_rewards/claim.php"): self._send_json( { "error": 0, "body": { "ad_rewards_status": { "ads_Tokens": 0, "ads_Revives": 0, "ads_CRM_EnergyRefillSeasonal": 0, "ads_CRM_DoubleBananasResult": 0, "ads_CRM_StoreIncentivizedReward": 0, "ads_Survey_Tokens": 0, "ads_Survey_Bananas": 0, "ads_CRM_Prop": 0, } }, } ) return True # 10. Graph activities if host.startswith("graph.") and request_path.endswith("/activities"): self._send_text("true") return True if ( GAME_HOST_RE.fullmatch(host) and request_path.startswith("/assets/") and request_path.endswith("/mnhtn_metadata_android") ): server_metadata_path = Path(self.translate_path(self.path)) downloaded_metadata_path = DOWNLOADED_DLC_DIR / "mnhtn_metadata_android" if not server_metadata_path.is_file() or not downloaded_metadata_path.is_file(): self.send_error(500, "Asset metadata is missing") return True payload = json.loads(server_metadata_path.read_text(encoding="utf-8")) downloaded_metadata = json.loads(downloaded_metadata_path.read_text(encoding="utf-8")) payload["index_asset_name"] = downloaded_metadata["index_asset_name"] self._send_json(payload) return True if request_path.endswith('/mnhtn_indeb_android'): self._send_text('mnhtn_metadata_android') return True # 10b. Fallback for missing game_object metadata if request_path.endswith("/game_object") and not Path(self.translate_path(self.path)).is_file(): self._send_json( { "federation_dc": "bob~gold", "save_path": "", "config": {}, "storage": {}, "ecomm_api_root": "https://gameloft.com", } ) return True # 11. Serve static file if present locally; 404 missing GETs, 200 OK for POSTs if GAME_HOST_RE.fullmatch(host): local_path = Path(self.translate_path(self.path)) if local_path.is_file(): return False if method == "GET": print(f"[MISSING ASSET 404] {local_path}") self.send_error(404, "File not found") return True self._send_json({"status": "success"}) return True return False def do_GET(self): if not self._handle_game_request("GET"): super().do_GET() def do_POST(self): if not self._handle_game_request("POST"): self._send_json({"status": "success"}) def make_ssl_context(): cert_file = SERVER_DIR / "cert.pem" key_file = SERVER_DIR / "key.pem" if not (cert_file.is_file() and key_file.is_file()): return None context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) context.load_cert_chain(certfile=str(cert_file), keyfile=str(key_file)) return context def start_server(port, ssl_context=None): httpd = LoggingTLSServer((IP_ADDRESS, port), MinionRushHandler, ssl_context=ssl_context) proto = "HTTPS" if ssl_context else "HTTP" print(f"{proto} listening on {proto.lower()}://{IP_ADDRESS}:{port}") httpd.serve_forever() if __name__ == "__main__": ctx = make_ssl_context() if ctx: threading.Thread(target=start_server, args=(HTTP_PORT, None), daemon=True).start() threading.Thread(target=start_server, args=(ALT_PORT, ctx), daemon=True).start() try: start_server(HTTPS_PORT, ctx) except KeyboardInterrupt: print("\nShutting down.") else: print("WARNING: cert.pem / key.pem not found; running HTTP only.") try: start_server(HTTP_PORT, None) except KeyboardInterrupt: print("\nShutting down.")