Skip to content

Commit

Permalink
Add instructions for port forwarding in the high-level multiplayer demos
Browse files Browse the repository at this point in the history
The instructions will only show when the player is hosting a server.
This also includes a button to get your public IP address.

This partially addresses godotengine#535.
  • Loading branch information
Calinou committed Nov 8, 2020
1 parent 2503599 commit 680a4eb
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 19 deletions.
4 changes: 3 additions & 1 deletion networking/multiplayer_bomber/gamestate.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
extends Node

# Default game port. Can be any number between 1024 and 49151.
# Default game server port. Can be any number between 1024 and 49151.
# Not on the list of registered or common ports as of November 2020:
# https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
const DEFAULT_PORT = 10567

# Max number of players.
Expand Down
4 changes: 4 additions & 0 deletions networking/multiplayer_bomber/lobby.gd
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,7 @@ func refresh_lobby():

func _on_start_pressed():
gamestate.begin_game()


func _on_find_public_ip_pressed():
OS.shell_open("https://icanhazip.com/")
20 changes: 20 additions & 0 deletions networking/multiplayer_bomber/lobby.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ margin_bottom = 296.0
size_flags_horizontal = 2
size_flags_vertical = 2

[node name="PortForward" type="Label" parent="Players"]
margin_left = -124.0
margin_top = 375.0
margin_right = 128.0
margin_bottom = 429.0
custom_constants/line_spacing = 6
text = "If you want non-LAN clients to connect,
make sure the port 10567 in UDP
is forwarded on your router."
align = 1

[node name="FindPublicIP" type="LinkButton" parent="Players"]
margin_left = 168.0
margin_top = 393.5
margin_right = 341.0
margin_bottom = 407.5
text = "Find your public IP address"

[node name="Connect" type="Panel" parent="."]
anchor_left = 0.5
anchor_top = 0.5
Expand Down Expand Up @@ -132,6 +150,8 @@ margin_right = 55.0
margin_bottom = 58.0
size_flags_horizontal = 2
size_flags_vertical = 2

[connection signal="pressed" from="Players/Start" to="." method="_on_start_pressed"]
[connection signal="pressed" from="Players/FindPublicIP" to="." method="_on_find_public_ip_pressed"]
[connection signal="pressed" from="Connect/Host" to="." method="_on_host_pressed"]
[connection signal="pressed" from="Connect/Join" to="." method="_on_join_pressed"]
7 changes: 1 addition & 6 deletions networking/multiplayer_bomber/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@

config_version=4

_global_script_classes=[ ]
_global_script_class_icons={

}

[application]

config/name="Multiplayer Bomber"
Expand All @@ -32,8 +27,8 @@ gdscript/warnings/return_value_discarded=false

[display]

window/vsync/use_vsync=false
window/dpi/allow_hidpi=true
window/vsync/use_vsync=false
window/stretch/mode="2d"
window/stretch/aspect="expand"

Expand Down
26 changes: 21 additions & 5 deletions networking/multiplayer_bomber/tileset.tres
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
[gd_resource type="TileSet" load_steps=2 format=2]
[gd_resource type="TileSet" load_steps=3 format=2]

[ext_resource path="res://brickfloor.png" type="Texture" id=1]

[sub_resource type="RectangleShape2D" id=1]

custom_solver_bias = 0.0
extents = Vector2( 24, 24 )

[resource]

0/name = "wall"
0/texture = ExtResource( 1 )
0/tex_offset = Vector2( 0, 0 )
0/modulate = Color( 1, 1, 1, 1 )
0/region = Rect2( 0, 0, 48, 48 )
0/tile_mode = 0
0/occluder_offset = Vector2( 24, 24 )
0/navigation_offset = Vector2( 24, 24 )
0/shape_offset = Vector2( 24, 24 )
0/shapes = [ SubResource( 1 ) ]
0/shape_transform = Transform2D( 1, 0, 0, 1, 24, 24 )
0/shape = SubResource( 1 )
0/shape_one_way = false
0/shape_one_way_margin = 1.0
0/shapes = [ {
"autotile_coord": Vector2( 0, 0 ),
"one_way": false,
"one_way_margin": 1.0,
"shape": SubResource( 1 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 24, 24 )
} ]
0/z_index = 0
1/name = "floor"
1/texture = ExtResource( 1 )
1/tex_offset = Vector2( 0, 0 )
1/modulate = Color( 1, 1, 1, 1 )
1/region = Rect2( 48, 0, 48, 48 )
1/tile_mode = 0
1/occluder_offset = Vector2( 24, 24 )
1/navigation_offset = Vector2( 24, 24 )
1/shape_offset = Vector2( 0, 0 )
1/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
1/shape_one_way = false
1/shape_one_way_margin = 0.0
1/shapes = [ ]
1/z_index = 0
1 change: 1 addition & 0 deletions networking/multiplayer_bomber/world.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,5 @@ __meta__ = {
[node name="Camera2D" type="Camera2D" parent="."]
offset = Vector2( 512, 300 )
current = true

[connection signal="pressed" from="Winner/ExitGame" to="Score" method="_on_exit_game_pressed"]
28 changes: 28 additions & 0 deletions networking/multiplayer_pong/lobby.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,33 @@ size_flags_horizontal = 2
size_flags_vertical = 0
custom_colors/font_color = Color( 1, 0, 0, 1 )
align = 1

[node name="PortForward" type="Label" parent="LobbyPanel"]
visible = false
margin_left = -128.0
margin_top = 136.0
margin_right = 124.0
margin_bottom = 184.0
custom_constants/line_spacing = 6
text = "If you want non-LAN clients to connect,
make sure the port 8910 in UDP
is forwarded on your router."
align = 1
__meta__ = {
"_edit_use_anchors_": false
}

[node name="FindPublicIP" type="LinkButton" parent="LobbyPanel"]
visible = false
margin_left = 155.0
margin_top = 152.0
margin_right = 328.0
margin_bottom = 166.0
text = "Find your public IP address"
__meta__ = {
"_edit_use_anchors_": false
}

[connection signal="pressed" from="LobbyPanel/HostButton" to="LobbyPanel" method="_on_host_pressed"]
[connection signal="pressed" from="LobbyPanel/JoinButton" to="LobbyPanel" method="_on_join_pressed"]
[connection signal="pressed" from="LobbyPanel/FindPublicIP" to="LobbyPanel" method="_on_find_public_ip_pressed"]
15 changes: 14 additions & 1 deletion networking/multiplayer_pong/logic/lobby.gd
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
extends Control

const DEFAULT_PORT = 8910 # An arbitrary number.
# Default game server port. Can be any number between 1024 and 49151.
# Not on the list of registered or common ports as of November 2020:
# https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
const DEFAULT_PORT = 8910

onready var address = $Address
onready var host_button = $HostButton
onready var join_button = $JoinButton
onready var status_ok = $StatusOk
onready var status_fail = $StatusFail
onready var port_forward_label = $PortForward
onready var find_public_ip_button = $FindPublicIP

var peer = null

Expand Down Expand Up @@ -95,6 +100,10 @@ func _on_host_pressed():
join_button.set_disabled(true)
_set_status("Waiting for player...", true)

# Only show hosting instructions when relevant.
port_forward_label.visible = true
find_public_ip_button.visible = true


func _on_join_pressed():
var ip = address.get_text()
Expand All @@ -108,3 +117,7 @@ func _on_join_pressed():
get_tree().set_network_peer(peer)

_set_status("Connecting...", true)


func _on_find_public_ip_pressed():
OS.shell_open("https://icanhazip.com/")
2 changes: 1 addition & 1 deletion networking/multiplayer_pong/pong.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ text = "Exit Game"
[node name="Camera2D" type="Camera2D" parent="."]
offset = Vector2( 320, 200 )
current = true

[connection signal="pressed" from="ExitGame" to="." method="_on_exit_game_pressed"]

[editable path="Player1"]

[editable path="Player2"]
5 changes: 0 additions & 5 deletions networking/multiplayer_pong/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@

config_version=4

_global_script_classes=[ ]
_global_script_class_icons={

}

[application]

config/name="Pong Multiplayer"
Expand Down

0 comments on commit 680a4eb

Please sign in to comment.