From e01b33777328b27901687fad4445685ec2b31ac7 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Thu, 8 Feb 2024 18:14:38 -0500 Subject: version num, held messages, updated lobby list --- racing/load.gd | 6 ++++++ racing/lobby.gd | 18 ++++++++++++++++-- racing/manager.gd | 1 + racing/multiplayer.gd | 52 ++++++++++++++++++++++++++++++--------------------- 4 files changed, 54 insertions(+), 23 deletions(-) (limited to 'racing') diff --git a/racing/load.gd b/racing/load.gd index 503aa3a..cd60c65 100644 --- a/racing/load.gd +++ b/racing/load.gd @@ -2,6 +2,8 @@ extends "res://scripts/load.gd" func _load(): + global._print("Hooked Load Start") + disable_saving = true var player = get_node("player") @@ -54,8 +56,12 @@ func _load(): "MeshInstance5" ) + global._print("Hooked Load Stop") + ._load() + global._print("MP Loaded") + multiplayer.player_loaded() diff --git a/racing/lobby.gd b/racing/lobby.gd index 87647bb..933345e 100644 --- a/racing/lobby.gd +++ b/racing/lobby.gd @@ -15,6 +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.2" const LL1_AREAS = [ ["Starting Room", 0, 0, 0], @@ -90,6 +91,9 @@ func _ready(): global.add_child(race_manager) + var race_manager = global.get_node("RaceManager") + race_manager.held_messages.clear() + var _ignore = get_node("Panel/main_button").connect("pressed", self, "_main_button_pressed") _ignore = get_node("Panel/return_button").connect("pressed", self, "_return_button_pressed") @@ -100,13 +104,14 @@ func _ready(): dynamic_font.outline_size = 2 get_node("Panel/ItemList").add_font_override("font", dynamic_font) - get_node("Panel/title").text = "LINGO RACING LOBBY (%s)" % global.save_file + get_node("Panel/title").text = "LINGO RACING %s LOBBY (%s)" % [VERSION, global.save_file] player_steam_id = Steam.getSteamID() _ignore = Steam.connect("lobby_match_list", self, "_on_lobby_match_list") _ignore = Steam.connect("lobby_created", self, "_on_lobby_created") _ignore = Steam.connect("lobby_joined", self, "_on_lobby_joined") + _ignore = Steam.connect("lobby_chat_update", self, "_on_lobby_chat_update") _ignore = Steam.connect("lobby_data_update", self, "_on_lobby_data_update") _ignore = Steam.connect("persona_state_change", self, "_on_persona_state_change") _ignore = Steam.connect("p2p_session_request", self, "_on_p2p_session_request") @@ -201,6 +206,12 @@ func _on_lobby_joined(lobby_id: int, _permissions: int, _locked: bool, result: i _update_lobby_members() +func _on_lobby_chat_update( + _lobby_id: int, _member_id: int, _making_change_id: int, _chat_state: int +) -> void: + _update_lobby_members() + + func _on_lobby_data_update(_lobby_id: int, _member_id: int, _key: int) -> void: _update_lobby_members() @@ -255,6 +266,10 @@ func _read_p2p_packet() -> void: var packet: Dictionary = Steam.readP2PPacket(packet_size, 0) var remote_id = packet["steam_id_remote"] if remote_id in active_lobby_members: + var race_manager = global.get_node("RaceManager") + if is_starting: + race_manager.held_messages.append(packet.duplicate(true)) + return var serialized: PoolByteArray = packet["data"] var data: Dictionary = bytes2var(serialized, false) if "message_id" in data: @@ -267,7 +282,6 @@ func _read_p2p_packet() -> void: false ) if "start_x" in data: - var race_manager = global.get_node("RaceManager") race_manager.start_pos = [ data["start_name"], int(data["start_x"]), diff --git a/racing/manager.gd b/racing/manager.gd index e2cd728..24ae409 100644 --- a/racing/manager.gd +++ b/racing/manager.gd @@ -5,6 +5,7 @@ var SCRIPT_multiplayer var start_pos var end_pos var lobby_id +var held_messages = [] func everyone_ready(): diff --git a/racing/multiplayer.gd b/racing/multiplayer.gd index 4255ba6..2df69c1 100644 --- a/racing/multiplayer.gd +++ b/racing/multiplayer.gd @@ -41,6 +41,11 @@ func _ready(): # _request_lobby_list() + var race_manager = global.get_node("RaceManager") + for packet in race_manager.held_messages: + _handle_packet(packet) + race_manager.held_messages.clear() + func _process(_delta: float) -> void: _read_p2p_packet() @@ -197,27 +202,32 @@ func _read_p2p_packet() -> void: var packet: Dictionary = Steam.readP2PPacket(packet_size, 0) var remote_id = packet["steam_id_remote"] if remote_id in active_lobby_members: - var serialized: PoolByteArray = packet["data"] - var data: Dictionary = bytes2var(serialized, false) - if "global_transform" in data: - _receive_member_location(remote_id, data["global_transform"]) - if "message_id" in data: - _send_p2p_packet( - { - "ack": data["message_id"], - }, - remote_id, - Steam.P2P_SEND_RELIABLE_WITH_BUFFERING, - false - ) - if "loaded" in data: - _update_lobby_members() - if "timeout" in data: - _update_lobby_members() - if "victory" in data: - _someone_victory(Steam.getFriendPersonaName(remote_id)) - if "ack" in data: - messages_needing_ack.erase(data["ack"]) + _handle_packet(packet) + + +func _handle_packet(packet): + var remote_id = packet["steam_id_remote"] + var serialized: PoolByteArray = packet["data"] + var data: Dictionary = bytes2var(serialized, false) + if "global_transform" in data: + _receive_member_location(remote_id, data["global_transform"]) + if "message_id" in data: + _send_p2p_packet( + { + "ack": data["message_id"], + }, + remote_id, + Steam.P2P_SEND_RELIABLE_WITH_BUFFERING, + false + ) + if "loaded" in data: + _update_lobby_members() + if "timeout" in data: + _update_lobby_members() + if "victory" in data: + _someone_victory(Steam.getFriendPersonaName(remote_id)) + if "ack" in data: + messages_needing_ack.erase(data["ack"]) func _receive_member_location(member_id: int, global_transform) -> void: -- cgit 1.4.1