Port forwarding
This commit is contained in:
parent
0501476a6e
commit
fc984d6b45
6 changed files with 56 additions and 1 deletions
|
|
@ -1,7 +1,9 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://cbtp4rvg66ba1"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://cbtp4rvg66ba1"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bsyuos803g7qf" path="res://gui/main_menu/main_menu_gui.gd" id="1_l6cm7"]
|
||||
[ext_resource type="Script" uid="uid://dh64rv15w8ecl" path="res://gui/main_menu/host_menu.gd" id="2_ekxnf"]
|
||||
[ext_resource type="Script" uid="uid://r1uwav8lrw6c" path="res://multiplayer/port_forward_button.gd" id="3_6wy0j"]
|
||||
[ext_resource type="Script" uid="uid://dq2pv2wy8uojd" path="res://multiplayer/ip_display.gd" id="3_qy2xc"]
|
||||
|
||||
[node name="MainMenu" type="CenterContainer"]
|
||||
anchors_preset = 15
|
||||
|
|
@ -189,6 +191,20 @@ value = 2.0
|
|||
rounded = true
|
||||
allow_greater = true
|
||||
|
||||
[node name="ForwardPortButton" type="Button" parent="Lobby/HBoxContainer/HostMenu"]
|
||||
layout_mode = 2
|
||||
text = "Попробовать пробросить порты"
|
||||
script = ExtResource("3_6wy0j")
|
||||
|
||||
[node name="Label" type="Label" parent="Lobby/HBoxContainer/HostMenu"]
|
||||
layout_mode = 2
|
||||
text = "Статус публичного IP:"
|
||||
|
||||
[node name="PublicIP" type="Label" parent="Lobby/HBoxContainer/HostMenu"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
script = ExtResource("3_qy2xc")
|
||||
|
||||
[connection signal="pressed" from="MainMenu/VBoxContainer/HostButton" to="." method="_on_host_button_pressed"]
|
||||
[connection signal="pressed" from="MainMenu/VBoxContainer/ConnectButton" to="." method="_on_connect_button_pressed"]
|
||||
[connection signal="pressed" from="Lobby/HBoxContainer/ClientMenu/Buttons/LeaveButton" to="." method="_on_leave_button_pressed"]
|
||||
|
|
|
|||
8
multiplayer/ip_display.gd
Normal file
8
multiplayer/ip_display.gd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
extends Label
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Lobby.update_ip.connect(on_update_ip)
|
||||
|
||||
func on_update_ip(to: StringName):
|
||||
text = to
|
||||
1
multiplayer/ip_display.gd.uid
Normal file
1
multiplayer/ip_display.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dq2pv2wy8uojd
|
||||
|
|
@ -9,6 +9,8 @@ signal lobby_joined
|
|||
signal lobby_closed
|
||||
signal update_teams_state
|
||||
|
||||
signal update_ip(StringName)
|
||||
|
||||
var in_lobby: bool = false
|
||||
|
||||
var attack_team: Array[int] = []
|
||||
|
|
@ -27,6 +29,9 @@ func _ready() -> void:
|
|||
multiplayer.server_disconnected.connect(server_disconnected)
|
||||
multiplayer.peer_connected.connect(add_and_sync_peer)
|
||||
|
||||
func _enter_tree() -> void:
|
||||
pass
|
||||
|
||||
func player_left(id: int) -> void:
|
||||
if attack_team.has(id):
|
||||
attack_team.erase(id)
|
||||
|
|
|
|||
24
multiplayer/port_forward_button.gd
Normal file
24
multiplayer/port_forward_button.gd
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
extends Button
|
||||
|
||||
|
||||
func _pressed() -> void:
|
||||
var upnp = UPNP.new()
|
||||
|
||||
var discover_error = upnp.discover()
|
||||
|
||||
if discover_error != UPNP.UPNPResult.UPNP_RESULT_SUCCESS:
|
||||
Lobby.update_ip.emit("Discover error: " + str(discover_error as UPNP.UPNPResult))
|
||||
return
|
||||
|
||||
var error_udp = upnp.add_port_mapping(Lobby.PORT)
|
||||
if error_udp != UPNP.UPNPResult.UPNP_RESULT_SUCCESS:
|
||||
Lobby.update_ip.emit("UDP forward error: " + str(error_udp as UPNP.UPNPResult))
|
||||
return
|
||||
|
||||
var error_tcp = upnp.add_port_mapping(Lobby.PORT,0,"","TCP")
|
||||
|
||||
if error_tcp != UPNP.UPNPResult.UPNP_RESULT_SUCCESS:
|
||||
Lobby.update_ip.emit("TCP forward error: " + str(error_tcp as UPNP.UPNPResult))
|
||||
return
|
||||
|
||||
Lobby.update_ip.emit(upnp.query_external_address())
|
||||
1
multiplayer/port_forward_button.gd.uid
Normal file
1
multiplayer/port_forward_button.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://r1uwav8lrw6c
|
||||
Loading…
Add table
Add a link
Reference in a new issue