feat: publish sanitized Linux cloud-game MAA adapter
This commit is contained in:
Executable
+53
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Local deterministic backend used to smoke-test the ADB shim and MaaCore."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
|
||||
from aiohttp import web
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
LOG_FILE = Path(os.getenv("MAA_ONLINE_FAKE_LOG", Path(__file__).with_name("fake-actions.jsonl")))
|
||||
|
||||
|
||||
def make_frame() -> bytes:
|
||||
image = Image.new("RGB", (1280, 720), "#111827")
|
||||
draw = ImageDraw.Draw(image)
|
||||
draw.rectangle((100, 100, 1180, 620), outline="#60a5fa", width=4)
|
||||
draw.text((480, 340), "MAA ONLINE SMOKE TEST", fill="white")
|
||||
output = BytesIO()
|
||||
image.save(output, "PNG")
|
||||
return output.getvalue()
|
||||
|
||||
|
||||
FRAME = make_frame()
|
||||
|
||||
|
||||
async def record(request: web.Request) -> web.Response:
|
||||
payload = await request.json() if request.can_read_body else {}
|
||||
with LOG_FILE.open("a", encoding="utf-8") as handle:
|
||||
handle.write(json.dumps({"path": request.path, "payload": payload}) + "\n")
|
||||
return web.json_response({"status": "ok"})
|
||||
|
||||
|
||||
async def info(_: web.Request) -> web.Response:
|
||||
return web.json_response({"status": "ok", "width": 1280, "height": 720})
|
||||
|
||||
|
||||
async def screenshot(_: web.Request) -> web.Response:
|
||||
return web.Response(body=FRAME, content_type="image/png")
|
||||
|
||||
|
||||
app = web.Application()
|
||||
app.router.add_get("/info", info)
|
||||
app.router.add_get("/screencap", screenshot)
|
||||
for path in ("/start", "/exit", "/click", "/swipe", "/input"):
|
||||
app.router.add_post(path, record)
|
||||
|
||||
if __name__ == "__main__":
|
||||
LOG_FILE.unlink(missing_ok=True)
|
||||
web.run_app(app, host="127.0.0.1", port=22889)
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Load the official Linux MaaCore and connect through adb-cloud."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import ctypes
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(os.getenv("MAA_ONLINE_ROOT", Path(__file__).resolve().parents[1]))
|
||||
RUNTIME_HOME = Path(os.getenv("MAA_ONLINE_HOME", ROOT / "runtime/home"))
|
||||
LIB_DIR = RUNTIME_HOME / ".local/share/maa/lib"
|
||||
RESOURCE_DIR = RUNTIME_HOME / ".local/share/maa"
|
||||
USER_DIR = RUNTIME_HOME / ".local/state/maa"
|
||||
ADB = ROOT / "bin/adb-cloud"
|
||||
USER_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
os.environ["MAA_ONLINE_API"] = "http://127.0.0.1:22889"
|
||||
os.environ["LD_LIBRARY_PATH"] = str(LIB_DIR) + os.pathsep + os.environ.get("LD_LIBRARY_PATH", "")
|
||||
|
||||
lib = ctypes.CDLL(str(LIB_DIR / "libMaaCore.so"))
|
||||
lib.AsstSetUserDir.argtypes = [ctypes.c_char_p]
|
||||
lib.AsstSetUserDir.restype = ctypes.c_uint8
|
||||
lib.AsstLoadResource.argtypes = [ctypes.c_char_p]
|
||||
lib.AsstLoadResource.restype = ctypes.c_uint8
|
||||
lib.AsstCreate.argtypes = []
|
||||
lib.AsstCreate.restype = ctypes.c_void_p
|
||||
lib.AsstSetInstanceOption.argtypes = [ctypes.c_void_p, ctypes.c_int32, ctypes.c_char_p]
|
||||
lib.AsstSetInstanceOption.restype = ctypes.c_uint8
|
||||
lib.AsstConnect.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p]
|
||||
lib.AsstConnect.restype = ctypes.c_uint8
|
||||
lib.AsstConnected.argtypes = [ctypes.c_void_p]
|
||||
lib.AsstConnected.restype = ctypes.c_uint8
|
||||
lib.AsstDestroy.argtypes = [ctypes.c_void_p]
|
||||
|
||||
assert lib.AsstSetUserDir(os.fsencode(USER_DIR)), "AsstSetUserDir failed"
|
||||
assert lib.AsstLoadResource(os.fsencode(RESOURCE_DIR)), "AsstLoadResource failed"
|
||||
handle = lib.AsstCreate()
|
||||
assert handle, "AsstCreate failed"
|
||||
try:
|
||||
# AsstInstanceOptionKey::TouchMode = 2, value 'adb'.
|
||||
assert lib.AsstSetInstanceOption(handle, 2, b"adb"), "setting ADB touch mode failed"
|
||||
connected = lib.AsstConnect(
|
||||
handle,
|
||||
os.fsencode(ADB),
|
||||
b"cloud-game:22888",
|
||||
b"General",
|
||||
)
|
||||
assert connected, "MaaCore failed to connect through adb-cloud"
|
||||
assert lib.AsstConnected(handle), "MaaCore did not remain connected"
|
||||
finally:
|
||||
lib.AsstDestroy(handle)
|
||||
|
||||
print("MaaCore -> adb-cloud -> fake backend: PASS")
|
||||
Reference in New Issue
Block a user