Compare commits
2 commits
cfb901ec46
...
eafdbba3d7
| Author | SHA1 | Date | |
|---|---|---|---|
| eafdbba3d7 | |||
| 6add0813d1 |
7 changed files with 120 additions and 30 deletions
|
|
@ -11,6 +11,6 @@ config_version=5
|
|||
[application]
|
||||
|
||||
config/name="you_done_it"
|
||||
run/main_scene="uid://bbvpj46frv0ho"
|
||||
run/main_scene="uid://dosb4sb7pvss4"
|
||||
config/features=PackedStringArray("4.5", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
[gd_scene format=3 uid="uid://dosb4sb7pvss4"]
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dosb4sb7pvss4"]
|
||||
|
||||
[node name="ServerNode" type="ServerNode"]
|
||||
[sub_resource type="QuadMesh" id="QuadMesh_usqe2"]
|
||||
|
||||
[node name="AspectRatioContainer" type="AspectRatioContainer" parent="."]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
ratio = 1.7778
|
||||
[node name="FlatscreenRoot" type="Node2D"]
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="AspectRatioContainer"]
|
||||
layout_mode = 2
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
|
||||
[node name="MeshInstance2D" type="MeshInstance2D" parent="."]
|
||||
position = Vector2(142, -50)
|
||||
scale = Vector2(762.00006, 514)
|
||||
mesh = SubResource("QuadMesh_usqe2")
|
||||
|
|
|
|||
68
flatscreen-project/scenes/start_server_ui.tscn
Normal file
68
flatscreen-project/scenes/start_server_ui.tscn
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://owa17yo7q6wo"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_usqe2"]
|
||||
resource_name = "StartServerUI"
|
||||
script/source = "extends CenterContainer
|
||||
|
||||
@onready var label := $VBoxContainer/ConnectingText
|
||||
@onready var open_server_btn := $VBoxContainer/OpenServerButton
|
||||
@onready var close_server_btn := $VBoxContainer/CloseServerButton
|
||||
|
||||
func _ready():
|
||||
ServerNode.get_singleton().connection_established.connect(self._on_server_node_connection_established)
|
||||
|
||||
func _on_open_button_pressed() -> void:
|
||||
if not ServerNode.get_singleton().is_open():
|
||||
if ServerNode.get_singleton().open():
|
||||
label.visible = true
|
||||
close_server_btn.visible = true
|
||||
open_server_btn.visible = false
|
||||
|
||||
func _on_close_button_pressed() -> void:
|
||||
if ServerNode.get_singleton().is_open():
|
||||
ServerNode.get_singleton().close()
|
||||
label.visible = false
|
||||
close_server_btn.visible = false
|
||||
open_server_btn.visible = true
|
||||
|
||||
func _on_server_node_connection_established() -> void:
|
||||
self.visible = false
|
||||
"
|
||||
|
||||
[node name="StartServerUI" type="CenterContainer"]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
script = SubResource("GDScript_usqe2")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="OpenServerButton" type="Button" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Host Game Server"
|
||||
|
||||
[node name="CloseServerButton" type="Button" parent="VBoxContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
text = "Cancel Connection"
|
||||
|
||||
[node name="ConnectingText" type="Label" parent="VBoxContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
text = "Waiting for client..."
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="PermissionsText" type="Label" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Requires permissions to open port 6667.
|
||||
If you have a firewall on your system you
|
||||
may need to open configure it"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[connection signal="pressed" from="VBoxContainer/OpenServerButton" to="." method="_on_open_button_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/CloseServerButton" to="." method="_on_close_button_pressed"]
|
||||
|
|
@ -13,6 +13,9 @@ void ServerNode::_bind_methods() {
|
|||
ADD_SIGNAL(MethodInfo(sig_connection_lost));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("open"), &self_type::open);
|
||||
ClassDB::bind_method(D_METHOD("close"), &self_type::close);
|
||||
ClassDB::bind_method(D_METHOD("is_open"), &self_type::is_open);
|
||||
ClassDB::bind_static_method(self_type::get_class_static(), "get_singleton", &self_type::get_singleton);
|
||||
}
|
||||
|
||||
void ServerNode::enter_tree() {
|
||||
|
|
@ -25,17 +28,20 @@ void ServerNode::enter_tree() {
|
|||
}
|
||||
|
||||
void ServerNode::process(double delta) {
|
||||
bool new_is_connected{ ydi::server::has_client() };
|
||||
if (this->is_connected != new_is_connected) {
|
||||
this->is_connected = new_is_connected;
|
||||
emit_signal(this->is_connected ? sig_connection_established : sig_connection_lost);
|
||||
}
|
||||
if (!ydi::server::has_client()) {
|
||||
return;
|
||||
}
|
||||
Vector<NetworkData::ClueID> new_clues{};
|
||||
if (ydi::server::receive::new_clues(new_clues)) {
|
||||
for (NetworkData::ClueID clue : new_clues) {
|
||||
emit_signal(sig_clue_revealed, clue);
|
||||
}
|
||||
}
|
||||
bool new_is_connected{ ydi::server::has_client() };
|
||||
if (this->is_connected != new_is_connected) {
|
||||
this->is_connected = new_is_connected;
|
||||
emit_signal(this->is_connected ? sig_connection_established : sig_connection_lost);
|
||||
}
|
||||
}
|
||||
|
||||
void ServerNode::exit_tree() {
|
||||
|
|
@ -69,6 +75,14 @@ ServerNode *ServerNode::get_singleton() {
|
|||
return singleton_instance;
|
||||
}
|
||||
|
||||
void ServerNode::open() {
|
||||
ydi::server::open();
|
||||
bool ServerNode::open() {
|
||||
return ydi::server::open();
|
||||
}
|
||||
|
||||
void ServerNode::close() {
|
||||
ydi::server::close();
|
||||
}
|
||||
|
||||
bool ServerNode::is_open() const {
|
||||
return ydi::server::is_running();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@ protected:
|
|||
|
||||
public:
|
||||
static ServerNode *get_singleton();
|
||||
void open();
|
||||
bool open();
|
||||
void close();
|
||||
bool is_open() const;
|
||||
|
||||
public:
|
||||
static String const sig_clue_revealed;
|
||||
|
|
|
|||
|
|
@ -99,10 +99,10 @@ void receive_thread_entry() {
|
|||
}
|
||||
}
|
||||
|
||||
void open() {
|
||||
bool open() {
|
||||
if (service) {
|
||||
print_error("Server: Detected attempt to open duplicate Server, exiting without action.");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
print_line("Server: Starting");
|
||||
service.emplace();
|
||||
|
|
@ -111,7 +111,7 @@ void open() {
|
|||
} catch (...) {
|
||||
service.reset();
|
||||
print_line("Server: Failed to create context");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
print_line("Server: Created zmq context");
|
||||
try {
|
||||
|
|
@ -121,7 +121,7 @@ void open() {
|
|||
service->context.reset();
|
||||
service.reset();
|
||||
print_line("Server: Failed to create socket");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
print_line("Server: Created socket");
|
||||
try {
|
||||
|
|
@ -133,12 +133,13 @@ void open() {
|
|||
service->context.reset();
|
||||
service.reset();
|
||||
print_line("Server: Failed to bind socket");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
print_line("Server: Bound socket");
|
||||
receive_thread.emplace(receive_thread_entry);
|
||||
assert(receive_thread->joinable());
|
||||
print_line("Server: Startup complete!");
|
||||
return true;
|
||||
}
|
||||
|
||||
void close() {
|
||||
|
|
@ -170,16 +171,22 @@ void close() {
|
|||
}
|
||||
|
||||
bool has_client() {
|
||||
if (service) {
|
||||
std::scoped_lock lock{ service->mtx };
|
||||
return service->client.has_value();
|
||||
} else {
|
||||
if (!service) {
|
||||
return false;
|
||||
}
|
||||
std::scoped_lock lock{ service->mtx };
|
||||
return service->client.has_value();
|
||||
}
|
||||
|
||||
bool is_running() {
|
||||
return service.has_value();
|
||||
}
|
||||
|
||||
namespace receive {
|
||||
bool new_clues(Vector<NetworkData::ClueID> &out) {
|
||||
if (!service) {
|
||||
return false;
|
||||
}
|
||||
std::scoped_lock lock{ service->mtx };
|
||||
bool const has_new{ !service->new_clues.is_empty() };
|
||||
if (has_new) {
|
||||
|
|
|
|||
|
|
@ -5,9 +5,10 @@
|
|||
#include <cassert>
|
||||
|
||||
namespace ydi::server {
|
||||
void open();
|
||||
bool open();
|
||||
void close();
|
||||
bool has_client();
|
||||
bool is_running();
|
||||
|
||||
namespace receive {
|
||||
bool new_clues(Vector<NetworkData::ClueID> &out);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue