Quake linux console support test 1
This commit is contained in:
parent
09d8099a2f
commit
18ebd785e2
1 changed files with 65 additions and 12 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import pty
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
|
@ -348,6 +349,30 @@ def change_mode():
|
||||||
send_command(pty_proc,f"echo _musicmode {current_mode}")
|
send_command(pty_proc,f"echo _musicmode {current_mode}")
|
||||||
playlist = load_playlist(playlist_path)
|
playlist = load_playlist(playlist_path)
|
||||||
|
|
||||||
|
def monitor_game_pty(master_fd):
|
||||||
|
buffer = b""
|
||||||
|
|
||||||
|
while not stop_flag.is_set():
|
||||||
|
try:
|
||||||
|
data = os.read(master_fd, 1024)
|
||||||
|
except OSError:
|
||||||
|
break
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
break
|
||||||
|
|
||||||
|
buffer += data
|
||||||
|
|
||||||
|
while b"\n" in buffer:
|
||||||
|
line, buffer = buffer.split(b"\n", 1)
|
||||||
|
line = strip_ansi(line.decode(errors="ignore")).strip()
|
||||||
|
if line:
|
||||||
|
if "--debug" in sys.argv:
|
||||||
|
print(f"[GAME] {line}", flush=True)
|
||||||
|
if "--rawdebug" in sys.argv:
|
||||||
|
print(f"[GAME RAW] {repr(line)}", flush=True)
|
||||||
|
handle_game_line(line, pty_proc)
|
||||||
|
|
||||||
def monitor_game(proc):
|
def monitor_game(proc):
|
||||||
#subprocess version
|
#subprocess version
|
||||||
global serverstatus_sent
|
global serverstatus_sent
|
||||||
|
|
@ -489,8 +514,11 @@ def handle_game_line(line, pty_proc):
|
||||||
def send_command(proc, cmd):
|
def send_command(proc, cmd):
|
||||||
#subprocess version
|
#subprocess version
|
||||||
try:
|
try:
|
||||||
|
if os.name == "nt":
|
||||||
proc.stdin.write((cmd + "\r\n").encode())
|
proc.stdin.write((cmd + "\r\n").encode())
|
||||||
proc.stdin.flush()
|
proc.stdin.flush()
|
||||||
|
else:
|
||||||
|
os.write(master_fd, (cmd + "\n").encode())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[DEBUG] Failed to send command: {e}")
|
print(f"[DEBUG] Failed to send command: {e}")
|
||||||
# ==========================================================
|
# ==========================================================
|
||||||
|
|
@ -523,19 +551,44 @@ def main():
|
||||||
watcher_thread = threading.Thread(target=track_watcher, daemon=True)
|
watcher_thread = threading.Thread(target=track_watcher, daemon=True)
|
||||||
watcher_thread.start()
|
watcher_thread.start()
|
||||||
|
|
||||||
# # Launch quake process via subprocess
|
# # # Launch quake process via subprocess
|
||||||
|
# pty_proc = subprocess.Popen(
|
||||||
|
# [game_exe, "+set", "ttycon", "1"] + sys.argv[1:],
|
||||||
|
# stdin=subprocess.PIPE,
|
||||||
|
# stdout=subprocess.PIPE,
|
||||||
|
# stderr=subprocess.STDOUT,
|
||||||
|
# bufsize=0, # unbuffered
|
||||||
|
# universal_newlines=False)
|
||||||
|
|
||||||
|
if os.name == "nt":
|
||||||
pty_proc = subprocess.Popen(
|
pty_proc = subprocess.Popen(
|
||||||
[game_exe, "+set", "ttycon", "1"] + sys.argv[1:],
|
[game_exe, "+set", "ttycon", "1"] + sys.argv[1:],
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
bufsize=0, # unbuffered
|
bufsize=0,
|
||||||
universal_newlines=False
|
universal_newlines=False
|
||||||
)
|
)
|
||||||
|
master_fd = None
|
||||||
|
else:
|
||||||
|
master_fd, slave_fd = pty.openpty()
|
||||||
|
|
||||||
|
pty_proc = subprocess.Popen(
|
||||||
|
[game_exe, "+set", "ttycon", "1"] + sys.argv[1:],
|
||||||
|
stdin=slave_fd,
|
||||||
|
stdout=slave_fd,
|
||||||
|
stderr=slave_fd,
|
||||||
|
close_fds=True
|
||||||
|
)
|
||||||
|
|
||||||
|
os.close(slave_fd)
|
||||||
|
|
||||||
# Monitor the game output
|
# Monitor the game output
|
||||||
try:
|
try:
|
||||||
|
if os.name == "nt":
|
||||||
monitor_game(pty_proc)
|
monitor_game(pty_proc)
|
||||||
|
else:
|
||||||
|
monitor_game_pty(master_fd)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("Exiting...")
|
print("Exiting...")
|
||||||
finally:
|
finally:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue