Showing the changes to interface/src/DataServerClient.cpp (1 of 1 file). Show all
Unified · Split
| @@ -18,9 +18,10 @@ · 17 unmodified lines | ||
| 18 | 18 | |
| 19 | 19 | #include "DataServerClient.h" |
| 20 | 20 | |
| 21 | − | |
| 22 | 21 | std::map<unsigned char*, int> DataServerClient::_unmatchedPackets; |
| 23 | 22 | |
| 23 | +const char MULTI_KEY_VALUE_SEPARATOR = '|'; | |
| 24 | + | |
| 24 | 25 | const char DATA_SERVER_HOSTNAME[] = "data.highfidelity.io"; |
| 25 | 26 | const unsigned short DATA_SERVER_PORT = 3282; |
| 26 | 27 | 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 | ||
| 85 | 86 | // pack one byte to designate the number of keys |
| 86 | 87 | getPacket[numPacketBytes++] = keys.size(); |
| 87 | 88 | |
| 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'); | |
| 95 | 94 | |
| 96 | 95 | // add the getPacket to our vector of uncofirmed packets, will be deleted once we get a response from the nameserver |
| 97 | 96 | // _unmatchedPackets.insert(std::pair<unsigned char*, int>(getPacket, numPacketBytes)); |
| @@ -119,39 +118,57 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 21 unmodified lines | ||
| 119 | 118 | |
| 120 | 119 | QUuid userUUID(userString); |
| 121 | 120 | |
| 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'); | |
| 124 | 124 | |
| 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); | |
| 127 | 127 | |
| 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 | + } | |
| 153 | 149 | } |
| 154 | 150 | } |
| 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]); | |
| 155 | 172 | } |
| 156 | 173 | } |
| 157 | 174 | } |