Decrease logging
This commit is contained in:
@@ -56,6 +56,7 @@ var session_id : String = ""
|
|||||||
var state : Dictionary = {}
|
var state : Dictionary = {}
|
||||||
var opponent_name : String = ""
|
var opponent_name : String = ""
|
||||||
var is_spectating : bool = false
|
var is_spectating : bool = false
|
||||||
|
var debug_output : bool = false
|
||||||
var _state_version : int = -1
|
var _state_version : int = -1
|
||||||
|
|
||||||
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
||||||
@@ -91,10 +92,12 @@ func start_spectating(sid: String) -> void:
|
|||||||
Network.request("game.spectate",
|
Network.request("game.spectate",
|
||||||
{ "sessionId": sid },
|
{ "sessionId": sid },
|
||||||
func(_t: String, p: Variant) -> void:
|
func(_t: String, p: Variant) -> void:
|
||||||
print("[Game] <<< game.spectate.ack")
|
if debug_output:
|
||||||
|
print("[Game] <<< game.spectate.ack")
|
||||||
_apply_state_from_payload(p),
|
_apply_state_from_payload(p),
|
||||||
func(code: String, msg: String) -> void:
|
func(code: String, msg: String) -> void:
|
||||||
print("[Game] ERR spectate ", code, " ", msg)
|
if debug_output:
|
||||||
|
print("[Game] ERR spectate ", code, " ", msg)
|
||||||
is_spectating = false)
|
is_spectating = false)
|
||||||
|
|
||||||
|
|
||||||
@@ -234,11 +237,13 @@ func board_height() -> int:
|
|||||||
# ── Server actions ────────────────────────────────────────────────────────────
|
# ── Server actions ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
func send_ready() -> void:
|
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",
|
Network.request("game.ready",
|
||||||
{ "sessionId": session_id },
|
{ "sessionId": session_id },
|
||||||
func(_t: String, p: Variant) -> void:
|
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
|
var d := p as Dictionary
|
||||||
if d.get("status", "") == "AlreadyStarted":
|
if d.get("status", "") == "AlreadyStarted":
|
||||||
# Restore opponent name on rejoin — the server includes it in the ack.
|
# Restore opponent name on rejoin — the server includes it in the ack.
|
||||||
@@ -247,7 +252,8 @@ func send_ready() -> void:
|
|||||||
opponent_name = oname
|
opponent_name = oname
|
||||||
_fetch_state(),
|
_fetch_state(),
|
||||||
func(code: String, msg: String) -> void:
|
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:
|
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:
|
func _game_request(msg_type: String, extra: Dictionary) -> void:
|
||||||
var payload := { "sessionId": session_id }
|
var payload := { "sessionId": session_id }
|
||||||
payload.merge(extra)
|
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,
|
Network.request(msg_type, payload,
|
||||||
func(_t: String, p: Variant) -> void:
|
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),
|
_apply_state_from_payload(p),
|
||||||
func(code: String, msg: String) -> void:
|
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:
|
func _apply_state_from_payload(p: Variant) -> void:
|
||||||
var d := p as Dictionary
|
var d := p as Dictionary
|
||||||
var s := d.get("state", {}) as Dictionary
|
var s := d.get("state", {}) as Dictionary
|
||||||
if s.is_empty():
|
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
|
return
|
||||||
_state_version = int(s.get("stateVersion", -1))
|
_state_version = int(s.get("stateVersion", -1))
|
||||||
print("[Game] state applied phase=", s.get("phase","?"),
|
if debug_output:
|
||||||
" turn=", s.get("turnNumber","?"),
|
print("[Game] state applied phase=", s.get("phase","?"),
|
||||||
" ver=", _state_version,
|
" turn=", s.get("turnNumber","?"),
|
||||||
" activePlayer=", str(s.get("activePlayerAccountId","?")).substr(0,8))
|
" ver=", _state_version,
|
||||||
|
" activePlayer=", str(s.get("activePlayerAccountId","?")).substr(0,8))
|
||||||
state = s
|
state = s
|
||||||
state_updated.emit(state)
|
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).
|
## Request a full state resync from the server (e.g. from in-game settings, or auto on missed delta).
|
||||||
func request_sync() -> void:
|
func request_sync() -> void:
|
||||||
if session_id.is_empty(): return
|
if session_id.is_empty(): return
|
||||||
print("[Game] requesting full state sync")
|
if debug_output:
|
||||||
|
print("[Game] requesting full state sync")
|
||||||
_fetch_state()
|
_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"])
|
if meta.has("turnNumber") and meta["turnNumber"] != null: state["turnNumber"] = int(meta["turnNumber"])
|
||||||
|
|
||||||
_state_version = int(delta.get("stateVersion", _state_version))
|
_state_version = int(delta.get("stateVersion", _state_version))
|
||||||
print("[Game] delta applied ver=", _state_version,
|
if debug_output:
|
||||||
" phase=", state.get("phase","?"),
|
print("[Game] delta applied ver=", _state_version,
|
||||||
" turn=", state.get("turnNumber","?"))
|
" phase=", state.get("phase","?"),
|
||||||
|
" turn=", state.get("turnNumber","?"))
|
||||||
state_updated.emit(state)
|
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:
|
func _on_server_push(type: String, payload: Variant) -> void:
|
||||||
if type.begins_with("game.") or type.begins_with("matchmaking."):
|
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:
|
match type:
|
||||||
"matchmaking.match_found":
|
"matchmaking.match_found":
|
||||||
var d := payload as Dictionary
|
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
|
var s := d.get("state", {}) as Dictionary
|
||||||
if not s.is_empty():
|
if not s.is_empty():
|
||||||
_state_version = int(s.get("stateVersion", -1))
|
_state_version = int(s.get("stateVersion", -1))
|
||||||
print("[Game] PUSH state_update phase=", s.get("phase","?"),
|
if debug_output:
|
||||||
" turn=", s.get("turnNumber","?"),
|
print("[Game] PUSH state_update phase=", s.get("phase","?"),
|
||||||
" ver=", _state_version,
|
" turn=", s.get("turnNumber","?"),
|
||||||
" activePlayer=", str(s.get("activePlayerAccountId","?")).substr(0,8))
|
" ver=", _state_version,
|
||||||
|
" activePlayer=", str(s.get("activePlayerAccountId","?")).substr(0,8))
|
||||||
state = s
|
state = s
|
||||||
state_updated.emit(state)
|
state_updated.emit(state)
|
||||||
else:
|
else:
|
||||||
print("[Game] PUSH state_update: no 'state' key")
|
if debug_output:
|
||||||
|
print("[Game] PUSH state_update: no 'state' key")
|
||||||
|
|
||||||
"game.state_delta":
|
"game.state_delta":
|
||||||
var d := payload as Dictionary
|
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
|
# Already up to date — acting player received full state in ACK
|
||||||
return
|
return
|
||||||
if _state_version >= 0 and v > _state_version + 1:
|
if _state_version >= 0 and v > _state_version + 1:
|
||||||
print("[Game] WARN: missed delta (have %d, got %d) — requesting full sync" \
|
if debug_output:
|
||||||
% [_state_version, v])
|
print("[Game] WARN: missed delta (have %d, got %d) — requesting full sync" \
|
||||||
|
% [_state_version, v])
|
||||||
_fetch_state()
|
_fetch_state()
|
||||||
return
|
return
|
||||||
print("[Delta] ", delta)
|
print("[Delta] ", delta)
|
||||||
@@ -624,26 +641,30 @@ func _on_server_push(type: String, payload: Variant) -> void:
|
|||||||
"game.session_abandoned":
|
"game.session_abandoned":
|
||||||
var d := payload as Dictionary
|
var d := payload as Dictionary
|
||||||
var reason : String = str(d.get("reason", "unknown"))
|
var reason : String = str(d.get("reason", "unknown"))
|
||||||
print("[Game] session abandoned: ", reason)
|
if debug_output:
|
||||||
|
print("[Game] session abandoned: ", reason)
|
||||||
_clear_state()
|
_clear_state()
|
||||||
session_abandoned.emit(reason)
|
session_abandoned.emit(reason)
|
||||||
|
|
||||||
"game.opponent_inactive":
|
"game.opponent_inactive":
|
||||||
var d := payload as Dictionary
|
var d := payload as Dictionary
|
||||||
var sid : String = str(d.get("sessionId", ""))
|
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)
|
opponent_inactive.emit(sid)
|
||||||
|
|
||||||
"game.inactive_warning":
|
"game.inactive_warning":
|
||||||
var d := payload as Dictionary
|
var d := payload as Dictionary
|
||||||
var sid : String = str(d.get("sessionId", ""))
|
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)
|
inactive_warning.emit(sid)
|
||||||
|
|
||||||
"game.both_idle_warning":
|
"game.both_idle_warning":
|
||||||
var d := payload as Dictionary
|
var d := payload as Dictionary
|
||||||
var sid : String = str(d.get("sessionId", ""))
|
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)
|
both_idle_warning.emit(sid)
|
||||||
|
|
||||||
"game.player_eliminated":
|
"game.player_eliminated":
|
||||||
|
|||||||
Reference in New Issue
Block a user