mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 19:10:01 +02:00
store username and not UUID for MyAvatar
This commit is contained in:
parent
98f435ccc2
commit
f36fd47ef7
5 changed files with 41 additions and 36 deletions
|
@ -13,7 +13,7 @@
|
|||
|
||||
#include "DataServerClient.h"
|
||||
|
||||
QUuid DataServerClient::_clientUUID;
|
||||
QString DataServerClient::_clientUsername;
|
||||
std::vector<unsigned char*> 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<unsigned char*>::iterator unconfirmedPacket = _unconfirmedPackets.begin();
|
||||
|
|
|
@ -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<unsigned char*> _unconfirmedPackets;
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue