Skip to content

Commit 59d6e14

Browse files
authored
fix: Stop signals and loops on disconnect (#530)
Fixes #511
1 parent 2fb8c76 commit 59d6e14

File tree

7 files changed

+18
-9
lines changed

7 files changed

+18
-9
lines changed

addons/netfox.extras/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox.extras"
44
description="Game-specific utilities for Netfox"
55
author="Tamas Galffy and contributors"
6-
version="1.35.0"
6+
version="1.35.1"
77
script="netfox-extras.gd"

addons/netfox.internals/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox.internals"
44
description="Shared internals for netfox addons"
55
author="Tamas Galffy and contributors"
6-
version="1.35.0"
6+
version="1.35.1"
77
script="plugin.gd"

addons/netfox.noray/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox.noray"
44
description="Bulletproof your connectivity with noray integration for netfox"
55
author="Tamas Galffy and contributors"
6-
version="1.35.0"
6+
version="1.35.1"
77
script="netfox-noray.gd"

addons/netfox/network-time-synchronizer.gd

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,17 @@ func _loop() -> void:
162162
on_initial_sync.emit()
163163

164164
while _active:
165+
if multiplayer.is_server():
166+
return stop()
167+
165168
var sample := NetworkClockSample.new()
166169
_awaiting_samples[_sample_idx] = sample
167-
170+
168171
sample.ping_sent = _clock.get_time()
169172
_send_ping.rpc_id(1, _sample_idx)
170-
173+
171174
_sample_idx += 1
172-
175+
173176
await get_tree().create_timer(sync_interval).timeout
174177

175178
func _discipline_clock() -> void:

addons/netfox/network-time.gd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ func start() -> int:
447447
_initial_sync_done = true
448448

449449
# Remove clients from the synced cache when disconnected
450-
multiplayer.peer_disconnected.connect(func(peer): _synced_peers.erase(peer))
450+
multiplayer.peer_disconnected.connect(_handle_peer_disconnect)
451451

452452
# Set initial clock state
453453
_clock.set_time(NetworkTimeSynchronizer.get_time())
@@ -470,6 +470,9 @@ func stop() -> void:
470470
_state = _STATE_INACTIVE
471471
_synced_peers.clear()
472472

473+
if multiplayer.peer_disconnected.is_connected(_handle_peer_disconnect):
474+
multiplayer.peer_disconnected.disconnect(_handle_peer_disconnect)
475+
473476
## Check if the initial time sync is done.
474477
func is_initial_sync_done() -> bool:
475478
return _initial_sync_done
@@ -583,6 +586,9 @@ func _notification(what) -> void:
583586
func _is_active() -> bool:
584587
return _state == _STATE_ACTIVE
585588

589+
func _handle_peer_disconnect(peer: int) -> void:
590+
_synced_peers.erase(peer)
591+
586592
@rpc("any_peer", "reliable", "call_local")
587593
func _submit_sync_success() -> void:
588594
var peer_id := multiplayer.get_remote_sender_id()

addons/netfox/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox"
44
description="Shared internals for netfox addons"
55
author="Tamas Galffy and contributors"
6-
version="1.35.0"
6+
version="1.35.1"
77
script="netfox.gd"

addons/netfox/time/network-tickrate-handshake.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func run() -> void:
5454
## [br][br]
5555
## Called by [_NetworkTime], no need to call manually.
5656
func stop() -> void:
57-
if multiplayer.is_server():
57+
if multiplayer.peer_connected.is_connected(_handle_new_peer):
5858
multiplayer.peer_connected.disconnect(_handle_new_peer)
5959

6060
func _ready() -> void:

0 commit comments

Comments
 (0)