summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--racing/load.gd6
-rw-r--r--racing/lobby.gd18
-rw-r--r--racing/manager.gd1
-rw-r--r--racing/multiplayer.gd52
4 files changed, 54 insertions, 23 deletions
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"
2 2
3 3
4func _load(): 4func _load():
5 global._print("Hooked Load Start")
6
5 disable_saving = true 7 disable_saving = true
6 8
7 var player = get_node("player") 9 var player = get_node("player")
@@ -54,8 +56,12 @@ func _load():
54 "MeshInstance5" 56 "MeshInstance5"
55 ) 57 )
56 58
59 global._print("Hooked Load Stop")
60
57 ._load() 61 ._load()
58 62
63 global._print("MP Loaded")
64
59 multiplayer.player_loaded() 65 multiplayer.player_loaded()
60 66
61 67
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
15const PROTOCOL_VERSION = 2 15const PROTOCOL_VERSION = 2
16const RECIPIENT_BROADCAST_ALL = -1 16const RECIPIENT_BROADCAST_ALL = -1
17const LOBBY_MAP_NAME = "ll1_racing" 17const LOBBY_MAP_NAME = "ll1_racing"
18const VERSION = "0.0.2"
18 19
19const LL1_AREAS = [ 20const LL1_AREAS = [
20 ["Starting Room", 0, 0, 0], 21 ["Starting Room", 0, 0, 0],
@@ -90,6 +91,9 @@ func _ready():
90 91
91 global.add_child(race_manager) 92 global.add_child(race_manager)
92 93
94 var race_manager = global.get_node("RaceManager")
95 race_manager.held_messages.clear()
96
93 var _ignore = get_node("Panel/main_button").connect("pressed", self, "_main_button_pressed") 97 var _ignore = get_node("Panel/main_button").connect("pressed", self, "_main_button_pressed")
94 _ignore = get_node("Panel/return_button").connect("pressed", self, "_return_button_pressed") 98 _ignore = get_node("Panel/return_button").connect("pressed", self, "_return_button_pressed")
95 99
@@ -100,13 +104,14 @@ func _ready():
100 dynamic_font.outline_size = 2 104 dynamic_font.outline_size = 2
101 get_node("Panel/ItemList").add_font_override("font", dynamic_font) 105 get_node("Panel/ItemList").add_font_override("font", dynamic_font)
102 106
103 get_node("Panel/title").text = "LINGO RACING LOBBY (%s)" % global.save_file 107 get_node("Panel/title").text = "LINGO RACING %s LOBBY (%s)" % [VERSION, global.save_file]
104 108
105 player_steam_id = Steam.getSteamID() 109 player_steam_id = Steam.getSteamID()
106 110
107 _ignore = Steam.connect("lobby_match_list", self, "_on_lobby_match_list") 111 _ignore = Steam.connect("lobby_match_list", self, "_on_lobby_match_list")
108 _ignore = Steam.connect("lobby_created", self, "_on_lobby_created") 112 _ignore = Steam.connect("lobby_created", self, "_on_lobby_created")
109 _ignore = Steam.connect("lobby_joined", self, "_on_lobby_joined") 113 _ignore = Steam.connect("lobby_joined", self, "_on_lobby_joined")
114 _ignore = Steam.connect("lobby_chat_update", self, "_on_lobby_chat_update")
110 _ignore = Steam.connect("lobby_data_update", self, "_on_lobby_data_update") 115 _ignore = Steam.connect("lobby_data_update", self, "_on_lobby_data_update")
111 _ignore = Steam.connect("persona_state_change", self, "_on_persona_state_change") 116 _ignore = Steam.connect("persona_state_change", self, "_on_persona_state_change")
112 _ignore = Steam.connect("p2p_session_request", self, "_on_p2p_session_request") 117 _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
201 _update_lobby_members() 206 _update_lobby_members()
202 207
203 208
209func _on_lobby_chat_update(
210 _lobby_id: int, _member_id: int, _making_change_id: int, _chat_state: int
211) -> void:
212 _update_lobby_members()
213
214
204func _on_lobby_data_update(_lobby_id: int, _member_id: int, _key: int) -> void: 215func _on_lobby_data_update(_lobby_id: int, _member_id: int, _key: int) -> void:
205 _update_lobby_members() 216 _update_lobby_members()
206 217
@@ -255,6 +266,10 @@ func _read_p2p_packet() -> void:
255 var packet: Dictionary = Steam.readP2PPacket(packet_size, 0) 266 var packet: Dictionary = Steam.readP2PPacket(packet_size, 0)
256 var remote_id = packet["steam_id_remote"] 267 var remote_id = packet["steam_id_remote"]
257 if remote_id in active_lobby_members: 268 if remote_id in active_lobby_members:
269 var race_manager = global.get_node("RaceManager")
270 if is_starting:
271 race_manager.held_messages.append(packet.duplicate(true))
272 return
258 var serialized: PoolByteArray = packet["data"] 273 var serialized: PoolByteArray = packet["data"]
259 var data: Dictionary = bytes2var(serialized, false) 274 var data: Dictionary = bytes2var(serialized, false)
260 if "message_id" in data: 275 if "message_id" in data:
@@ -267,7 +282,6 @@ func _read_p2p_packet() -> void:
267 false 282 false
268 ) 283 )
269 if "start_x" in data: 284 if "start_x" in data:
270 var race_manager = global.get_node("RaceManager")
271 race_manager.start_pos = [ 285 race_manager.start_pos = [
272 data["start_name"], 286 data["start_name"],
273 int(data["start_x"]), 287 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
5var start_pos 5var start_pos
6var end_pos 6var end_pos
7var lobby_id 7var lobby_id
8var held_messages = []
8 9
9 10
10func everyone_ready(): 11func 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():
41 41
42 # _request_lobby_list() 42 # _request_lobby_list()
43 43
44 var race_manager = global.get_node("RaceManager")
45 for packet in race_manager.held_messages:
46 _handle_packet(packet)
47 race_manager.held_messages.clear()
48
44 49
45func _process(_delta: float) -> void: 50func _process(_delta: float) -> void:
46 _read_p2p_packet() 51 _read_p2p_packet()
@@ -197,27 +202,32 @@ func _read_p2p_packet() -> void:
197 var packet: Dictionary = Steam.readP2PPacket(packet_size, 0) 202 var packet: Dictionary = Steam.readP2PPacket(packet_size, 0)
198 var remote_id = packet["steam_id_remote"] 203 var remote_id = packet["steam_id_remote"]
199 if remote_id in active_lobby_members: 204 if remote_id in active_lobby_members:
200 var serialized: PoolByteArray = packet["data"] 205 _handle_packet(packet)
201 var data: Dictionary = bytes2var(serialized, false) 206
202 if "global_transform" in data: 207
203 _receive_member_location(remote_id, data["global_transform"]) 208func _handle_packet(packet):
204 if "message_id" in data: 209 var remote_id = packet["steam_id_remote"]
205 _send_p2p_packet( 210 var serialized: PoolByteArray = packet["data"]
206 { 211 var data: Dictionary = bytes2var(serialized, false)
207 "ack": data["message_id"], 212 if "global_transform" in data:
208 }, 213 _receive_member_location(remote_id, data["global_transform"])
209 remote_id, 214 if "message_id" in data:
210 Steam.P2P_SEND_RELIABLE_WITH_BUFFERING, 215 _send_p2p_packet(
211 false 216 {
212 ) 217 "ack": data["message_id"],
213 if "loaded" in data: 218 },
214 _update_lobby_members() 219 remote_id,
215 if "timeout" in data: 220 Steam.P2P_SEND_RELIABLE_WITH_BUFFERING,
216 _update_lobby_members() 221 false
217 if "victory" in data: 222 )
218 _someone_victory(Steam.getFriendPersonaName(remote_id)) 223 if "loaded" in data:
219 if "ack" in data: 224 _update_lobby_members()
220 messages_needing_ack.erase(data["ack"]) 225 if "timeout" in data:
226 _update_lobby_members()
227 if "victory" in data:
228 _someone_victory(Steam.getFriendPersonaName(remote_id))
229 if "ack" in data:
230 messages_needing_ack.erase(data["ack"])
221 231
222 232
223func _receive_member_location(member_id: int, global_transform) -> void: 233func _receive_member_location(member_id: int, global_transform) -> void: