Showing the changes to interface/src/DataServerClient.cpp (1 of 10 files). Show all
Unified · Split
| @@ -34,33 +34,33 @@ const HifiSockAddr& DataServerClient::dataServerSockAddr() { · 33 unmodified lines | ||
| 34 | 34 | void DataServerClient::putValueForKey(const QString& key, const char* value) { |
| 35 | 35 | QString clientString = Application::getInstance()->getProfile()->getUserString(); |
| 36 | 36 | if (!clientString.isEmpty()) { |
| 37 | − | |
| 37 | + | |
| 38 | 38 | unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE]; |
| 39 | − | |
| 39 | + | |
| 40 | 40 | // setup the header for this packet |
| 41 | 41 | int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); |
| 42 | − | |
| 42 | + | |
| 43 | 43 | // pack the client UUID, null terminated |
| 44 | 44 | memcpy(putPacket + numPacketBytes, clientString.toLocal8Bit().constData(), clientString.toLocal8Bit().size()); |
| 45 | 45 | numPacketBytes += clientString.toLocal8Bit().size(); |
| 46 | 46 | putPacket[numPacketBytes++] = '\0'; |
| 47 | − | |
| 47 | + | |
| 48 | 48 | // pack a 1 to designate that we are putting a single value |
| 49 | 49 | putPacket[numPacketBytes++] = 1; |
| 50 | − | |
| 50 | + | |
| 51 | 51 | // pack the key, null terminated |
| 52 | 52 | strcpy((char*) putPacket + numPacketBytes, key.toLocal8Bit().constData()); |
| 53 | 53 | numPacketBytes += key.size(); |
| 54 | 54 | putPacket[numPacketBytes++] = '\0'; |
| 55 | − | |
| 55 | + | |
| 56 | 56 | // pack the value, null terminated |
| 57 | 57 | strcpy((char*) putPacket + numPacketBytes, value); |
| 58 | 58 | numPacketBytes += strlen(value); |
| 59 | 59 | putPacket[numPacketBytes++] = '\0'; |
| 60 | − | |
| 60 | + | |
| 61 | 61 | // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed |
| 62 | 62 | // _unmatchedPackets.insert(std::pair<unsigned char*, int>(putPacket, numPacketBytes)); |
| 63 | − | |
| 63 | + | |
| 64 | 64 | // send this put request to the data server |
| 65 | 65 | NodeList::getInstance()->getNodeSocket().writeDatagram((char*) putPacket, numPacketBytes, |
| 66 | 66 | dataServerSockAddr().getAddress(), |
| @@ -81,27 +81,27 @@ void DataServerClient::getValuesForKeysAndUUID(const QStringList& keys, const QU · 14 unmodified lines | ||
| 81 | 81 | void DataServerClient::getValuesForKeysAndUserString(const QStringList& keys, const QString& userString) { |
| 82 | 82 | if (!userString.isEmpty() && keys.size() <= UCHAR_MAX) { |
| 83 | 83 | unsigned char* getPacket = new unsigned char[MAX_PACKET_SIZE]; |
| 84 | − | |
| 84 | + | |
| 85 | 85 | // setup the header for this packet |
| 86 | 86 | int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET); |
| 87 | − | |
| 87 | + | |
| 88 | 88 | // pack the user string (could be username or UUID string), null-terminate |
| 89 | 89 | memcpy(getPacket + numPacketBytes, userString.toLocal8Bit().constData(), userString.toLocal8Bit().size()); |
| 90 | 90 | numPacketBytes += userString.toLocal8Bit().size(); |
| 91 | 91 | getPacket[numPacketBytes++] = '\0'; |
| 92 | − | |
| 92 | + | |
| 93 | 93 | // pack one byte to designate the number of keys |
| 94 | 94 | getPacket[numPacketBytes++] = keys.size(); |
| 95 | − | |
| 95 | + | |
| 96 | 96 | QString keyString = keys.join(MULTI_KEY_VALUE_SEPARATOR); |
| 97 | − | |
| 97 | + | |
| 98 | 98 | // pack the key string, null terminated |
| 99 | 99 | strcpy((char*) getPacket + numPacketBytes, keyString.toLocal8Bit().constData()); |
| 100 | 100 | numPacketBytes += keyString.size() + sizeof('\0'); |
| 101 | − | |
| 101 | + | |
| 102 | 102 | // add the getPacket to our vector of uncofirmed packets, will be deleted once we get a response from the nameserver |
| 103 | 103 | // _unmatchedPackets.insert(std::pair<unsigned char*, int>(getPacket, numPacketBytes)); |
| 104 | − | |
| 104 | + | |
| 105 | 105 | // send the get to the data server |
| 106 | 106 | NodeList::getInstance()->getNodeSocket().writeDatagram((char*) getPacket, numPacketBytes, |
| 107 | 107 | dataServerSockAddr().getAddress(), |
| @@ -120,25 +120,25 @@ void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, i · 12 unmodified lines | ||
| 120 | 120 | void DataServerClient::processSendFromDataServer(unsigned char* packetData, int numPacketBytes) { |
| 121 | 121 | // pull the user string from the packet so we know who to associate this with |
| 122 | 122 | int numHeaderBytes = numBytesForPacketHeader(packetData); |
| 123 | − | |
| 123 | + | |
| 124 | 124 | char* userStringPosition = (char*) packetData + numHeaderBytes; |
| 125 | − | |
| 125 | + | |
| 126 | 126 | QString userString(QByteArray(userStringPosition, strlen(userStringPosition))); |
| 127 | − | |
| 127 | + | |
| 128 | 128 | QUuid userUUID(userString); |
| 129 | − | |
| 129 | + | |
| 130 | 130 | char* keysPosition = (char*) packetData + numHeaderBytes + strlen(userStringPosition) |
| 131 | 131 | + sizeof('\0') + sizeof(unsigned char); |
| 132 | 132 | char* valuesPosition = keysPosition + strlen(keysPosition) + sizeof('\0'); |
| 133 | − | |
| 133 | + | |
| 134 | 134 | QStringList keyList = QString(keysPosition).split(MULTI_KEY_VALUE_SEPARATOR); |
| 135 | 135 | QStringList valueList = QString(valuesPosition).split(MULTI_KEY_VALUE_SEPARATOR); |
| 136 | − | |
| 136 | + | |
| 137 | 137 | // user string was UUID, find matching avatar and associate data |
| 138 | − for (int i = 0; i < keyList.size(); i++) { | |
| 138 | + for (size_t i = 0; i < keyList.size(); i++) { | |
| 139 | 139 | if (valueList[i] != " ") { |
| 140 | 140 | if (keyList[i] == DataServerKey::FaceMeshURL) { |
| 141 | − | |
| 141 | + | |
| 142 | 142 | if (userUUID.isNull() || userUUID == Application::getInstance()->getProfile()->getUUID()) { |
| 143 | 143 | qDebug("Changing user's face model URL to %s\n", valueList[i].toLocal8Bit().constData()); |
| 144 | 144 | Application::getInstance()->getProfile()->setFaceModelURL(QUrl(valueList[i])); |
| @@ -148,7 +148,7 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 3 unmodified lines | ||
| 148 | 148 | for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { |
| 149 | 149 | if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { |
| 150 | 150 | Avatar* avatar = (Avatar *) node->getLinkedData(); |
| 151 | − | |
| 151 | + | |
| 152 | 152 | if (avatar->getUUID() == userUUID) { |
| 153 | 153 | QMetaObject::invokeMethod(&avatar->getHead().getFaceModel(), |
| 154 | 154 | "setURL", Q_ARG(QUrl, QUrl(valueList[i]))); |
| @@ -157,7 +157,7 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 2 unmodified lines | ||
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | } else if (keyList[i] == DataServerKey::SkeletonURL) { |
| 160 | − | |
| 160 | + | |
| 161 | 161 | if (userUUID.isNull() || userUUID == Application::getInstance()->getProfile()->getUUID()) { |
| 162 | 162 | qDebug("Changing user's skeleton URL to %s\n", valueList[i].toLocal8Bit().constData()); |
| 163 | 163 | Application::getInstance()->getProfile()->setSkeletonModelURL(QUrl(valueList[i])); |
| @@ -167,7 +167,7 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 3 unmodified lines | ||
| 167 | 167 | for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { |
| 168 | 168 | if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { |
| 169 | 169 | Avatar* avatar = (Avatar *) node->getLinkedData(); |
| 170 | − | |
| 170 | + | |
| 171 | 171 | if (avatar->getUUID() == userUUID) { |
| 172 | 172 | QMetaObject::invokeMethod(&avatar->getSkeletonModel(), "setURL", |
| 173 | 173 | Q_ARG(QUrl, QUrl(valueList[i]))); |
| @@ -177,33 +177,33 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 3 unmodified lines | ||
| 177 | 177 | } |
| 178 | 178 | } else if (keyList[i] == DataServerKey::Domain && keyList[i + 1] == DataServerKey::Position |
| 179 | 179 | && valueList[i] != " " && valueList[i + 1] != " ") { |
| 180 | − | |
| 180 | + | |
| 181 | 181 | QStringList coordinateItems = valueList[i + 1].split(','); |
| 182 | − | |
| 182 | + | |
| 183 | 183 | if (coordinateItems.size() == 3) { |
| 184 | − | |
| 184 | + | |
| 185 | 185 | // send a node kill request, indicating to other clients that they should play the "disappeared" effect |
| 186 | 186 | NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1); |
| 187 | − | |
| 187 | + | |
| 188 | 188 | qDebug() << "Changing domain to" << valueList[i].toLocal8Bit().constData() << |
| 189 | 189 | "and position to" << valueList[i + 1].toLocal8Bit().constData() << |
| 190 | 190 | "to go to" << userString << "\n"; |
| 191 | − | |
| 191 | + | |
| 192 | 192 | NodeList::getInstance()->setDomainHostname(valueList[i]); |
| 193 | − | |
| 193 | + | |
| 194 | 194 | glm::vec3 newPosition(coordinateItems[0].toFloat(), |
| 195 | 195 | coordinateItems[1].toFloat(), |
| 196 | 196 | coordinateItems[2].toFloat()); |
| 197 | 197 | Application::getInstance()->getAvatar()->setPosition(newPosition); |
| 198 | 198 | } |
| 199 | − | |
| 199 | + | |
| 200 | 200 | } else if (keyList[i] == DataServerKey::UUID) { |
| 201 | 201 | // this is the user's UUID - set it on the profile |
| 202 | 202 | Application::getInstance()->getProfile()->setUUID(valueList[i]); |
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | − | |
| 206 | + | |
| 207 | 207 | // remove the matched packet from our map so it isn't re-sent to the data-server |
| 208 | 208 | // removeMatchedPacketFromMap(packetData, numPacketBytes); |
| 209 | 209 | } |
| @@ -228,12 +228,12 @@ void DataServerClient::removeMatchedPacketFromMap(unsigned char* packetData, int · 18 unmodified lines | ||
| 228 | 228 | if (memcmp(mapIterator->first + sizeof(PACKET_TYPE), |
| 229 | 229 | packetData + sizeof(PACKET_TYPE), |
| 230 | 230 | numPacketBytes - sizeof(PACKET_TYPE)) == 0) { |
| 231 | − | |
| 231 | + | |
| 232 | 232 | // this is a match - remove the confirmed packet from the vector and delete associated member |
| 233 | 233 | // so it isn't sent back out |
| 234 | 234 | delete[] mapIterator->first; |
| 235 | 235 | _unmatchedPackets.erase(mapIterator); |
| 236 | − | |
| 236 | + | |
| 237 | 237 | // we've matched the packet - bail out |
| 238 | 238 | break; |
| 239 | 239 | } |