Handle domain reconnections

This commit is contained in:
Atlante45 2017-02-01 14:09:12 -08:00
parent 191121888c
commit 35f8afe456
2 changed files with 27 additions and 6 deletions

View file

@ -18,18 +18,21 @@ EntityScriptServerLogDialog::EntityScriptServerLogDialog(QWidget* parent) : Base
auto& packetReceiver = nodeList->getPacketReceiver();
packetReceiver.registerListener(PacketType::EntityServerScriptLog, this, "handleEntityServerScriptLogPacket");
auto shouldEnableLog = [this] {
auto nodeList = DependencyManager::get<NodeList>();
enableToEntityServerScriptLog(nodeList->getThisNodeCanRez() || nodeList->getThisNodeCanRezTmp());
};
QObject::connect(nodeList.data(), &NodeList::canRezChanged, this, shouldEnableLog);
QObject::connect(nodeList.data(), &NodeList::canRezTmpChanged, this, shouldEnableLog);
QObject::connect(nodeList.data(), &NodeList::nodeActivated, this, &EntityScriptServerLogDialog::nodeActivated);
QObject::connect(nodeList.data(), &NodeList::nodeKilled, this, &EntityScriptServerLogDialog::nodeKilled);
QObject::connect(nodeList.data(), &NodeList::canRezChanged, this, &EntityScriptServerLogDialog::shouldEnableLog);
QObject::connect(nodeList.data(), &NodeList::canRezTmpChanged, this, &EntityScriptServerLogDialog::shouldEnableLog);
shouldEnableLog();
}
EntityScriptServerLogDialog::~EntityScriptServerLogDialog() {
enableToEntityServerScriptLog(false);
}
void EntityScriptServerLogDialog::shouldEnableLog() {
auto nodeList = DependencyManager::get<NodeList>();
enableToEntityServerScriptLog(nodeList->getThisNodeCanRez() || nodeList->getThisNodeCanRezTmp());
};
void EntityScriptServerLogDialog::enableToEntityServerScriptLog(bool enable) {
auto nodeList = DependencyManager::get<NodeList>();
@ -56,3 +59,16 @@ void EntityScriptServerLogDialog::handleEntityServerScriptLogPacket(QSharedPoint
auto lines = QString::fromUtf8(message->readAll());
QMetaObject::invokeMethod(this, "appendLogLine", Q_ARG(QString, lines));
}
void EntityScriptServerLogDialog::nodeActivated(SharedNodePointer activatedNode) {
if (_subscribed && activatedNode->getType() == NodeType::EntityScriptServer) {
_subscribed = false;
shouldEnableLog();
}
}
void EntityScriptServerLogDialog::nodeKilled(SharedNodePointer killedNode) {
if (killedNode->getType() == NodeType::EntityScriptServer) {
appendLogLine("====================== Connection to the Entity Script Server lost ======================");
}
}

View file

@ -30,6 +30,11 @@ private slots:
void enableToEntityServerScriptLog(bool enable);
void handleEntityServerScriptLogPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
void nodeActivated(SharedNodePointer activatedNode);
void nodeKilled(SharedNodePointer killedNode);
void shouldEnableLog();
private:
bool _subscribed { false };
};