From 0882c770f4bbd5e4cb63e0da56e547862136960e Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 21 Sep 2020 15:17:29 +0200 Subject: [PATCH 1/3] Added host as spectator option. Fix #15 --- Game.gd | 7 ++++--- Game.tscn | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Game.gd b/Game.gd index 8f0439c..fb956ed 100644 --- a/Game.gd +++ b/Game.gd @@ -1,4 +1,4 @@ -extends Spatial +extends Node export var SERVER_PORT = 9999 setget , get_port export(String, "172.28.162.191", "172.28.166.24", "127.0.0.1") var SERVER_IP = "172.28.162.191" setget , get_ip @@ -136,14 +136,15 @@ func get_ip(): func get_port(): return SERVER_PORT -func initialize_server(): +func initialize_server(join=true): var peer = NetworkedMultiplayerENet.new() peer.create_server(SERVER_PORT, MAX_PLAYERS) get_tree().connect("network_peer_connected", self, "on_peer_connected") get_tree().connect("network_peer_disconnected", self, "on_peer_disconnected") get_tree().network_peer = peer close_menus() - add_player(1, false) + if join: + add_player(1, false) func initialize_client(): var peer = NetworkedMultiplayerENet.new() diff --git a/Game.tscn b/Game.tscn index 3d57adf..a7f7496 100644 --- a/Game.tscn +++ b/Game.tscn @@ -26,7 +26,7 @@ glow_blend_mode = 0 glow_hdr_threshold = 1.5 glow_bicubic_upscale = true -[node name="Game" type="Spatial"] +[node name="Game" type="Node"] script = ExtResource( 2 ) SERVER_IP = "127.0.0.1" @@ -68,6 +68,8 @@ margin_bottom = 24.0 size_flags_horizontal = 3 size_flags_stretch_ratio = 2.38 placeholder_text = "IP address" +caret_blink = true +caret_blink_speed = 0.5 [node name="Port" type="LineEdit" parent="MenuContainer/MainMenu/Destination"] margin_left = 282.0 @@ -75,6 +77,8 @@ margin_right = 400.0 margin_bottom = 24.0 size_flags_horizontal = 3 placeholder_text = "port" +caret_blink = true +caret_blink_speed = 0.5 [node name="NetworkType" type="HBoxContainer" parent="MenuContainer/MainMenu"] margin_top = 52.0 @@ -82,13 +86,20 @@ margin_right = 400.0 margin_bottom = 72.0 [node name="Host" type="Button" parent="MenuContainer/MainMenu/NetworkType"] -margin_right = 198.0 +margin_right = 130.0 margin_bottom = 20.0 size_flags_horizontal = 3 text = "Host" +[node name="HostAsSpectator" type="Button" parent="MenuContainer/MainMenu/NetworkType"] +margin_left = 134.0 +margin_right = 265.0 +margin_bottom = 20.0 +size_flags_horizontal = 3 +text = "Host As Spectator" + [node name="Join" type="Button" parent="MenuContainer/MainMenu/NetworkType"] -margin_left = 202.0 +margin_left = 269.0 margin_right = 400.0 margin_bottom = 20.0 size_flags_horizontal = 3 @@ -221,6 +232,7 @@ text = "Fullscreen" [connection signal="pressed" from="MenuContainer/MainMenu/QuickJoin" to="." method="open_menu" binds= [ "QuickJoinMenu" ]] [connection signal="text_changed" from="MenuContainer/MainMenu/Destination/IPAdress" to="." method="set_ip"] [connection signal="pressed" from="MenuContainer/MainMenu/NetworkType/Host" to="." method="initialize_server"] +[connection signal="pressed" from="MenuContainer/MainMenu/NetworkType/HostAsSpectator" to="." method="initialize_server" binds= [ false ]] [connection signal="pressed" from="MenuContainer/MainMenu/NetworkType/Join" to="." method="initialize_client"] [connection signal="pressed" from="MenuContainer/MainMenu/Options" to="." method="open_menu" binds= [ "OptionsMenu" ]] [connection signal="pressed" from="MenuContainer/MainMenu/Quit" to="." method="quit"] From 2a0a7f19ffc0e72c106795538702df14e394accc Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 21 Sep 2020 17:01:39 +0200 Subject: [PATCH 2/3] Added auto host option and server scene to automatically start server through CLI --- Game.gd | 14 ++++++++++---- Game.tscn | 1 - Server.tscn | 6 ++++++ 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 Server.tscn diff --git a/Game.gd b/Game.gd index fb956ed..191a0bc 100644 --- a/Game.gd +++ b/Game.gd @@ -1,9 +1,10 @@ extends Node export var SERVER_PORT = 9999 setget , get_port -export(String, "172.28.162.191", "172.28.166.24", "127.0.0.1") var SERVER_IP = "172.28.162.191" setget , get_ip +export(String, "172.28.162.191", "172.28.166.24", "127.0.0.1") var SERVER_IP = "172.28.162.191" setget , get_ip export var MAX_PLAYERS = 10 export (String, "MENU", "PLAYING") var GAME_MODE = "MENU" +export var auto_host = false var mouse_sensitivity_multiplier = 1.0 @@ -20,6 +21,10 @@ func _ready(): $MenuContainer/MainMenu/Destination/Port.set_text(str(SERVER_PORT)) load_settings() + + if auto_host: + initialize_server(false) + print("qwueyhgfiuyqwgaadsf") func load_settings(): var load_settings = File.new() @@ -71,9 +76,10 @@ func open_menus(): $MenuContainer.show() func close_menus(): - GAME_MODE = "PLAYING" - Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) - $MenuContainer.hide() + if has_node("MenuContainer"): + GAME_MODE = "PLAYING" + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + $MenuContainer.hide() func return_to_menu(type): for menu in $MenuContainer.get_children(): diff --git a/Game.tscn b/Game.tscn index a7f7496..c40ffdf 100644 --- a/Game.tscn +++ b/Game.tscn @@ -36,7 +36,6 @@ environment = SubResource( 2 ) [node name="Level" parent="." instance=ExtResource( 3 )] [node name="Players" type="Spatial" parent="."] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 12.6315, 8.00684, -4.99273 ) [node name="MenuContainer" type="CenterContainer" parent="."] anchor_right = 1.0 diff --git a/Server.tscn b/Server.tscn new file mode 100644 index 0000000..c06ce81 --- /dev/null +++ b/Server.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Game.tscn" type="PackedScene" id=2] + +[node name="Game" instance=ExtResource( 2 )] +auto_host = true From b3c65bb0d45e4080bb972ffbc651515fb137d003 Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 21 Sep 2020 19:40:53 +0200 Subject: [PATCH 3/3] For testing purposes, made port 80 the default port --- Game.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Game.gd b/Game.gd index 191a0bc..dfc9e29 100644 --- a/Game.gd +++ b/Game.gd @@ -1,6 +1,6 @@ extends Node -export var SERVER_PORT = 9999 setget , get_port +export var SERVER_PORT = 80 setget , get_port export(String, "172.28.162.191", "172.28.166.24", "127.0.0.1") var SERVER_IP = "172.28.162.191" setget , get_ip export var MAX_PLAYERS = 10 export (String, "MENU", "PLAYING") var GAME_MODE = "MENU"