120 lines
3.7 KiB
C++
120 lines
3.7 KiB
C++
#pragma once
|
|
|
|
#include "core/object/class_db.h"
|
|
#include "core/object/object.h"
|
|
#include "you_done_it/macros.h"
|
|
#include "zmq.hpp"
|
|
#include "zmq_addon.hpp"
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
class NetworkData : public Object {
|
|
GDCLASS(NetworkData, Object);
|
|
static void _bind_methods();
|
|
|
|
public:
|
|
GDENUM(MessageType,
|
|
MSG_NONE,
|
|
// connection management messages
|
|
MSG_CONNECT,
|
|
MSG_OK,
|
|
MSG_NOK,
|
|
MSG_HEART,
|
|
MSG_BEAT,
|
|
// gameplay messages
|
|
MSG_REVEAL,
|
|
MSG_CONCLUSION,
|
|
// end of messages
|
|
MSG_INVALID);
|
|
|
|
GDENUM(ClueID,
|
|
CLUE_STAPLER,
|
|
CLUE_VICTIM_BLOOD,
|
|
CLUE_MURDERER_BLOOD,
|
|
CLUE_KNIFE,
|
|
CLUE_APPLE,
|
|
CLUE_CONTRACT_FLOYD,
|
|
CLUE_FOOTPRINTS_DOOR,
|
|
CLUE_BUSINESS_CARD_BARNEY,
|
|
CLUE_CONTRACT_FLORA,
|
|
CLUE_FINGERPRINT,
|
|
CLUE_HAIR,
|
|
CLUE_FLORA_LAMB,
|
|
CLUE_VELMA_GRAVES,
|
|
CLUE_FLOYD_HUNT,
|
|
CLUE_RICHARD_OBRIEN,
|
|
CLUE_GORDON_CHEVIELD,
|
|
CLUE_SADIE_WOOD,
|
|
CLUE_URSULA_GLASS,
|
|
CLUE_BARNEY_ORTIZ,
|
|
CLUE_AMOS_SHWARTZ,
|
|
CLUE_GRACE_ROSS,
|
|
CLUE_BUSINESS_CARD_VELMA,
|
|
CLUE_VICTIM_BLOOD_TABLE,
|
|
CLUE_FOOTPRINTS_BLOODY,
|
|
CLUE_BODY,
|
|
CLUE_MAX);
|
|
|
|
GDENUM(ConnectionStatus,
|
|
CONNECTION_DISCONNECTED,
|
|
CONNECTION_CONNECTED,
|
|
CONNECTION_AUTHENTICATED);
|
|
|
|
enum NOKReason {
|
|
NOK_UNAUTHENTICATED, //!< message sender is not known by recipient.
|
|
NOK_UNKNOWN_MSG, //!< message type is not valid now or ever for recipient.
|
|
NOK_OUT_OF_CONTEXT, //!< this means a received message type is not valid in the recipient's current state, but COULD otherwise be valid.
|
|
NOK_MALFORMED_ARGUMENTS, //!< message type is valid but arguments could not be interpreted.
|
|
NOK_INVALID_REASON //!< this means the value could not be parsed as a NOKReason, not that the reason is an invalid message. Use UNKNOWN_MSG for that.
|
|
};
|
|
};
|
|
|
|
MAKE_TYPE_INFO(NetworkData::ClueID, Variant::INT);
|
|
MAKE_TYPE_INFO(NetworkData::ConnectionStatus, Variant::INT);
|
|
|
|
namespace ydi {
|
|
int to_int(zmq::message_t const &msg, int failure = 0);
|
|
NetworkData::MessageType to_message_type(zmq::message_t const &msg);
|
|
NetworkData::NOKReason to_nok_reason(zmq::message_t const &msg);
|
|
NetworkData::ClueID to_clue_id(zmq::message_t const &msg);
|
|
|
|
void print_message_contents(zmq::multipart_t const &mpart);
|
|
|
|
void extend_multipart(zmq::multipart_t &mpart, NetworkData::MessageType type);
|
|
void extend_multipart(zmq::multipart_t &mpart, NetworkData::ClueID id);
|
|
|
|
void extend_multipart(zmq::multipart_t &mpart, std::string const &string);
|
|
void extend_multipart(zmq::multipart_t &mpart, std::string_view const &strv);
|
|
void extend_multipart(zmq::multipart_t &mpart, char const *cstr);
|
|
void extend_multipart(zmq::multipart_t &mpart, int const &arg);
|
|
void extend_multipart(zmq::multipart_t &mpart, zmq::multipart_t const &right);
|
|
void extend_multipart(zmq::multipart_t &mpart, std::pair<zmq::multipart_t::iterator, zmq::multipart_t::iterator> range);
|
|
void extend_multipart(zmq::multipart_t &mpart, std::pair<zmq::multipart_t::const_iterator, zmq::multipart_t::const_iterator> range);
|
|
|
|
void extend_multipart(zmq::multipart_t &mpart);
|
|
|
|
template <typename TArg>
|
|
void extend_multipart_recurse(zmq::multipart_t &mpart, TArg const &arg) {
|
|
extend_multipart(mpart, arg);
|
|
}
|
|
|
|
template <typename TArg, typename... TArgs>
|
|
void extend_multipart_recurse(zmq::multipart_t &mpart, TArg const &arg, TArgs const &...args) {
|
|
extend_multipart(mpart, arg);
|
|
extend_multipart_recurse(mpart, args...);
|
|
}
|
|
|
|
template <typename TArg>
|
|
zmq::multipart_t multipart(TArg const &arg) {
|
|
zmq::multipart_t mpart{};
|
|
extend_multipart(mpart, arg);
|
|
return mpart;
|
|
}
|
|
|
|
template <typename TArg, typename... TArgs>
|
|
zmq::multipart_t multipart(TArg const &arg, TArgs const &...args) {
|
|
zmq::multipart_t mpart{ multipart(arg) };
|
|
extend_multipart_recurse(mpart, args...);
|
|
return mpart;
|
|
}
|
|
} //namespace ydi
|