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 | #include "DataServerClient.h" | 19 | #include "DataServerClient.h" |
| 20 | 20 | ||
| 21 | |||
| 22 | std::map<unsigned char*, int> DataServerClient::_unmatchedPackets; | 21 | std::map<unsigned char*, int> DataServerClient::_unmatchedPackets; |
| 23 | 22 | ||
| 23 | const char MULTI_KEY_VALUE_SEPARATOR = '|'; | ||
| 24 | |||
| 24 | const char DATA_SERVER_HOSTNAME[] = "data.highfidelity.io"; | 25 | const char DATA_SERVER_HOSTNAME[] = "data.highfidelity.io"; |
| 25 | const unsigned short DATA_SERVER_PORT = 3282; | 26 | const unsigned short DATA_SERVER_PORT = 3282; |
| 26 | const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT); | 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 | // pack one byte to designate the number of keys | 86 | // pack one byte to designate the number of keys |
| 86 | getPacket[numPacketBytes++] = keys.size(); | 87 | getPacket[numPacketBytes++] = keys.size(); |
| 87 | 88 | ||
| 88 | for (int i = 0; i < keys.size(); ++i) { | 89 | QString keyString = keys.join(MULTI_KEY_VALUE_SEPARATOR); |
| 89 | // pack the keys, null terminated | 90 | |
| 90 | strcpy((char*) getPacket + numPacketBytes, keys[i].toLocal8Bit().constData()); | 91 | // pack the key string, null terminated |
| 91 | 92 | strcpy((char*) getPacket + numPacketBytes, keyString.toLocal8Bit().constData()); | |
| 92 | numPacketBytes += keys[i].size(); | 93 | numPacketBytes += keyString.size() + sizeof('\0'); |
| 93 | getPacket[numPacketBytes++] = '\0'; | ||
| 94 | } | ||
| 95 | 94 | ||
| 96 | // add the getPacket to our vector of uncofirmed packets, will be deleted once we get a response from the nameserver | 95 | // add the getPacket to our vector of uncofirmed packets, will be deleted once we get a response from the nameserver |
| 97 | // _unmatchedPackets.insert(std::pair<unsigned char*, int>(getPacket, numPacketBytes)); | 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 | QUuid userUUID(userString); | 119 | QUuid userUUID(userString); |
| 121 | 120 | ||
| 122 | char* dataKeyPosition = (char*) packetData + numHeaderBytes + strlen(userStringPosition) + sizeof('\0'); | 121 | char* keysPosition = (char*) packetData + numHeaderBytes + strlen(userStringPosition) |
| 123 | char* dataValuePosition = dataKeyPosition + strlen(dataKeyPosition) + sizeof(char); | 122 | + sizeof('\0') + sizeof(unsigned char); |
| 123 | char* valuesPosition = keysPosition + strlen(keysPosition) + sizeof('\0'); | ||
| 124 | 124 | ||
| 125 | QString dataValueString(QByteArray(dataValuePosition, | 125 | QStringList keyList = QString(keysPosition).split(MULTI_KEY_VALUE_SEPARATOR); |
| 126 | numPacketBytes - ((unsigned char*) dataValuePosition - packetData))); | 126 | QStringList valueList = QString(valuesPosition).split(MULTI_KEY_VALUE_SEPARATOR); |
| 127 | 127 | ||
| 128 | if (userUUID.isNull()) { | 128 | // user string was UUID, find matching avatar and associate data |
| 129 | // the user string was a username | 129 | for (int i = 0; i < keyList.size(); i++) { |
| 130 | // for now assume this means that it is for our avatar | 130 | if (valueList[i] != " ") { |
| 131 | 131 | if (keyList[i] == DataServerKey::FaceMeshURL) { | |
| 132 | if (strcmp(dataKeyPosition, DataServerKey::FaceMeshURL.toLocal8Bit().constData()) == 0) { | 132 | |
| 133 | // pull the user's face mesh and set it on the Avatar instance | 133 | if (userUUID.isNull() || userUUID == Application::getInstance()->getProfile()->getUUID()) { |
| 134 | 134 | qDebug("Changing user's face model URL to %s\n", valueList[0].toLocal8Bit().constData()); | |
| 135 | qDebug("Changing user's face model URL to %s\n", dataValueString.toLocal8Bit().constData()); | 135 | Application::getInstance()->getProfile()->setFaceModelURL(QUrl(valueList[0])); |
| 136 | Application::getInstance()->getProfile()->setFaceModelURL(QUrl(dataValueString)); | 136 | } else { |
| 137 | } else if (strcmp(dataKeyPosition, DataServerKey::UUID.toLocal8Bit().constData()) == 0) { | 137 | // mesh URL for a UUID, find avatar in our list |
| 138 | // this is the user's UUID - set it on the profile | 138 | NodeList* nodeList = NodeList::getInstance(); |
| 139 | Application::getInstance()->getProfile()->setUUID(dataValueString); | 139 | for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { |
| 140 | } | 140 | if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { |
| 141 | } else { | 141 | Avatar* avatar = (Avatar *) node->getLinkedData(); |
| 142 | // user string was UUID, find matching avatar and associate data | 142 | |
| 143 | if (strcmp(dataKeyPosition, DataServerKey::FaceMeshURL.toLocal8Bit().constData()) == 0) { | 143 | if (avatar->getUUID() == userUUID) { |
| 144 | NodeList* nodeList = NodeList::getInstance(); | 144 | QMetaObject::invokeMethod(&avatar->getHead().getBlendFace(), |
| 145 | for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { | 145 | "setModelURL", |
| 146 | if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { | 146 | Q_ARG(QUrl, QUrl(valueList[0]))); |
| 147 | Avatar* avatar = (Avatar *) node->getLinkedData(); | 147 | } |
| 148 | 148 | } | |
| 149 | if (avatar->getUUID() == userUUID) { | ||
| 150 | QMetaObject::invokeMethod(&avatar->getHead().getBlendFace(), | ||
| 151 | "setModelURL", | ||
| 152 | Q_ARG(QUrl, QUrl(dataValueString))); | ||
| 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 | } |