mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 09:24:00 +02:00
update user's domain in data-server after connection to new one
This commit is contained in:
parent
340248ac43
commit
6df317e8e6
8 changed files with 50 additions and 151 deletions
|
@ -219,6 +219,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
|||
audioThread->start();
|
||||
|
||||
connect(&nodeList->getDomainInfo(), SIGNAL(hostnameChanged(const QString&)), SLOT(domainChanged(const QString&)));
|
||||
connect(&nodeList->getDomainInfo(), SIGNAL(connectedToDomain(const QString&)), SLOT(connectedToDomain(const QString&)));
|
||||
|
||||
connect(nodeList, &NodeList::nodeAdded, this, &Application::nodeAdded);
|
||||
connect(nodeList, &NodeList::nodeKilled, this, &Application::nodeKilled);
|
||||
|
@ -1484,6 +1485,8 @@ void Application::timer() {
|
|||
|
||||
// ask the node list to check in with the domain server
|
||||
NodeList::getInstance()->sendDomainServerCheckIn();
|
||||
|
||||
|
||||
}
|
||||
|
||||
static glm::vec3 getFaceVector(BoxFace face) {
|
||||
|
@ -3951,6 +3954,19 @@ void Application::domainChanged(const QString& domainHostname) {
|
|||
_particles.clear();
|
||||
}
|
||||
|
||||
void Application::connectedToDomain(const QString& hostname) {
|
||||
AccountManager& accountManager = AccountManager::getInstance();
|
||||
|
||||
if (accountManager.isLoggedIn()) {
|
||||
// update our domain-server with the data-server we're logged in with
|
||||
|
||||
QString domainPutJsonString = "{\"location\":{\"domain\":\"" + hostname + "\"}}";
|
||||
|
||||
accountManager.authenticatedRequest("/api/v1/users/location", QNetworkAccessManager::PutOperation,
|
||||
JSONCallbackParameters(), domainPutJsonString.toUtf8());
|
||||
}
|
||||
}
|
||||
|
||||
void Application::nodeAdded(SharedNodePointer node) {
|
||||
if (node->getType() == NodeType::AvatarMixer) {
|
||||
// new avatar mixer, send off our identity packet right away
|
||||
|
|
|
@ -253,6 +253,8 @@ public slots:
|
|||
private slots:
|
||||
void timer();
|
||||
void idle();
|
||||
|
||||
void connectedToDomain(const QString& hostname);
|
||||
|
||||
void setFullscreen(bool fullscreen);
|
||||
void setEnable3DTVMode(bool enable3DTVMode);
|
||||
|
|
|
@ -104,8 +104,16 @@ void AccountManager::invokedRequest(const QString& path, QNetworkAccessManager::
|
|||
networkReply = _networkAccessManager.get(authenticatedRequest);
|
||||
break;
|
||||
case QNetworkAccessManager::PostOperation:
|
||||
authenticatedRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
networkReply = _networkAccessManager.post(authenticatedRequest, dataByteArray);
|
||||
case QNetworkAccessManager::PutOperation:
|
||||
authenticatedRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
if (operation == QNetworkAccessManager::PostOperation) {
|
||||
networkReply = _networkAccessManager.post(authenticatedRequest, dataByteArray);
|
||||
} else {
|
||||
networkReply = _networkAccessManager.put(authenticatedRequest, dataByteArray);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
// other methods not yet handled
|
||||
break;
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
|
||||
void setRootURL(const QUrl& rootURL);
|
||||
|
||||
bool isLoggedIn() { return !_rootURL.isEmpty() && hasValidAccessToken(); }
|
||||
bool hasValidAccessToken();
|
||||
bool checkAndSignalForAccessToken();
|
||||
|
||||
|
|
|
@ -1,148 +0,0 @@
|
|||
//
|
||||
// DataServerClient.cpp
|
||||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 10/7/13.
|
||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtNetwork/QUdpSocket>
|
||||
|
||||
#include "NodeList.h"
|
||||
#include "PacketHeaders.h"
|
||||
#include "UUID.h"
|
||||
|
||||
#include "DataServerClient.h"
|
||||
|
||||
QMap<quint8, QByteArray> DataServerClient::_unmatchedPackets;
|
||||
QMap<quint8, DataServerCallbackObject*> DataServerClient::_callbackObjects;
|
||||
quint8 DataServerClient::_sequenceNumber = 0;
|
||||
|
||||
const char MULTI_KEY_VALUE_SEPARATOR = '|';
|
||||
|
||||
const char DATA_SERVER_HOSTNAME[] = "data.highfidelity.io";
|
||||
const unsigned short DATA_SERVER_PORT = 3282;
|
||||
|
||||
const HifiSockAddr& DataServerClient::dataServerSockAddr() {
|
||||
static HifiSockAddr dsSockAddr = HifiSockAddr(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT);
|
||||
return dsSockAddr;
|
||||
}
|
||||
|
||||
void DataServerClient::putValueForKeyAndUserString(const QString& key, const QString& value, const QString& userString) {
|
||||
// setup the header for this packet and push packetStream to desired spot
|
||||
QByteArray putPacket = byteArrayWithPopulatedHeader(PacketTypeDataServerPut);
|
||||
QDataStream packetStream(&putPacket, QIODevice::Append);
|
||||
|
||||
// pack our data for the put packet
|
||||
packetStream << _sequenceNumber << userString << key << value;
|
||||
|
||||
// add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed
|
||||
_unmatchedPackets.insert(_sequenceNumber, putPacket);
|
||||
|
||||
// send this put request to the data server
|
||||
NodeList::getInstance()->getNodeSocket().writeDatagram(putPacket, dataServerSockAddr().getAddress(),
|
||||
dataServerSockAddr().getPort());
|
||||
|
||||
// push the sequence number forwards
|
||||
_sequenceNumber++;
|
||||
}
|
||||
|
||||
void DataServerClient::putValueForKeyAndUUID(const QString& key, const QString& value, const QUuid& uuid) {
|
||||
putValueForKeyAndUserString(key, value, uuidStringWithoutCurlyBraces(uuid));
|
||||
}
|
||||
|
||||
void DataServerClient::getValueForKeyAndUUID(const QString& key, const QUuid &uuid, DataServerCallbackObject* callbackObject) {
|
||||
getValuesForKeysAndUUID(QStringList(key), uuid, callbackObject);
|
||||
}
|
||||
|
||||
void DataServerClient::getValuesForKeysAndUUID(const QStringList& keys, const QUuid& uuid,
|
||||
DataServerCallbackObject* callbackObject) {
|
||||
if (!uuid.isNull()) {
|
||||
getValuesForKeysAndUserString(keys, uuidStringWithoutCurlyBraces(uuid), callbackObject);
|
||||
}
|
||||
}
|
||||
|
||||
void DataServerClient::getValuesForKeysAndUserString(const QStringList& keys, const QString& userString,
|
||||
DataServerCallbackObject* callbackObject) {
|
||||
if (!userString.isEmpty() && keys.size() <= UCHAR_MAX) {
|
||||
QByteArray getPacket = byteArrayWithPopulatedHeader(PacketTypeDataServerGet);
|
||||
QDataStream packetStream(&getPacket, QIODevice::Append);
|
||||
|
||||
// pack our data for the getPacket
|
||||
packetStream << _sequenceNumber << userString << keys.join(MULTI_KEY_VALUE_SEPARATOR);
|
||||
|
||||
// add the getPacket to our map of unconfirmed packets, will be deleted once we get a response from the nameserver
|
||||
_unmatchedPackets.insert(_sequenceNumber, getPacket);
|
||||
_callbackObjects.insert(_sequenceNumber, callbackObject);
|
||||
|
||||
// send the get to the data server
|
||||
NodeList::getInstance()->getNodeSocket().writeDatagram(getPacket, dataServerSockAddr().getAddress(),
|
||||
dataServerSockAddr().getPort());
|
||||
_sequenceNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
void DataServerClient::getValueForKeyAndUserString(const QString& key, const QString& userString,
|
||||
DataServerCallbackObject* callbackObject) {
|
||||
getValuesForKeysAndUserString(QStringList(key), userString, callbackObject);
|
||||
}
|
||||
|
||||
void DataServerClient::processConfirmFromDataServer(const QByteArray& packet) {
|
||||
removeMatchedPacketFromMap(packet);
|
||||
}
|
||||
|
||||
void DataServerClient::processSendFromDataServer(const QByteArray& packet) {
|
||||
// pull the user string from the packet so we know who to associate this with
|
||||
QDataStream packetStream(packet);
|
||||
packetStream.skipRawData(numBytesForPacketHeader(packet));
|
||||
|
||||
quint8 sequenceNumber = 0;
|
||||
packetStream >> sequenceNumber;
|
||||
|
||||
if (_callbackObjects.find(sequenceNumber) != _callbackObjects.end()) {
|
||||
// remove the packet from our two maps, it's matched
|
||||
DataServerCallbackObject* callbackObject = _callbackObjects.take(sequenceNumber);
|
||||
_unmatchedPackets.remove(sequenceNumber);
|
||||
|
||||
QString userString, keyListString, valueListString;
|
||||
|
||||
packetStream >> userString >> keyListString >> valueListString;
|
||||
|
||||
callbackObject->processDataServerResponse(userString, keyListString.split(MULTI_KEY_VALUE_SEPARATOR),
|
||||
valueListString.split(MULTI_KEY_VALUE_SEPARATOR));
|
||||
}
|
||||
}
|
||||
|
||||
void DataServerClient::processMessageFromDataServer(const QByteArray& packet) {
|
||||
switch (packetTypeForPacket(packet)) {
|
||||
case PacketTypeDataServerSend:
|
||||
processSendFromDataServer(packet);
|
||||
break;
|
||||
case PacketTypeDataServerConfirm:
|
||||
processConfirmFromDataServer(packet);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DataServerClient::removeMatchedPacketFromMap(const QByteArray& packet) {
|
||||
quint8 sequenceNumber = packet[numBytesForPacketHeader(packet)];
|
||||
|
||||
// attempt to remove a packet with this sequence number from the QMap of unmatched packets
|
||||
_unmatchedPackets.remove(sequenceNumber);
|
||||
}
|
||||
|
||||
void DataServerClient::resendUnmatchedPackets() {
|
||||
if (_unmatchedPackets.size() > 0) {
|
||||
qDebug() << "Resending" << _unmatchedPackets.size() << "packets to the data server.";
|
||||
|
||||
foreach (const QByteArray& packet, _unmatchedPackets) {
|
||||
// send the unmatched packet to the data server
|
||||
NodeList::getInstance()->getNodeSocket().writeDatagram(packet.data(), packet.size(),
|
||||
dataServerSockAddr().getAddress(),
|
||||
dataServerSockAddr().getPort());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,7 +17,8 @@ DomainInfo::DomainInfo() :
|
|||
_connectionSecret(),
|
||||
_registrationToken(),
|
||||
_rootAuthenticationURL(),
|
||||
_publicKey()
|
||||
_publicKey(),
|
||||
_isConnected(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -31,6 +32,7 @@ void DomainInfo::reset() {
|
|||
_registrationToken = QByteArray();
|
||||
_rootAuthenticationURL = QUrl();
|
||||
_publicKey = QString();
|
||||
_isConnected = false;
|
||||
}
|
||||
|
||||
void DomainInfo::parseAuthInformationFromJsonObject(const QJsonObject& jsonObject) {
|
||||
|
@ -86,3 +88,13 @@ void DomainInfo::completedHostnameLookup(const QHostInfo& hostInfo) {
|
|||
// if we got here then we failed to lookup the address
|
||||
qDebug("Failed domain server lookup");
|
||||
}
|
||||
|
||||
void DomainInfo::setIsConnected(bool isConnected) {
|
||||
if (_isConnected != isConnected) {
|
||||
_isConnected = isConnected;
|
||||
|
||||
if (_isConnected) {
|
||||
emit connectedToDomain(_hostname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,10 +51,14 @@ public:
|
|||
const QUrl& getRootAuthenticationURL() const { return _rootAuthenticationURL; }
|
||||
void setRootAuthenticationURL(const QUrl& rootAuthenticationURL) { _rootAuthenticationURL = rootAuthenticationURL; }
|
||||
|
||||
bool isConnected() const { return _isConnected; }
|
||||
void setIsConnected(bool isConnected);
|
||||
|
||||
private slots:
|
||||
void completedHostnameLookup(const QHostInfo& hostInfo);
|
||||
signals:
|
||||
void hostnameChanged(const QString& hostname);
|
||||
void connectedToDomain(const QString& hostname);
|
||||
private:
|
||||
void reset();
|
||||
|
||||
|
@ -66,6 +70,7 @@ private:
|
|||
QByteArray _registrationToken;
|
||||
QUrl _rootAuthenticationURL;
|
||||
QString _publicKey;
|
||||
bool _isConnected;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__DomainInfo__) */
|
||||
|
|
|
@ -567,6 +567,9 @@ void NodeList::setSessionUUID(const QUuid& sessionUUID) {
|
|||
int NodeList::processDomainServerList(const QByteArray& packet) {
|
||||
// this is a packet from the domain server, reset the count of un-replied check-ins
|
||||
_numNoReplyDomainCheckIns = 0;
|
||||
|
||||
// if this was the first domain-server list from this domain, we've now connected
|
||||
_domainInfo.setIsConnected(true);
|
||||
|
||||
int readNodes = 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue