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