diff options
Diffstat (limited to 'tools/gateway.py')
| -rw-r--r-- | tools/gateway.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tools/gateway.py b/tools/gateway.py index 3129773..3b18024 100644 --- a/tools/gateway.py +++ b/tools/gateway.py @@ -46,6 +46,10 @@ def http_fetch(payload): def handle(payload, mode): if mode == "http": return http_fetch(payload) + if mode == "chat": + msg = bytes(payload).decode("latin1", "replace") + sys.stderr.write("\n[gw] GB says: %s\n" % msg) + return [("<bot> " + msg).encode()] # a simple echo-bot peer return [bytes(payload)] # echo def reader(out, inp, mode): @@ -75,15 +79,23 @@ def reader(out, inp, mode): def main(): ap = argparse.ArgumentParser() - ap.add_argument("--mode", default="echo", choices=["echo", "http"]) + ap.add_argument("--mode", default="echo", choices=["echo", "http", "chat"]) ap.add_argument("--cmd", default="necho") ap.add_argument("--rom", default=os.path.join(os.path.dirname(__file__), "..", "gbos.gb")) + ap.add_argument("--keys", default=None) a = ap.parse_args() - p = subprocess.Popen([EMU, "--headless", "--uncapped", a.rom], + cmd = [EMU, "--headless", "--uncapped"] + if a.keys: cmd += ["--keys", a.keys] + cmd.append(a.rom) + p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, bufsize=0) threading.Thread(target=reader, args=(p.stdout, p.stdin, a.mode), daemon=True).start() time.sleep(1.0) p.stdin.write((a.cmd + "\n").encode()); p.stdin.flush() + if a.mode == "chat": + time.sleep(1.0) + for m in [b"welcome to sl0pchat", b"<alice> hey gameboy!", b"<bob> nice link cable"]: + p.stdin.write(slip_encode(m)); p.stdin.flush(); time.sleep(0.6) time.sleep(4.0) p.stdin.write(b"exit\n"); p.stdin.flush() try: p.wait(timeout=3) |
