24 lines
636 B
GDScript
24 lines
636 B
GDScript
# Runs server side per game
|
|
|
|
extends Node
|
|
|
|
var port: int
|
|
var MAX_CLIENTS := 32
|
|
|
|
func _ready():
|
|
var m = SceneMultiplayer.new()
|
|
get_tree().set_multiplayer(m, get_path())
|
|
var peer := ENetMultiplayerPeer.new()
|
|
peer.create_server(port, MAX_CLIENTS)
|
|
m.multiplayer_peer = peer
|
|
m.peer_connected.connect(peer_connected)
|
|
m.peer_disconnected.connect(peer_disconnected)
|
|
|
|
func peer_connected(id: int):
|
|
print("Client " + str(id) + "connected to lobby " + str(get_path()))
|
|
$level.server_add_player(id)
|
|
|
|
func peer_disconnected(id: int):
|
|
print("Client " + str(id) + "disconnected to lobby " + str(get_path()))
|
|
$level.server_remove_player(id)
|