straywild/network/network_transport.gd
Voyager 3b84bfe3a0 feat: expand progression and multiplayer systems
Add named save slots, progression import/export, and a unified play flow. Add live friend requests, presence, invitations, and relationship controls without durable discovery-server social storage. Advance the network protocol with isolated channels, movement reconciliation, late-join recovery, fishing replication, and animation synchronization. Preserve per-species catch totals, refine generated-world startup and water recovery, and complete the related input and interface improvements.
2026-08-23 20:49:54 -04:00

54 lines
1.5 KiB
GDScript

class_name NetworkTransport
extends Node
@warning_ignore("unused_signal")
signal transport_error(message: String)
var _peer: MultiplayerPeer
var _route_description: String = ""
func start_host(
_port: int,
_max_clients: int,
_bind_address: String = "*",
) -> Error:
return ERR_UNAVAILABLE
func connect_to_route(_route: ConnectionRoute) -> Error:
return ERR_UNAVAILABLE
func disconnect_transport() -> void:
if _peer != null:
# Give ENet one poll cycle to emit its graceful disconnect packets before
# closing the socket. This keeps a host from retaining a departed player
# until the extended generated-world liveness timeout expires.
if (
_peer is ENetMultiplayerPeer
and _peer.get_connection_status()
== MultiplayerPeer.CONNECTION_CONNECTED
):
var enet_peer := _peer as ENetMultiplayerPeer
# A host explicitly notifies each still-live client before closing.
# Clients rely on ENetMultiplayerPeer.close(); their cached SceneTree
# peer list can briefly outlive the underlying ENet peer after a remote
# disconnect, making disconnect_peer() race and report an engine error.
if enet_peer.get_unique_id() == 1:
for peer_id: int in multiplayer.get_peers():
if enet_peer.get_peer(peer_id) != null:
enet_peer.disconnect_peer(peer_id, false)
if enet_peer.host != null:
enet_peer.host.flush()
_peer.close()
_peer = null
_route_description = ""
func get_multiplayer_peer() -> MultiplayerPeer:
return _peer
func get_route_description() -> String:
return _route_description