Showing the changes to interface/src/DataServerClient.cpp (1 of 9 files). Show all
Unified · Split
| @@ -14,9 +14,11 @@ · 13 unmodified lines | ||
| 14 | 14 | #include <UUID.h> |
| 15 | 15 | |
| 16 | 16 | #include "Application.h" |
| 17 | +#include "Profile.h" | |
| 18 | + | |
| 17 | 19 | #include "DataServerClient.h" |
| 18 | 20 | |
| 19 | −QString DataServerClient::_clientUsername; | |
| 21 | + | |
| 20 | 22 | std::map<unsigned char*, int> DataServerClient::_unmatchedPackets; |
| 21 | 23 | |
| 22 | 24 | const char DATA_SERVER_HOSTNAME[] = "127.0.0.1"; |
| @@ -24,33 +26,36 @@ const unsigned short DATA_SERVER_PORT = 3282; · 1 unmodified line | ||
| 24 | 26 | const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT); |
| 25 | 27 | |
| 26 | 28 | void DataServerClient::putValueForKey(const char* key, const char* value) { |
| 27 | − if (!_clientUsername.isEmpty()) { | |
| 28 | − unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE]; | |
| 29 | − | |
| 30 | − // setup the header for this packet | |
| 31 | − int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); | |
| 32 | − | |
| 33 | − // pack the client UUID, null terminated | |
| 34 | − memcpy(putPacket + numPacketBytes, _clientUsername.toLocal8Bit().constData(), _clientUsername.toLocal8Bit().size()); | |
| 35 | − numPacketBytes += _clientUsername.toLocal8Bit().size(); | |
| 36 | − putPacket[numPacketBytes++] = '\0'; | |
| 37 | − | |
| 38 | − // pack the key, null terminated | |
| 39 | − strcpy((char*) putPacket + numPacketBytes, key); | |
| 40 | − numPacketBytes += strlen(key); | |
| 41 | − putPacket[numPacketBytes++] = '\0'; | |
| 42 | − | |
| 43 | − // pack the value, null terminated | |
| 44 | − strcpy((char*) putPacket + numPacketBytes, value); | |
| 45 | − numPacketBytes += strlen(value); | |
| 46 | − putPacket[numPacketBytes++] = '\0'; | |
| 47 | − | |
| 48 | − // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed | |
| 49 | − _unmatchedPackets.insert(std::pair<unsigned char*, int>(putPacket, numPacketBytes)); | |
| 50 | − | |
| 51 | − // send this put request to the data server | |
| 52 | − NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes); | |
| 53 | − } | |
| 29 | + Profile* userProfile = Application::getInstance()->getProfile(); | |
| 30 | + QString clientString = userProfile->getUUID().isNull() ? userProfile->getUsername() : userProfile->getUUID().toString(); | |
| 31 | + | |
| 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); | |
| 54 | 59 | } |
| 55 | 60 | |
| 56 | 61 | void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) { |
| @@ -83,7 +88,9 @@ void DataServerClient::getValueForKeyAndUserString(const char* key, QString& use · 26 unmodified lines | ||
| 83 | 88 | NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes); |
| 84 | 89 | } |
| 85 | 90 | |
| 86 | − | |
| 91 | +void DataServerClient::getClientValueForKey(const char* key) { | |
| 92 | + getValueForKeyAndUserString(key, Application::getInstance()->getProfile()->getUsername()); | |
| 93 | +} | |
| 87 | 94 | |
| 88 | 95 | void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) { |
| 89 | 96 | removeMatchedPacketFromMap(packetData, numPacketBytes); |
| @@ -102,18 +109,22 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 12 unmodified lines | ||
| 102 | 109 | // for now assume this means that it is for our avatar |
| 103 | 110 | |
| 104 | 111 | char* dataKeyPosition = (char*) packetData + numHeaderBytes + sizeof(userString); |
| 112 | + char* dataValuePosition = dataKeyPosition + strlen(dataKeyPosition) + sizeof(char); | |
| 113 | + | |
| 114 | + QString dataValueString(QByteArray(dataValuePosition, | |
| 115 | + numPacketBytes - ((unsigned char*) dataValuePosition - packetData))); | |
| 105 | 116 | |
| 106 | 117 | if (strcmp(dataKeyPosition, DataServerKey::FaceMeshURL) == 0) { |
| 107 | 118 | // pull the user's face mesh and set it on the Avatar instance |
| 108 | − char* faceMeshPosition = dataKeyPosition + strlen(dataKeyPosition) + sizeof(char); | |
| 109 | − | |
| 110 | − QUrl faceMeshURL(QByteArray(faceMeshPosition, | |
| 111 | − numPacketBytes - ((unsigned char*) faceMeshPosition - packetData))); | |
| 112 | 119 | |
| 113 | − qDebug("Changing user's face model URL to %s\n", faceMeshURL.toString().toLocal8Bit().constData()); | |
| 120 | + | |
| 121 | + qDebug("Changing user's face model URL to %s\n", dataValueString.toLocal8Bit().constData()); | |
| 114 | 122 | QMetaObject::invokeMethod(&Application::getInstance()->getAvatar()->getHead().getBlendFace(), |
| 115 | 123 | "setModelURL", |
| 116 | − Q_ARG(QUrl, faceMeshURL)); | |
| 124 | + Q_ARG(QUrl, QUrl(dataValueString))); | |
| 125 | + } else if (strcmp(dataKeyPosition, DataServerKey::UUID) == 0) { | |
| 126 | + // this is the user's UUID - set it on the profile | |
| 127 | + Application::getInstance()->getProfile()->setUUID(dataValueString); | |
| 117 | 128 | } |
| 118 | 129 | } else { |
| 119 | 130 | // user string was UUID, find matching avatar and associate data |