Showing the changes to assignment-client/src/scripts/EntityScriptServer.cpp (1 of 7 files). Show all
Unified · Split
| @@ -85,6 +85,7 @@ EntityScriptServer::EntityScriptServer(ReceivedMessage& message) : ThreadedAssig · 84 unmodified lines | ||
| 85 | 85 | packetReceiver.registerListener(PacketType::ReloadEntityServerScript, this, "handleReloadEntityServerScriptPacket"); |
| 86 | 86 | packetReceiver.registerListener(PacketType::EntityScriptGetStatus, this, "handleEntityScriptGetStatusPacket"); |
| 87 | 87 | packetReceiver.registerListener(PacketType::EntityServerScriptLog, this, "handleEntityServerScriptLogPacket"); |
| 88 | + packetReceiver.registerListener(PacketType::EntityScriptCallMethod, this, "handleEntityScriptCallMethodPacket"); | |
| 88 | 89 | |
| 89 | 90 | static const int LOG_INTERVAL = MSECS_PER_SECOND / 10; |
| 90 | 91 | auto timer = new QTimer(this); |
| @@ -231,6 +232,33 @@ void EntityScriptServer::pushLogs() { · 140 unmodified lines | ||
| 231 | 232 | } |
| 232 | 233 | } |
| 233 | 234 | |
| 235 | +void EntityScriptServer::handleEntityScriptCallMethodPacket(QSharedPointer<ReceivedMessage> receivedMessage, SharedNodePointer senderNode) { | |
| 236 | + | |
| 237 | + if (_entitiesScriptEngine && _entityViewer.getTree() && !_shuttingDown) { | |
| 238 | + auto entityID = QUuid::fromRfc4122(receivedMessage->read(NUM_BYTES_RFC4122_UUID)); | |
| 239 | + | |
| 240 | + quint16 methodLength; | |
| 241 | + receivedMessage->readPrimitive(&methodLength); | |
| 242 | + auto methodData = receivedMessage->read(methodLength); | |
| 243 | + auto method = QString::fromUtf8(methodData); | |
| 244 | + | |
| 245 | + quint16 paramCount; | |
| 246 | + receivedMessage->readPrimitive(¶mCount); | |
| 247 | + | |
| 248 | + QStringList params; | |
| 249 | + for (int param = 0; param < paramCount; param++) { | |
| 250 | + quint16 paramLength; | |
| 251 | + receivedMessage->readPrimitive(¶mLength); | |
| 252 | + auto paramData = receivedMessage->read(paramLength); | |
| 253 | + auto paramString = QString::fromUtf8(paramData); | |
| 254 | + params << paramString; | |
| 255 | + } | |
| 256 | + | |
| 257 | + _entitiesScriptEngine->callEntityScriptMethod(entityID, method, params); | |
| 258 | + } | |
| 259 | +} | |
| 260 | + | |
| 261 | + | |
| 234 | 262 | void EntityScriptServer::run() { |
| 235 | 263 | // make sure we request our script once the agent connects to the domain |
| 236 | 264 | auto nodeList = DependencyManager::get<NodeList>(); |