feat: implemented full connection protocol (both)
This commit is contained in:
parent
acb7351ea7
commit
8086924141
12 changed files with 268 additions and 73 deletions
|
|
@ -2,9 +2,16 @@
|
|||
#include "ydi_server.h"
|
||||
#include <core/config/engine.h>
|
||||
|
||||
String const ServerNode::sig_clue_revealed{ "clue_revealed" };
|
||||
String const ServerNode::sig_connection_established{ "connection_established" };
|
||||
String const ServerNode::sig_connection_lost{ "connection_lost" };
|
||||
|
||||
void ServerNode::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("new_clue", PropertyInfo(Variant::INT, "id")));
|
||||
ADD_SIGNAL(MethodInfo(sig_clue_revealed, PropertyInfo(Variant::INT, "id")));
|
||||
ADD_SIGNAL(MethodInfo(sig_connection_established));
|
||||
ADD_SIGNAL(MethodInfo(sig_connection_lost));
|
||||
}
|
||||
|
||||
void ServerNode::enter_tree() {
|
||||
ydi::server::open();
|
||||
}
|
||||
|
|
@ -13,9 +20,14 @@ void ServerNode::process(double delta) {
|
|||
Vector<NetworkData::ClueID> new_clues{};
|
||||
if (ydi::server::receive::new_clues(new_clues)) {
|
||||
for (NetworkData::ClueID clue : new_clues) {
|
||||
emit_signal("new_clue", clue);
|
||||
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() {
|
||||
|
|
@ -28,6 +40,7 @@ void ServerNode::_notification(int what) {
|
|||
}
|
||||
switch (what) {
|
||||
case NOTIFICATION_ENTER_TREE:
|
||||
set_process(true);
|
||||
enter_tree();
|
||||
return;
|
||||
case NOTIFICATION_PROCESS:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue