Files
pokerfreak/sicht/start.py
T
mmintel 9c79d8236b Acceptance 5.11.: channel play without AFK, quiet focus, working Cockpit, stronger play
- Practice tables: 20-min session 54/54 turns at the server, control session 28 turns,
  0 timeouts; stage: 3 tables, two rounds each, clean teardown.
- Never let the clock run: an engine abstention becomes check or fold (nie_verstreichen).
- Mittler join in a fixed order (kill the duplicate, then announce), a mittler ends with its
  game, the laufwache opens no tables, stop waits for the runner to stand up.
- Focus: no lobby connections from HUD, probes or layout; "Focus Window on Turn" off.
- Tables: disconnected or sitting-out opponents do not count; a table without channel is
  closed and avoided after 45 s; the join event keeps the writer's pid (strict invariants).
- Geldwache: same room list as the runner, the table's own report, stand up before closing.
- Engine: the small blind completes the top 65 % against limpers (price per fair share);
  the calling range of a bet is as wide as the villain calls - value bets into stations.
- Cockpit: the source tree never comes from SHELL; one operating set for laufwache and
  Cockpit (sicht/start.py --client, ServerStart).
- Project lives in ~/Projects/pokerfreak (kern was a detour).
2026-11-05 16:10:43 +01:00

92 lines
3.7 KiB
Python

#!/usr/bin/env python3
"""Startet die Datenschicht des Cockpits fuer die Mac-App (mac/, nur 127.0.0.1).
python3 sicht/start.py [--port 8787] Server (die App startet ihn selbst)
python3 sicht/start.py --uebernehmen ein laufendes Cockpit (App oder Terminal) abloesen
python3 sicht/start.py --client am Client: Log, Debug-Port und Betriebs-Satz des
Clients (umgebung.betrieb_am_client), auch fuer
den Laeufer, den es startet
Es laeuft hoechstens ein Cockpit (sicht/instanz.py): laeuft schon eines, startet dieses nicht
und endet mit Code 3.
Ohne --client zeigt es den Klon (die Vorgabe der Naht, client/umgebung.py). Es liest nur; der
Laeufer laeuft auch ohne. Strg-C beendet es sauber.
"""
import argparse
import os
import signal
import sys
import time
_h = os.path.dirname(os.path.abspath(__file__))
if _h not in sys.path:
sys.path.insert(0, _h)
_w = os.path.dirname(_h)
for _u in ("sicht", "lesen", "betrieb", "client"): # quellen/ansicht ziehen Hilfsmodule von dort
_p = os.path.join(_w, _u)
if os.path.isdir(_p) and _p not in sys.path:
sys.path.append(_p)
import umgebung # client/umgebung.py: die Naht (Vorgabe Klon, CLIENT=1/Log -> Client)
def umgebung_fuer(argv):
"""Was der Start am Client in die Umgebung legt: mit `--client` den Betriebs-Satz, sonst nichts.
Die Mac-App setzte dafuer `CLIENT=0` - das heisst an der Naht Klon (5.11.)."""
return umgebung.betrieb_am_client() if "--client" in argv else {}
# VOR allen anderen Modulen: manche lesen die Naht schon beim Import (hand/sitzen.DIALOG).
os.environ.update(umgebung_fuer(sys.argv[1:]))
import instanz # noqa: E402
import server # noqa: E402
import sperre # noqa: E402
def argumente(argv=None):
a = argparse.ArgumentParser(description=__doc__.split("\n")[0])
a.add_argument("--port", type=int, default=server.STANDARD_PORT)
a.add_argument("--uebernehmen", action="store_true", help="ein laufendes Cockpit beenden und abloesen")
a.add_argument("--art", default="Terminal", help="wer startet (die Mac-App sagt App)")
a.add_argument("--client", action="store_true", help="am Client statt am Klon (umgebung_fuer)")
return a.parse_args(argv)
def main(argv=None):
args = argumente(argv)
pfade = instanz.Pfade()
r = instanz.uebernehmen(pfade) if args.uebernehmen else sperre.nehmen(pfade.sperre)
if isinstance(r, sperre.Belegt):
print(instanz.belegt_zeile(pfade, r.besitzer), flush=True)
print("Es läuft schon ein Cockpit - mit --uebernehmen ablösen.", flush=True)
return instanz.BELEGT_CODE
# SIGTERM (die App beim Beenden, kill) wie Strg-C: sauber aufraeumen. SIGINT ausdruecklich
# setzen: mit & oder nohup gestartet ist es sonst ignoriert, und --uebernehmen liefe ins Leere.
signal.signal(signal.SIGINT, signal.default_int_handler)
signal.signal(signal.SIGTERM, lambda *_: (_ for _ in ()).throw(KeyboardInterrupt()))
c = server.Cockpit(args.port)
try:
port = c.starten()
except OSError as e:
instanz.aufraeumen(pfade)
print(f"Cockpit startet nicht: {e}", file=sys.stderr)
return 1
instanz.beschreiben(pfade, port=port, art=args.art)
modus = "Klon" if umgebung.klon() else "Client"
url = f"http://{server.HOST}:{port}"
print(f"Cockpit: {url} ({modus})", flush=True)
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("Cockpit beendet.")
finally:
c.beenden()
instanz.aufraeumen(pfade)
return 0
if __name__ == "__main__":
sys.exit(main())