History

handle get of multiple values in single packet

Stephen Birarda committed 13 years ago

Commit 33e6e191 parent 78512511 file · +54 −37Browse files

Showing the changes to interface/src/DataServerClient.cpp (1 of 1 file). Show all

Unified · Split

interface/src/DataServerClient.cpp+54−37
@@ -18,9 +18,10 @@ · 17 unmodified lines
1818
1919 #include "DataServerClient.h"
2020
21−
2221 std::map<unsigned char*, int> DataServerClient::_unmatchedPackets;
2322
23+const char MULTI_KEY_VALUE_SEPARATOR = '|';
24+
2425 const char DATA_SERVER_HOSTNAME[] = "data.highfidelity.io";
2526 const unsigned short DATA_SERVER_PORT = 3282;
2627 const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT);
@@ -85,13 +86,11 @@ void DataServerClient::getValuesForKeysAndUserString(const QStringList& keys, co · 58 unmodified lines
8586 // pack one byte to designate the number of keys
8687 getPacket[numPacketBytes++] = keys.size();
8788
88− for (int i = 0; i < keys.size(); ++i) {
89− // pack the keys, null terminated
90− strcpy((char*) getPacket + numPacketBytes, keys[i].toLocal8Bit().constData());
91−
92− numPacketBytes += keys[i].size();
93− getPacket[numPacketBytes++] = '\0';
94− }
89+ QString keyString = keys.join(MULTI_KEY_VALUE_SEPARATOR);
90+
91+ // pack the key string, null terminated
92+ strcpy((char*) getPacket + numPacketBytes, keyString.toLocal8Bit().constData());
93+ numPacketBytes += keyString.size() + sizeof('\0');
9594
9695 // add the getPacket to our vector of uncofirmed packets, will be deleted once we get a response from the nameserver
9796 // _unmatchedPackets.insert(std::pair<unsigned char*, int>(getPacket, numPacketBytes));
@@ -119,39 +118,57 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 21 unmodified lines
119118
120119 QUuid userUUID(userString);
121120
122− char* dataKeyPosition = (char*) packetData + numHeaderBytes + strlen(userStringPosition) + sizeof('\0');
123− char* dataValuePosition = dataKeyPosition + strlen(dataKeyPosition) + sizeof(char);
121+ char* keysPosition = (char*) packetData + numHeaderBytes + strlen(userStringPosition)
122+ + sizeof('\0') + sizeof(unsigned char);
123+ char* valuesPosition = keysPosition + strlen(keysPosition) + sizeof('\0');
124124
125− QString dataValueString(QByteArray(dataValuePosition,
126− numPacketBytes - ((unsigned char*) dataValuePosition - packetData)));
125+ QStringList keyList = QString(keysPosition).split(MULTI_KEY_VALUE_SEPARATOR);
126+ QStringList valueList = QString(valuesPosition).split(MULTI_KEY_VALUE_SEPARATOR);
127127
128− if (userUUID.isNull()) {
129− // the user string was a username
130− // for now assume this means that it is for our avatar
131−
132− if (strcmp(dataKeyPosition, DataServerKey::FaceMeshURL.toLocal8Bit().constData()) == 0) {
133− // pull the user's face mesh and set it on the Avatar instance
134−
135− qDebug("Changing user's face model URL to %s\n", dataValueString.toLocal8Bit().constData());
136− Application::getInstance()->getProfile()->setFaceModelURL(QUrl(dataValueString));
137− } else if (strcmp(dataKeyPosition, DataServerKey::UUID.toLocal8Bit().constData()) == 0) {
138− // this is the user's UUID - set it on the profile
139− Application::getInstance()->getProfile()->setUUID(dataValueString);
140− }
141− } else {
142− // user string was UUID, find matching avatar and associate data
143− if (strcmp(dataKeyPosition, DataServerKey::FaceMeshURL.toLocal8Bit().constData()) == 0) {
144− NodeList* nodeList = NodeList::getInstance();
145− for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
146− if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
147− Avatar* avatar = (Avatar *) node->getLinkedData();
148−
149− if (avatar->getUUID() == userUUID) {
150− QMetaObject::invokeMethod(&avatar->getHead().getBlendFace(),
151− "setModelURL",
152− Q_ARG(QUrl, QUrl(dataValueString)));
128+ // user string was UUID, find matching avatar and associate data
129+ for (int i = 0; i < keyList.size(); i++) {
130+ if (valueList[i] != " ") {
131+ if (keyList[i] == DataServerKey::FaceMeshURL) {
132+
133+ if (userUUID.isNull() || userUUID == Application::getInstance()->getProfile()->getUUID()) {
134+ qDebug("Changing user's face model URL to %s\n", valueList[0].toLocal8Bit().constData());
135+ Application::getInstance()->getProfile()->setFaceModelURL(QUrl(valueList[0]));
136+ } else {
137+ // mesh URL for a UUID, find avatar in our list
138+ NodeList* nodeList = NodeList::getInstance();
139+ for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
140+ if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
141+ Avatar* avatar = (Avatar *) node->getLinkedData();
142+
143+ if (avatar->getUUID() == userUUID) {
144+ QMetaObject::invokeMethod(&avatar->getHead().getBlendFace(),
145+ "setModelURL",
146+ Q_ARG(QUrl, QUrl(valueList[0])));
147+ }
148+ }
153149 }
154150 }
151+ } else if (keyList[i] == DataServerKey::Domain) {
152+ qDebug() << "Changing domain hostname to" << valueList[i].toLocal8Bit().constData() <<
153+ "to go to" << userString << "\n";
154+ NodeList::getInstance()->setDomainHostname(valueList[i]);
155+ } else if (keyList[i] == DataServerKey::Position) {
156+ QStringList coordinateItems = valueList[i].split(',');
157+
158+ if (coordinateItems.size() == 3) {
159+ qDebug() << "Changing position to" << valueList[i].toLocal8Bit().constData() <<
160+ "to go to" << userString << "\n";
161+
162+ glm::vec3 newPosition(coordinateItems[0].toFloat(),
163+ coordinateItems[1].toFloat(),
164+ coordinateItems[2].toFloat());
165+ Application::getInstance()->getAvatar()->setPosition(newPosition);
166+ }
167+
168+
169+ } else if (keyList[i] == DataServerKey::UUID) {
170+ // this is the user's UUID - set it on the profile
171+ Application::getInstance()->getProfile()->setUUID(valueList[0]);
155172 }
156173 }
157174 }