History

shore up receipt of face mesh URL from data-server

Stephen Birarda committed 13 years ago

Commit 4b620261 parent b33843f3 files · +62 −10Browse files

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

Unified · Split

interface/src/DataServerClient.cpp+53−8
@@ -6,15 +6,18 @@ · 5 unmodified lines
66 // Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
77 //
88
9+#include <QtCore/QUrl>
10+
911 #include <NodeList.h>
1012 #include <PacketHeaders.h>
1113 #include <UDPSocket.h>
1214 #include <UUID.h>
1315
16+#include "Application.h"
1417 #include "DataServerClient.h"
1518
1619 QString DataServerClient::_clientUsername;
17−std::vector<unsigned char*> DataServerClient::_unconfirmedPackets;
20+std::vector<unsigned char*> DataServerClient::_unmatchedPackets;
1821
1922 const char DATA_SERVER_HOSTNAME[] = "127.0.0.1";
2023 const unsigned short DATA_SERVER_PORT = 3282;
@@ -27,9 +30,10 @@ void DataServerClient::putValueForKey(const char* key, const char* value) { · 6 unmodified lines
2730 // setup the header for this packet
2831 int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT);
2932
30− // pack the client UUID
33+ // pack the client UUID, null terminated
3134 memcpy(putPacket + numPacketBytes, _clientUsername.toLocal8Bit().constData(), _clientUsername.toLocal8Bit().size());
3235 numPacketBytes += _clientUsername.toLocal8Bit().size();
36+ putPacket[numPacketBytes++] = '\0';
3337
3438 // pack the key, null terminated
3539 strcpy((char*) putPacket + numPacketBytes, key);
@@ -42,7 +46,7 @@ void DataServerClient::putValueForKey(const char* key, const char* value) { · 6 unmodified lines
4246 putPacket[numPacketBytes++] = '\0';
4347
4448 // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed
45− _unconfirmedPackets.push_back(putPacket);
49+ _unmatchedPackets.push_back(putPacket);
4650
4751 // send this put request to the data server
4852 NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes);
@@ -62,9 +66,10 @@ void DataServerClient::getValueForKeyAndUserString(const char* key, QString& use · 13 unmodified lines
6266 // setup the header for this packet
6367 int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET);
6468
65− // pack the user string (could be username or UUID string)
69+ // pack the user string (could be username or UUID string), null-terminate
6670 memcpy(getPacket + numPacketBytes, userString.toLocal8Bit().constData(), userString.toLocal8Bit().size());
6771 numPacketBytes += userString.toLocal8Bit().size();
72+ getPacket[numPacketBytes++] = '\0';
6873
6974 // pack the key, null terminated
7075 strcpy((char*) getPacket + numPacketBytes, key);
@@ -77,14 +82,14 @@ void DataServerClient::getValueForKeyAndUserString(const char* key, QString& use · 6 unmodified lines
7782
7883 void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {
7984
80− for (std::vector<unsigned char*>::iterator unconfirmedPacket = _unconfirmedPackets.begin();
81− unconfirmedPacket != _unconfirmedPackets.end();
85+ for (std::vector<unsigned char*>::iterator unconfirmedPacket = _unmatchedPackets.begin();
86+ unconfirmedPacket != _unmatchedPackets.end();
8287 ++unconfirmedPacket) {
8388 if (memcmp(*unconfirmedPacket + sizeof(PACKET_TYPE),
8489 packetData + sizeof(PACKET_TYPE),
8590 numPacketBytes - sizeof(PACKET_TYPE)) == 0) {
8691 // this is a match - remove the confirmed packet from the vector so it isn't sent back out
87− _unconfirmedPackets.erase(unconfirmedPacket);
92+ _unmatchedPackets.erase(unconfirmedPacket);
8893
8994 // we've matched the packet - bail out
9095 break;
@@ -95,6 +100,46 @@ void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, i · 4 unmodified lines
95100 }
96101 }
97102
98−void DataServerClient::processGetFromDataServer(unsigned char* packetData, int numPacketBytes) {
103+void DataServerClient::processSendFromDataServer(unsigned char* packetData, int numPacketBytes) {
104+ // pull the user string from the packet so we know who to associate this with
105+ int numHeaderBytes = numBytesForPacketHeader(packetData);
106+
107+ QString userString(QByteArray((char*) packetData + numHeaderBytes, strlen((char*) packetData + numHeaderBytes)));
108+
109+ QUuid userUUID(userString);
99110
111+ if (userUUID.isNull()) {
112+ // the user string was a username
113+ // for now assume this means that it is for our avatar
114+
115+ char* dataKeyPosition = (char*) packetData + numHeaderBytes + sizeof(userString);
116+
117+ if (strcmp(dataKeyPosition, DataServerKey::FaceMeshURL) == 0) {
118+ // pull the user's face mesh and set it on the Avatar instance
119+ char* faceMeshPosition = dataKeyPosition + strlen(dataKeyPosition) + sizeof(char);
120+
121+ QUrl faceMeshURL(QByteArray(faceMeshPosition,
122+ numPacketBytes - ((unsigned char*) faceMeshPosition - packetData)));
123+
124+ qDebug("Changing user's face model URL to %s\n", faceMeshURL.toString().toLocal8Bit().constData());
125+ QMetaObject::invokeMethod(&Application::getInstance()->getAvatar()->getHead().getBlendFace(),
126+ "setModelURL",
127+ Q_ARG(QUrl, faceMeshURL));
128+ }
129+ } else {
130+ // user string was UUID, find matching avatar and associate data
131+ }
132+}
133+
134+void DataServerClient::processMessageFromDataServer(unsigned char* packetData, int numPacketBytes) {
135+ switch (packetData[0]) {
136+ case PACKET_TYPE_DATA_SERVER_SEND:
137+ processSendFromDataServer(packetData, numPacketBytes);
138+ break;
139+ case PACKET_TYPE_DATA_SERVER_CONFIRM:
140+ processConfirmFromDataServer(packetData, numPacketBytes);
141+ break;
142+ default:
143+ break;
144+ }
100145 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t