Commit 7fe7ef43 authored by Steven vanZyl's avatar Steven vanZyl
Browse files

UPnP support

I think I got UPnP working but I can't test it on the RPI
network I think.
parent 4bd5b9d9
......@@ -57,6 +57,6 @@ margin_top = 695.152
margin_right = 1263.36
margin_bottom = 709.152
custom_styles/normal = SubResource( 1 )
text = "Version: 0.0.1"
text = "Version: 0.2.0"
[connection signal="pressed" from="VBoxContainer/ConnectButton" to="." method="_on_ConnectButton_pressed"]
[connection signal="pressed" from="VBoxContainer/HostButton" to="." method="_on_HostButton_pressed"]
......@@ -6,7 +6,6 @@ const MAX_PLAYERS = 5
# To be used for UPNP later
var server_ip = DEFAULT_IP
var server_port = DEFAULT_PORT
var peer
......@@ -19,15 +18,26 @@ onready var _multimesh: MultiMeshInstance
func _ready():
get_tree().connect("network_peer_disconnected", self, "_on_player_disconnected")
get_tree().connect("network_peer_connected", self, "_on_player_connected")
get_tree().connect("server_disconnected", self, "_on_server_disconnect")
func set_multi_mesh(mm: MultiMeshInstance):
_multimesh = mm
func create_server(name):
# setup UPNP so you don't need to port-forward
var upnp = UPNP.new()
upnp.discover()
upnp.add_port_mapping(DEFAULT_PORT)
server_ip = upnp.query_external_address()
if server_ip:
Debug.set_field("external ip", server_ip)
else:
Debug.set_field("external ip", "UPnP failed")
self_data.name = name
players[1] = self_data
peer = NetworkedMultiplayerENet.new()
peer.create_server(server_port, MAX_PLAYERS)
peer.create_server(DEFAULT_PORT, MAX_PLAYERS)
get_tree().set_network_peer(peer)
_load_game()
......@@ -35,7 +45,7 @@ func connect_to_server(name, ip):
self_data.name = name
get_tree().connect("connected_to_server", self, "_connected_to_server")
peer = NetworkedMultiplayerENet.new()
peer.create_client(ip, server_port)
peer.create_client(ip, DEFAULT_PORT)
get_tree().set_network_peer(peer)
func disconnect_from_server():
......@@ -79,6 +89,9 @@ func _on_player_disconnected(id):
players.erase(id)
get_tree().get_root().get_node(str(id)).queue_free()
func _on_server_disconnect():
disconnect_from_server()
remotesync func update_color(id, color: Color):
players[id].paint_color = color
get_tree().get_root().get_node(str(id)).set_color(color)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment