Decrease logging

This commit is contained in:
dingo
2026-04-14 09:18:15 -04:00
parent e204cdf74e
commit 5136a16fc0
+50 -29
View File
@@ -56,6 +56,7 @@ var session_id : String = ""
var state : Dictionary = {}
var opponent_name : String = ""
var is_spectating : bool = false
var debug_output : bool = false
var _state_version : int = -1
# ── Lifecycle ─────────────────────────────────────────────────────────────────
@@ -91,10 +92,12 @@ func start_spectating(sid: String) -> void:
Network.request("game.spectate",
{ "sessionId": sid },
func(_t: String, p: Variant) -> void:
print("[Game] <<< game.spectate.ack")
if debug_output:
print("[Game] <<< game.spectate.ack")
_apply_state_from_payload(p),
func(code: String, msg: String) -> void:
print("[Game] ERR spectate ", code, " ", msg)
if debug_output:
print("[Game] ERR spectate ", code, " ", msg)
is_spectating = false)
@@ -234,11 +237,13 @@ func board_height() -> int:
# ── Server actions ────────────────────────────────────────────────────────────
func send_ready() -> void:
print("[Game] >>> game.ready sessionId=", session_id)
if debug_output:
print("[Game] >>> game.ready sessionId=", session_id)
Network.request("game.ready",
{ "sessionId": session_id },
func(_t: String, p: Variant) -> void:
print("[Game] <<< game.ready.ack ", JSON.stringify(p))
if debug_output:
print("[Game] <<< game.ready.ack ", JSON.stringify(p))
var d := p as Dictionary
if d.get("status", "") == "AlreadyStarted":
# Restore opponent name on rejoin — the server includes it in the ack.
@@ -247,7 +252,8 @@ func send_ready() -> void:
opponent_name = oname
_fetch_state(),
func(code: String, msg: String) -> void:
print("[Game] ERR game.ready code=", code, " msg=", msg))
if debug_output:
print("[Game] ERR game.ready code=", code, " msg=", msg))
func _fetch_state() -> void:
@@ -349,26 +355,31 @@ func send_triggered_target_response(request_id: String, targets: Array) -> void:
func _game_request(msg_type: String, extra: Dictionary) -> void:
var payload := { "sessionId": session_id }
payload.merge(extra)
print("[Game] >>> ", msg_type, " ", JSON.stringify(extra))
if debug_output:
print("[Game] >>> ", msg_type, " ", JSON.stringify(extra))
Network.request(msg_type, payload,
func(_t: String, p: Variant) -> void:
print("[Game] <<< ", msg_type, ".ack payload=", JSON.stringify(p))
if debug_output:
print("[Game] <<< ", msg_type, ".ack payload=", JSON.stringify(p))
_apply_state_from_payload(p),
func(code: String, msg: String) -> void:
print("[Game] ERR ", msg_type, " code=", code, " msg=", msg))
if debug_output:
print("[Game] ERR ", msg_type, " code=", code, " msg=", msg))
func _apply_state_from_payload(p: Variant) -> void:
var d := p as Dictionary
var s := d.get("state", {}) as Dictionary
if s.is_empty():
print("[Game] _apply_state_from_payload: no 'state' key in payload ", JSON.stringify(p))
if debug_output:
print("[Game] _apply_state_from_payload: no 'state' key in payload ", JSON.stringify(p))
return
_state_version = int(s.get("stateVersion", -1))
print("[Game] state applied phase=", s.get("phase","?"),
" turn=", s.get("turnNumber","?"),
" ver=", _state_version,
" activePlayer=", str(s.get("activePlayerAccountId","?")).substr(0,8))
if debug_output:
print("[Game] state applied phase=", s.get("phase","?"),
" turn=", s.get("turnNumber","?"),
" ver=", _state_version,
" activePlayer=", str(s.get("activePlayerAccountId","?")).substr(0,8))
state = s
state_updated.emit(state)
@@ -376,7 +387,8 @@ func _apply_state_from_payload(p: Variant) -> void:
## Request a full state resync from the server (e.g. from in-game settings, or auto on missed delta).
func request_sync() -> void:
if session_id.is_empty(): return
print("[Game] requesting full state sync")
if debug_output:
print("[Game] requesting full state sync")
_fetch_state()
@@ -539,9 +551,10 @@ func _apply_delta(delta: Dictionary) -> void:
if meta.has("turnNumber") and meta["turnNumber"] != null: state["turnNumber"] = int(meta["turnNumber"])
_state_version = int(delta.get("stateVersion", _state_version))
print("[Game] delta applied ver=", _state_version,
" phase=", state.get("phase","?"),
" turn=", state.get("turnNumber","?"))
if debug_output:
print("[Game] delta applied ver=", _state_version,
" phase=", state.get("phase","?"),
" turn=", state.get("turnNumber","?"))
state_updated.emit(state)
@@ -567,7 +580,8 @@ func _merge_unit_delta(unit: Dictionary, ud: Dictionary) -> void:
func _on_server_push(type: String, payload: Variant) -> void:
if type.begins_with("game.") or type.begins_with("matchmaking."):
print("[Game] PUSH ", type, " ", JSON.stringify(payload).substr(0, 800))
if debug_output:
print("[Game] PUSH ", type, " ", JSON.stringify(payload).substr(0, 800))
match type:
"matchmaking.match_found":
var d := payload as Dictionary
@@ -584,14 +598,16 @@ func _on_server_push(type: String, payload: Variant) -> void:
var s := d.get("state", {}) as Dictionary
if not s.is_empty():
_state_version = int(s.get("stateVersion", -1))
print("[Game] PUSH state_update phase=", s.get("phase","?"),
" turn=", s.get("turnNumber","?"),
" ver=", _state_version,
" activePlayer=", str(s.get("activePlayerAccountId","?")).substr(0,8))
if debug_output:
print("[Game] PUSH state_update phase=", s.get("phase","?"),
" turn=", s.get("turnNumber","?"),
" ver=", _state_version,
" activePlayer=", str(s.get("activePlayerAccountId","?")).substr(0,8))
state = s
state_updated.emit(state)
else:
print("[Game] PUSH state_update: no 'state' key")
if debug_output:
print("[Game] PUSH state_update: no 'state' key")
"game.state_delta":
var d := payload as Dictionary
@@ -602,8 +618,9 @@ func _on_server_push(type: String, payload: Variant) -> void:
# Already up to date — acting player received full state in ACK
return
if _state_version >= 0 and v > _state_version + 1:
print("[Game] WARN: missed delta (have %d, got %d) — requesting full sync" \
% [_state_version, v])
if debug_output:
print("[Game] WARN: missed delta (have %d, got %d) — requesting full sync" \
% [_state_version, v])
_fetch_state()
return
print("[Delta] ", delta)
@@ -624,26 +641,30 @@ func _on_server_push(type: String, payload: Variant) -> void:
"game.session_abandoned":
var d := payload as Dictionary
var reason : String = str(d.get("reason", "unknown"))
print("[Game] session abandoned: ", reason)
if debug_output:
print("[Game] session abandoned: ", reason)
_clear_state()
session_abandoned.emit(reason)
"game.opponent_inactive":
var d := payload as Dictionary
var sid : String = str(d.get("sessionId", ""))
print("[Game] PUSH opponent_inactive session=", sid)
if debug_output:
print("[Game] PUSH opponent_inactive session=", sid)
opponent_inactive.emit(sid)
"game.inactive_warning":
var d := payload as Dictionary
var sid : String = str(d.get("sessionId", ""))
print("[Game] PUSH inactive_warning session=", sid)
if debug_output:
print("[Game] PUSH inactive_warning session=", sid)
inactive_warning.emit(sid)
"game.both_idle_warning":
var d := payload as Dictionary
var sid : String = str(d.get("sessionId", ""))
print("[Game] PUSH both_idle_warning session=", sid)
if debug_output:
print("[Game] PUSH both_idle_warning session=", sid)
both_idle_warning.emit(sid)
"game.player_eliminated":