feat: full flow from startup to gameplay & clues sending
This commit is contained in:
parent
c765f7daf9
commit
261694773f
9 changed files with 213 additions and 12 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#include "client_node.h"
|
||||
#include "core/config/engine.h"
|
||||
#include "scene/main/node.h"
|
||||
#include "you_done_it/clue_data.h"
|
||||
#include "you_done_it/clue_db.h"
|
||||
#include "you_done_it/ydi_client.h"
|
||||
|
|
@ -54,6 +55,19 @@ void ClientNode::_notification(int what) {
|
|||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
return;
|
||||
}
|
||||
switch (what) {
|
||||
default:
|
||||
return;
|
||||
case NOTIFICATION_ENTER_TREE:
|
||||
set_process(true);
|
||||
return;
|
||||
case NOTIFICATION_PROCESS:
|
||||
process();
|
||||
return;
|
||||
case NOTIFICATION_EXIT_TREE:
|
||||
exit_tree();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ClientNode *ClientNode::get_singleton() {
|
||||
|
|
|
|||
|
|
@ -34,8 +34,6 @@ void handle_ok(zmq::multipart_t const &message) {
|
|||
}
|
||||
|
||||
void handle_message(zmq::multipart_t const &message) {
|
||||
print_line("Client handle_message:");
|
||||
print_message_contents(message);
|
||||
NetworkData::MessageType type{ to_message_type(message[0]) };
|
||||
switch (type) {
|
||||
case NetworkData::MSG_OK:
|
||||
|
|
@ -43,11 +41,11 @@ void handle_message(zmq::multipart_t const &message) {
|
|||
handle_ok(message);
|
||||
return;
|
||||
case NetworkData::MSG_HEART:
|
||||
print_line("Client: Received HEART, sending BEAT");
|
||||
multipart(NetworkData::MSG_BEAT).send(*connection->socket);
|
||||
return;
|
||||
default:
|
||||
print_line("Client: Message not handled");
|
||||
print_line("Client: Message not handled:");
|
||||
print_message_contents(message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -132,12 +130,18 @@ void disconnect() {
|
|||
}
|
||||
|
||||
NetworkData::ConnectionStatus status() {
|
||||
return connection ? NetworkData::ConnectionStatus(connection->status) : NetworkData::CONNECTION_DISCONNECTED;
|
||||
if (!connection) {
|
||||
return NetworkData::CONNECTION_DISCONNECTED;
|
||||
} else {
|
||||
std::scoped_lock lock{ connection->mtx };
|
||||
return connection->status;
|
||||
}
|
||||
}
|
||||
|
||||
namespace send {
|
||||
void reveal_clue(NetworkData::ClueID id) {
|
||||
if (connection) {
|
||||
print_line("Sending Clue ", id);
|
||||
std::scoped_lock lock{ connection->mtx };
|
||||
multipart(NetworkData::MSG_REVEAL, id).send(*connection->socket);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ void handle_reveal_clue(zmq::multipart_t const &message) {
|
|||
void handle_authorised_message(std::string_view const &sender, NetworkData::MessageType type, zmq::multipart_t &message) {
|
||||
switch (type) {
|
||||
case NetworkData::MSG_BEAT:
|
||||
print_line("Server: Received beat, storing timestamp");
|
||||
service->lastBeat = Time::get_singleton()->get_unix_time_from_system();
|
||||
return;
|
||||
case NetworkData::MSG_REVEAL:
|
||||
|
|
@ -44,6 +43,7 @@ void handle_authorised_message(std::string_view const &sender, NetworkData::Mess
|
|||
return;
|
||||
default:
|
||||
print_line("Server: Encountered unknown message type, sending NOK_UNKNOWN_MSG response");
|
||||
print_message_contents(message);
|
||||
multipart(sender, NetworkData::MSG_NOK, NetworkData::NOK_UNKNOWN_MSG, message).send(*service->socket);
|
||||
return;
|
||||
}
|
||||
|
|
@ -60,15 +60,12 @@ void ping_thread_entry() {
|
|||
while (!service->stop_threads) {
|
||||
std::this_thread::sleep_for(1s);
|
||||
std::scoped_lock lock{ service->mtx };
|
||||
print_line("Server: Send HEART");
|
||||
multipart(*service->client, NetworkData::MSG_HEART).send(*service->socket);
|
||||
service->lastHeart = Time::get_singleton()->get_unix_time_from_system();
|
||||
}
|
||||
}
|
||||
|
||||
void handle_message(zmq::multipart_t &message) {
|
||||
print_line("Server handle_message:");
|
||||
print_message_contents(message);
|
||||
std::string_view const sender{ message.at(0).to_string_view() };
|
||||
NetworkData::MessageType type{ to_message_type(message.at(1)) };
|
||||
std::scoped_lock lock{ service->mtx };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue