History

add a guard for trading entity servers by checking node count

Stephen Birarda committed 9 years ago

Commit 0a118bd1 parent c63a2c91 file · +20 −1Browse files

Showing the changes to assignment-client/src/scripts/EntityScriptServer.cpp (1 of 1 file). Show all

Unified · Split

assignment-client/src/scripts/EntityScriptServer.cpp+20−1
@@ -326,7 +326,26 @@ void EntityScriptServer::nodeActivated(SharedNodePointer activatedNode) { · 325 unmodified lines
326326 void EntityScriptServer::nodeKilled(SharedNodePointer killedNode) {
327327 switch (killedNode->getType()) {
328328 case NodeType::EntityServer: {
329− clear();
329+ // Before we clear, make sure this was our only entity server.
330+ // Otherwise we're assuming that we have "trading" entity servers
331+ // (an old one going away and a new one coming onboard)
332+ // and that we shouldn't clear here because we're still doing work.
333+ bool hasAnotherEntityServer = false;
334+ auto nodeList = DependencyManager::get<NodeList>();
335+
336+ nodeList->eachNodeBreakable([&hasAnotherEntityServer, &killedNode](const SharedNodePointer& node){
337+ if (node->getType() == NodeType::EntityServer && node->getUUID() != killedNode->getUUID()) {
338+ // we're talking to > 1 entity servers, we know we won't clear
339+ hasAnotherEntityServer = true;
340+ return false;
341+ }
342+
343+ return true;
344+ });
345+
346+ if (hasAnotherEntityServer) {
347+ clear();
348+ }
330349
331350 break;
332351 }