#include "./ngc_ext_common.hpp" //#include //#include #include //#include //#include //#include //#include //#include bool _GroupKey::operator<(const _GroupKey& rhs) const { for (size_t i = 0; i < data.size(); i++) { if (data[i] < rhs.data[i]) { return true; } else if (data[i] > rhs.data[i]) { return false; } } return false; // equal } bool _GroupKey::operator==(const _GroupKey& rhs) const { for (size_t i = 0; i < data.size(); i++) { if (data[i] != rhs.data[i]) { return false; } } return true; } bool _PeerKey::operator<(const _PeerKey& rhs) const { for (size_t i = 0; i < data.size(); i++) { if (data[i] < rhs.data[i]) { return true; } else if (data[i] > rhs.data[i]) { return false; } } return false; // equal } bool _PeerKey::operator==(const _PeerKey& rhs) const { for (size_t i = 0; i < data.size(); i++) { if (data[i] != rhs.data[i]) { return false; } } return true; } NGC_EXT_CTX* NGC_EXT_new(void) { auto* ctx = new NGC_EXT_CTX; // TODO: this is likely not necessary for (auto& it : ctx->callbacks) { it = nullptr; } return ctx; } void NGC_EXT_kill(NGC_EXT_CTX* ngc_ext_ctx) { delete ngc_ext_ctx; } #define _EXT_HAVE(x, error) if ((length - curser) < (x)) { error; } void NGC_EXT_handle_group_custom_packet( Tox* tox, NGC_EXT_CTX* ngc_ext_ctx, uint32_t group_number, uint32_t peer_number, const uint8_t *data, size_t length //void *user_data ) { size_t curser = 0; _EXT_HAVE(1, return) _PacketType pkg_type = static_cast<_PacketType>(*(data + curser)); curser++; fprintf(stderr, "custom_packet [%s] %lu\n", _pkgid2str(pkg_type), length); if (pkg_type == INVALID) { fprintf(stderr, "(invalid)\n"); return; } auto handle_fn = ngc_ext_ctx->callbacks[pkg_type]; if (handle_fn == nullptr) { fprintf(stderr, "!!! no handler for packet\n"); return; } handle_fn(tox, ngc_ext_ctx, group_number, peer_number, data+curser, length-curser); } #undef _EXT_HAVE