feat(network): add selectable privacy-preserving discovery
This commit is contained in:
parent
9cf0c8fc9c
commit
4d31fd1517
26 changed files with 959 additions and 153 deletions
|
|
@ -178,16 +178,39 @@ func _run() -> void:
|
|||
)
|
||||
assert(not FileAccess.file_exists(discovery_settings_path))
|
||||
assert(discovery.set_room_name("Client Room"))
|
||||
assert(
|
||||
discovery.get_host_discovery_mode()
|
||||
== DiscoveryClient.HOST_DISCOVERY_PRIVATE
|
||||
)
|
||||
assert(discovery.set_host_connection_mode(
|
||||
DiscoveryClient.HOST_CONNECTION_RELAY
|
||||
))
|
||||
assert(
|
||||
discovery.get_host_connection_mode()
|
||||
== DiscoveryClient.HOST_CONNECTION_RELAY
|
||||
)
|
||||
assert(
|
||||
discovery.get_host_discovery_mode()
|
||||
== DiscoveryClient.HOST_DISCOVERY_PRIVATE
|
||||
)
|
||||
var client_settings: PackedByteArray = FileAccess.get_file_as_bytes(
|
||||
discovery_settings_path
|
||||
)
|
||||
assert(not client_settings.is_empty())
|
||||
var dedicated_discovery := DiscoveryClient.new()
|
||||
dedicated_discovery.call("_load_settings")
|
||||
dedicated_discovery.set(
|
||||
"_host_connection_preference",
|
||||
DiscoveryClient.HOST_CONNECTION_RELAY,
|
||||
)
|
||||
assert(
|
||||
dedicated_discovery.configure_dedicated_runtime("Headless Room")
|
||||
)
|
||||
assert(dedicated_discovery.get_room_name() == "Headless Room")
|
||||
assert(
|
||||
dedicated_discovery.get_host_connection_mode()
|
||||
== DiscoveryClient.HOST_CONNECTION_DIRECT
|
||||
)
|
||||
assert(
|
||||
FileAccess.get_file_as_bytes(discovery_settings_path)
|
||||
== client_settings
|
||||
|
|
@ -210,16 +233,26 @@ func _run() -> void:
|
|||
var listed_room := {
|
||||
"room_id": "empty-dedicated-room",
|
||||
"room_name": "Empty Dedicated Room",
|
||||
"address": "203.0.113.10",
|
||||
"port": 7777,
|
||||
"current_players": 0,
|
||||
"max_players": 8,
|
||||
"game_version": str(ProjectSettings.get_setting(
|
||||
"application/config/version", "unknown"
|
||||
)),
|
||||
"protocol_version": NetworkProtocol.PROTOCOL_VERSION,
|
||||
"connection_mode": "direct",
|
||||
"ip_privacy": "peer_visible",
|
||||
"host_kind": "dedicated",
|
||||
}
|
||||
assert(bool(discovery.call("_valid_public_room", listed_room)))
|
||||
assert(not listed_room.has("address"))
|
||||
assert(not listed_room.has("port"))
|
||||
var relayed_room: Dictionary = listed_room.duplicate(true)
|
||||
relayed_room["connection_mode"] = "relay"
|
||||
relayed_room["ip_privacy"] = "relayed"
|
||||
assert(not bool(discovery.call("_valid_public_room", relayed_room)))
|
||||
var player_relayed_room: Dictionary = relayed_room.duplicate(true)
|
||||
player_relayed_room["host_kind"] = "player"
|
||||
assert(bool(discovery.call("_valid_public_room", player_relayed_room)))
|
||||
var incompatible_room: Dictionary = listed_room.duplicate(true)
|
||||
incompatible_room["game_version"] = "0.0.0-alpha"
|
||||
assert(not bool(discovery.call("_valid_public_room", incompatible_room)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue