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
27 27
28void DataServerClient::putValueForKey(const char* key, const char* value) {28void DataServerClient::putValueForKey(const char* key, const char* value) {
29 Profile* userProfile = Application::getInstance()->getProfile();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();34 if (!clientString.isEmpty()) {
33 35
34 unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE];36 unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE];
35 37
36 // setup the header for this packet38 // setup the header for this packet
37 int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT);39 int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT);
38 40
39 // pack the client UUID, null terminated41 // pack the client UUID, null terminated
40 memcpy(putPacket + numPacketBytes, clientString.toLocal8Bit().constData(), clientString.toLocal8Bit().size());42 memcpy(putPacket + numPacketBytes, clientString.toLocal8Bit().constData(), clientString.toLocal8Bit().size());
41 numPacketBytes += clientString.toLocal8Bit().size();43 numPacketBytes += clientString.toLocal8Bit().size();
42 putPacket[numPacketBytes++] = '\0';44 putPacket[numPacketBytes++] = '\0';
43 45
44 // pack the key, null terminated46 // pack the key, null terminated
45 strcpy((char*) putPacket + numPacketBytes, key);47 strcpy((char*) putPacket + numPacketBytes, key);
46 numPacketBytes += strlen(key);48 numPacketBytes += strlen(key);
47 putPacket[numPacketBytes++] = '\0';49 putPacket[numPacketBytes++] = '\0';
48 50
49 // pack the value, null terminated51 // pack the value, null terminated
50 strcpy((char*) putPacket + numPacketBytes, value);52 strcpy((char*) putPacket + numPacketBytes, value);
51 numPacketBytes += strlen(value);53 numPacketBytes += strlen(value);
52 putPacket[numPacketBytes++] = '\0';54 putPacket[numPacketBytes++] = '\0';
53 55
54 // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed56 // 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));57 _unmatchedPackets.insert(std::pair<unsigned char*, int>(putPacket, numPacketBytes));
56 58
57 // send this put request to the data server59 // send this put request to the data server
58 NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes);60 NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes);
61 }
59}62}
60 63
61void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) {64void DataServerClient::getValueForKeyAndUUID(const char* key, const QUuid &uuid) {
62 if (!uuid.isNull()) {65 if (!uuid.isNull()) {
63 QString uuidString = uuidStringWithoutCurlyBraces(uuid);66 getValueForKeyAndUserString(key, uuidStringWithoutCurlyBraces(uuid));
64 getValueForKeyAndUserString(key, uuidString);
65 }67 }
66}68}
67 69
68void DataServerClient::getValueForKeyAndUserString(const char* key, QString& userString) {70void DataServerClient::getValueForKeyAndUserString(const char* key, const QString& userString) {
69 unsigned char getPacket[MAX_PACKET_SIZE];71 unsigned char* getPacket = new unsigned char[MAX_PACKET_SIZE];
70 72
71 // setup the header for this packet73 // setup the header for this packet
72 int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET);74 int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET);
@@ -103,21 +105,23 @@ void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, i · 30 unmodified lines
103void DataServerClient::processSendFromDataServer(unsigned char* packetData, int numPacketBytes) {105void DataServerClient::processSendFromDataServer(unsigned char* packetData, int numPacketBytes) {
104 // pull the user string from the packet so we know who to associate this with106 // pull the user string from the packet so we know who to associate this with
105 int numHeaderBytes = numBytesForPacketHeader(packetData);107 int numHeaderBytes = numBytesForPacketHeader(packetData);
106 108
107 QString userString(QByteArray((char*) packetData + numHeaderBytes, strlen((char*) packetData + numHeaderBytes)));109 char* userStringPosition = (char*) packetData + numHeaderBytes;
110
111 QString userString(QByteArray(userStringPosition, strlen(userStringPosition)));
108 112
109 QUuid userUUID(userString);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 if (userUUID.isNull()) {121 if (userUUID.isNull()) {
112 // the user string was a username122 // the user string was a username
113 // for now assume this means that it is for our avatar123 // 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 if (strcmp(dataKeyPosition, DataServerKey::FaceMeshURL) == 0) {125 if (strcmp(dataKeyPosition, DataServerKey::FaceMeshURL) == 0) {
122 // pull the user's face mesh and set it on the Avatar instance126 // 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 } else {134 } else {
131 // user string was UUID, find matching avatar and associate data135 // 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 // remove the matched packet from our map so it isn't re-sent to the data-server152 // remove the matched packet from our map so it isn't re-sent to the data-server