Port forwarding
This commit is contained in:
parent
0501476a6e
commit
fc984d6b45
6 changed files with 56 additions and 1 deletions
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