History

complete setting of user model from data-server

Stephen Birarda committed 13 years ago

Commit 9c6cdcc1 parent 233c1593 files · +61 −45Browse files

Showing the changes to interface/src/DataServerClient.cpp (1 of 3 files). Show all

Unified · Split

interface/src/DataServerClient.cpp+59−42
@@ -27,46 +27,48 @@ const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SE · 26 unmodified lines
2727
2828 void DataServerClient::putValueForKey(const char* key, const char* value) {
2929 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());
3133
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+ }
5962 }
6063
61−void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) {
64+void DataServerClient::getValueForKeyAndUUID(const char* key, const QUuid &uuid) {
6265 if (!uuid.isNull()) {
63− QString uuidString = uuidStringWithoutCurlyBraces(uuid);
64− getValueForKeyAndUserString(key, uuidString);
66+ getValueForKeyAndUserString(key, uuidStringWithoutCurlyBraces(uuid));
6567 }
6668 }
6769
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];
7072
7173 // setup the header for this packet
7274 int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET);
@@ -103,21 +105,23 @@ void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, i · 30 unmodified lines
103105 void DataServerClient::processSendFromDataServer(unsigned char* packetData, int numPacketBytes) {
104106 // pull the user string from the packet so we know who to associate this with
105107 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)));
108112
109113 QUuid userUUID(userString);
110114
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+
111121 if (userUUID.isNull()) {
112122 // the user string was a username
113123 // for now assume this means that it is for our avatar
114124
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−
121125 if (strcmp(dataKeyPosition, DataServerKey::FaceMeshURL) == 0) {
122126 // pull the user's face mesh and set it on the Avatar instance
123127
@@ -129,7 +133,20 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int · 5 unmodified lines
129133 }
130134 } else {
131135 // 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+ }
133150 }
134151
135152 // remove the matched packet from our map so it isn't re-sent to the data-server