From 09e500f0c1cacc8142bbaba0f801bfcfb082ec18 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Thu, 8 Feb 2024 18:55:25 -0500 Subject: logging + ack check --- racing/lobby.gd | 17 ++++++++++++++++- racing/manager.gd | 2 ++ racing/multiplayer.gd | 11 +++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) (limited to 'racing') diff --git a/racing/lobby.gd b/racing/lobby.gd index 94fe993..374fc07 100644 --- a/racing/lobby.gd +++ b/racing/lobby.gd @@ -15,7 +15,7 @@ const MAX_PLAYERS = 250 const PROTOCOL_VERSION = 2 const RECIPIENT_BROADCAST_ALL = -1 const LOBBY_MAP_NAME = "ll1_racing" -const VERSION = "0.0.3" +const VERSION = "0.0.4" const LL1_AREAS = [ ["Starting Room", 0, 0, 0], @@ -73,6 +73,7 @@ const LL1_AREAS = [ func _ready(): + global._print("Starting Lobby") installScriptExtension(ResourceLoader.load("user://maps/racing/load.gd")) # P2P solve messages should still be received while paused. @@ -128,6 +129,7 @@ func _process(_delta: float) -> void: func _exit_tree(): if active_lobby_id != 0 and !is_starting: + global._print("Lobby Exit Tree") Steam.leaveLobby(active_lobby_id) active_lobby_id = 0 @@ -145,6 +147,7 @@ func _resend_messages_needing_ack(): for message_id in messages_needing_ack: var message = messages_needing_ack[message_id] if message["recipient_id"] in active_lobby_members: + global._print("Resending Packet") _send_p2p_packet(message["data"], message["recipient_id"], message["mode"], true) else: messages_needing_ack.erase(message_id) @@ -177,8 +180,10 @@ func _on_lobby_match_list(lobbies: Array) -> void: best_lobby_id = lobby_id best_lobby_size = lobby_size if best_lobby_id == 0: + global._print("Creating Lobby") Steam.createLobby(Steam.LOBBY_TYPE_INVISIBLE, MAX_PLAYERS) elif best_lobby_id != active_lobby_id: + global._print("Joining Lobby %d" % best_lobby_id) Steam.joinLobby(best_lobby_id) elif best_lobby_size <= 1: _request_lobby_list() @@ -198,6 +203,7 @@ func _on_lobby_created(result: int, lobby_id: int) -> void: func _on_lobby_joined(lobby_id: int, _permissions: int, _locked: bool, result: int) -> void: if result != Steam.RESULT_OK: return + global._print("Joined Lobby %d" % lobby_id) if active_lobby_id != 0 && active_lobby_id != lobby_id: Steam.leaveLobby(active_lobby_id) active_lobby_id = lobby_id @@ -239,6 +245,8 @@ func _update_lobby_members(): itemlist.set_item_custom_fg_color(itemlist.get_item_count() - 1, Color.green) else: temp_everyone_ready = false + if !everyone_ready and everyone_ready: + global._print("Everyone Is Ready") everyone_ready = temp_everyone_ready var main_button = get_node("Panel/main_button") if everyone_ready and is_vip: @@ -271,6 +279,7 @@ func _read_p2p_packet() -> void: race_manager.held_messages.append(packet.duplicate(true)) var serialized: PoolByteArray = packet["data"] var data: Dictionary = bytes2var(serialized, false) + global._print("RECEIVED Packet %s" % JSON.print(data)) if "message_id" in data: _send_p2p_packet( { @@ -297,6 +306,9 @@ func _read_p2p_packet() -> void: messages_needing_ack.erase(data["ack"]) if is_starting: + global._print( + "Members Remaining Before Starting: %s" % JSON.print(members_to_join) + ) members_to_join.erase(remote_id) if members_to_join.empty(): @@ -304,6 +316,7 @@ func _read_p2p_packet() -> void: func _send_p2p_packet(data: Dictionary, recipient_id: int, mode: int, needs_ack: bool) -> void: + global._print("SENDING Packet %s" % JSON.print(data)) if recipient_id == RECIPIENT_BROADCAST_ALL: for member_id in active_lobby_members: _send_p2p_packet(data.duplicate(), member_id, mode, needs_ack) @@ -389,6 +402,8 @@ func _return_button_pressed(): func _start_game(): + global._print("Starting Game") + var race_manager = global.get_node("RaceManager") race_manager.lobby_id = active_lobby_id diff --git a/racing/manager.gd b/racing/manager.gd index 24ae409..f8b7ef7 100644 --- a/racing/manager.gd +++ b/racing/manager.gd @@ -9,6 +9,8 @@ var held_messages = [] func everyone_ready(): + global._print("RM: Everyone Ready") + var player = get_tree().get_root().get_node("Spatial/player") get_node("/root/Spatial").remove_child(get_node("/root/Spatial/blindfold")) var indicator = player.get_node("pivot/camera/achievement_label") diff --git a/racing/multiplayer.gd b/racing/multiplayer.gd index 2df69c1..e740cee 100644 --- a/racing/multiplayer.gd +++ b/racing/multiplayer.gd @@ -43,6 +43,7 @@ func _ready(): var race_manager = global.get_node("RaceManager") for packet in race_manager.held_messages: + global._print("(MP) Handling held packet") _handle_packet(packet) race_manager.held_messages.clear() @@ -178,8 +179,10 @@ func _update_lobby_members(): active_lobby_members[member_id].steam_name = steam_name if Steam.getLobbyMemberData(active_lobby_id, member_id, "loaded") != "true": everyone_ready = false + global._print("%d is not ready" % member_id) if Steam.getLobbyMemberData(active_lobby_id, member_id, "timeout") != "true": everyone_activated = false + global._print("%d is not activated" % member_id) for member in prior_lobby_members.values(): if not member.steam_id in active_lobby_members: member.queue_free() @@ -209,6 +212,7 @@ func _handle_packet(packet): var remote_id = packet["steam_id_remote"] var serialized: PoolByteArray = packet["data"] var data: Dictionary = bytes2var(serialized, false) + global._print("(MP) RECEIVED Packet %s" % JSON.print(data)) if "global_transform" in data: _receive_member_location(remote_id, data["global_transform"]) if "message_id" in data: @@ -228,6 +232,7 @@ func _handle_packet(packet): _someone_victory(Steam.getFriendPersonaName(remote_id)) if "ack" in data: messages_needing_ack.erase(data["ack"]) + _update_lobby_members() func _receive_member_location(member_id: int, global_transform) -> void: @@ -239,6 +244,7 @@ func _receive_member_location(member_id: int, global_transform) -> void: func _send_p2p_packet(data: Dictionary, recipient_id: int, mode: int, needs_ack: bool) -> void: if recipient_id == RECIPIENT_BROADCAST_ALL: + global._print("(MP) SENDING packet %s" % JSON.print(data)) for member_id in active_lobby_members.keys(): _send_p2p_packet(data.duplicate(), member_id, mode, needs_ack) return @@ -263,6 +269,7 @@ func _send_p2p_packet(data: Dictionary, recipient_id: int, mode: int, needs_ack: func player_loaded(): + global._print("(MP) Player has loaded") is_loaded = true if active_lobby_id != 0: Steam.setLobbyMemberData(active_lobby_id, "loaded", "true") @@ -271,6 +278,7 @@ func player_loaded(): func send_timeout(): + global._print("(MP) Player is activating") is_activating = true Steam.setLobbyMemberData(active_lobby_id, "timeout", "true") _send_p2p_packet({"timeout": "true"}, RECIPIENT_BROADCAST_ALL, Steam.P2P_SEND_RELIABLE, true) @@ -278,6 +286,7 @@ func send_timeout(): func time_to_start(): + global._print("(MP) Time To Start") var player = get_tree().get_root().get_node("Spatial/player") player.playable = true get_node("/root/Spatial/label").text = ( @@ -288,6 +297,7 @@ func time_to_start(): func player_victory(): if !is_victory: + global._print("(MP) Victory!") is_victory = true _send_p2p_packet( {"victory": "true"}, RECIPIENT_BROADCAST_ALL, Steam.P2P_SEND_RELIABLE, true @@ -297,6 +307,7 @@ func player_victory(): func _someone_victory(name): if !victorious_players.has(name): + global._print("(MP) Someone's victory") victorious_players.append(name) var label = get_node("/root/Spatial/label") -- cgit 1.4.1