From 4cc9f29c8368d737e085a1b712f87eaf7f29d6e1 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 7 Oct 2013 09:55:08 -0700 Subject: [PATCH 01/25] initial stub of data server client code in Interface --- interface/src/DataServerClient.cpp | 70 ++++++++++++++++++++++++++++ interface/src/DataServerClient.h | 28 +++++++++++ libraries/shared/src/PacketHeaders.h | 2 + 3 files changed, 100 insertions(+) create mode 100644 interface/src/DataServerClient.cpp create mode 100644 interface/src/DataServerClient.h diff --git a/interface/src/DataServerClient.cpp b/interface/src/DataServerClient.cpp new file mode 100644 index 0000000000..57789fa8d3 --- /dev/null +++ b/interface/src/DataServerClient.cpp @@ -0,0 +1,70 @@ +// +// DataServerClient.cpp +// hifi +// +// Created by Stephen Birarda on 10/7/13. +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. +// + +#include +#include +#include + +#include "DataServerClient.h" + +const char DATA_SERVER_HOSTNAME[] = "data.highfidelity.io"; +const unsigned short DATA_SERVER_PORT = 3282; +const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT); + +void DataServerClient::putValueForKey(const char* key, const char* value) { + unsigned char putPacket[MAX_PACKET_SIZE]; + + // setup the header for this packet + int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); + + // pack the client UUID + QByteArray rfcUUID = _clientUUID.toRfc4122(); + memcpy(putPacket + numPacketBytes, rfcUUID.constData(), rfcUUID.size()); + numPacketBytes += rfcUUID.size(); + + // pack the key, null terminated + strcpy((char*) putPacket + numPacketBytes, key); + numPacketBytes += strlen(key); + putPacket[numPacketBytes++] = '\0'; + + // pack the value, null terminated + strcpy((char*) putPacket + numPacketBytes, value); + numPacketBytes += strlen(value); + putPacket[numPacketBytes++] = '\0'; + + // send this put request to the data server + NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes); +} + +void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) { + unsigned char getPacket[MAX_PACKET_SIZE]; + + // setup the header for this packet + int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET); + + // pack the UUID we're asking for data for + QByteArray rfcUUID = uuid.toRfc4122(); + memcpy(getPacket + numPacketBytes, rfcUUID, rfcUUID.size()); + numPacketBytes += rfcUUID.size(); + + // pack the key, null terminated + strcpy((char*) getPacket + numPacketBytes, key); + numPacketBytes += strlen(key); + getPacket[numPacketBytes++] = '\0'; + + // send the get to the data server + NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes); +} + +void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) { + +} + +void DataServerClient::processGetFromDataServer(unsigned char* packetData, int numPacketBytes) { + +} diff --git a/interface/src/DataServerClient.h b/interface/src/DataServerClient.h new file mode 100644 index 0000000000..08d828ed49 --- /dev/null +++ b/interface/src/DataServerClient.h @@ -0,0 +1,28 @@ +// +// DataServerClient.h +// hifi +// +// Created by Stephen Birarda on 10/7/13. +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. +// + +#ifndef __hifi__DataServerClient__ +#define __hifi__DataServerClient__ + +#include + +class DataServerClient { +public: + static void putValueForKey(const char* key, const char* value); + static void getValueForKeyAndUUID(const char* key, QUuid& uuid); + static void getClientValueForKey(const char* key) { getValueForKeyAndUUID(key, _clientUUID); } + static void processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes); + static void processGetFromDataServer(unsigned char* packetData, int numPacketBytes); + + static void setClientUUID(QUuid& clientUUID) { _clientUUID = clientUUID; } + static QUuid& getClientUUID() { return _clientUUID; } +private: + static QUuid _clientUUID; +}; + +#endif /* defined(__hifi__DataServerClient__) */ diff --git a/libraries/shared/src/PacketHeaders.h b/libraries/shared/src/PacketHeaders.h index 6d20eac078..c41bc83e03 100644 --- a/libraries/shared/src/PacketHeaders.h +++ b/libraries/shared/src/PacketHeaders.h @@ -41,6 +41,8 @@ const PACKET_TYPE PACKET_TYPE_DEPLOY_ASSIGNMENT = 'd'; const PACKET_TYPE PACKET_TYPE_VOXEL_STATS = '#'; const PACKET_TYPE PACKET_TYPE_VOXEL_JURISDICTION = 'J'; const PACKET_TYPE PACKET_TYPE_VOXEL_JURISDICTION_REQUEST = 'j'; +const PACKET_TYPE PACKET_TYPE_DATA_SERVER_PUT = 'p'; +const PACKET_TYPE PACKET_TYPE_DATA_SERVER_GET = 'g'; typedef char PACKET_VERSION; From 13232a4c0b9955f8b53b87dd83c74c3b661d0968 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 7 Oct 2013 10:45:54 -0700 Subject: [PATCH 02/25] stubbing of mechanism to confirm packets sent to data server --- interface/src/DataServerClient.cpp | 21 ++++++++++++++++++++- interface/src/DataServerClient.h | 3 +++ libraries/shared/src/PacketHeaders.h | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/interface/src/DataServerClient.cpp b/interface/src/DataServerClient.cpp index 57789fa8d3..8afe5f0291 100644 --- a/interface/src/DataServerClient.cpp +++ b/interface/src/DataServerClient.cpp @@ -17,7 +17,7 @@ const unsigned short DATA_SERVER_PORT = 3282; const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT); void DataServerClient::putValueForKey(const char* key, const char* value) { - unsigned char putPacket[MAX_PACKET_SIZE]; + unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE]; // setup the header for this packet int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); @@ -37,6 +37,9 @@ void DataServerClient::putValueForKey(const char* key, const char* value) { numPacketBytes += strlen(value); putPacket[numPacketBytes++] = '\0'; + // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed + _unconfirmedPackets.push_back(putPacket); + // send this put request to the data server NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes); } @@ -63,6 +66,22 @@ void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) { void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) { + for (std::vector::iterator unconfirmedPacket = _unconfirmedPackets.begin(); + unconfirmedPacket != _unconfirmedPackets.end(); + ++unconfirmedPacket) { + if (memcmp(*unconfirmedPacket + sizeof(PACKET_TYPE), + packetData + sizeof(PACKET_TYPE), + numPacketBytes - sizeof(PACKET_TYPE)) == 0) { + // this is a match - remove the confirmed packet from the vector so it isn't sent back out + _unconfirmedPackets.erase(unconfirmedPacket); + + // we've matched the packet - bail out + break; + } else { + // no match, just push the iterator + unconfirmedPacket++; + } + } } void DataServerClient::processGetFromDataServer(unsigned char* packetData, int numPacketBytes) { diff --git a/interface/src/DataServerClient.h b/interface/src/DataServerClient.h index 08d828ed49..f858aff497 100644 --- a/interface/src/DataServerClient.h +++ b/interface/src/DataServerClient.h @@ -9,6 +9,8 @@ #ifndef __hifi__DataServerClient__ #define __hifi__DataServerClient__ +#include + #include class DataServerClient { @@ -23,6 +25,7 @@ public: static QUuid& getClientUUID() { return _clientUUID; } private: static QUuid _clientUUID; + static std::vector _unconfirmedPackets; }; #endif /* defined(__hifi__DataServerClient__) */ diff --git a/libraries/shared/src/PacketHeaders.h b/libraries/shared/src/PacketHeaders.h index c41bc83e03..254f2f74fc 100644 --- a/libraries/shared/src/PacketHeaders.h +++ b/libraries/shared/src/PacketHeaders.h @@ -43,6 +43,8 @@ const PACKET_TYPE PACKET_TYPE_VOXEL_JURISDICTION = 'J'; const PACKET_TYPE PACKET_TYPE_VOXEL_JURISDICTION_REQUEST = 'j'; const PACKET_TYPE PACKET_TYPE_DATA_SERVER_PUT = 'p'; const PACKET_TYPE PACKET_TYPE_DATA_SERVER_GET = 'g'; +const PACKET_TYPE PACKET_TYPE_DATA_SERVER_SEND = 'u'; +const PACKET_TYPE PACKET_TYPE_DATA_SERVER_CONFIRM = 'c'; typedef char PACKET_VERSION; From 5a7d21f529bf4e93d6ccd88571b00aca98ca9e12 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 7 Oct 2013 10:56:23 -0700 Subject: [PATCH 03/25] add UUID helper class to get UUID string without braces --- assignment-client/src/Agent.cpp | 3 ++- domain-server/src/DomainServer.cpp | 3 ++- interface/src/DataServerClient.cpp | 3 +++ libraries/shared/src/Assignment.cpp | 4 ---- libraries/shared/src/Assignment.h | 1 - libraries/shared/src/UUID.cpp | 14 ++++++++++++++ libraries/shared/src/UUID.h | 16 ++++++++++++++++ 7 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 libraries/shared/src/UUID.cpp create mode 100644 libraries/shared/src/UUID.h diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index 2906233d78..133a72859e 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include "Agent.h" @@ -50,7 +51,7 @@ void Agent::run() { // figure out the URL for the script for this agent assignment QString scriptURLString("http://%1:8080/assignment/%2"); scriptURLString = scriptURLString.arg(NodeList::getInstance()->getDomainIP().toString(), - this->getUUIDStringWithoutCurlyBraces()); + uuidStringWithoutCurlyBraces(_uuid)); // setup curl for script download CURLcode curlResult; diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index a062c22ad3..62dfea3857 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -12,6 +12,7 @@ #include #include +#include #include "DomainServer.h" @@ -62,7 +63,7 @@ void DomainServer::civetwebUploadHandler(struct mg_connection *connection, const QString newPath(ASSIGNMENT_SCRIPT_HOST_LOCATION); newPath += "/"; // append the UUID for this script as the new filename, remove the curly braces - newPath += scriptAssignment->getUUIDStringWithoutCurlyBraces(); + newPath += uuidStringWithoutCurlyBraces(scriptAssignment->getUUID()); // rename the saved script to the GUID of the assignment and move it to the script host locaiton rename(path, newPath.toLocal8Bit().constData()); diff --git a/interface/src/DataServerClient.cpp b/interface/src/DataServerClient.cpp index 8afe5f0291..00bc4d4077 100644 --- a/interface/src/DataServerClient.cpp +++ b/interface/src/DataServerClient.cpp @@ -12,6 +12,9 @@ #include "DataServerClient.h" +QUuid DataServerClient::_clientUUID; +std::vector DataServerClient::_unconfirmedPackets; + const char DATA_SERVER_HOSTNAME[] = "data.highfidelity.io"; const unsigned short DATA_SERVER_PORT = 3282; const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT); diff --git a/libraries/shared/src/Assignment.cpp b/libraries/shared/src/Assignment.cpp index f9cf727894..6829a8b266 100644 --- a/libraries/shared/src/Assignment.cpp +++ b/libraries/shared/src/Assignment.cpp @@ -139,10 +139,6 @@ void Assignment::setPayload(const uchar* payload, int numBytes) { memcpy(_payload, payload, _numPayloadBytes); } -QString Assignment::getUUIDStringWithoutCurlyBraces() const { - return _uuid.toString().mid(1, _uuid.toString().length() - 2); -} - int Assignment::packToBuffer(unsigned char* buffer) { int numPackedBytes = 0; diff --git a/libraries/shared/src/Assignment.h b/libraries/shared/src/Assignment.h index 55e9f2816b..694be61e0e 100644 --- a/libraries/shared/src/Assignment.h +++ b/libraries/shared/src/Assignment.h @@ -60,7 +60,6 @@ public: void setUUID(const QUuid& uuid) { _uuid = uuid; } const QUuid& getUUID() const { return _uuid; } - QString getUUIDStringWithoutCurlyBraces() const; void resetUUID() { _uuid = QUuid::createUuid(); } Assignment::Command getCommand() const { return _command; } diff --git a/libraries/shared/src/UUID.cpp b/libraries/shared/src/UUID.cpp new file mode 100644 index 0000000000..e24c81ebe3 --- /dev/null +++ b/libraries/shared/src/UUID.cpp @@ -0,0 +1,14 @@ +// +// UUID.cpp +// hifi +// +// Created by Stephen Birarda on 10/7/13. +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. +// + +#include "UUID.h" + +QString uuidStringWithoutCurlyBraces(const QUuid& uuid) { + QString uuidStringNoBraces = uuid.toString().mid(1, uuid.toString().length() - 2); + return uuidStringNoBraces; +} \ No newline at end of file diff --git a/libraries/shared/src/UUID.h b/libraries/shared/src/UUID.h new file mode 100644 index 0000000000..985f44ae7b --- /dev/null +++ b/libraries/shared/src/UUID.h @@ -0,0 +1,16 @@ +// +// UUID.h +// hifi +// +// Created by Stephen Birarda on 10/7/13. +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. +// + +#ifndef __hifi__UUID__ +#define __hifi__UUID__ + +#include + +QString uuidStringWithoutCurlyBraces(const QUuid& uuid); + +#endif /* defined(__hifi__UUID__) */ From fea3ca82298c75889e3088a8ba1ec4442ae51d40 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 7 Oct 2013 10:58:26 -0700 Subject: [PATCH 04/25] pack string representation of UUID for data server communication --- interface/src/DataServerClient.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/interface/src/DataServerClient.cpp b/interface/src/DataServerClient.cpp index 00bc4d4077..250557242e 100644 --- a/interface/src/DataServerClient.cpp +++ b/interface/src/DataServerClient.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "DataServerClient.h" @@ -26,9 +27,9 @@ void DataServerClient::putValueForKey(const char* key, const char* value) { int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); // pack the client UUID - QByteArray rfcUUID = _clientUUID.toRfc4122(); - memcpy(putPacket + numPacketBytes, rfcUUID.constData(), rfcUUID.size()); - numPacketBytes += rfcUUID.size(); + QString uuidString = uuidStringWithoutCurlyBraces(_clientUUID); + memcpy(putPacket + numPacketBytes, uuidString.toLocal8Bit().constData(), uuidString.toLocal8Bit().size()); + numPacketBytes += uuidString.toLocal8Bit().size(); // pack the key, null terminated strcpy((char*) putPacket + numPacketBytes, key); @@ -54,9 +55,9 @@ void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) { int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET); // pack the UUID we're asking for data for - QByteArray rfcUUID = uuid.toRfc4122(); - memcpy(getPacket + numPacketBytes, rfcUUID, rfcUUID.size()); - numPacketBytes += rfcUUID.size(); + QString uuidString = uuidStringWithoutCurlyBraces(uuid); + memcpy(getPacket + numPacketBytes, uuidString.toLocal8Bit().constData(), uuidString.toLocal8Bit().size()); + numPacketBytes += uuidString.toLocal8Bit().size(); // pack the key, null terminated strcpy((char*) getPacket + numPacketBytes, key); From 98f435ccc2b1f3a854e19367ca2698add5f23638 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 7 Oct 2013 12:03:04 -0700 Subject: [PATCH 05/25] link mesh URL and UUID in prefs to data server client --- interface/src/DataServerClient.cpp | 90 ++++++++++++++++-------------- interface/src/Menu.cpp | 33 +++++++++-- interface/src/avatar/Avatar.cpp | 47 +--------------- interface/src/avatar/Avatar.h | 9 +-- interface/src/avatar/MyAvatar.cpp | 60 ++++++++++++++++++++ interface/src/avatar/MyAvatar.h | 9 ++- 6 files changed, 149 insertions(+), 99 deletions(-) diff --git a/interface/src/DataServerClient.cpp b/interface/src/DataServerClient.cpp index 250557242e..3c4546e7a1 100644 --- a/interface/src/DataServerClient.cpp +++ b/interface/src/DataServerClient.cpp @@ -16,56 +16,60 @@ QUuid DataServerClient::_clientUUID; std::vector DataServerClient::_unconfirmedPackets; -const char DATA_SERVER_HOSTNAME[] = "data.highfidelity.io"; +const char DATA_SERVER_HOSTNAME[] = "127.0.0.1"; const unsigned short DATA_SERVER_PORT = 3282; const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT); void DataServerClient::putValueForKey(const char* key, const char* value) { - unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE]; - - // setup the header for this packet - int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); - - // pack the client UUID - QString uuidString = uuidStringWithoutCurlyBraces(_clientUUID); - memcpy(putPacket + numPacketBytes, uuidString.toLocal8Bit().constData(), uuidString.toLocal8Bit().size()); - numPacketBytes += uuidString.toLocal8Bit().size(); - - // pack the key, null terminated - strcpy((char*) putPacket + numPacketBytes, key); - numPacketBytes += strlen(key); - putPacket[numPacketBytes++] = '\0'; - - // pack the value, null terminated - strcpy((char*) putPacket + numPacketBytes, value); - numPacketBytes += strlen(value); - putPacket[numPacketBytes++] = '\0'; - - // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed - _unconfirmedPackets.push_back(putPacket); - - // send this put request to the data server - NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes); + if (!_clientUUID.isNull()) { + unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE]; + + // setup the header for this packet + int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); + + // pack the client UUID + QString uuidString = uuidStringWithoutCurlyBraces(_clientUUID); + memcpy(putPacket + numPacketBytes, uuidString.toLocal8Bit().constData(), uuidString.toLocal8Bit().size()); + numPacketBytes += uuidString.toLocal8Bit().size(); + + // pack the key, null terminated + strcpy((char*) putPacket + numPacketBytes, key); + numPacketBytes += strlen(key); + putPacket[numPacketBytes++] = '\0'; + + // pack the value, null terminated + strcpy((char*) putPacket + numPacketBytes, value); + numPacketBytes += strlen(value); + putPacket[numPacketBytes++] = '\0'; + + // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed + _unconfirmedPackets.push_back(putPacket); + + // send this put request to the data server + NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes); + } } void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) { - unsigned char getPacket[MAX_PACKET_SIZE]; - - // setup the header for this packet - int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET); - - // pack the UUID we're asking for data for - QString uuidString = uuidStringWithoutCurlyBraces(uuid); - memcpy(getPacket + numPacketBytes, uuidString.toLocal8Bit().constData(), uuidString.toLocal8Bit().size()); - numPacketBytes += uuidString.toLocal8Bit().size(); - - // pack the key, null terminated - strcpy((char*) getPacket + numPacketBytes, key); - numPacketBytes += strlen(key); - getPacket[numPacketBytes++] = '\0'; - - // send the get to the data server - NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes); + if (!uuid.isNull()) { + unsigned char getPacket[MAX_PACKET_SIZE]; + + // setup the header for this packet + int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET); + + // pack the UUID we're asking for data for + QString uuidString = uuidStringWithoutCurlyBraces(uuid); + memcpy(getPacket + numPacketBytes, uuidString.toLocal8Bit().constData(), uuidString.toLocal8Bit().size()); + numPacketBytes += uuidString.toLocal8Bit().size(); + + // pack the key, null terminated + strcpy((char*) getPacket + numPacketBytes, key); + numPacketBytes += strlen(key); + getPacket[numPacketBytes++] = '\0'; + + // send the get to the data server + NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes); + } } void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) { diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index ededcbccd0..17b9901c12 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -19,8 +19,12 @@ #include #include #include +#include + +#include #include "Application.h" +#include "DataServerClient.h" #include "PairingHandler.h" #include "Menu.h" #include "Util.h" @@ -736,6 +740,7 @@ QLineEdit* lineEditForDomainHostname() { void Menu::editPreferences() { Application* applicationInstance = Application::getInstance(); + QDialog dialog(applicationInstance->getGLWidget()); dialog.setWindowTitle("Interface Preferences"); QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); @@ -744,13 +749,19 @@ void Menu::editPreferences() { QFormLayout* form = new QFormLayout(); layout->addLayout(form, 1); + QUuid avatarUUID = applicationInstance->getAvatar()->getUUID(); + QLineEdit* avatarUUIDLineEdit = new QLineEdit(avatarUUID.isNull() ? QString() : uuidStringWithoutCurlyBraces(avatarUUID)); + avatarUUIDLineEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH); + form->addRow("UUID:", avatarUUIDLineEdit); + QLineEdit* avatarURL = new QLineEdit(applicationInstance->getAvatar()->getVoxels()->getVoxelURL().toString()); avatarURL->setMinimumWidth(QLINE_MINIMUM_WIDTH); form->addRow("Avatar URL:", avatarURL); - QLineEdit* faceURL = new QLineEdit(applicationInstance->getAvatar()->getHead().getBlendFace().getModelURL().toString()); - faceURL->setMinimumWidth(QLINE_MINIMUM_WIDTH); - form->addRow("Face URL:", faceURL); + QString faceURLString = applicationInstance->getAvatar()->getHead().getBlendFace().getModelURL().toString(); + QLineEdit* faceURLEdit = new QLineEdit(faceURLString); + faceURLEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH); + form->addRow("Face URL:", faceURLEdit); QSlider* pupilDilation = new QSlider(Qt::Horizontal); pupilDilation->setValue(applicationInstance->getAvatar()->getHead().getPupilDilation() * pupilDilation->maximum()); @@ -793,11 +804,23 @@ void Menu::editPreferences() { return; } + QUuid newUUID(avatarUUIDLineEdit->text()); + if (newUUID != avatarUUID) { + // there has been a UUID change - set the new UUID on the avatar instance + applicationInstance->getAvatar()->setUUID(newUUID); + + } + QUrl avatarVoxelURL(avatarURL->text()); applicationInstance->getAvatar()->getVoxels()->setVoxelURL(avatarVoxelURL); - QUrl faceModelURL(faceURL->text()); - applicationInstance->getAvatar()->getHead().getBlendFace().setModelURL(faceModelURL); + QUrl faceModelURL(faceURLEdit->text()); + if (faceModelURL.toString() != faceURLString) { + applicationInstance->getAvatar()->getHead().getBlendFace().setModelURL(faceModelURL); + + // send the new face mesh URL to the data-server (if we have a client UUID) + DataServerClient::putValueForKey("mesh", faceModelURL.toString().toLocal8Bit().constData()); + } Avatar::sendAvatarURLsMessage(avatarVoxelURL, faceModelURL); diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index c278f9b697..873bae5e2b 100755 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -102,6 +102,7 @@ Avatar::Avatar(Node* owningNode) : _leadingAvatar(NULL), _voxels(this), _moving(false), + _uuid(), _initialized(false), _handHoldingPosition(0.0f, 0.0f, 0.0f), _maxArmLength(0.0f), @@ -751,31 +752,6 @@ void Avatar::renderBody(bool lookingInMirror, bool renderAvatarBalls) { _hand.render(lookingInMirror); } - -void Avatar::loadData(QSettings* settings) { - settings->beginGroup("Avatar"); - - // in case settings is corrupt or missing loadSetting() will check for NaN - _bodyYaw = loadSetting(settings, "bodyYaw", 0.0f); - _bodyPitch = loadSetting(settings, "bodyPitch", 0.0f); - _bodyRoll = loadSetting(settings, "bodyRoll", 0.0f); - _position.x = loadSetting(settings, "position_x", 0.0f); - _position.y = loadSetting(settings, "position_y", 0.0f); - _position.z = loadSetting(settings, "position_z", 0.0f); - - _voxels.setVoxelURL(settings->value("voxelURL").toUrl()); - _head.getBlendFace().setModelURL(settings->value("faceModelURL").toUrl()); - _head.setPupilDilation(settings->value("pupilDilation", 0.0f).toFloat()); - - _leanScale = loadSetting(settings, "leanScale", 0.05f); - - _newScale = loadSetting(settings, "scale", 1.0f); - setScale(_scale); - Application::getInstance()->getCamera()->setScale(_scale); - - settings->endGroup(); -} - void Avatar::getBodyBallTransform(AvatarJointID jointID, glm::vec3& position, glm::quat& rotation) const { position = _bodyBall[jointID].position; rotation = _bodyBall[jointID].rotation; @@ -805,27 +781,6 @@ int Avatar::parseData(unsigned char* sourceBuffer, int numBytes) { return bytesRead; } -void Avatar::saveData(QSettings* set) { - set->beginGroup("Avatar"); - - set->setValue("bodyYaw", _bodyYaw); - set->setValue("bodyPitch", _bodyPitch); - set->setValue("bodyRoll", _bodyRoll); - - set->setValue("position_x", _position.x); - set->setValue("position_y", _position.y); - set->setValue("position_z", _position.z); - - set->setValue("voxelURL", _voxels.getVoxelURL()); - set->setValue("faceModelURL", _head.getBlendFace().getModelURL()); - set->setValue("pupilDilation", _head.getPupilDilation()); - - set->setValue("leanScale", _leanScale); - set->setValue("scale", _newScale); - - set->endGroup(); -} - // render a makeshift cone section that serves as a body part connecting joint spheres void Avatar::renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2, float radius1, float radius2) { diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index 9396480d27..ae8067c6d4 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -11,7 +11,7 @@ #include #include -#include +#include #include @@ -156,9 +156,8 @@ public: glm::quat getWorldAlignedOrientation() const; AvatarVoxelSystem* getVoxels() { return &_voxels; } - // get/set avatar data - void saveData(QSettings* set); - void loadData(QSettings* set); + QUuid& getUUID() { return _uuid; } + void setUUID(const QUuid& uuid) { _uuid = uuid; } // Get the position/rotation of a single body ball void getBodyBallTransform(AvatarJointID jointID, glm::vec3& position, glm::quat& rotation) const; @@ -226,6 +225,7 @@ protected: AvatarVoxelSystem _voxels; bool _moving; ///< set when position is changing + QUuid _uuid; // protected methods... glm::vec3 getBodyRightDirection() const { return getOrientation() * IDENTITY_RIGHT; } @@ -247,6 +247,7 @@ private: float _maxArmLength; float _pelvisStandingHeight; + // private methods... glm::vec3 calculateAverageEyePosition() { return _head.calculateAverageEyePosition(); } // get the position smack-dab between the eyes (for lookat) float getBallRenderAlpha(int ball, bool lookingInMirror) const; diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index f7c26e75aa..3a92a910ed 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -16,6 +16,7 @@ #include #include "Application.h" +#include "DataServerClient.h" #include "MyAvatar.h" #include "Physics.h" #include "devices/OculusManager.h" @@ -71,6 +72,15 @@ void MyAvatar::setMoveTarget(const glm::vec3 moveTarget) { _moveTargetStepCounter = 0; } +void MyAvatar::setUUID(const QUuid& uuid) { + _uuid = uuid; + + qDebug() << "giving" << _uuid << "to DSC class.\n"; + + // give this UUID to the DataServerClient class as our client UUID + DataServerClient::setClientUUID(_uuid); +} + void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) { glm::quat orientation = getOrientation(); @@ -524,6 +534,56 @@ void MyAvatar::renderScreenTint(ScreenTintLayer layer, Camera& whichCamera) { } } +void MyAvatar::saveData(QSettings* settings) { + settings->beginGroup("Avatar"); + + settings->setValue("UUID", _uuid); + + settings->setValue("bodyYaw", _bodyYaw); + settings->setValue("bodyPitch", _bodyPitch); + settings->setValue("bodyRoll", _bodyRoll); + + settings->setValue("position_x", _position.x); + settings->setValue("position_y", _position.y); + settings->setValue("position_z", _position.z); + + settings->setValue("voxelURL", _voxels.getVoxelURL()); + settings->setValue("faceModelURL", _head.getBlendFace().getModelURL()); + settings->setValue("pupilDilation", _head.getPupilDilation()); + + settings->setValue("leanScale", _leanScale); + settings->setValue("scale", _newScale); + + settings->endGroup(); +} + +void MyAvatar::loadData(QSettings* settings) { + settings->beginGroup("Avatar"); + + setUUID(settings->value("UUID").toUuid()); + + // in case settings is corrupt or missing loadSetting() will check for NaN + _bodyYaw = loadSetting(settings, "bodyYaw", 0.0f); + _bodyPitch = loadSetting(settings, "bodyPitch", 0.0f); + _bodyRoll = loadSetting(settings, "bodyRoll", 0.0f); + _position.x = loadSetting(settings, "position_x", 0.0f); + _position.y = loadSetting(settings, "position_y", 0.0f); + _position.z = loadSetting(settings, "position_z", 0.0f); + + _voxels.setVoxelURL(settings->value("voxelURL").toUrl()); + _head.getBlendFace().setModelURL(settings->value("faceModelURL").toUrl()); + _head.setPupilDilation(settings->value("pupilDilation", 0.0f).toFloat()); + + _leanScale = loadSetting(settings, "leanScale", 0.05f); + + _newScale = loadSetting(settings, "scale", 1.0f); + setScale(_scale); + Application::getInstance()->getCamera()->setScale(_scale); + + settings->endGroup(); +} + + float MyAvatar::getAbsoluteHeadYaw() const { return glm::yaw(_head.getOrientation()); } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 95c1efd5a8..54e2e37344 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -9,6 +9,8 @@ #ifndef __interface__myavatar__ #define __interface__myavatar__ +#include + #include "Avatar.h" class MyAvatar : public Avatar { @@ -32,6 +34,7 @@ public: void setNewScale(const float scale); void setWantCollisionsOn(bool wantCollisionsOn) { _isCollisionsOn = wantCollisionsOn; } void setMoveTarget(const glm::vec3 moveTarget); + void setUUID(const QUuid& uuid); // getters float getNewScale() const { return _newScale; } @@ -47,6 +50,10 @@ public: glm::vec3 getGravity() const { return _gravity; } glm::vec3 getUprightHeadPosition() const; glm::vec3 getUprightEyeLevelPosition() const; + + // get/set avatar data + void saveData(QSettings* settings); + void loadData(QSettings* settings); // Set what driving keys are being pressed to control thrust levels void setDriveKeys(int key, bool val) { _driveKeys[key] = val; }; @@ -57,7 +64,7 @@ public: void addThrust(glm::vec3 newThrust) { _thrust += newThrust; }; glm::vec3 getThrust() { return _thrust; }; - private: +private: bool _mousePressed; float _bodyPitchDelta; float _bodyRollDelta; From f36fd47ef71201e64eff7e5c8b2ba61afaf425bc Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 7 Oct 2013 12:17:47 -0700 Subject: [PATCH 06/25] store username and not UUID for MyAvatar --- interface/src/DataServerClient.cpp | 45 ++++++++++++++++-------------- interface/src/DataServerClient.h | 9 +++--- interface/src/Menu.cpp | 15 +++++----- interface/src/avatar/MyAvatar.cpp | 4 +-- interface/src/avatar/MyAvatar.h | 4 ++- 5 files changed, 41 insertions(+), 36 deletions(-) diff --git a/interface/src/DataServerClient.cpp b/interface/src/DataServerClient.cpp index 3c4546e7a1..5c16544ba2 100644 --- a/interface/src/DataServerClient.cpp +++ b/interface/src/DataServerClient.cpp @@ -13,7 +13,7 @@ #include "DataServerClient.h" -QUuid DataServerClient::_clientUUID; +QString DataServerClient::_clientUsername; std::vector DataServerClient::_unconfirmedPackets; const char DATA_SERVER_HOSTNAME[] = "127.0.0.1"; @@ -21,16 +21,15 @@ const unsigned short DATA_SERVER_PORT = 3282; const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT); void DataServerClient::putValueForKey(const char* key, const char* value) { - if (!_clientUUID.isNull()) { + if (!_clientUsername.isEmpty()) { unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE]; // setup the header for this packet int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); // pack the client UUID - QString uuidString = uuidStringWithoutCurlyBraces(_clientUUID); - memcpy(putPacket + numPacketBytes, uuidString.toLocal8Bit().constData(), uuidString.toLocal8Bit().size()); - numPacketBytes += uuidString.toLocal8Bit().size(); + memcpy(putPacket + numPacketBytes, _clientUsername.toLocal8Bit().constData(), _clientUsername.toLocal8Bit().size()); + numPacketBytes += _clientUsername.toLocal8Bit().size(); // pack the key, null terminated strcpy((char*) putPacket + numPacketBytes, key); @@ -52,26 +51,30 @@ void DataServerClient::putValueForKey(const char* key, const char* value) { void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) { if (!uuid.isNull()) { - unsigned char getPacket[MAX_PACKET_SIZE]; - - // setup the header for this packet - int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET); - - // pack the UUID we're asking for data for QString uuidString = uuidStringWithoutCurlyBraces(uuid); - memcpy(getPacket + numPacketBytes, uuidString.toLocal8Bit().constData(), uuidString.toLocal8Bit().size()); - numPacketBytes += uuidString.toLocal8Bit().size(); - - // pack the key, null terminated - strcpy((char*) getPacket + numPacketBytes, key); - numPacketBytes += strlen(key); - getPacket[numPacketBytes++] = '\0'; - - // send the get to the data server - NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes); + getValueforKeyAndUserString(key, uuidString); } } +void DataServerClient::getValueforKeyAndUserString(const char* key, QString& userString) { + unsigned char getPacket[MAX_PACKET_SIZE]; + + // setup the header for this packet + int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET); + + // pack the user string (could be username or UUID string) + memcpy(getPacket + numPacketBytes, userString.toLocal8Bit().constData(), userString.toLocal8Bit().size()); + numPacketBytes += userString.toLocal8Bit().size(); + + // pack the key, null terminated + strcpy((char*) getPacket + numPacketBytes, key); + numPacketBytes += strlen(key); + getPacket[numPacketBytes++] = '\0'; + + // send the get to the data server + NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes); +} + void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) { for (std::vector::iterator unconfirmedPacket = _unconfirmedPackets.begin(); diff --git a/interface/src/DataServerClient.h b/interface/src/DataServerClient.h index f858aff497..19969b3345 100644 --- a/interface/src/DataServerClient.h +++ b/interface/src/DataServerClient.h @@ -17,14 +17,15 @@ class DataServerClient { public: static void putValueForKey(const char* key, const char* value); static void getValueForKeyAndUUID(const char* key, QUuid& uuid); - static void getClientValueForKey(const char* key) { getValueForKeyAndUUID(key, _clientUUID); } + static void getValueforKeyAndUserString(const char* key, QString& userString); + static void getClientValueForKey(const char* key) { getValueForKeyAndUserString(key, _clientUsername); } static void processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes); static void processGetFromDataServer(unsigned char* packetData, int numPacketBytes); - static void setClientUUID(QUuid& clientUUID) { _clientUUID = clientUUID; } - static QUuid& getClientUUID() { return _clientUUID; } + static void setClientUsername(QString& clientUsername) { _clientUsername = clientUsername; } + static QString& setClientUsername() { return _clientUsername; } private: - static QUuid _clientUUID; + static QString _clientUsername; static std::vector _unconfirmedPackets; }; diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 17b9901c12..7f3858ac75 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -749,10 +749,10 @@ void Menu::editPreferences() { QFormLayout* form = new QFormLayout(); layout->addLayout(form, 1); - QUuid avatarUUID = applicationInstance->getAvatar()->getUUID(); - QLineEdit* avatarUUIDLineEdit = new QLineEdit(avatarUUID.isNull() ? QString() : uuidStringWithoutCurlyBraces(avatarUUID)); - avatarUUIDLineEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH); - form->addRow("UUID:", avatarUUIDLineEdit); + QString avatarUsername = applicationInstance->getAvatar()->getUsername(); + QLineEdit* avatarUsernameEdit = new QLineEdit(avatarUsername); + avatarUsernameEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH); + form->addRow("Username:", avatarUsernameEdit); QLineEdit* avatarURL = new QLineEdit(applicationInstance->getAvatar()->getVoxels()->getVoxelURL().toString()); avatarURL->setMinimumWidth(QLINE_MINIMUM_WIDTH); @@ -804,10 +804,9 @@ void Menu::editPreferences() { return; } - QUuid newUUID(avatarUUIDLineEdit->text()); - if (newUUID != avatarUUID) { + if (avatarUsernameEdit->text() != avatarUsername) { // there has been a UUID change - set the new UUID on the avatar instance - applicationInstance->getAvatar()->setUUID(newUUID); + applicationInstance->getAvatar()->setUsername(avatarUsernameEdit->text()); } @@ -819,7 +818,7 @@ void Menu::editPreferences() { applicationInstance->getAvatar()->getHead().getBlendFace().setModelURL(faceModelURL); // send the new face mesh URL to the data-server (if we have a client UUID) - DataServerClient::putValueForKey("mesh", faceModelURL.toString().toLocal8Bit().constData()); + DataServerClient::putValueForKey("mesh", faceModelURL.toString().toLocal8Bit().constData()); } Avatar::sendAvatarURLsMessage(avatarVoxelURL, faceModelURL); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 3a92a910ed..f1875ee344 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -537,7 +537,7 @@ void MyAvatar::renderScreenTint(ScreenTintLayer layer, Camera& whichCamera) { void MyAvatar::saveData(QSettings* settings) { settings->beginGroup("Avatar"); - settings->setValue("UUID", _uuid); + settings->setValue("Username", _username); settings->setValue("bodyYaw", _bodyYaw); settings->setValue("bodyPitch", _bodyPitch); @@ -560,7 +560,7 @@ void MyAvatar::saveData(QSettings* settings) { void MyAvatar::loadData(QSettings* settings) { settings->beginGroup("Avatar"); - setUUID(settings->value("UUID").toUuid()); + setUUID(settings->value("Usernmame").toString(); // in case settings is corrupt or missing loadSetting() will check for NaN _bodyYaw = loadSetting(settings, "bodyYaw", 0.0f); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 54e2e37344..dec6891807 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -34,7 +34,7 @@ public: void setNewScale(const float scale); void setWantCollisionsOn(bool wantCollisionsOn) { _isCollisionsOn = wantCollisionsOn; } void setMoveTarget(const glm::vec3 moveTarget); - void setUUID(const QUuid& uuid); + void setUsername(const QString& username) { _username = username; } // getters float getNewScale() const { return _newScale; } @@ -50,6 +50,7 @@ public: glm::vec3 getGravity() const { return _gravity; } glm::vec3 getUprightHeadPosition() const; glm::vec3 getUprightEyeLevelPosition() const; + const QString& getUsername() const { return _username; } // get/set avatar data void saveData(QSettings* settings); @@ -83,6 +84,7 @@ private: float _collisionRadius; glm::vec3 _moveTarget; int _moveTargetStepCounter; + QString _username; // private methods float getBallRenderAlpha(int ball, bool lookingInMirror) const; From e9e77d8276da6ffff1306d5a2001c0982515e048 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 7 Oct 2013 13:35:16 -0700 Subject: [PATCH 07/25] set username instead of UUID in Interface preferences --- interface/src/DataServerClient.cpp | 4 ++-- interface/src/DataServerClient.h | 4 ++-- interface/src/avatar/MyAvatar.cpp | 11 ++++------- interface/src/avatar/MyAvatar.h | 2 +- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/interface/src/DataServerClient.cpp b/interface/src/DataServerClient.cpp index 5c16544ba2..2eefef8ce4 100644 --- a/interface/src/DataServerClient.cpp +++ b/interface/src/DataServerClient.cpp @@ -52,11 +52,11 @@ void DataServerClient::putValueForKey(const char* key, const char* value) { void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) { if (!uuid.isNull()) { QString uuidString = uuidStringWithoutCurlyBraces(uuid); - getValueforKeyAndUserString(key, uuidString); + getValueForKeyAndUserString(key, uuidString); } } -void DataServerClient::getValueforKeyAndUserString(const char* key, QString& userString) { +void DataServerClient::getValueForKeyAndUserString(const char* key, QString& userString) { unsigned char getPacket[MAX_PACKET_SIZE]; // setup the header for this packet diff --git a/interface/src/DataServerClient.h b/interface/src/DataServerClient.h index 19969b3345..c1e5ad088c 100644 --- a/interface/src/DataServerClient.h +++ b/interface/src/DataServerClient.h @@ -17,12 +17,12 @@ class DataServerClient { public: static void putValueForKey(const char* key, const char* value); static void getValueForKeyAndUUID(const char* key, QUuid& uuid); - static void getValueforKeyAndUserString(const char* key, QString& userString); + static void getValueForKeyAndUserString(const char* key, QString& userString); static void getClientValueForKey(const char* key) { getValueForKeyAndUserString(key, _clientUsername); } static void processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes); static void processGetFromDataServer(unsigned char* packetData, int numPacketBytes); - static void setClientUsername(QString& clientUsername) { _clientUsername = clientUsername; } + static void setClientUsername(const QString& clientUsername) { _clientUsername = clientUsername; } static QString& setClientUsername() { return _clientUsername; } private: static QString _clientUsername; diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index f1875ee344..c08843b118 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -72,13 +72,10 @@ void MyAvatar::setMoveTarget(const glm::vec3 moveTarget) { _moveTargetStepCounter = 0; } -void MyAvatar::setUUID(const QUuid& uuid) { - _uuid = uuid; +void MyAvatar::setUsername(const QString& username) { + _username = username; - qDebug() << "giving" << _uuid << "to DSC class.\n"; - - // give this UUID to the DataServerClient class as our client UUID - DataServerClient::setClientUUID(_uuid); + DataServerClient::setClientUsername(username); } void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) { @@ -560,7 +557,7 @@ void MyAvatar::saveData(QSettings* settings) { void MyAvatar::loadData(QSettings* settings) { settings->beginGroup("Avatar"); - setUUID(settings->value("Usernmame").toString(); + setUsername(settings->value("Username").toString()); // in case settings is corrupt or missing loadSetting() will check for NaN _bodyYaw = loadSetting(settings, "bodyYaw", 0.0f); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index dec6891807..4b37e28f55 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -34,7 +34,7 @@ public: void setNewScale(const float scale); void setWantCollisionsOn(bool wantCollisionsOn) { _isCollisionsOn = wantCollisionsOn; } void setMoveTarget(const glm::vec3 moveTarget); - void setUsername(const QString& username) { _username = username; } + void setUsername(const QString& username); // getters float getNewScale() const { return _newScale; } From b33843fddcfdc358e3602083e22fe05bc672a3b7 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 7 Oct 2013 13:52:46 -0700 Subject: [PATCH 08/25] ask for a mesh if username is present on login or is changed --- interface/src/Application.cpp | 6 ++++++ interface/src/DataServerClient.h | 4 ++++ interface/src/Menu.cpp | 12 +++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 6d7686328f..a078820e3d 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -58,6 +58,7 @@ #include #include "Application.h" +#include "DataServerClient.h" #include "LogDisplay.h" #include "Menu.h" #include "Swatch.h" @@ -1585,6 +1586,11 @@ void Application::init() { _audio.setJitterBufferSamples(Menu::getInstance()->getAudioJitterBufferSamples()); } qDebug("Loaded settings.\n"); + + if (!_myAvatar.getUsername().isEmpty()) { + // we have a username for this avatar, ask the data-server for the mesh URL for this avatar + DataServerClient::getClientValueForKey(DataServerKey::FaceMeshURL); + } // Set up VoxelSystem after loading preferences so we can get the desired max voxel count _voxels.setMaxVoxels(Menu::getInstance()->getMaxVoxels()); diff --git a/interface/src/DataServerClient.h b/interface/src/DataServerClient.h index c1e5ad088c..993608ef81 100644 --- a/interface/src/DataServerClient.h +++ b/interface/src/DataServerClient.h @@ -29,4 +29,8 @@ private: static std::vector _unconfirmedPackets; }; +namespace DataServerKey { + const char FaceMeshURL[] = "mesh"; +} + #endif /* defined(__hifi__DataServerClient__) */ diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 7f3858ac75..afaec2305e 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -804,21 +804,27 @@ void Menu::editPreferences() { return; } + QUrl faceModelURL(faceURLEdit->text()); + if (avatarUsernameEdit->text() != avatarUsername) { - // there has been a UUID change - set the new UUID on the avatar instance + // there has been a username change - set the new UUID on the avatar instance applicationInstance->getAvatar()->setUsername(avatarUsernameEdit->text()); + if (faceModelURL.toString() == faceURLString) { + // if there was no change to the face model URL then ask the data-server for what it is + DataServerClient::getClientValueForKey(DataServerKey::FaceMeshURL); + } } QUrl avatarVoxelURL(avatarURL->text()); applicationInstance->getAvatar()->getVoxels()->setVoxelURL(avatarVoxelURL); - QUrl faceModelURL(faceURLEdit->text()); if (faceModelURL.toString() != faceURLString) { applicationInstance->getAvatar()->getHead().getBlendFace().setModelURL(faceModelURL); // send the new face mesh URL to the data-server (if we have a client UUID) - DataServerClient::putValueForKey("mesh", faceModelURL.toString().toLocal8Bit().constData()); + DataServerClient::putValueForKey(DataServerKey::FaceMeshURL, + faceModelURL.toString().toLocal8Bit().constData()); } Avatar::sendAvatarURLsMessage(avatarVoxelURL, faceModelURL); From 4b62026c2518a5769254cbef370e5d614219a9e5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 7 Oct 2013 17:06:33 -0700 Subject: [PATCH 09/25] shore up receipt of face mesh URL from data-server --- interface/src/Application.cpp | 6 +++ interface/src/DataServerClient.cpp | 61 ++++++++++++++++++++++++++---- interface/src/DataServerClient.h | 5 ++- 3 files changed, 62 insertions(+), 10 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a078820e3d..06070094d2 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3613,6 +3613,12 @@ void* Application::networkReceive(void* args) { case PACKET_TYPE_AVATAR_FACE_VIDEO: processAvatarFaceVideoMessage(app->_incomingPacket, bytesReceived); break; + case PACKET_TYPE_DATA_SERVER_GET: + case PACKET_TYPE_DATA_SERVER_PUT: + case PACKET_TYPE_DATA_SERVER_SEND: + case PACKET_TYPE_DATA_SERVER_CONFIRM: + DataServerClient::processMessageFromDataServer(app->_incomingPacket, bytesReceived); + break; default: NodeList::getInstance()->processNodeData(&senderAddress, app->_incomingPacket, bytesReceived); break; diff --git a/interface/src/DataServerClient.cpp b/interface/src/DataServerClient.cpp index 2eefef8ce4..ba748b401b 100644 --- a/interface/src/DataServerClient.cpp +++ b/interface/src/DataServerClient.cpp @@ -6,15 +6,18 @@ // Copyright (c) 2013 HighFidelity, Inc. All rights reserved. // +#include + #include #include #include #include +#include "Application.h" #include "DataServerClient.h" QString DataServerClient::_clientUsername; -std::vector DataServerClient::_unconfirmedPackets; +std::vector DataServerClient::_unmatchedPackets; const char DATA_SERVER_HOSTNAME[] = "127.0.0.1"; const unsigned short DATA_SERVER_PORT = 3282; @@ -27,9 +30,10 @@ void DataServerClient::putValueForKey(const char* key, const char* value) { // setup the header for this packet int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); - // pack the client UUID + // pack the client UUID, null terminated memcpy(putPacket + numPacketBytes, _clientUsername.toLocal8Bit().constData(), _clientUsername.toLocal8Bit().size()); numPacketBytes += _clientUsername.toLocal8Bit().size(); + putPacket[numPacketBytes++] = '\0'; // pack the key, null terminated strcpy((char*) putPacket + numPacketBytes, key); @@ -42,7 +46,7 @@ void DataServerClient::putValueForKey(const char* key, const char* value) { putPacket[numPacketBytes++] = '\0'; // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed - _unconfirmedPackets.push_back(putPacket); + _unmatchedPackets.push_back(putPacket); // send this put request to the data server NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes); @@ -62,9 +66,10 @@ void DataServerClient::getValueForKeyAndUserString(const char* key, QString& use // setup the header for this packet int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET); - // pack the user string (could be username or UUID string) + // pack the user string (could be username or UUID string), null-terminate memcpy(getPacket + numPacketBytes, userString.toLocal8Bit().constData(), userString.toLocal8Bit().size()); numPacketBytes += userString.toLocal8Bit().size(); + getPacket[numPacketBytes++] = '\0'; // pack the key, null terminated strcpy((char*) getPacket + numPacketBytes, key); @@ -77,14 +82,14 @@ void DataServerClient::getValueForKeyAndUserString(const char* key, QString& use void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) { - for (std::vector::iterator unconfirmedPacket = _unconfirmedPackets.begin(); - unconfirmedPacket != _unconfirmedPackets.end(); + for (std::vector::iterator unconfirmedPacket = _unmatchedPackets.begin(); + unconfirmedPacket != _unmatchedPackets.end(); ++unconfirmedPacket) { if (memcmp(*unconfirmedPacket + sizeof(PACKET_TYPE), packetData + sizeof(PACKET_TYPE), numPacketBytes - sizeof(PACKET_TYPE)) == 0) { // this is a match - remove the confirmed packet from the vector so it isn't sent back out - _unconfirmedPackets.erase(unconfirmedPacket); + _unmatchedPackets.erase(unconfirmedPacket); // we've matched the packet - bail out break; @@ -95,6 +100,46 @@ void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, i } } -void DataServerClient::processGetFromDataServer(unsigned char* packetData, int numPacketBytes) { +void DataServerClient::processSendFromDataServer(unsigned char* packetData, int numPacketBytes) { + // pull the user string from the packet so we know who to associate this with + int numHeaderBytes = numBytesForPacketHeader(packetData); + + QString userString(QByteArray((char*) packetData + numHeaderBytes, strlen((char*) packetData + numHeaderBytes))); + QUuid userUUID(userString); + + if (userUUID.isNull()) { + // the user string was a username + // for now assume this means that it is for our avatar + + char* dataKeyPosition = (char*) packetData + numHeaderBytes + sizeof(userString); + + if (strcmp(dataKeyPosition, DataServerKey::FaceMeshURL) == 0) { + // pull the user's face mesh and set it on the Avatar instance + char* faceMeshPosition = dataKeyPosition + strlen(dataKeyPosition) + sizeof(char); + + QUrl faceMeshURL(QByteArray(faceMeshPosition, + numPacketBytes - ((unsigned char*) faceMeshPosition - packetData))); + + qDebug("Changing user's face model URL to %s\n", faceMeshURL.toString().toLocal8Bit().constData()); + QMetaObject::invokeMethod(&Application::getInstance()->getAvatar()->getHead().getBlendFace(), + "setModelURL", + Q_ARG(QUrl, faceMeshURL)); + } + } else { + // user string was UUID, find matching avatar and associate data + } +} + +void DataServerClient::processMessageFromDataServer(unsigned char* packetData, int numPacketBytes) { + switch (packetData[0]) { + case PACKET_TYPE_DATA_SERVER_SEND: + processSendFromDataServer(packetData, numPacketBytes); + break; + case PACKET_TYPE_DATA_SERVER_CONFIRM: + processConfirmFromDataServer(packetData, numPacketBytes); + break; + default: + break; + } } diff --git a/interface/src/DataServerClient.h b/interface/src/DataServerClient.h index 993608ef81..594f4b5692 100644 --- a/interface/src/DataServerClient.h +++ b/interface/src/DataServerClient.h @@ -20,13 +20,14 @@ public: static void getValueForKeyAndUserString(const char* key, QString& userString); static void getClientValueForKey(const char* key) { getValueForKeyAndUserString(key, _clientUsername); } static void processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes); - static void processGetFromDataServer(unsigned char* packetData, int numPacketBytes); + static void processSendFromDataServer(unsigned char* packetData, int numPacketBytes); + static void processMessageFromDataServer(unsigned char* packetData, int numPacketBytes); static void setClientUsername(const QString& clientUsername) { _clientUsername = clientUsername; } static QString& setClientUsername() { return _clientUsername; } private: static QString _clientUsername; - static std::vector _unconfirmedPackets; + static std::vector _unmatchedPackets; }; namespace DataServerKey { From 26d5e2cfec239b3c2f94d4739939be50733653d5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 7 Oct 2013 17:24:07 -0700 Subject: [PATCH 10/25] clear the face model URL if the username is changed in preferences --- interface/src/Menu.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index afaec2305e..923b563af4 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -806,19 +806,18 @@ void Menu::editPreferences() { QUrl faceModelURL(faceURLEdit->text()); + if (avatarUsernameEdit->text() != avatarUsername) { // there has been a username change - set the new UUID on the avatar instance applicationInstance->getAvatar()->setUsername(avatarUsernameEdit->text()); if (faceModelURL.toString() == faceURLString) { - // if there was no change to the face model URL then ask the data-server for what it is + // if there was no change to the face model URL then clear it and ask the data-server for what it is + applicationInstance->getAvatar()->getHead().getBlendFace().setModelURL(QUrl()); DataServerClient::getClientValueForKey(DataServerKey::FaceMeshURL); } } - QUrl avatarVoxelURL(avatarURL->text()); - applicationInstance->getAvatar()->getVoxels()->setVoxelURL(avatarVoxelURL); - if (faceModelURL.toString() != faceURLString) { applicationInstance->getAvatar()->getHead().getBlendFace().setModelURL(faceModelURL); @@ -827,6 +826,11 @@ void Menu::editPreferences() { faceModelURL.toString().toLocal8Bit().constData()); } + QUrl avatarVoxelURL(avatarURL->text()); + applicationInstance->getAvatar()->getVoxels()->setVoxelURL(avatarVoxelURL); + + + Avatar::sendAvatarURLsMessage(avatarVoxelURL, faceModelURL); applicationInstance->getAvatar()->getHead().setPupilDilation(pupilDilation->value() / (float)pupilDilation->maximum()); From 7964f360ab5ad1aa43b87ae5164433fec515dd7e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 7 Oct 2013 17:52:21 -0700 Subject: [PATCH 11/25] add method to DataServerClient to resend unmatched packets --- interface/src/DataServerClient.cpp | 33 ++++++++++++++++++++---------- interface/src/DataServerClient.h | 5 +++-- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/interface/src/DataServerClient.cpp b/interface/src/DataServerClient.cpp index ba748b401b..e7d5287d4c 100644 --- a/interface/src/DataServerClient.cpp +++ b/interface/src/DataServerClient.cpp @@ -17,7 +17,7 @@ #include "DataServerClient.h" QString DataServerClient::_clientUsername; -std::vector DataServerClient::_unmatchedPackets; +std::map DataServerClient::_unmatchedPackets; const char DATA_SERVER_HOSTNAME[] = "127.0.0.1"; const unsigned short DATA_SERVER_PORT = 3282; @@ -46,7 +46,7 @@ void DataServerClient::putValueForKey(const char* key, const char* value) { putPacket[numPacketBytes++] = '\0'; // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed - _unmatchedPackets.push_back(putPacket); + _unmatchedPackets.insert(std::pair(putPacket, numPacketBytes)); // send this put request to the data server NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes); @@ -82,20 +82,20 @@ void DataServerClient::getValueForKeyAndUserString(const char* key, QString& use void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) { - for (std::vector::iterator unconfirmedPacket = _unmatchedPackets.begin(); - unconfirmedPacket != _unmatchedPackets.end(); - ++unconfirmedPacket) { - if (memcmp(*unconfirmedPacket + sizeof(PACKET_TYPE), + for (std::map::iterator mapIterator = _unmatchedPackets.begin(); + mapIterator != _unmatchedPackets.end(); + ++mapIterator) { + if (memcmp(mapIterator->first + sizeof(PACKET_TYPE), packetData + sizeof(PACKET_TYPE), numPacketBytes - sizeof(PACKET_TYPE)) == 0) { - // this is a match - remove the confirmed packet from the vector so it isn't sent back out - _unmatchedPackets.erase(unconfirmedPacket); + + // this is a match - remove the confirmed packet from the vector and delete associated member + // so it isn't sent back out + delete[] mapIterator->first; + _unmatchedPackets.erase(mapIterator); // we've matched the packet - bail out break; - } else { - // no match, just push the iterator - unconfirmedPacket++; } } } @@ -143,3 +143,14 @@ void DataServerClient::processMessageFromDataServer(unsigned char* packetData, i break; } } + +void DataServerClient::resendUnmatchedPackets() { + for (std::map::iterator mapIterator = _unmatchedPackets.begin(); + mapIterator != _unmatchedPackets.end(); + ++mapIterator) { + // send the unmatched packet to the data server + NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, + mapIterator->first, + mapIterator->second); + } +} diff --git a/interface/src/DataServerClient.h b/interface/src/DataServerClient.h index 594f4b5692..e7a7b26beb 100644 --- a/interface/src/DataServerClient.h +++ b/interface/src/DataServerClient.h @@ -9,7 +9,7 @@ #ifndef __hifi__DataServerClient__ #define __hifi__DataServerClient__ -#include +#include #include @@ -22,12 +22,13 @@ public: static void processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes); static void processSendFromDataServer(unsigned char* packetData, int numPacketBytes); static void processMessageFromDataServer(unsigned char* packetData, int numPacketBytes); + static void resendUnmatchedPackets(); static void setClientUsername(const QString& clientUsername) { _clientUsername = clientUsername; } static QString& setClientUsername() { return _clientUsername; } private: static QString _clientUsername; - static std::vector _unmatchedPackets; + static std::map _unmatchedPackets; }; namespace DataServerKey { From 56b71eb61ac07de538b2f8e15dbd596b3a39088c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 8 Oct 2013 11:33:14 -0700 Subject: [PATCH 12/25] re-send data-server GET requests if they are unmatched --- interface/src/DataServerClient.cpp | 46 +++++++++++++++++++----------- interface/src/DataServerClient.h | 1 + 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/interface/src/DataServerClient.cpp b/interface/src/DataServerClient.cpp index e7d5287d4c..529ce9bd83 100644 --- a/interface/src/DataServerClient.cpp +++ b/interface/src/DataServerClient.cpp @@ -76,28 +76,17 @@ void DataServerClient::getValueForKeyAndUserString(const char* key, QString& use numPacketBytes += strlen(key); getPacket[numPacketBytes++] = '\0'; + // add the getPacket to our vector of uncofirmed packets, will be deleted once we get a response from the nameserver + _unmatchedPackets.insert(std::pair(getPacket, numPacketBytes)); + // send the get to the data server NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes); } + + void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) { - - for (std::map::iterator mapIterator = _unmatchedPackets.begin(); - mapIterator != _unmatchedPackets.end(); - ++mapIterator) { - if (memcmp(mapIterator->first + sizeof(PACKET_TYPE), - packetData + sizeof(PACKET_TYPE), - numPacketBytes - sizeof(PACKET_TYPE)) == 0) { - - // this is a match - remove the confirmed packet from the vector and delete associated member - // so it isn't sent back out - delete[] mapIterator->first; - _unmatchedPackets.erase(mapIterator); - - // we've matched the packet - bail out - break; - } - } + removeMatchedPacketFromMap(packetData, numPacketBytes); } void DataServerClient::processSendFromDataServer(unsigned char* packetData, int numPacketBytes) { @@ -128,7 +117,11 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int } } else { // user string was UUID, find matching avatar and associate data + } + + // remove the matched packet from our map so it isn't re-sent to the data-server + removeMatchedPacketFromMap(packetData, numPacketBytes); } void DataServerClient::processMessageFromDataServer(unsigned char* packetData, int numPacketBytes) { @@ -144,6 +137,25 @@ void DataServerClient::processMessageFromDataServer(unsigned char* packetData, i } } +void DataServerClient::removeMatchedPacketFromMap(unsigned char* packetData, int numPacketBytes) { + for (std::map::iterator mapIterator = _unmatchedPackets.begin(); + mapIterator != _unmatchedPackets.end(); + ++mapIterator) { + if (memcmp(mapIterator->first + sizeof(PACKET_TYPE), + packetData + sizeof(PACKET_TYPE), + numPacketBytes - sizeof(PACKET_TYPE)) == 0) { + + // this is a match - remove the confirmed packet from the vector and delete associated member + // so it isn't sent back out + delete[] mapIterator->first; + _unmatchedPackets.erase(mapIterator); + + // we've matched the packet - bail out + break; + } + } +} + void DataServerClient::resendUnmatchedPackets() { for (std::map::iterator mapIterator = _unmatchedPackets.begin(); mapIterator != _unmatchedPackets.end(); diff --git a/interface/src/DataServerClient.h b/interface/src/DataServerClient.h index e7a7b26beb..072236545d 100644 --- a/interface/src/DataServerClient.h +++ b/interface/src/DataServerClient.h @@ -22,6 +22,7 @@ public: static void processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes); static void processSendFromDataServer(unsigned char* packetData, int numPacketBytes); static void processMessageFromDataServer(unsigned char* packetData, int numPacketBytes); + static void removeMatchedPacketFromMap(unsigned char* packetData, int numPacketBytes); static void resendUnmatchedPackets(); static void setClientUsername(const QString& clientUsername) { _clientUsername = clientUsername; } From 85edb93710d8d42cf0053a0d88b511964aeed722 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 8 Oct 2013 12:13:45 -0700 Subject: [PATCH 13/25] add a Profile class to hold user data from data-server --- interface/src/Application.cpp | 2 +- interface/src/Application.h | 3 ++ interface/src/DataServerClient.cpp | 81 +++++++++++++++++------------- interface/src/DataServerClient.h | 9 ++-- interface/src/Menu.cpp | 5 +- interface/src/avatar/MyAvatar.cpp | 10 ---- interface/src/avatar/MyAvatar.h | 3 -- interface/src/avatar/Profile.cpp | 54 ++++++++++++++++++++ interface/src/avatar/Profile.h | 39 ++++++++++++++ 9 files changed, 150 insertions(+), 56 deletions(-) create mode 100644 interface/src/avatar/Profile.cpp create mode 100644 interface/src/avatar/Profile.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 408724d1a3..ff84b4ee2d 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1587,7 +1587,7 @@ void Application::init() { } qDebug("Loaded settings.\n"); - if (!_myAvatar.getUsername().isEmpty()) { + if (!_profile.getUsername().isEmpty()) { // we have a username for this avatar, ask the data-server for the mesh URL for this avatar DataServerClient::getClientValueForKey(DataServerKey::FaceMeshURL); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 620d6d57f5..a4994d7f6c 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -44,6 +44,7 @@ #include "VoxelImporter.h" #include "avatar/Avatar.h" #include "avatar/MyAvatar.h" +#include "avatar/Profile.h" #include "avatar/HandControl.h" #include "devices/Faceshift.h" #include "devices/SerialInterface.h" @@ -110,6 +111,7 @@ public: QGLWidget* getGLWidget() { return _glWidget; } MyAvatar* getAvatar() { return &_myAvatar; } + Profile* getProfile() { return &_profile; } Audio* getAudio() { return &_audio; } Camera* getCamera() { return &_myCamera; } ViewFrustum* getViewFrustum() { return &_viewFrustum; } @@ -275,6 +277,7 @@ private: Oscilloscope _audioScope; MyAvatar _myAvatar; // The rendered avatar of oneself + Profile _profile; // The data-server linked profile for this user Transmitter _myTransmitter; // Gets UDP data from transmitter app used to animate the avatar diff --git a/interface/src/DataServerClient.cpp b/interface/src/DataServerClient.cpp index 529ce9bd83..27fbb44d13 100644 --- a/interface/src/DataServerClient.cpp +++ b/interface/src/DataServerClient.cpp @@ -14,9 +14,11 @@ #include #include "Application.h" +#include "Profile.h" + #include "DataServerClient.h" -QString DataServerClient::_clientUsername; + std::map DataServerClient::_unmatchedPackets; const char DATA_SERVER_HOSTNAME[] = "127.0.0.1"; @@ -24,33 +26,36 @@ const unsigned short DATA_SERVER_PORT = 3282; const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT); void DataServerClient::putValueForKey(const char* key, const char* value) { - if (!_clientUsername.isEmpty()) { - unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE]; - - // setup the header for this packet - int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); - - // pack the client UUID, null terminated - memcpy(putPacket + numPacketBytes, _clientUsername.toLocal8Bit().constData(), _clientUsername.toLocal8Bit().size()); - numPacketBytes += _clientUsername.toLocal8Bit().size(); - putPacket[numPacketBytes++] = '\0'; - - // pack the key, null terminated - strcpy((char*) putPacket + numPacketBytes, key); - numPacketBytes += strlen(key); - putPacket[numPacketBytes++] = '\0'; - - // pack the value, null terminated - strcpy((char*) putPacket + numPacketBytes, value); - numPacketBytes += strlen(value); - putPacket[numPacketBytes++] = '\0'; - - // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed - _unmatchedPackets.insert(std::pair(putPacket, numPacketBytes)); - - // send this put request to the data server - NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes); - } + Profile* userProfile = Application::getInstance()->getProfile(); + QString clientString = userProfile->getUUID().isNull() ? userProfile->getUsername() : userProfile->getUUID().toString(); + + Application::getInstance(); + + unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE]; + + // setup the header for this packet + int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); + + // pack the client UUID, null terminated + memcpy(putPacket + numPacketBytes, clientString.toLocal8Bit().constData(), clientString.toLocal8Bit().size()); + numPacketBytes += clientString.toLocal8Bit().size(); + putPacket[numPacketBytes++] = '\0'; + + // pack the key, null terminated + strcpy((char*) putPacket + numPacketBytes, key); + numPacketBytes += strlen(key); + putPacket[numPacketBytes++] = '\0'; + + // pack the value, null terminated + strcpy((char*) putPacket + numPacketBytes, value); + numPacketBytes += strlen(value); + putPacket[numPacketBytes++] = '\0'; + + // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed + _unmatchedPackets.insert(std::pair(putPacket, numPacketBytes)); + + // send this put request to the data server + NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes); } void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) { @@ -83,7 +88,9 @@ void DataServerClient::getValueForKeyAndUserString(const char* key, QString& use NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes); } - +void DataServerClient::getClientValueForKey(const char* key) { + getValueForKeyAndUserString(key, Application::getInstance()->getProfile()->getUsername()); +} void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) { removeMatchedPacketFromMap(packetData, numPacketBytes); @@ -102,18 +109,22 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int // for now assume this means that it is for our avatar char* dataKeyPosition = (char*) packetData + numHeaderBytes + sizeof(userString); + char* dataValuePosition = dataKeyPosition + strlen(dataKeyPosition) + sizeof(char); + + QString dataValueString(QByteArray(dataValuePosition, + numPacketBytes - ((unsigned char*) dataValuePosition - packetData))); if (strcmp(dataKeyPosition, DataServerKey::FaceMeshURL) == 0) { // pull the user's face mesh and set it on the Avatar instance - char* faceMeshPosition = dataKeyPosition + strlen(dataKeyPosition) + sizeof(char); - - QUrl faceMeshURL(QByteArray(faceMeshPosition, - numPacketBytes - ((unsigned char*) faceMeshPosition - packetData))); - qDebug("Changing user's face model URL to %s\n", faceMeshURL.toString().toLocal8Bit().constData()); + + qDebug("Changing user's face model URL to %s\n", dataValueString.toLocal8Bit().constData()); QMetaObject::invokeMethod(&Application::getInstance()->getAvatar()->getHead().getBlendFace(), "setModelURL", - Q_ARG(QUrl, faceMeshURL)); + Q_ARG(QUrl, QUrl(dataValueString))); + } else if (strcmp(dataKeyPosition, DataServerKey::UUID) == 0) { + // this is the user's UUID - set it on the profile + Application::getInstance()->getProfile()->setUUID(dataValueString); } } else { // user string was UUID, find matching avatar and associate data diff --git a/interface/src/DataServerClient.h b/interface/src/DataServerClient.h index 072236545d..1a26cdb23d 100644 --- a/interface/src/DataServerClient.h +++ b/interface/src/DataServerClient.h @@ -13,27 +13,26 @@ #include +#include "Application.h" + class DataServerClient { public: static void putValueForKey(const char* key, const char* value); static void getValueForKeyAndUUID(const char* key, QUuid& uuid); static void getValueForKeyAndUserString(const char* key, QString& userString); - static void getClientValueForKey(const char* key) { getValueForKeyAndUserString(key, _clientUsername); } + static void getClientValueForKey(const char* key); static void processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes); static void processSendFromDataServer(unsigned char* packetData, int numPacketBytes); static void processMessageFromDataServer(unsigned char* packetData, int numPacketBytes); static void removeMatchedPacketFromMap(unsigned char* packetData, int numPacketBytes); static void resendUnmatchedPackets(); - - static void setClientUsername(const QString& clientUsername) { _clientUsername = clientUsername; } - static QString& setClientUsername() { return _clientUsername; } private: - static QString _clientUsername; static std::map _unmatchedPackets; }; namespace DataServerKey { const char FaceMeshURL[] = "mesh"; + const char UUID[] = "uuid"; } #endif /* defined(__hifi__DataServerClient__) */ diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 9274674947..74bfc0527a 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -504,6 +504,7 @@ void Menu::loadSettings(QSettings* settings) { settings->endGroup(); scanMenuBar(&loadAction, settings); + Application::getInstance()->getProfile()->loadData(settings); Application::getInstance()->getAvatar()->loadData(settings); Application::getInstance()->getSwatch()->loadData(settings); } @@ -755,7 +756,7 @@ void Menu::editPreferences() { QFormLayout* form = new QFormLayout(); layout->addLayout(form, 1); - QString avatarUsername = applicationInstance->getAvatar()->getUsername(); + QString avatarUsername = applicationInstance->getProfile()->getUsername(); QLineEdit* avatarUsernameEdit = new QLineEdit(avatarUsername); avatarUsernameEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH); form->addRow("Username:", avatarUsernameEdit); @@ -815,7 +816,7 @@ void Menu::editPreferences() { if (avatarUsernameEdit->text() != avatarUsername) { // there has been a username change - set the new UUID on the avatar instance - applicationInstance->getAvatar()->setUsername(avatarUsernameEdit->text()); + applicationInstance->getProfile()->setUsername(avatarUsernameEdit->text()); if (faceModelURL.toString() == faceURLString) { // if there was no change to the face model URL then clear it and ask the data-server for what it is diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index c08843b118..2a4ec30621 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -72,12 +72,6 @@ void MyAvatar::setMoveTarget(const glm::vec3 moveTarget) { _moveTargetStepCounter = 0; } -void MyAvatar::setUsername(const QString& username) { - _username = username; - - DataServerClient::setClientUsername(username); -} - void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) { glm::quat orientation = getOrientation(); @@ -534,8 +528,6 @@ void MyAvatar::renderScreenTint(ScreenTintLayer layer, Camera& whichCamera) { void MyAvatar::saveData(QSettings* settings) { settings->beginGroup("Avatar"); - settings->setValue("Username", _username); - settings->setValue("bodyYaw", _bodyYaw); settings->setValue("bodyPitch", _bodyPitch); settings->setValue("bodyRoll", _bodyRoll); @@ -557,8 +549,6 @@ void MyAvatar::saveData(QSettings* settings) { void MyAvatar::loadData(QSettings* settings) { settings->beginGroup("Avatar"); - setUsername(settings->value("Username").toString()); - // in case settings is corrupt or missing loadSetting() will check for NaN _bodyYaw = loadSetting(settings, "bodyYaw", 0.0f); _bodyPitch = loadSetting(settings, "bodyPitch", 0.0f); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 4b37e28f55..e6cea94988 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -34,7 +34,6 @@ public: void setNewScale(const float scale); void setWantCollisionsOn(bool wantCollisionsOn) { _isCollisionsOn = wantCollisionsOn; } void setMoveTarget(const glm::vec3 moveTarget); - void setUsername(const QString& username); // getters float getNewScale() const { return _newScale; } @@ -50,7 +49,6 @@ public: glm::vec3 getGravity() const { return _gravity; } glm::vec3 getUprightHeadPosition() const; glm::vec3 getUprightEyeLevelPosition() const; - const QString& getUsername() const { return _username; } // get/set avatar data void saveData(QSettings* settings); @@ -84,7 +82,6 @@ private: float _collisionRadius; glm::vec3 _moveTarget; int _moveTargetStepCounter; - QString _username; // private methods float getBallRenderAlpha(int ball, bool lookingInMirror) const; diff --git a/interface/src/avatar/Profile.cpp b/interface/src/avatar/Profile.cpp new file mode 100644 index 0000000000..fcd4365c82 --- /dev/null +++ b/interface/src/avatar/Profile.cpp @@ -0,0 +1,54 @@ +// +// Profile.cpp +// hifi +// +// Created by Stephen Birarda on 10/8/13. +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. +// + +#include + +#include "Profile.h" +#include "DataServerClient.h" + +Profile::Profile() : + _username(), + _uuid(), + _faceModelURL() +{ + +} + +void Profile::clear() { + _username.clear(); + _uuid = QUuid(); + _faceModelURL.clear(); +} + +void Profile::setUsername(const QString &username) { + this->clear(); + _username = username; + + // we've been given a new username, ask the data-server for our UUID + DataServerClient::getClientValueForKey(DataServerKey::UUID); +} + +void Profile::saveData(QSettings* settings) { + settings->beginGroup("Profile"); + + settings->setValue("username", _username); + settings->setValue("UUID", _uuid); + settings->setValue("faceModelURL", _faceModelURL); + + settings->endGroup(); +} + +void Profile::loadData(QSettings* settings) { + settings->beginGroup("Profile"); + + _username = settings->value("username").toString(); + _uuid = settings->value("UUID").toUuid(); + _faceModelURL = settings->value("faceModelURL").toUrl(); + + settings->endGroup(); +} \ No newline at end of file diff --git a/interface/src/avatar/Profile.h b/interface/src/avatar/Profile.h new file mode 100644 index 0000000000..02c8b0ad9e --- /dev/null +++ b/interface/src/avatar/Profile.h @@ -0,0 +1,39 @@ +// +// Profile.h +// hifi +// +// Created by Stephen Birarda on 10/8/13. +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. +// + +#ifndef __hifi__Profile__ +#define __hifi__Profile__ + +#include +#include +#include + +class Profile { +public: + Profile(); + + void setUsername(const QString& username); + QString& getUsername() { return _username; } + + void setUUID(const QUuid& uuid) { _uuid = uuid; } + QUuid& getUUID() { return _uuid; } + + void setFaceModelURL(const QUrl& faceModelURL) { _faceModelURL = faceModelURL; } + QUrl& getFaceModelURL() { return _faceModelURL; } + + void clear(); + + void saveData(QSettings* settings); + void loadData(QSettings* settings); +private: + QString _username; + QUuid _uuid; + QUrl _faceModelURL; +}; + +#endif /* defined(__hifi__Profile__) */ From ae59ce22b7583a17a4835cf703499f43ba801845 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 8 Oct 2013 12:22:02 -0700 Subject: [PATCH 14/25] send an empty key when making a UUID request --- interface/src/DataServerClient.cpp | 8 ++++++-- interface/src/DataServerClient.h | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/interface/src/DataServerClient.cpp b/interface/src/DataServerClient.cpp index 27fbb44d13..aea7e2d4c2 100644 --- a/interface/src/DataServerClient.cpp +++ b/interface/src/DataServerClient.cpp @@ -78,8 +78,12 @@ void DataServerClient::getValueForKeyAndUserString(const char* key, QString& use // pack the key, null terminated strcpy((char*) getPacket + numPacketBytes, key); - numPacketBytes += strlen(key); - getPacket[numPacketBytes++] = '\0'; + int numKeyBytes = strlen(key); + + if (numKeyBytes > 0) { + numPacketBytes += numKeyBytes; + getPacket[numPacketBytes++] = '\0'; + } // add the getPacket to our vector of uncofirmed packets, will be deleted once we get a response from the nameserver _unmatchedPackets.insert(std::pair(getPacket, numPacketBytes)); diff --git a/interface/src/DataServerClient.h b/interface/src/DataServerClient.h index 1a26cdb23d..fed956833d 100644 --- a/interface/src/DataServerClient.h +++ b/interface/src/DataServerClient.h @@ -32,7 +32,7 @@ private: namespace DataServerKey { const char FaceMeshURL[] = "mesh"; - const char UUID[] = "uuid"; + const char UUID[] = ""; } #endif /* defined(__hifi__DataServerClient__) */ From d843285db727a056d97efb42e3978281adc2fa0b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 8 Oct 2013 12:40:09 -0700 Subject: [PATCH 15/25] save profile to settings, fix UUID storage --- interface/src/DataServerClient.h | 2 +- interface/src/Menu.cpp | 1 + interface/src/avatar/Profile.cpp | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/interface/src/DataServerClient.h b/interface/src/DataServerClient.h index fed956833d..1a26cdb23d 100644 --- a/interface/src/DataServerClient.h +++ b/interface/src/DataServerClient.h @@ -32,7 +32,7 @@ private: namespace DataServerKey { const char FaceMeshURL[] = "mesh"; - const char UUID[] = ""; + const char UUID[] = "uuid"; } #endif /* defined(__hifi__DataServerClient__) */ diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 74bfc0527a..0a20f8271a 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -527,6 +527,7 @@ void Menu::saveSettings(QSettings* settings) { scanMenuBar(&saveAction, settings); Application::getInstance()->getAvatar()->saveData(settings); + Application::getInstance()->getProfile()->saveData(settings); Application::getInstance()->getSwatch()->saveData(settings); // ask the NodeList to save its data diff --git a/interface/src/avatar/Profile.cpp b/interface/src/avatar/Profile.cpp index fcd4365c82..763e74fdd9 100644 --- a/interface/src/avatar/Profile.cpp +++ b/interface/src/avatar/Profile.cpp @@ -29,8 +29,10 @@ void Profile::setUsername(const QString &username) { this->clear(); _username = username; - // we've been given a new username, ask the data-server for our UUID - DataServerClient::getClientValueForKey(DataServerKey::UUID); + if (!_username.isEmpty()) { + // we've been given a new username, ask the data-server for our UUID + DataServerClient::getClientValueForKey(DataServerKey::UUID); + } } void Profile::saveData(QSettings* settings) { From f5912f07a83bf36b3f3b0a5a5b50449614ce0fef Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 8 Oct 2013 12:45:18 -0700 Subject: [PATCH 16/25] make sure username is not empty before requesting faceMesh --- interface/src/Menu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 0a20f8271a..67d0de1094 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -819,7 +819,7 @@ void Menu::editPreferences() { // there has been a username change - set the new UUID on the avatar instance applicationInstance->getProfile()->setUsername(avatarUsernameEdit->text()); - if (faceModelURL.toString() == faceURLString) { + if (faceModelURL.toString() == faceURLString && !avatarUsernameEdit->text().isEmpty()) { // if there was no change to the face model URL then clear it and ask the data-server for what it is applicationInstance->getAvatar()->getHead().getBlendFace().setModelURL(QUrl()); DataServerClient::getClientValueForKey(DataServerKey::FaceMeshURL); From 6bd71da84ef38b2af420e015fb2fc8f410c897d6 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 8 Oct 2013 13:31:39 -0700 Subject: [PATCH 17/25] pack the UUID with the avatar data --- interface/src/avatar/Avatar.cpp | 1 - interface/src/avatar/Avatar.h | 4 ---- libraries/avatars/src/AvatarData.cpp | 11 +++++++++++ libraries/avatars/src/AvatarData.h | 7 ++++++- libraries/shared/src/PacketHeaders.cpp | 2 +- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 873bae5e2b..5a7060fd32 100755 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -102,7 +102,6 @@ Avatar::Avatar(Node* owningNode) : _leadingAvatar(NULL), _voxels(this), _moving(false), - _uuid(), _initialized(false), _handHoldingPosition(0.0f, 0.0f, 0.0f), _maxArmLength(0.0f), diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index ae8067c6d4..3cdf061499 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -155,9 +155,6 @@ public: glm::quat getOrientation() const; glm::quat getWorldAlignedOrientation() const; AvatarVoxelSystem* getVoxels() { return &_voxels; } - - QUuid& getUUID() { return _uuid; } - void setUUID(const QUuid& uuid) { _uuid = uuid; } // Get the position/rotation of a single body ball void getBodyBallTransform(AvatarJointID jointID, glm::vec3& position, glm::quat& rotation) const; @@ -225,7 +222,6 @@ protected: AvatarVoxelSystem _voxels; bool _moving; ///< set when position is changing - QUuid _uuid; // protected methods... glm::vec3 getBodyRightDirection() const { return getOrientation() * IDENTITY_RIGHT; } diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index edc76bedca..41c8270e29 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -23,6 +23,7 @@ static const float fingerVectorRadix = 4; // bits of precision when converting f AvatarData::AvatarData(Node* owningNode) : NodeData(owningNode), + _uuid(), _handPosition(0,0,0), _bodyYaw(-90.0), _bodyPitch(0.0), @@ -116,6 +117,11 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { _handData = new HandData(this); } + // UUID + QByteArray uuidByteArray = _uuid.toRfc4122(); + memcpy(destinationBuffer, &uuidByteArray, uuidByteArray.size()); + destinationBuffer += uuidByteArray.size(); + // Body world position memcpy(destinationBuffer, &_position, sizeof(float) * 3); destinationBuffer += sizeof(float) * 3; @@ -249,6 +255,11 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { // push past the node ID sourceBuffer += sizeof(uint16_t); + // UUID + const int NUM_BYTES_RFC4122_UUID = 16; + _uuid = QUuid::fromRfc4122(QByteArray((char*) sourceBuffer, NUM_BYTES_RFC4122_UUID)); + sourceBuffer += NUM_BYTES_RFC4122_UUID; + // Body world position memcpy(&_position, sourceBuffer, sizeof(float) * 3); sourceBuffer += sizeof(float) * 3; diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 82ef0d671a..57327f3bba 100755 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -72,6 +73,9 @@ public: int getBroadcastData(unsigned char* destinationBuffer); int parseData(unsigned char* sourceBuffer, int numBytes); + QUuid& getUUID() { return _uuid; } + void setUUID(const QUuid& uuid) { _uuid = uuid; } + // Body Rotation float getBodyYaw() const { return _bodyYaw; } void setBodyYaw(float bodyYaw) { _bodyYaw = bodyYaw; } @@ -79,7 +83,6 @@ public: void setBodyPitch(float bodyPitch) { _bodyPitch = bodyPitch; } float getBodyRoll() const { return _bodyRoll; } void setBodyRoll(float bodyRoll) { _bodyRoll = bodyRoll; } - // Hand State void setHandState(char s) { _handState = s; } @@ -133,6 +136,8 @@ public slots: void setWantOcclusionCulling(bool wantOcclusionCulling) { _wantOcclusionCulling = wantOcclusionCulling; } protected: + QUuid _uuid; + glm::vec3 _position; glm::vec3 _handPosition; diff --git a/libraries/shared/src/PacketHeaders.cpp b/libraries/shared/src/PacketHeaders.cpp index 1d5eb3f5d4..19efd7bd5a 100644 --- a/libraries/shared/src/PacketHeaders.cpp +++ b/libraries/shared/src/PacketHeaders.cpp @@ -20,7 +20,7 @@ PACKET_VERSION versionForPacketType(PACKET_TYPE type) { return 1; case PACKET_TYPE_HEAD_DATA: - return 8; + return 9; case PACKET_TYPE_AVATAR_URLS: return 1; From 8bac70e4a58668dcebb074f4f4f111cbcb7841f5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 8 Oct 2013 13:43:31 -0700 Subject: [PATCH 18/25] pass UUID from data-server to avatar-mixer --- interface/src/avatar/Profile.cpp | 9 ++++++++- interface/src/avatar/Profile.h | 2 +- libraries/avatars/src/AvatarData.cpp | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/interface/src/avatar/Profile.cpp b/interface/src/avatar/Profile.cpp index 763e74fdd9..976c60f1cb 100644 --- a/interface/src/avatar/Profile.cpp +++ b/interface/src/avatar/Profile.cpp @@ -35,6 +35,13 @@ void Profile::setUsername(const QString &username) { } } +void Profile::setUUID(const QUuid& uuid) { + _uuid = uuid; + + // when the UUID is changed we need set it appropriately on our avatar instance + Application::getInstance()->getAvatar()->setUUID(_uuid); +} + void Profile::saveData(QSettings* settings) { settings->beginGroup("Profile"); @@ -49,7 +56,7 @@ void Profile::loadData(QSettings* settings) { settings->beginGroup("Profile"); _username = settings->value("username").toString(); - _uuid = settings->value("UUID").toUuid(); + this->setUUID(settings->value("UUID").toUuid()); _faceModelURL = settings->value("faceModelURL").toUrl(); settings->endGroup(); diff --git a/interface/src/avatar/Profile.h b/interface/src/avatar/Profile.h index 02c8b0ad9e..7f84f0c4f8 100644 --- a/interface/src/avatar/Profile.h +++ b/interface/src/avatar/Profile.h @@ -20,7 +20,7 @@ public: void setUsername(const QString& username); QString& getUsername() { return _username; } - void setUUID(const QUuid& uuid) { _uuid = uuid; } + void setUUID(const QUuid& uuid); QUuid& getUUID() { return _uuid; } void setFaceModelURL(const QUrl& faceModelURL) { _faceModelURL = faceModelURL; } diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 41c8270e29..f0085a4138 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -119,7 +119,7 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { // UUID QByteArray uuidByteArray = _uuid.toRfc4122(); - memcpy(destinationBuffer, &uuidByteArray, uuidByteArray.size()); + memcpy(destinationBuffer, uuidByteArray.constData(), uuidByteArray.size()); destinationBuffer += uuidByteArray.size(); // Body world position @@ -270,7 +270,7 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &_bodyRoll); // Body scale - sourceBuffer += unpackFloatRatioFromTwoByte( sourceBuffer, _newScale); + sourceBuffer += unpackFloatRatioFromTwoByte(sourceBuffer, _newScale); // Follow mode info memcpy(&_leaderID, sourceBuffer, sizeof(uint16_t)); From b17e12460c48b86ddde8349c4c6a5fe5f79a0dc9 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 8 Oct 2013 13:52:04 -0700 Subject: [PATCH 19/25] shift get/set of face model URL to Profile class --- interface/src/DataServerClient.cpp | 5 +---- interface/src/Menu.cpp | 10 ++++------ interface/src/avatar/MyAvatar.cpp | 2 -- interface/src/avatar/Profile.cpp | 8 ++++++++ interface/src/avatar/Profile.h | 2 +- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/interface/src/DataServerClient.cpp b/interface/src/DataServerClient.cpp index aea7e2d4c2..9f5475e383 100644 --- a/interface/src/DataServerClient.cpp +++ b/interface/src/DataServerClient.cpp @@ -121,11 +121,8 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int if (strcmp(dataKeyPosition, DataServerKey::FaceMeshURL) == 0) { // pull the user's face mesh and set it on the Avatar instance - qDebug("Changing user's face model URL to %s\n", dataValueString.toLocal8Bit().constData()); - QMetaObject::invokeMethod(&Application::getInstance()->getAvatar()->getHead().getBlendFace(), - "setModelURL", - Q_ARG(QUrl, QUrl(dataValueString))); + Application::getInstance()->getProfile()->setFaceModelURL(QUrl(dataValueString)); } else if (strcmp(dataKeyPosition, DataServerKey::UUID) == 0) { // this is the user's UUID - set it on the profile Application::getInstance()->getProfile()->setUUID(dataValueString); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 67d0de1094..161ae046dd 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -766,7 +766,7 @@ void Menu::editPreferences() { avatarURL->setMinimumWidth(QLINE_MINIMUM_WIDTH); form->addRow("Avatar URL:", avatarURL); - QString faceURLString = applicationInstance->getAvatar()->getHead().getBlendFace().getModelURL().toString(); + QString faceURLString = applicationInstance->getProfile()->getFaceModelURL().toString(); QLineEdit* faceURLEdit = new QLineEdit(faceURLString); faceURLEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH); form->addRow("Face URL:", faceURLEdit); @@ -820,14 +820,14 @@ void Menu::editPreferences() { applicationInstance->getProfile()->setUsername(avatarUsernameEdit->text()); if (faceModelURL.toString() == faceURLString && !avatarUsernameEdit->text().isEmpty()) { - // if there was no change to the face model URL then clear it and ask the data-server for what it is - applicationInstance->getAvatar()->getHead().getBlendFace().setModelURL(QUrl()); + // if there was no change to the face model URL then ask the data-server for what it is DataServerClient::getClientValueForKey(DataServerKey::FaceMeshURL); } } if (faceModelURL.toString() != faceURLString) { - applicationInstance->getAvatar()->getHead().getBlendFace().setModelURL(faceModelURL); + // change the faceModelURL in the profile, it will also update this user's BlendFace + applicationInstance->getProfile()->setFaceModelURL(faceModelURL); // send the new face mesh URL to the data-server (if we have a client UUID) DataServerClient::putValueForKey(DataServerKey::FaceMeshURL, @@ -837,8 +837,6 @@ void Menu::editPreferences() { QUrl avatarVoxelURL(avatarURL->text()); applicationInstance->getAvatar()->getVoxels()->setVoxelURL(avatarVoxelURL); - - Avatar::sendAvatarURLsMessage(avatarVoxelURL, faceModelURL); applicationInstance->getAvatar()->getHead().setPupilDilation(pupilDilation->value() / (float)pupilDilation->maximum()); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 2a4ec30621..74c39dfa4c 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -537,7 +537,6 @@ void MyAvatar::saveData(QSettings* settings) { settings->setValue("position_z", _position.z); settings->setValue("voxelURL", _voxels.getVoxelURL()); - settings->setValue("faceModelURL", _head.getBlendFace().getModelURL()); settings->setValue("pupilDilation", _head.getPupilDilation()); settings->setValue("leanScale", _leanScale); @@ -558,7 +557,6 @@ void MyAvatar::loadData(QSettings* settings) { _position.z = loadSetting(settings, "position_z", 0.0f); _voxels.setVoxelURL(settings->value("voxelURL").toUrl()); - _head.getBlendFace().setModelURL(settings->value("faceModelURL").toUrl()); _head.setPupilDilation(settings->value("pupilDilation", 0.0f).toFloat()); _leanScale = loadSetting(settings, "leanScale", 0.05f); diff --git a/interface/src/avatar/Profile.cpp b/interface/src/avatar/Profile.cpp index 976c60f1cb..7a0d86189f 100644 --- a/interface/src/avatar/Profile.cpp +++ b/interface/src/avatar/Profile.cpp @@ -42,6 +42,14 @@ void Profile::setUUID(const QUuid& uuid) { Application::getInstance()->getAvatar()->setUUID(_uuid); } +void Profile::setFaceModelURL(const QUrl& faceModelURL) { + _faceModelURL = faceModelURL; + + QMetaObject::invokeMethod(&Application::getInstance()->getAvatar()->getHead().getBlendFace(), + "setModelURL", + Q_ARG(QUrl, _faceModelURL)); +} + void Profile::saveData(QSettings* settings) { settings->beginGroup("Profile"); diff --git a/interface/src/avatar/Profile.h b/interface/src/avatar/Profile.h index 7f84f0c4f8..34ffc5bd25 100644 --- a/interface/src/avatar/Profile.h +++ b/interface/src/avatar/Profile.h @@ -23,7 +23,7 @@ public: void setUUID(const QUuid& uuid); QUuid& getUUID() { return _uuid; } - void setFaceModelURL(const QUrl& faceModelURL) { _faceModelURL = faceModelURL; } + void setFaceModelURL(const QUrl& faceModelURL); QUrl& getFaceModelURL() { return _faceModelURL; } void clear(); From 15ddd9989b3421d037053426388a72cc62540287 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 8 Oct 2013 13:59:28 -0700 Subject: [PATCH 20/25] ovverride UUID setter in Avatar for DataServerClient get request --- interface/src/avatar/Avatar.cpp | 5 +++++ interface/src/avatar/Avatar.h | 1 + 2 files changed, 6 insertions(+) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 5a7060fd32..963f1e028f 100755 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -425,6 +425,11 @@ void Avatar::setMouseRay(const glm::vec3 &origin, const glm::vec3 &direction) { _mouseRayDirection = direction; } +void Avatar::setUUID(const QUuid& uuid) { + qDebug() << "Setting UUID for avatar!\n"; + _uuid = uuid; +} + void Avatar::updateHandMovementAndTouching(float deltaTime, bool enableHandMovement) { glm::quat orientation = getOrientation(); diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index 3cdf061499..7eef01ea87 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -142,6 +142,7 @@ public: //setters void setDisplayingLookatVectors(bool displayingLookatVectors) { _head.setRenderLookatVectors(displayingLookatVectors); } void setMouseRay(const glm::vec3 &origin, const glm::vec3 &direction); + void setUUID(const QUuid& uuid); //getters bool isInitialized() const { return _initialized; } From 10f29dfe905edd406000808f8c8a4c6d2ebd3448 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 8 Oct 2013 14:02:57 -0700 Subject: [PATCH 21/25] ask the data-server for a face mesh on UUID change --- interface/src/avatar/Avatar.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 963f1e028f..53792de29e 100755 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -18,6 +18,7 @@ #include "Application.h" #include "Avatar.h" +#include "DataServerClient.h" #include "Hand.h" #include "Head.h" #include "Physics.h" @@ -426,7 +427,12 @@ void Avatar::setMouseRay(const glm::vec3 &origin, const glm::vec3 &direction) { } void Avatar::setUUID(const QUuid& uuid) { - qDebug() << "Setting UUID for avatar!\n"; + if (uuid != _uuid) { + // UUID has changed + // ask for the face mesh URL for this avatar, request won't be made if UUID is null + DataServerClient::getValueForKeyAndUUID(DataServerKey::FaceMeshURL, _uuid); + } + _uuid = uuid; } From 233c1599bdf42dcf155c2ea845194191661100b9 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 8 Oct 2013 14:25:53 -0700 Subject: [PATCH 22/25] leverage existing URL update rate for interim face model update solution --- interface/src/Application.cpp | 12 ++++++------ interface/src/Menu.cpp | 2 +- interface/src/avatar/Avatar.cpp | 13 +------------ interface/src/avatar/Avatar.h | 2 +- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ff84b4ee2d..71677cc918 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1253,13 +1253,14 @@ void Application::processAvatarURLsMessage(unsigned char* packetData, size_t dat return; } QDataStream in(QByteArray((char*)packetData, dataBytes)); - QUrl voxelURL, faceURL; + QUrl voxelURL; in >> voxelURL; - in >> faceURL; // invoke the set URL functions on the simulate/render thread QMetaObject::invokeMethod(avatar->getVoxels(), "setVoxelURL", Q_ARG(QUrl, voxelURL)); - QMetaObject::invokeMethod(&avatar->getHead().getBlendFace(), "setModelURL", Q_ARG(QUrl, faceURL)); + + // use this timing to as the data-server for an updated mesh for this avatar (if we have UUID) + DataServerClient::getValueForKeyAndUUID(DataServerKey::FaceMeshURL, avatar->getUUID()); } void Application::processAvatarFaceVideoMessage(unsigned char* packetData, size_t dataBytes) { @@ -1600,7 +1601,7 @@ void Application::init() { _voxels.init(); - Avatar::sendAvatarURLsMessage(_myAvatar.getVoxels()->getVoxelURL(), _myAvatar.getHead().getBlendFace().getModelURL()); + Avatar::sendAvatarURLsMessage(_myAvatar.getVoxels()->getVoxelURL()); _palette.init(_glWidget->width(), _glWidget->height()); _palette.addAction(Menu::getInstance()->getActionForOption(MenuOption::VoxelAddMode), 0, 0); @@ -2175,8 +2176,7 @@ void Application::updateAvatar(float deltaTime) { // once in a while, send my urls const float AVATAR_URLS_SEND_INTERVAL = 1.0f; // seconds if (shouldDo(AVATAR_URLS_SEND_INTERVAL, deltaTime)) { - Avatar::sendAvatarURLsMessage(_myAvatar.getVoxels()->getVoxelURL(), - _myAvatar.getHead().getBlendFace().getModelURL()); + Avatar::sendAvatarURLsMessage(_myAvatar.getVoxels()->getVoxelURL()); } } } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 161ae046dd..0f5e3fc58e 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -837,7 +837,7 @@ void Menu::editPreferences() { QUrl avatarVoxelURL(avatarURL->text()); applicationInstance->getAvatar()->getVoxels()->setVoxelURL(avatarVoxelURL); - Avatar::sendAvatarURLsMessage(avatarVoxelURL, faceModelURL); + Avatar::sendAvatarURLsMessage(avatarVoxelURL); applicationInstance->getAvatar()->getHead().setPupilDilation(pupilDilation->value() / (float)pupilDilation->maximum()); diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 53792de29e..762652217a 100755 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -60,7 +60,7 @@ const int NUM_BODY_CONE_SIDES = 9; const float chatMessageScale = 0.0015; const float chatMessageHeight = 0.20; -void Avatar::sendAvatarURLsMessage(const QUrl& voxelURL, const QUrl& faceURL) { +void Avatar::sendAvatarURLsMessage(const QUrl& voxelURL) { uint16_t ownerID = NodeList::getInstance()->getOwnerID(); if (ownerID == UNKNOWN_NODE_ID) { @@ -77,7 +77,6 @@ void Avatar::sendAvatarURLsMessage(const QUrl& voxelURL, const QUrl& faceURL) { QDataStream out(&message, QIODevice::WriteOnly | QIODevice::Append); out << voxelURL; - out << faceURL; Application::controlledBroadcastToNodes((unsigned char*)message.data(), message.size(), &NODE_TYPE_AVATAR_MIXER, 1); } @@ -426,16 +425,6 @@ void Avatar::setMouseRay(const glm::vec3 &origin, const glm::vec3 &direction) { _mouseRayDirection = direction; } -void Avatar::setUUID(const QUuid& uuid) { - if (uuid != _uuid) { - // UUID has changed - // ask for the face mesh URL for this avatar, request won't be made if UUID is null - DataServerClient::getValueForKeyAndUUID(DataServerKey::FaceMeshURL, _uuid); - } - - _uuid = uuid; -} - void Avatar::updateHandMovementAndTouching(float deltaTime, bool enableHandMovement) { glm::quat orientation = getOrientation(); diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index 7eef01ea87..f347b44794 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -129,7 +129,7 @@ class Avatar : public AvatarData { Q_OBJECT public: - static void sendAvatarURLsMessage(const QUrl& voxelURL, const QUrl& faceURL); + static void sendAvatarURLsMessage(const QUrl& voxelURL); Avatar(Node* owningNode = NULL); ~Avatar(); From 9c6cdcc70b0bd3b90285ce8f042a1c247c39b238 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 8 Oct 2013 15:39:04 -0700 Subject: [PATCH 23/25] complete setting of user model from data-server --- interface/src/DataServerClient.cpp | 107 +++++++++++++++++------------ interface/src/DataServerClient.h | 4 +- interface/src/avatar/Avatar.h | 1 - 3 files changed, 64 insertions(+), 48 deletions(-) diff --git a/interface/src/DataServerClient.cpp b/interface/src/DataServerClient.cpp index 9f5475e383..736ea519f3 100644 --- a/interface/src/DataServerClient.cpp +++ b/interface/src/DataServerClient.cpp @@ -27,46 +27,48 @@ const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SE void DataServerClient::putValueForKey(const char* key, const char* value) { Profile* userProfile = Application::getInstance()->getProfile(); - QString clientString = userProfile->getUUID().isNull() ? userProfile->getUsername() : userProfile->getUUID().toString(); + QString clientString = userProfile->getUUID().isNull() + ? userProfile->getUsername() + : uuidStringWithoutCurlyBraces(userProfile->getUUID().toString()); - Application::getInstance(); - - unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE]; - - // setup the header for this packet - int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); - - // pack the client UUID, null terminated - memcpy(putPacket + numPacketBytes, clientString.toLocal8Bit().constData(), clientString.toLocal8Bit().size()); - numPacketBytes += clientString.toLocal8Bit().size(); - putPacket[numPacketBytes++] = '\0'; - - // pack the key, null terminated - strcpy((char*) putPacket + numPacketBytes, key); - numPacketBytes += strlen(key); - putPacket[numPacketBytes++] = '\0'; - - // pack the value, null terminated - strcpy((char*) putPacket + numPacketBytes, value); - numPacketBytes += strlen(value); - putPacket[numPacketBytes++] = '\0'; - - // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed - _unmatchedPackets.insert(std::pair(putPacket, numPacketBytes)); - - // send this put request to the data server - NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes); -} - -void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) { - if (!uuid.isNull()) { - QString uuidString = uuidStringWithoutCurlyBraces(uuid); - getValueForKeyAndUserString(key, uuidString); + if (!clientString.isEmpty()) { + + unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE]; + + // setup the header for this packet + int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); + + // pack the client UUID, null terminated + memcpy(putPacket + numPacketBytes, clientString.toLocal8Bit().constData(), clientString.toLocal8Bit().size()); + numPacketBytes += clientString.toLocal8Bit().size(); + putPacket[numPacketBytes++] = '\0'; + + // pack the key, null terminated + strcpy((char*) putPacket + numPacketBytes, key); + numPacketBytes += strlen(key); + putPacket[numPacketBytes++] = '\0'; + + // pack the value, null terminated + strcpy((char*) putPacket + numPacketBytes, value); + numPacketBytes += strlen(value); + putPacket[numPacketBytes++] = '\0'; + + // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed + _unmatchedPackets.insert(std::pair(putPacket, numPacketBytes)); + + // send this put request to the data server + NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes); } } -void DataServerClient::getValueForKeyAndUserString(const char* key, QString& userString) { - unsigned char getPacket[MAX_PACKET_SIZE]; +void DataServerClient::getValueForKeyAndUUID(const char* key, const QUuid &uuid) { + if (!uuid.isNull()) { + getValueForKeyAndUserString(key, uuidStringWithoutCurlyBraces(uuid)); + } +} + +void DataServerClient::getValueForKeyAndUserString(const char* key, const QString& userString) { + unsigned char* getPacket = new unsigned char[MAX_PACKET_SIZE]; // setup the header for this packet int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET); @@ -103,21 +105,23 @@ void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, i void DataServerClient::processSendFromDataServer(unsigned char* packetData, int numPacketBytes) { // pull the user string from the packet so we know who to associate this with int numHeaderBytes = numBytesForPacketHeader(packetData); - - QString userString(QByteArray((char*) packetData + numHeaderBytes, strlen((char*) packetData + numHeaderBytes))); + + char* userStringPosition = (char*) packetData + numHeaderBytes; + + QString userString(QByteArray(userStringPosition, strlen(userStringPosition))); QUuid userUUID(userString); + char* dataKeyPosition = (char*) packetData + numHeaderBytes + strlen(userStringPosition) + sizeof('\0'); + char* dataValuePosition = dataKeyPosition + strlen(dataKeyPosition) + sizeof(char); + + QString dataValueString(QByteArray(dataValuePosition, + numPacketBytes - ((unsigned char*) dataValuePosition - packetData))); + if (userUUID.isNull()) { // the user string was a username // for now assume this means that it is for our avatar - char* dataKeyPosition = (char*) packetData + numHeaderBytes + sizeof(userString); - char* dataValuePosition = dataKeyPosition + strlen(dataKeyPosition) + sizeof(char); - - QString dataValueString(QByteArray(dataValuePosition, - numPacketBytes - ((unsigned char*) dataValuePosition - packetData))); - if (strcmp(dataKeyPosition, DataServerKey::FaceMeshURL) == 0) { // pull the user's face mesh and set it on the Avatar instance @@ -129,7 +133,20 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int } } else { // user string was UUID, find matching avatar and associate data - + if (strcmp(dataKeyPosition, DataServerKey::FaceMeshURL) == 0) { + NodeList* nodeList = NodeList::getInstance(); + for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { + if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { + Avatar* avatar = (Avatar *) node->getLinkedData(); + + if (avatar->getUUID() == userUUID) { + QMetaObject::invokeMethod(&avatar->getHead().getBlendFace(), + "setModelURL", + Q_ARG(QUrl, QUrl(dataValueString))); + } + } + } + } } // remove the matched packet from our map so it isn't re-sent to the data-server diff --git a/interface/src/DataServerClient.h b/interface/src/DataServerClient.h index 1a26cdb23d..e4f5290fd5 100644 --- a/interface/src/DataServerClient.h +++ b/interface/src/DataServerClient.h @@ -18,8 +18,8 @@ class DataServerClient { public: static void putValueForKey(const char* key, const char* value); - static void getValueForKeyAndUUID(const char* key, QUuid& uuid); - static void getValueForKeyAndUserString(const char* key, QString& userString); + static void getValueForKeyAndUUID(const char* key, const QUuid& uuid); + static void getValueForKeyAndUserString(const char* key, const QString& userString); static void getClientValueForKey(const char* key); static void processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes); static void processSendFromDataServer(unsigned char* packetData, int numPacketBytes); diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index f347b44794..4fd3f49880 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -142,7 +142,6 @@ public: //setters void setDisplayingLookatVectors(bool displayingLookatVectors) { _head.setRenderLookatVectors(displayingLookatVectors); } void setMouseRay(const glm::vec3 &origin, const glm::vec3 &direction); - void setUUID(const QUuid& uuid); //getters bool isInitialized() const { return _initialized; } From 268a64d3d54377cdf858e9c853dadc5d8f7dd2ae Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 9 Oct 2013 10:27:02 -0700 Subject: [PATCH 24/25] change data-server hostname to hifi global data-server --- interface/src/DataServerClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/DataServerClient.cpp b/interface/src/DataServerClient.cpp index 736ea519f3..82deaacef1 100644 --- a/interface/src/DataServerClient.cpp +++ b/interface/src/DataServerClient.cpp @@ -21,7 +21,7 @@ std::map DataServerClient::_unmatchedPackets; -const char DATA_SERVER_HOSTNAME[] = "127.0.0.1"; +const char DATA_SERVER_HOSTNAME[] = "data.highfidelity.io"; const unsigned short DATA_SERVER_PORT = 3282; const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT); From 478214f9da98becd674e187ac4300570494b1b35 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 9 Oct 2013 11:14:26 -0700 Subject: [PATCH 25/25] fix Profile include from DataServerClient --- interface/src/DataServerClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/DataServerClient.cpp b/interface/src/DataServerClient.cpp index 82deaacef1..ff8afeb942 100644 --- a/interface/src/DataServerClient.cpp +++ b/interface/src/DataServerClient.cpp @@ -14,7 +14,7 @@ #include #include "Application.h" -#include "Profile.h" +#include "avatar/Profile.h" #include "DataServerClient.h"