store username and not UUID for MyAvatar

This commit is contained in:
Stephen Birarda 2013-10-07 12:17:47 -07:00
parent 98f435ccc2
commit f36fd47ef7
5 changed files with 41 additions and 36 deletions

View file

@ -13,7 +13,7 @@
#include "DataServerClient.h" #include "DataServerClient.h"
QUuid DataServerClient::_clientUUID; QString DataServerClient::_clientUsername;
std::vector<unsigned char*> DataServerClient::_unconfirmedPackets; std::vector<unsigned char*> DataServerClient::_unconfirmedPackets;
const char DATA_SERVER_HOSTNAME[] = "127.0.0.1"; 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); const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT);
void DataServerClient::putValueForKey(const char* key, const char* value) { void DataServerClient::putValueForKey(const char* key, const char* value) {
if (!_clientUUID.isNull()) { if (!_clientUsername.isEmpty()) {
unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE]; unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE];
// setup the header for this packet // setup the header for this packet
int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT);
// pack the client UUID // pack the client UUID
QString uuidString = uuidStringWithoutCurlyBraces(_clientUUID); memcpy(putPacket + numPacketBytes, _clientUsername.toLocal8Bit().constData(), _clientUsername.toLocal8Bit().size());
memcpy(putPacket + numPacketBytes, uuidString.toLocal8Bit().constData(), uuidString.toLocal8Bit().size()); numPacketBytes += _clientUsername.toLocal8Bit().size();
numPacketBytes += uuidString.toLocal8Bit().size();
// pack the key, null terminated // pack the key, null terminated
strcpy((char*) putPacket + numPacketBytes, key); 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) { void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) {
if (!uuid.isNull()) { 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); QString uuidString = uuidStringWithoutCurlyBraces(uuid);
memcpy(getPacket + numPacketBytes, uuidString.toLocal8Bit().constData(), uuidString.toLocal8Bit().size()); getValueforKeyAndUserString(key, uuidString);
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::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) { void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) {
for (std::vector<unsigned char*>::iterator unconfirmedPacket = _unconfirmedPackets.begin(); for (std::vector<unsigned char*>::iterator unconfirmedPacket = _unconfirmedPackets.begin();

View file

@ -17,14 +17,15 @@ class DataServerClient {
public: public:
static void putValueForKey(const char* key, const char* value); static void putValueForKey(const char* key, const char* value);
static void getValueForKeyAndUUID(const char* key, QUuid& uuid); 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 processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes);
static void processGetFromDataServer(unsigned char* packetData, int numPacketBytes); static void processGetFromDataServer(unsigned char* packetData, int numPacketBytes);
static void setClientUUID(QUuid& clientUUID) { _clientUUID = clientUUID; } static void setClientUsername(QString& clientUsername) { _clientUsername = clientUsername; }
static QUuid& getClientUUID() { return _clientUUID; } static QString& setClientUsername() { return _clientUsername; }
private: private:
static QUuid _clientUUID; static QString _clientUsername;
static std::vector<unsigned char*> _unconfirmedPackets; static std::vector<unsigned char*> _unconfirmedPackets;
}; };

View file

@ -749,10 +749,10 @@ void Menu::editPreferences() {
QFormLayout* form = new QFormLayout(); QFormLayout* form = new QFormLayout();
layout->addLayout(form, 1); layout->addLayout(form, 1);
QUuid avatarUUID = applicationInstance->getAvatar()->getUUID(); QString avatarUsername = applicationInstance->getAvatar()->getUsername();
QLineEdit* avatarUUIDLineEdit = new QLineEdit(avatarUUID.isNull() ? QString() : uuidStringWithoutCurlyBraces(avatarUUID)); QLineEdit* avatarUsernameEdit = new QLineEdit(avatarUsername);
avatarUUIDLineEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH); avatarUsernameEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH);
form->addRow("UUID:", avatarUUIDLineEdit); form->addRow("Username:", avatarUsernameEdit);
QLineEdit* avatarURL = new QLineEdit(applicationInstance->getAvatar()->getVoxels()->getVoxelURL().toString()); QLineEdit* avatarURL = new QLineEdit(applicationInstance->getAvatar()->getVoxels()->getVoxelURL().toString());
avatarURL->setMinimumWidth(QLINE_MINIMUM_WIDTH); avatarURL->setMinimumWidth(QLINE_MINIMUM_WIDTH);
@ -804,10 +804,9 @@ void Menu::editPreferences() {
return; return;
} }
QUuid newUUID(avatarUUIDLineEdit->text()); if (avatarUsernameEdit->text() != avatarUsername) {
if (newUUID != avatarUUID) {
// there has been a UUID change - set the new UUID on the avatar instance // 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); applicationInstance->getAvatar()->getHead().getBlendFace().setModelURL(faceModelURL);
// send the new face mesh URL to the data-server (if we have a client UUID) // 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); Avatar::sendAvatarURLsMessage(avatarVoxelURL, faceModelURL);

View file

@ -537,7 +537,7 @@ void MyAvatar::renderScreenTint(ScreenTintLayer layer, Camera& whichCamera) {
void MyAvatar::saveData(QSettings* settings) { void MyAvatar::saveData(QSettings* settings) {
settings->beginGroup("Avatar"); settings->beginGroup("Avatar");
settings->setValue("UUID", _uuid); settings->setValue("Username", _username);
settings->setValue("bodyYaw", _bodyYaw); settings->setValue("bodyYaw", _bodyYaw);
settings->setValue("bodyPitch", _bodyPitch); settings->setValue("bodyPitch", _bodyPitch);
@ -560,7 +560,7 @@ void MyAvatar::saveData(QSettings* settings) {
void MyAvatar::loadData(QSettings* settings) { void MyAvatar::loadData(QSettings* settings) {
settings->beginGroup("Avatar"); 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 // in case settings is corrupt or missing loadSetting() will check for NaN
_bodyYaw = loadSetting(settings, "bodyYaw", 0.0f); _bodyYaw = loadSetting(settings, "bodyYaw", 0.0f);

View file

@ -34,7 +34,7 @@ public:
void setNewScale(const float scale); void setNewScale(const float scale);
void setWantCollisionsOn(bool wantCollisionsOn) { _isCollisionsOn = wantCollisionsOn; } void setWantCollisionsOn(bool wantCollisionsOn) { _isCollisionsOn = wantCollisionsOn; }
void setMoveTarget(const glm::vec3 moveTarget); void setMoveTarget(const glm::vec3 moveTarget);
void setUUID(const QUuid& uuid); void setUsername(const QString& username) { _username = username; }
// getters // getters
float getNewScale() const { return _newScale; } float getNewScale() const { return _newScale; }
@ -50,6 +50,7 @@ public:
glm::vec3 getGravity() const { return _gravity; } glm::vec3 getGravity() const { return _gravity; }
glm::vec3 getUprightHeadPosition() const; glm::vec3 getUprightHeadPosition() const;
glm::vec3 getUprightEyeLevelPosition() const; glm::vec3 getUprightEyeLevelPosition() const;
const QString& getUsername() const { return _username; }
// get/set avatar data // get/set avatar data
void saveData(QSettings* settings); void saveData(QSettings* settings);
@ -83,6 +84,7 @@ private:
float _collisionRadius; float _collisionRadius;
glm::vec3 _moveTarget; glm::vec3 _moveTarget;
int _moveTargetStepCounter; int _moveTargetStepCounter;
QString _username;
// private methods // private methods
float getBallRenderAlpha(int ball, bool lookingInMirror) const; float getBallRenderAlpha(int ball, bool lookingInMirror) const;