extends Node


const MAX_PLAYERS: int = 10
const PORT: int = 7777

signal lobby_created
signal lobby_joined
signal lobby_closed

func host() -> void:
	var peer: ENetMultiplayerPeer = ENetMultiplayerPeer.new()
	peer.create_server(PORT,MAX_PLAYERS)
	multiplayer.multiplayer_peer = peer
	lobby_created.emit()

func join(ip: String) -> Error:
	var peer: ENetMultiplayerPeer = ENetMultiplayerPeer.new()
	var res = peer.create_client(ip,PORT) 
	if res != 0:
		return res
	multiplayer.multiplayer_peer = peer
	lobby_joined.emit()
	return Error.OK

func leave() -> void:
	multiplayer.multiplayer_peer = OfflineMultiplayerPeer.new()
	lobby_closed.emit()

@rpc("authority","call_local","reliable")
func start_game() -> void:
	get_tree().change_scene_to_file("res://levels/prototype_scene.tscn")
