|
@@ -0,0 +1,32 @@
|
|
|
+extends Node
|
|
|
+
|
|
|
+var net = NetworkedMultiplayerENet.new()
|
|
|
+var api = MultiplayerAPI.new()
|
|
|
+var port = 8081
|
|
|
+var maxplayer = 4
|
|
|
+export(NodePath) var database
|
|
|
+
|
|
|
+func _ready():
|
|
|
+ print('listening to port: ' + str(port))
|
|
|
+ net.create_server(port, maxplayer)
|
|
|
+
|
|
|
+ self.set_custom_multiplayer(api)
|
|
|
+ custom_multiplayer.set_root_node(self)
|
|
|
+ custom_multiplayer.set_network_peer(net)
|
|
|
+
|
|
|
+ net.connect("peer_disconnected",self,"disc")
|
|
|
+ net.connect("peer_connected",self,"conn")
|
|
|
+ pass # Replace with function body.
|
|
|
+
|
|
|
+func _process(_delta):
|
|
|
+ custom_multiplayer.poll()
|
|
|
+
|
|
|
+func conn(arg):
|
|
|
+ print('client connected, id: ' + str(arg))
|
|
|
+ yield(get_tree(),"physics_frame")
|
|
|
+ rpc_id(arg,'ping')
|
|
|
+ print('clients connected: ' + str(custom_multiplayer.get_network_connected_peers().size()))
|
|
|
+
|
|
|
+func disc(arg):
|
|
|
+ print('client disconnected, id: ' + str(arg))
|
|
|
+
|