summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2021-02-17 13:18:56 +0100
committerDaniel Weipert <code@drogueronin.de>2021-02-17 13:18:56 +0100
commit293e317e13c3c95104b18f2dd57ffda3e19d98ab (patch)
treee8939a40ddfc28ab1e6ea0d32c38ac3aedb4fdea
parentf960df10d5a18eafdf08d222ca2190c1b0806656 (diff)
Adds Remote IP in Lobby
-rw-r--r--Network/Lobby.gd19
-rw-r--r--Network/Lobby.tscn19
2 files changed, 34 insertions, 4 deletions
diff --git a/Network/Lobby.gd b/Network/Lobby.gd
index 15f27ba..be045b0 100644
--- a/Network/Lobby.gd
+++ b/Network/Lobby.gd
@@ -7,6 +7,7 @@ func _ready():
Network.connect("player_list_changed", self, "refresh_lobby")
Network.connect("game_error", self, "_on_game_error")
Network.connect("game_ended", self, "_on_game_ended")
+ $HTTPRequest.connect("request_completed", self, '_set_remote_ip')
if OS.has_environment("USERNAME"):
$Connect/Name.text = OS.get_environment("USERNAME")
@@ -39,11 +40,27 @@ func refresh_lobby():
func set_ip():
+ self.set_local_ip()
+ self.set_remote_ip()
+
+func set_local_ip():
for ip in IP.get_local_addresses():
if ip.begins_with("192.168"):
- $Players/IP.text = ip
+ $Players/LocalIP.text = ip
break
+func set_remote_ip():
+ $Players/RemoteIP.text = ""
+ $HTTPRequest.request("https://ipv4.icanhazip.com/")
+
+func _set_remote_ip(result, response_code, headers, body):
+ if response_code == 200:
+ $Players/RemoteIP.text = body.get_string_from_utf8()
+ else:
+ $Players/RemoteIP.text = "Remote IP request failed!"
+ self._on_game_error("Remote IP request failed!")
+
+
func _on_connection_succeeded():
$Connect.hide()
$Players.show()
diff --git a/Network/Lobby.tscn b/Network/Lobby.tscn
index cbe5be9..d019cc0 100644
--- a/Network/Lobby.tscn
+++ b/Network/Lobby.tscn
@@ -78,11 +78,22 @@ __meta__ = {
"_edit_use_anchors_": false
}
-[node name="IP" type="Label" parent="Players"]
+[node name="LocalIP" type="Label" parent="Players"]
margin_left = 128.0
-margin_top = 16.0
+margin_top = 24.0
margin_right = 240.0
-margin_bottom = 30.0
+margin_bottom = 38.0
+text = "000.000.000.000"
+align = 2
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="RemoteIP" type="Label" parent="Players"]
+margin_left = 128.0
+margin_top = 8.0
+margin_right = 240.0
+margin_bottom = 22.0
text = "000.000.000.000"
align = 2
__meta__ = {
@@ -123,6 +134,8 @@ margin_bottom = 58.0
[node name="MenuButton" parent="." instance=ExtResource( 2 )]
margin_left = 976.0
margin_right = 0.0
+
+[node name="HTTPRequest" type="HTTPRequest" parent="."]
[connection signal="pressed" from="Connect/Host" to="." method="_on_Host_pressed"]
[connection signal="pressed" from="Connect/Join" to="." method="_on_Join_pressed"]
[connection signal="pressed" from="Players/Start" to="." method="_on_Start_pressed"]