367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
480 lines
28 KiB
Python
480 lines
28 KiB
Python
#!/usr/bin/env python3
|
|
"""Linux development launcher adapter; reuse verified native startup machinery.
|
|
|
|
Only bounded public status goes to stdout. Detailed diagnostics stay in a private
|
|
runtime log. This process never types, saves or transports a password, and does
|
|
not translate gameplay packets. The existing owner remains a runtime dependency.
|
|
"""
|
|
import argparse
|
|
from contextlib import redirect_stdout, redirect_stderr
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import select
|
|
import subprocess
|
|
import sys
|
|
import threading
|
|
import time
|
|
import re
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
PUBLIC = sys.stdout
|
|
|
|
|
|
def emit(phase, message, **fields):
|
|
try:
|
|
print(json.dumps(dict(schema=1, phase=phase, message=message, **fields)), file=PUBLIC, flush=True)
|
|
except (BrokenPipeError, OSError):
|
|
# The diagnostic owner and game must survive a closed launcher output.
|
|
pass
|
|
|
|
|
|
def choose_realm(account):
|
|
rows = account["realms"]
|
|
emit("realms", "Choose a real realm. Authentication is already verified; no password will be resent.",
|
|
realms=[dict(index=r["index"], name=r["name"], offline=bool(r["flags"] & 2)) for r in rows])
|
|
if not select.select([sys.stdin], [], [], 90)[0]:
|
|
raise RuntimeError("realm-choice-expired")
|
|
raw = sys.stdin.readline(257)
|
|
if len(raw) > 256:
|
|
raise ValueError("invalid-realm-choice")
|
|
choice = json.loads(raw)
|
|
if not isinstance(choice, dict) or set(choice) != {"realm_index"} or type(choice["realm_index"]) is not int:
|
|
raise ValueError("invalid-realm-choice")
|
|
return choice["realm_index"]
|
|
|
|
|
|
def select_pending_realm(controller, account, profile, *, preference_path=None, validator=None, chooser=None,
|
|
requested_index=None,expected_generation=None,expected_ui_request=None):
|
|
"""Choose from genuine discoveries, then revalidate immediately before RPC."""
|
|
import launcher_realm_preference as memory
|
|
if validator is None:
|
|
from native_manual_login import require_realm
|
|
validator = require_realm
|
|
path = preference_path or ROOT / "runtime/launcher-last-realm.json"
|
|
if account.get("state") != 5 or account.get("transport_prepared"):
|
|
raise ValueError("Pending realm selection expired or changed")
|
|
if expected_generation is not None and account.get('memory_credentials',{}).get('generation')!=expected_generation:
|
|
raise ValueError('Source UI authentication generation changed')
|
|
if requested_index is not None:
|
|
index=requested_index
|
|
else:
|
|
index = memory.matching_index(account, memory.read(path), profile, validator)
|
|
if index is None:
|
|
index = (chooser or choose_realm)(account)
|
|
wanted = memory.identity(profile, validator(account, index, profile))
|
|
# The authenticated list can change while a user answers the dialog.
|
|
fresh = controller.rpc("inspect-wire-account")
|
|
if fresh.get("state") != 5 or fresh.get("transport_prepared"):
|
|
raise ValueError("Pending realm selection expired or changed")
|
|
if expected_generation is not None and fresh.get('memory_credentials',{}).get('generation')!=expected_generation:
|
|
raise ValueError('Source UI authentication generation changed')
|
|
if expected_ui_request is not None:
|
|
ui=fresh.get('source_ui',{})
|
|
if not ui.get('available') or not ui.get('enabled') or ui.get('state')!=1 or ui.get('request')!=expected_ui_request:
|
|
raise ValueError('Source UI realm proposal changed')
|
|
index = memory.matching_index(fresh, wanted, profile, validator)
|
|
if index is None:
|
|
raise ValueError("Selected realm discovery changed or became unavailable")
|
|
validator(fresh, index, profile)
|
|
controller.rpc("select-native-realm", index=index)
|
|
return index
|
|
|
|
def consume_ui_realm_proposal(controller,account,profile,*,validator=None):
|
|
"""Delegate native UI intent to the existing genuine Source realm policy."""
|
|
ui=account.get('source_ui',{})
|
|
if not ui.get('available') or not ui.get('enabled') or ui.get('state')!=1:return None
|
|
request=ui.get('request');generation=ui.get('request_generation');index=ui.get('request_index')
|
|
if (type(request)is not int or not 0<request<1<<64 or type(generation)is not int or not 0<generation<1<<32 or
|
|
type(index)is not int or not 0<=index<64 or request!=((generation<<32)|(index+1))):
|
|
raise ValueError('Invalid owned Source UI realm proposal')
|
|
try:
|
|
chosen=select_pending_realm(controller,account,profile,validator=validator,requested_index=index,
|
|
expected_generation=generation,expected_ui_request=request)
|
|
except ValueError:
|
|
controller.rpc('resolve-native-ui-realm-request',request=request,error=-1)
|
|
emit('preparing','That realm choice is unavailable. Choose another realm in the game client.')
|
|
return None
|
|
controller.rpc('resolve-native-ui-realm-request',request=request,error=0)
|
|
return chosen
|
|
|
|
def wait_native_ui_realm(controller,account,profile,*,timeout=300,validator=None):
|
|
"""Wait in the authenticated attempt; no desktop prompt or auth replay."""
|
|
emit('preparing','Select an online realm in the game client.')
|
|
consume_ui_realm_proposal(controller,account,profile,validator=validator)
|
|
def observe():
|
|
fresh=controller.rpc('inspect-wire-account')
|
|
if fresh.get('state') not in (0,1,5):return fresh
|
|
ui=fresh.get('source_ui',{})
|
|
if not ui.get('available') or not ui.get('enabled'):
|
|
raise ValueError('Owned native realm UI became unavailable; authenticated client preserved')
|
|
if fresh.get('state')==5:consume_ui_realm_proposal(controller,fresh,profile,validator=validator)
|
|
return False
|
|
return controller.wait(observe,timeout)
|
|
|
|
|
|
def remember_verified_realm(account, profile, report, *, preference_path=None, validator=None):
|
|
"""Save only a proof-backed character or independently authenticated world success."""
|
|
import launcher_realm_preference as memory
|
|
basis = ("original-character-selection" if report.get("actual_character_selection_verified") is True
|
|
else "authenticated-native-world-transport" if report.get("authenticated_world_transport_verified") is True
|
|
else None)
|
|
if (basis is None or account.get("state") != 2 or account.get("transport_prepared") != 1):
|
|
return False
|
|
if validator is None:
|
|
from native_manual_login import require_realm
|
|
validator = require_realm
|
|
try:
|
|
row = validator(account, account["selected_index"], profile)
|
|
saved = memory.save(preference_path or ROOT / "runtime/launcher-last-realm.json",
|
|
memory.identity(profile, row))
|
|
if saved:
|
|
report["last_realm_success_basis"] = basis
|
|
return saved
|
|
except (KeyError, ValueError, TypeError):
|
|
return False
|
|
|
|
|
|
def readiness_diagnostics(report):
|
|
"""Export only readiness booleans; no account, realm, trace or exception data."""
|
|
names=('authenticated_transport_verified','source_roster_queued',
|
|
'native_character_consumer_verified','pipe_error','pipe_closed',
|
|
'readiness_deadline_reached')
|
|
source=report.get('post_login_readiness')
|
|
source=source if isinstance(source,dict) else {}
|
|
result={name:(source.get(name) if type(source.get(name)) is bool else None) for name in names}
|
|
for name in ('actual_character_selection_verified','authenticated_character_roster_available',
|
|
'authenticated_world_transport_verified','waiting_for_original_post_login_ui'):
|
|
result[name]=report.get(name) if type(report.get(name)) is bool else None
|
|
return result
|
|
|
|
|
|
def finish_native_client(identity,pipe=None,*,grace_seconds=30,observed_exit=None):
|
|
"""Factual exit classification from an actual exact-child wait receipt only."""
|
|
import native_client_lifecycle as lifecycle
|
|
result=observed_exit if observed_exit is not None else lifecycle.await_exit(ROOT,identity,timeout=grace_seconds)
|
|
if result.get('state')=='success':
|
|
try:diagnostics=lifecycle.save_outcome(ROOT,identity,result,pipe)
|
|
except (OSError,ValueError,TypeError,KeyError):
|
|
emit('blocked','The client exit was observed, but its diagnostic receipt could not be saved.',lifecycle_state='diagnostic-unavailable')
|
|
return 2
|
|
emit('closed','Client closed; diagnostics saved.',**diagnostics)
|
|
return 0
|
|
emit('blocked','The native connection ended without a verified successful client exit. Diagnostics preserved; no automatic credential retry.',
|
|
lifecycle_state=result.get('state','unknown'))
|
|
return 2
|
|
|
|
|
|
def manual_login_handoff(args,log,pid,controller,*,retirement_generation=None,resume_armed=False):
|
|
"""One fresh user submission; no automatic credential reuse or auth retry."""
|
|
if type(resume_armed)is not bool or (resume_armed and retirement_generation is not None):
|
|
raise ValueError('Existing armed observer cannot be combined with retirement')
|
|
from native_manual_login import run
|
|
report = {"actual_character_selection_verified": False}
|
|
if retirement_generation is not None:report["retirement_generation"] = retirement_generation
|
|
account = None
|
|
# Existing function arms the validated original Login boundary and
|
|
# releases input immediately. It never automatically submits a login.
|
|
emit("preparing", "Preparing the original account/password form. Wait for the Login-ready message.")
|
|
# run() changes this public phase only after the original Login callback
|
|
# has been observed. No account fields, trace contents or RPCs are read
|
|
# by this observer; it only dismisses the ready panel after submission.
|
|
stop = threading.Event()
|
|
observer = threading.Thread(target=observe_authentication, args=(report, stop), daemon=True)
|
|
stream = sys.stdout
|
|
if isinstance(stream, StatusLog):
|
|
stream.report = report;stream.ready_sent = False
|
|
observer.start()
|
|
try:
|
|
status = run(argparse.Namespace(resume=None, resume_armed=resume_armed, endpoint_profile=args.endpoint_profile, arm=not resume_armed,
|
|
manual_wait_seconds=305, continuous_manual_wait=True,background_manual_arm=True, observe_character_ui=False, post_login_wait_seconds=300,
|
|
retirement_generation=retirement_generation,
|
|
source_realm_ui_readiness=getattr(args,'source_realm_ui_readiness',None),
|
|
readiness_progress=lambda message: emit("preparing", message)), report)
|
|
finally:
|
|
stop.set();observer.join(timeout=1)
|
|
if isinstance(stream, StatusLog):stream.report = None
|
|
return finish_authenticated_handoff(args,controller,pid,report,status,account)
|
|
|
|
|
|
def finish_authenticated_handoff(args,controller,pid,report,status,account=None):
|
|
"""Continue a genuine pending choice without submitting credentials again."""
|
|
from native_manual_login import character_selection
|
|
if report.get("phase") == "realm-selection-required":
|
|
if account is None:
|
|
account = controller.rpc("inspect-wire-account")
|
|
from native_realm_contract import require_genuine
|
|
require_genuine(account)
|
|
if account.get('source_ui',{}).get('available') and account['source_ui'].get('enabled'):
|
|
account=wait_native_ui_realm(controller,account,args.endpoint_profile)
|
|
else:
|
|
select_pending_realm(controller, account, args.endpoint_profile)
|
|
account = controller.wait(lambda: (r if (r := controller.rpc("inspect-wire-account"))["state"] not in (0, 1, 5) else False), 20)
|
|
status = character_selection(controller, pid, account, args.endpoint_profile, report,
|
|
progress=lambda message: emit("preparing", message), observe_ui=False, readiness_timeout=300)
|
|
if status != 0 or not (report.get("actual_character_selection_verified") is True
|
|
or report.get("authenticated_world_transport_verified") is True
|
|
or report.get("authenticated_character_roster_available") is True):
|
|
emit("blocked", "Native character readiness was not verified within the bounded wait. Client preserved; no automatic retry.",
|
|
readiness=readiness_diagnostics(report))
|
|
return None
|
|
realm_remembered = remember_verified_realm(account if account is not None else report["account"],
|
|
args.endpoint_profile, report)
|
|
if report.get("actual_character_selection_verified") is True:
|
|
emit("characters", "Native character selection is ready. Select your character and enter the world in Forever.")
|
|
elif report.get("authenticated_world_transport_verified") is True:
|
|
emit("preparing", "Authenticated world transport verified. Finishing the existing native gameplay route.")
|
|
else:
|
|
emit("preparing", "Server character roster received. Finish any original experience preset and enter the world in Forever.")
|
|
return report,account if account is not None else report['account'],realm_remembered
|
|
|
|
|
|
class ManualLoginRestartRequired(RuntimeError):
|
|
"""A preserved native reset barrier requires ordinary client shutdown."""
|
|
|
|
|
|
def retire_for_manual_login(args,pid,controller,pipe):
|
|
"""Two explicit Login presses; the first observes intent without input copy."""
|
|
from launcher_account_generation import closed_receipt,save_closed_receipt,require_retirement_ack
|
|
from native_manual_login import read_trace
|
|
account=controller.rpc('inspect-wire-account')
|
|
receipt=closed_receipt(pid,pipe,account)
|
|
save_closed_receipt(ROOT,receipt) # Preserve real errors BEFORE requesting cleanup.
|
|
controller.wait(lambda:(row if(row:=controller.rpc('inspect-wire-account')).get('state')in(3,4)else False),5)
|
|
published=time.time();trace_path=ROOT/'runtime/original-relogin-intent.json'
|
|
controller.rpc('observe-original-relogin-intent',profile=args.endpoint_profile,arm_seconds=300)
|
|
controller.wait(lambda:(row if(row:=read_trace(trace_path,pid,published))and row.get('status')=='hardware-breakpoint-armed'else False),5)
|
|
print(json.dumps(dict(kind='manual-login-transition',phase='reset-intent-listening',pid=pid)),flush=True)
|
|
emit('preparing',"Listening for a session reset request. Enter your account and password in Forever and press Log In once. Wait for 'Fresh login ready' before the next login press.",manual_login_stage='switch-intent')
|
|
trace=controller.wait(lambda:(row if(row:=read_trace(trace_path,pid,published))and row.get('status')!='hardware-breakpoint-armed'else False),305)
|
|
facts=trace.get('metadata',{})
|
|
if(trace.get('status')!='real-callback-observed-only'or trace.get('hardware_registers_restored')is not True or
|
|
facts.get('kind')!='fresh-observed-original-login-intent'or
|
|
any(facts.get(key)is not False for key in ('credential_bytes_read','credential_descriptors_read','authentication_attempted','native_state_written'))):
|
|
raise ValueError('Fresh credential-free Login intent was not verified')
|
|
emit('preparing','The original Login intent was observed. Clearing only the disconnected previous session; no authentication was attempted.')
|
|
request=controller.rpc('request-native-session-retirement')
|
|
ack=controller.wait(lambda:(row if(row:=controller.rpc('inspect-native-session-retirement')).get('state')in(2,3)else False),10)
|
|
if ack.get('state')==3 and ack.get('result')==-12:
|
|
print(json.dumps(dict(kind='manual-login-transition',phase='blocked',
|
|
reason='original-primary-pipe-present',pid=pid,
|
|
retirement_state=ack['state'],retirement_result=ack['result'])),flush=True)
|
|
raise ManualLoginRestartRequired('normal-client-restart-required')
|
|
generation=require_retirement_ack(request,ack)
|
|
finalized=controller.rpc('finalize-native-session-retirement')
|
|
if(require_retirement_ack(request,finalized)!=generation or finalized.get('ready_for_fresh_original_login')is not True):
|
|
raise ValueError('Fresh manual Login generation is not acknowledged')
|
|
print(json.dumps(dict(kind='manual-login-transition',phase='reset-finalized',pid=pid,retirement_generation=generation)),flush=True)
|
|
return generation
|
|
|
|
|
|
def supervise(args, log):
|
|
from native_engine_character_test import Controller
|
|
from native_manual_login import run, character_selection, require_realm, binding_for, authenticated_world_ready
|
|
from native_world_entry_test import enable_gameplay
|
|
|
|
import native_client_lifecycle as lifecycle
|
|
existing_pid=getattr(args,"existing_client_pid",None)
|
|
lifecycle_identity=None
|
|
if existing_pid is not None:
|
|
if type(existing_pid)is not int or existing_pid<=0 or int((ROOT/"runtime/native-client.pid").read_text())!=existing_pid:
|
|
raise ValueError("Existing client PID differs; no client started")
|
|
lifecycle_identity=lifecycle.read_launch(ROOT,existing_pid)
|
|
if lifecycle_identity is None:raise ValueError("Existing owned client lifetime differs; no client started")
|
|
pid=existing_pid
|
|
emit("host","Reusing this owned client only. No client launch or credential submission.")
|
|
else:
|
|
emit("starting", "Checking the private client and starting its native compatibility host.")
|
|
command = [sys.executable, "-u", str(ROOT / "ops/start_native_client.py"),
|
|
"--endpoint-profile", "octo" if args.endpoint_profile == "octo" else "local",
|
|
"--background-manual-arm"]
|
|
if args.character_guid is not None:
|
|
command += ["--character-guid", str(args.character_guid)]
|
|
subprocess.run(command, cwd=ROOT, check=True, timeout=90, stdout=log, stderr=log)
|
|
emit("host", "The client compatibility host started. Preparing the original Login handoff.")
|
|
pid = int((ROOT / "runtime/native-client.pid").read_text())
|
|
lifecycle_identity=lifecycle.read_launch(ROOT,pid)
|
|
controller = Controller(pid)
|
|
report = {"actual_character_selection_verified": False}
|
|
realm_remembered = False
|
|
binding_path = ROOT / "runtime/engine-poll-binding.json"
|
|
if getattr(args,'resume_armed',False):
|
|
if existing_pid is None:raise ValueError('An existing owned client is required for an armed observer')
|
|
result=manual_login_handoff(args,log,pid,controller,resume_armed=True)
|
|
if result is None:return 2
|
|
report,account,realm_remembered=result
|
|
elif binding_path.exists():
|
|
binding = json.loads(binding_path.read_text())
|
|
if binding.get("pid") == pid and not binding.get("restored") and not binding.get("wire_ping_only"):
|
|
# Play must not re-arm credentials in an authenticated session.
|
|
binding_for(pid, args.endpoint_profile)
|
|
account = controller.rpc("inspect-wire-account")
|
|
if account.get("state") == 0 and existing_pid is not None:
|
|
# The continuation verifies the original observer is still armed;
|
|
# it never arms or submits a second login on this path.
|
|
result = manual_login_handoff(args,log,pid,controller,resume_armed=True)
|
|
if result is None:return 2
|
|
report,account,realm_remembered=result
|
|
elif account.get("state") == 5:
|
|
report["phase"] = "realm-selection-required"
|
|
result = finish_authenticated_handoff(args,controller,pid,report,0,account)
|
|
if result is None:return 2
|
|
report,account,realm_remembered=result
|
|
else:
|
|
require_realm(account, account["selected_index"], args.endpoint_profile)
|
|
emit("characters", "Reusing the existing authenticated client; no login request was sent.")
|
|
else:
|
|
account = None
|
|
else:
|
|
account = None
|
|
if account is None:
|
|
result=manual_login_handoff(args,log,pid,controller)
|
|
if result is None:return 2
|
|
report,account,realm_remembered=result
|
|
from launcher_trace_journal import TraceJournal
|
|
journal = TraceJournal.from_release(ROOT, pid, log=log)
|
|
last_pipe=None
|
|
try:
|
|
enabled = False
|
|
while (Path("/proc") / str(pid)).exists():
|
|
try:
|
|
pipe = controller.rpc("inspect-engine-pipe")
|
|
last_pipe=pipe
|
|
journal.sample(pipe)
|
|
except (OSError, RuntimeError):
|
|
if not (Path("/proc") / str(pid)).exists():
|
|
break
|
|
raise
|
|
if pipe.get("error") or pipe.get("closed"):
|
|
# A socket close can coincide with a real client exit. Give the
|
|
# original owner a short window to publish its exact waitpid
|
|
# receipt before treating a still-present PID as a relogin.
|
|
if pipe.get('closed') and lifecycle_identity is not None:
|
|
exit_result=lifecycle.await_exit(ROOT,lifecycle_identity,timeout=.5)
|
|
if exit_result.get('state') in ('success','abnormal'):
|
|
return finish_native_client(lifecycle_identity,pipe,observed_exit=exit_result)
|
|
# Every prior error remains in its private receipt. Cleanup
|
|
# follows only a NEW explicit original Login intent and a real
|
|
# native acknowledgment; no credentials are retried or reused.
|
|
if pipe.get('closed')and(Path('/proc')/str(pid)).exists():
|
|
emit('preparing','The previous connection ended. Its diagnostics are preserved; another account requires a fresh manual Login.')
|
|
try:
|
|
generation=retire_for_manual_login(args,pid,controller,pipe)
|
|
result=manual_login_handoff(args,log,pid,controller,retirement_generation=generation)
|
|
if result is None:return 2
|
|
report,account,realm_remembered=result
|
|
enabled=False
|
|
journal.close();journal=TraceJournal.from_release(ROOT,pid,log=log)
|
|
continue
|
|
except ManualLoginRestartRequired:
|
|
emit('blocked','A normal client restart is required to clear the previous connection. Close this client normally and restart it before logging in again. Disconnect diagnostics were saved.')
|
|
return 2
|
|
except (OSError,ValueError,RuntimeError) as error:
|
|
print(json.dumps(dict(kind='manual-login-transition',phase='blocked',
|
|
reason='retirement-or-fresh-login-unverified',pid=pid,
|
|
failure_type=type(error).__name__)),flush=True)
|
|
emit('blocked','Account switching was not verified. Existing client and disconnect diagnostics preserved; no authentication retry.')
|
|
return 2
|
|
emit('preparing','The connection ended. Waiting briefly for the owned client exit; diagnostics are retained.')
|
|
return finish_native_client(lifecycle_identity,pipe)
|
|
world = pipe.get("world", {})
|
|
if not enabled and pipe.get("world_auth") and world.get("login_sent") == 1 and world.get("self_create"):
|
|
# Self-create can arrive while the main thread is still loading.
|
|
# Publish only once, then observe its real safepoint, not an eight-
|
|
# second world-already-ready test deadline. Never resend on expiry.
|
|
binding_for(pid, args.endpoint_profile)
|
|
current_account = controller.rpc("inspect-wire-account")
|
|
require_realm(current_account, current_account["selected_index"], args.endpoint_profile)
|
|
if not authenticated_world_ready(current_account, args.endpoint_profile, pipe):
|
|
raise ValueError("Authenticated world transport changed before gameplay enablement")
|
|
enable_gameplay(controller, timeout=90)
|
|
enabled = True
|
|
report["authenticated_world_transport_verified"] = True
|
|
if not realm_remembered:
|
|
realm_remembered = remember_verified_realm(current_account, args.endpoint_profile, report)
|
|
emit("world", "Authenticated world and native gameplay route are ready. Gameplay remains inside the client.")
|
|
time.sleep(.5)
|
|
finally:
|
|
journal.close()
|
|
return finish_native_client(lifecycle_identity,last_pipe)
|
|
|
|
|
|
def observe_authentication(report, stop):
|
|
while not stop.wait(.1):
|
|
if report.get("phase") == "awaiting-genuine-srp-and-realms":
|
|
emit("authenticating", "Your original Login submission was observed. Waiting for server authentication.")
|
|
return
|
|
|
|
|
|
class StatusLog:
|
|
"""Forward only a known readiness message, never raw RPC/exception output."""
|
|
def __init__(self, log, report=None):
|
|
self.log, self.pending, self.report = log, "", report
|
|
self.ready_sent = False
|
|
|
|
def write(self, text):
|
|
self.log.write(text)
|
|
self.pending = (self.pending + text)[-4096:]
|
|
while "\n" in self.pending:
|
|
line, self.pending = self.pending.split("\n", 1)
|
|
if (not self.ready_sent and self.report is not None
|
|
and self.report.get("phase") == "awaiting-user-login"
|
|
and self.report.get("authentication_armed") is True
|
|
and re.fullmatch(r"Original Login is armed for (?:octo|local-explicit)\. Enter your account and password yourself in the existing game form, then press Enter once\. No automatic submission or retry\.", line)):
|
|
self.ready_sent = True
|
|
if self.report.get('retirement_generation')is not None:
|
|
emit('login','Fresh login ready. The previous session was cleared. Re-enter the account and password in Forever, then press Log In once.',manual_login_stage='switch-capture')
|
|
else:
|
|
emit("login", "Login ready. Enter your account and password in Forever, then press Enter once.")
|
|
return len(text)
|
|
|
|
def flush(self):
|
|
self.log.flush()
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--endpoint-profile", choices=("local-explicit", "octo"), required=True)
|
|
parser.add_argument("--character-guid", type=int)
|
|
parser.add_argument("--existing-client-pid",type=int,help="Reuse only this owned live client; never launch a client")
|
|
parser.add_argument("--resume-armed",action="store_true",help="Continue an existing owned original Login observer without re-arming")
|
|
parser.add_argument("--source-realm-ui-readiness",type=Path,help="Explicit installed Source realm UI pair readiness receipt")
|
|
parser.add_argument("--source-realm-ui-readiness-sha256",help="Pinned SHA256 of that readiness receipt")
|
|
args = parser.parse_args()
|
|
if args.resume_armed and args.existing_client_pid is None:
|
|
parser.error('--resume-armed requires --existing-client-pid')
|
|
if bool(args.source_realm_ui_readiness)!=bool(args.source_realm_ui_readiness_sha256):
|
|
parser.error('Source realm UI activation requires both readiness path and SHA256')
|
|
args.source_realm_ui_readiness=(dict(path=str(args.source_realm_ui_readiness),sha256=args.source_realm_ui_readiness_sha256)
|
|
if args.source_realm_ui_readiness is not None else None)
|
|
os.umask(0o077)
|
|
# Startup readiness and the original manual form need no virtual keyboard
|
|
# device. Use the existing X11 backend without requiring /dev/uinput access.
|
|
os.environ.setdefault("GW_CLIENT_INPUT", "x11")
|
|
runtime = ROOT / "runtime"
|
|
lock = runtime / "launcher-session.lock"
|
|
# flock releases on exit and never removes another session's lock file.
|
|
import fcntl
|
|
with lock.open("a") as guard:
|
|
try:
|
|
fcntl.flock(guard, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
except BlockingIOError:
|
|
emit("blocked", "A launcher already supervises this installation. Existing client preserved.")
|
|
return 2
|
|
log_path = runtime / ("launcher-" + str(time.time_ns()) + ".log")
|
|
with log_path.open("x", encoding="utf-8", buffering=1) as log:
|
|
log_path.chmod(0o600)
|
|
try:
|
|
with redirect_stdout(StatusLog(log)), redirect_stderr(log):
|
|
return supervise(args, log)
|
|
except Exception as error:
|
|
# Detailed exception belongs only in the private local log.
|
|
import traceback
|
|
traceback.print_exc(file=log)
|
|
emit("error", "Startup stopped safely (" + type(error).__name__ + "). See " + log_path.name + "; client and owner preserved.")
|
|
return 2
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|