-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.gd
More file actions
38 lines (29 loc) · 986 Bytes
/
Copy pathserver.gd
File metadata and controls
38 lines (29 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
extends Node
var port = Overseer.game_settings["port"]
var max_clients = Overseer.game_settings["max_clients"]
@onready var peer = ENetMultiplayerPeer.new()
signal put_infoboxline
signal player_disconnected
func _ready():
multiplayer.peer_connected.connect(peer_connected)
multiplayer.peer_disconnected.connect(peer_disconnected)
upnp_setup()
peer.create_server(port, max_clients)
multiplayer.multiplayer_peer = peer
func upnp_setup():
if get_parent().upnp:
var upnp = UPNP.new()
upnp.discover()
upnp.add_port_mapping(port)
put_infoboxline.emit("External IP: " + upnp.query_external_address())
func peer_connected(id):
print("Client connected: ", id)
put_infoboxline.emit("Client connected: " + str(id))
func peer_disconnected(id):
player_disconnected.emit(id)
print("Client disconnected: ", id)
put_infoboxline.emit("Client disconnected: " + str(id))
func terminate():
print("Terminating server")
put_infoboxline.emit("Terminating server")
peer.close()