grounders-slowjam-2024/server/client_lobbies.gd

26 lines
707 B
GDScript3
Raw Normal View History

2024-05-25 17:15:59 -06:00
extends Control
var address: String
var port: int
func _ready():
var m = SceneMultiplayer.new()
get_tree().set_multiplayer(m, %LobbyList.get_path())
var peer := ENetMultiplayerPeer.new()
var error := peer.create_client(address, port)
if error:
push_error(error)
m.multiplayer_peer = peer
m.connected_to_server.connect(connected_to_server)
%LobbyList.set_multiplayer_authority(1)
func connected_to_server():
print("Connected to master server @ " + address + ":" + str(port))
func _on_lobby_list_join_lobby(join_addr, join_port):
queue_free()
var client := preload("res://server/client.tscn").instantiate()
client.address = join_addr
client.port = join_port
get_parent().add_child(client)