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
6// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.6// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
7//7//
8 8
9#include <QtCore/QUrl>
10
9#include <NodeList.h>11#include <NodeList.h>
10#include <PacketHeaders.h>12#include <PacketHeaders.h>
11#include <UDPSocket.h>13#include <UDPSocket.h>
12#include <UUID.h>14#include <UUID.h>
13 15
16#include "Application.h"
14#include "DataServerClient.h"17#include "DataServerClient.h"
15 18
16QString DataServerClient::_clientUsername;19QString DataServerClient::_clientUsername;
17std::vector<unsigned char*> DataServerClient::_unconfirmedPackets;20std::vector<unsigned char*> DataServerClient::_unmatchedPackets;
18 21
19const char DATA_SERVER_HOSTNAME[] = "127.0.0.1";22const char DATA_SERVER_HOSTNAME[] = "127.0.0.1";
20const unsigned short DATA_SERVER_PORT = 3282;23const unsigned short DATA_SERVER_PORT = 3282;
@@ -27,9 +30,10 @@ void DataServerClient::putValueForKey(const char* key, const char* value) { · 6 unmodified lines
27 // setup the header for this packet30 // setup the header for this packet
28 int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT);31 int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT);
29 32
30 // pack the client UUID33 // pack the client UUID, null terminated
31 memcpy(putPacket + numPacketBytes, _clientUsername.toLocal8Bit().constData(), _clientUsername.toLocal8Bit().size());34 memcpy(putPacket + numPacketBytes, _clientUsername.toLocal8Bit().constData(), _clientUsername.toLocal8Bit().size());
32 numPacketBytes += _clientUsername.toLocal8Bit().size();35 numPacketBytes += _clientUsername.toLocal8Bit().size();
36 putPacket[numPacketBytes++] = '\0';
33 37
34 // pack the key, null terminated38 // pack the key, null terminated
35 strcpy((char*) putPacket + numPacketBytes, key);39 strcpy((char*) putPacket + numPacketBytes, key);
@@ -42,7 +46,7 @@ void DataServerClient::putValueForKey(const char* key, const char* value) { · 6 unmodified lines
42 putPacket[numPacketBytes++] = '\0';46 putPacket[numPacketBytes++] = '\0';
43 47
44 // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed48 // 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);
46 50
47 // send this put request to the data server51 // send this put request to the data server
48 NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes);52 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
62 // setup the header for this packet66 // setup the header for this packet
63 int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET);67 int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET);
64 68
65 // pack the user string (could be username or UUID string)69 // pack the user string (could be username or UUID string), null-terminate
66 memcpy(getPacket + numPacketBytes, userString.toLocal8Bit().constData(), userString.toLocal8Bit().size());70 memcpy(getPacket + numPacketBytes, userString.toLocal8Bit().constData(), userString.toLocal8Bit().size());
67 numPacketBytes += userString.toLocal8Bit().size();71 numPacketBytes += userString.toLocal8Bit().size();
72 getPacket[numPacketBytes++] = '\0';
68 73
69 // pack the key, null terminated74 // pack the key, null terminated
70 strcpy((char*) getPacket + numPacketBytes, key);75 strcpy((char*) getPacket + numPacketBytes, key);
@@ -77,14 +82,14 @@ void DataServerClient::getValueForKeyAndUserString(const char* key, QString& use · 6 unmodified lines
77 82
78void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {83void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {
79 84
80 for (std::vector<unsigned char*>::iterator unconfirmedPacket = _unconfirmedPackets.begin();85 for (std::vector<unsigned char*>::iterator unconfirmedPacket = _unmatchedPackets.begin();
81 unconfirmedPacket != _unconfirmedPackets.end();86 unconfirmedPacket != _unmatchedPackets.end();
82 ++unconfirmedPacket) {87 ++unconfirmedPacket) {
83 if (memcmp(*unconfirmedPacket + sizeof(PACKET_TYPE),88 if (memcmp(*unconfirmedPacket + sizeof(PACKET_TYPE),
84 packetData + sizeof(PACKET_TYPE),89 packetData + sizeof(PACKET_TYPE),
85 numPacketBytes - sizeof(PACKET_TYPE)) == 0) {90 numPacketBytes - sizeof(PACKET_TYPE)) == 0) {
86 // this is a match - remove the confirmed packet from the vector so it isn't sent back out91 // 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);
88 93
89 // we've matched the packet - bail out94 // we've matched the packet - bail out
90 break;95 break;
@@ -95,6 +100,46 @@ void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, i · 4 unmodified lines
95 }100 }
96}101}
97 102
98void DataServerClient::processGetFromDataServer(unsigned char* packetData, int numPacketBytes) {103void 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);
99 110
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
134void 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 }
100}145}

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