2024-05-25 17:15:59 -06:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
@export var external_address := "127.0.0.1"
|
|
|
|
var master_server_port := 3000
|
|
|
|
var next_port_num := master_server_port + 1
|
|
|
|
const MAX_CLIENTS = 4095
|
|
|
|
|
|
|
|
func _ready():
|
2024-05-26 07:24:38 -06:00
|
|
|
PhysicsServer3D.set_active(false)
|
2024-05-25 17:15:59 -06:00
|
|
|
var m = SceneMultiplayer.new()
|
|
|
|
get_tree().set_multiplayer(m, %LobbyList.get_path())
|
|
|
|
var peer := ENetMultiplayerPeer.new()
|
|
|
|
var error := peer.create_server(master_server_port, MAX_CLIENTS)
|
|
|
|
if error:
|
|
|
|
push_error(error)
|
|
|
|
m.multiplayer_peer = peer
|
|
|
|
m.peer_connected.connect(peer_connected)
|
|
|
|
|
|
|
|
func peer_connected(id: int):
|
|
|
|
print("Client " + str(id) + " connected to master server")
|
|
|
|
for lobby in %LobbyList.lobbies():
|
2024-05-31 16:47:56 -06:00
|
|
|
%LobbyList.add.rpc_id(id, lobby.port)
|
2024-05-25 17:15:59 -06:00
|
|
|
|
|
|
|
func create_lobby():
|
|
|
|
var lobby := preload("res://server/lobby.tscn").instantiate()
|
|
|
|
lobby.port = next_port_num
|
|
|
|
next_port_num += 1
|
|
|
|
%Lobbies.add_child(lobby)
|
2024-05-31 16:47:56 -06:00
|
|
|
%LobbyList.add.rpc(lobby.port)
|
2024-05-25 17:15:59 -06:00
|
|
|
|
|
|
|
func _on_create_lobby_pressed():
|
|
|
|
create_lobby()
|