From f36fd47ef71201e64eff7e5c8b2ba61afaf425bc Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 7 Oct 2013 12:17:47 -0700 Subject: [PATCH] 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;