History

implement support for Entities.callEntityServerMethod()

ZappoMan committed 9 years ago

Commit 934c9471 parent e85494b7 files · +95 −7Browse files

Showing the changes to libraries/networking/src/EntityScriptClient.cpp (1 of 7 files). Show all

Unified · Split

libraries/networking/src/EntityScriptClient.cpp+30−0
@@ -69,6 +69,36 @@ bool EntityScriptClient::reloadServerScript(QUuid entityID) { · 68 unmodified lines
6969 return false;
7070 }
7171
72+void EntityScriptClient::callEntityServerMethod(QUuid entityID, const QString& method, const QStringList& params) {
73+ // Send packet to entity script server
74+ auto nodeList = DependencyManager::get<NodeList>();
75+ SharedNodePointer entityScriptServer = nodeList->soloNodeOfType(NodeType::EntityScriptServer);
76+
77+ if (entityScriptServer) {
78+ auto packetList = NLPacketList::create(PacketType::EntityScriptCallMethod, QByteArray(), true, true);
79+
80+ packetList->write(entityID.toRfc4122());
81+
82+ auto methodUtf8 = method.toUtf8();
83+ quint16 methodLength = methodUtf8.length();
84+ packetList->writePrimitive(methodLength);
85+ packetList->write(methodUtf8);
86+
87+ quint16 paramCount = params.length();
88+ packetList->writePrimitive(paramCount);
89+
90+ foreach(const QString& param, params) {
91+ auto paramUtf8 = param.toUtf8();
92+ quint16 paramLength = paramUtf8.length();
93+ packetList->writePrimitive(paramLength);
94+ packetList->write(paramUtf8);
95+ }
96+
97+ nodeList->sendPacketList(std::move(packetList), *entityScriptServer);
98+ }
99+}
100+
101+
72102 MessageID EntityScriptClient::getEntityServerScriptStatus(QUuid entityID, GetScriptStatusCallback callback) {
73103 auto nodeList = DependencyManager::get<NodeList>();
74104 SharedNodePointer entityScriptServer = nodeList->soloNodeOfType(NodeType::EntityScriptServer);