Showing the changes to interface/src/DataServerClient.cpp (1 of 3 files). Show all
Unified · Split
| @@ -27,46 +27,48 @@ const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SE · 26 unmodified lines | ||
| 27 | 27 | |
| 28 | 28 | void DataServerClient::putValueForKey(const char* key, const char* value) { |
| 29 | 29 | Profile* userProfile = Application::getInstance()->getProfile(); |
| 30 | − QString clientString = userProfile->getUUID().isNull() ? userProfile->getUsername() : userProfile->getUUID().toString(); | |
| 30 | + QString clientString = userProfile->getUUID().isNull() | |
| 31 | + ? userProfile->getUsername() | |
| 32 | + : uuidStringWithoutCurlyBraces(userProfile->getUUID().toString()); | |
| 31 | 33 | |
| 32 | − Application::getInstance(); | |
| 33 | − | |
| 34 | − unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE]; | |
| 35 | − | |
| 36 | − // setup the header for this packet | |
| 37 | − int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); | |
| 38 | − | |
| 39 | − // pack the client UUID, null terminated | |
| 40 | − memcpy(putPacket + numPacketBytes, clientString.toLocal8Bit().constData(), clientString.toLocal8Bit().size()); | |
| 41 | − numPacketBytes += clientString.toLocal8Bit().size(); | |
| 42 | − putPacket[numPacketBytes++] = '\0'; | |
| 43 | − | |
| 44 | − // pack the key, null terminated | |
| 45 | − strcpy((char*) putPacket + numPacketBytes, key); | |
| 46 | − numPacketBytes += strlen(key); | |
| 47 | − putPacket[numPacketBytes++] = '\0'; | |
| 48 | − | |
| 49 | − // pack the value, null terminated | |
| 50 | − strcpy((char*) putPacket + numPacketBytes, value); | |
| 51 | − numPacketBytes += strlen(value); | |
| 52 | − putPacket[numPacketBytes++] = '\0'; | |
| 53 | − | |
| 54 | − // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed | |
| 55 | − _unmatchedPackets.insert(std::pair<unsigned char*, int>(putPacket, numPacketBytes)); | |
| 56 | − | |
| 57 | − // send this put request to the data server | |
| 58 | − NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes); | |
| 34 | + if (!clientString.isEmpty()) { | |
| 35 | + | |
| 36 | + unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE]; | |
| 37 | + | |
| 38 | + // setup the header for this packet | |
| 39 | + int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); | |
| 40 | + | |
| 41 | + // pack the client UUID, null terminated | |
| 42 | + memcpy(putPacket + numPacketBytes, clientString.toLocal8Bit().constData(), clientString.toLocal8Bit().size()); | |
| 43 | + numPacketBytes += clientString.toLocal8Bit().size(); | |
| 44 | + putPacket[numPacketBytes++] = '\0'; | |
| 45 | + | |
| 46 | + // pack the key, null terminated | |
| 47 | + strcpy((char*) putPacket + numPacketBytes, key); | |
| 48 | + numPacketBytes += strlen(key); | |
| 49 | + putPacket[numPacketBytes++] = '\0'; | |
| 50 | + | |
| 51 | + // pack the value, null terminated | |
| 52 | + strcpy((char*) putPacket + numPacketBytes, value); | |
| 53 | + numPacketBytes += strlen(value); | |
| 54 | + putPacket[numPacketBytes++] = '\0'; | |
| 55 | + | |
| 56 | + // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed | |
| 57 | + _unmatchedPackets.insert(std::pair<unsigned char*, int>(putPacket, numPacketBytes)); | |
| 58 | + | |
| 59 | + // send this put request to the data server | |
| 60 | + NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes); | |
| 61 | + } | |
| 59 | 62 | } |
| 60 | 63 | |
| 61 | −void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) { | |
| 64 | +void DataServerClient::getValueForKeyAndUUID(const char* key, const QUuid &uuid) { | |
| 62 | 65 | if (!uuid.isNull()) { |
| 63 | − QString uuidString = uuidStringWithoutCurlyBraces(uuid); | |
| 64 | − getValueForKeyAndUserString(key, uuidString); | |
| 66 | + getValueForKeyAndUserString(key, uuidStringWithoutCurlyBraces(uuid)); | |
| 65 | 67 | } |
| 66 | 68 | } |
| 67 | 69 | |
| 68 | −void DataServerClient::getValueForKeyAndUserString(const char* key, QString& userString) { | |
| 69 | − unsigned char getPacket[MAX_PACKET_SIZE]; | |
| 70 | +void DataServerClient::getValueForKeyAndUserString(const char* key, const QString& userString) { | |
| 71 | + unsigned char* getPacket = new unsigned char[MAX_PACKET_SIZE]; | |
| 70 | 72 | |
| 71 | 73 | // setup the header for this packet |
| 72 | 74 | int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET); |
| @@ -103,21 +105,23 @@ void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, i · 30 unmodified lines | ||
| 103 | 105 | void DataServerClient::processSendFromDataServer(unsigned char* packetData, int numPacketBytes) { |
| 104 | 106 | // pull the user string from the packet so we know who to associate this with |
| 105 | 107 | int numHeaderBytes = numBytesForPacketHeader(packetData); |
| 106 | − | |
| 107 | − QString userString(QByteArray((char*) packetData + numHeaderBytes, strlen((char*) packetData + numHeaderBytes))); | |
| 108 | + | |
| 109 | + char* userStringPosition = (char*) packetData + numHeaderBytes; | |
| 110 | + | |
| 111 | + QString userString(QByteArray(userStringPosition, strlen(userStringPosition))); | |
| 108 | 112 | |
| 109 | 113 | QUuid userUUID(userString); |
| 110 | 114 | |
| 115 | + char* dataKeyPosition = (char*) packetData + numHeaderBytes + strlen(userStringPosition) + sizeof('\0'); | |
| 116 | + char* dataValuePosition = dataKeyPosition + strlen(dataKeyPosition) + sizeof(char); | |
| 117 | + | |
| 118 | + QString dataValueString(QByteArray(dataValuePosition, | |
| 119 | + numPacketBytes - ((unsigned char*) dataValuePosition - packetData))); | |
| 120 | + | |
| 111 | 121 | if (userUUID.isNull()) { |
| 112 | 122 | // the user string was a username |
| 113 | 123 | // for now assume this means that it is for our avatar |
| 114 | 124 | |
| 115 | − char* dataKeyPosition = (char*) packetData + numHeaderBytes + sizeof(userString); | |
| 116 | − char* dataValuePosition = dataKeyPosition + strlen(dataKeyPosition) + sizeof(char); | |
| 117 | − | |
| 118 | − QString dataValueString(QByteArray(dataValuePosition, | |
| 119 | − numPacketBytes - ((unsigned char*) dataValuePosition - packetData))); | |
| 120 | − | |
| 121 | 125 | if (strcmp(dataKeyPosition, DataServerKey::FaceMeshURL) == 0) { |
| 122 | 126 | // pull the user's face mesh and set it on the Avatar instance |
| 123 | 127 | |
| @@ -129,7 +133,20 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 5 unmodified lines | ||
| 129 | 133 | } |
| 130 | 134 | } else { |
| 131 | 135 | // user string was UUID, find matching avatar and associate data |
| 132 | − | |
| 136 | + if (strcmp(dataKeyPosition, DataServerKey::FaceMeshURL) == 0) { | |
| 137 | + NodeList* nodeList = NodeList::getInstance(); | |
| 138 | + for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { | |
| 139 | + if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { | |
| 140 | + Avatar* avatar = (Avatar *) node->getLinkedData(); | |
| 141 | + | |
| 142 | + if (avatar->getUUID() == userUUID) { | |
| 143 | + QMetaObject::invokeMethod(&avatar->getHead().getBlendFace(), | |
| 144 | + "setModelURL", | |
| 145 | + Q_ARG(QUrl, QUrl(dataValueString))); | |
| 146 | + } | |
| 147 | + } | |
| 148 | + } | |
| 149 | + } | |
| 133 | 150 | } |
| 134 | 151 | |
| 135 | 152 | // remove the matched packet from our map so it isn't re-sent to the data-server |