Ejemplo n.º 1
0
void NodeList::sendKeepAlivePings() {
    eachMatchingNode([this](const SharedNodePointer& node)->bool {
        return _nodeTypesOfInterest.contains(node->getType());
    }, [&](const SharedNodePointer& node) {
        sendPacket(constructPingPacket(), *node);
    });
}
Ejemplo n.º 2
0
void Agent::sendPingRequests() {
    auto nodeList = DependencyManager::get<NodeList>();

    nodeList->eachMatchingNode([](const SharedNodePointer& node)->bool {
        switch (node->getType()) {
        case NodeType::AvatarMixer:
        case NodeType::AudioMixer:
        case NodeType::EntityServer:
            return true;
        default:
            return false;
        }
    }, [nodeList](const SharedNodePointer& node) {
        nodeList->sendPacket(nodeList->constructPingPacket(), *node);
    });
}
Ejemplo n.º 3
0
void MessagesMixer::handleMessages(QSharedPointer<NLPacketList> packetList, SharedNodePointer senderNode) {
    QString channel, message;
    QUuid senderID;
    MessagesClient::decodeMessagesPacket(packetList, channel, message, senderID);

    auto nodeList = DependencyManager::get<NodeList>();

    nodeList->eachMatchingNode(
        [&](const SharedNodePointer& node)->bool {
        return node->getType() == NodeType::Agent && node->getActiveSocket() &&
                _channelSubscribers[channel].contains(node->getUUID());
    },
        [&](const SharedNodePointer& node) {
        auto packetList = MessagesClient::encodeMessagesPacket(channel, message, senderID);
        nodeList->sendPacketList(std::move(packetList), *node);
    });
}
Ejemplo n.º 4
0
void MessagesMixer::handleMessages(QSharedPointer<NLPacketList> packetList, SharedNodePointer senderNode) {
    Q_ASSERT(packetList->getType() == PacketType::MessagesData);

    QByteArray packetData = packetList->getMessage();
    QBuffer packet{ &packetData };
    packet.open(QIODevice::ReadOnly);

    quint16 channelLength;
    packet.read(reinterpret_cast<char*>(&channelLength), sizeof(channelLength));
    auto channelData = packet.read(channelLength);
    QString channel = QString::fromUtf8(channelData);

    quint16 messageLength;
    packet.read(reinterpret_cast<char*>(&messageLength), sizeof(messageLength));
    auto messageData = packet.read(messageLength);
    QString message = QString::fromUtf8(messageData);
    
    auto nodeList = DependencyManager::get<NodeList>();

    nodeList->eachMatchingNode(
        [&](const SharedNodePointer& node)->bool {

        return node->getType() == NodeType::Agent && node->getActiveSocket() &&
                _channelSubscribers[channel].contains(node->getUUID());
    },
        [&](const SharedNodePointer& node) {

        auto packetList = NLPacketList::create(PacketType::MessagesData, QByteArray(), true, true);

        auto channelUtf8 = channel.toUtf8();
        quint16 channelLength = channelUtf8.length();
        packetList->writePrimitive(channelLength);
        packetList->write(channelUtf8);

        auto messageUtf8 = message.toUtf8();
        quint16 messageLength = messageUtf8.length();
        packetList->writePrimitive(messageLength);
        packetList->write(messageUtf8);

        nodeList->sendPacketList(std::move(packetList), *node);
    });
}