mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 18:01:15 +02:00
request shareable name in AddressManager once connected
This commit is contained in:
parent
21bc06f154
commit
2b5d862263
3 changed files with 66 additions and 0 deletions
|
@ -651,6 +651,9 @@ bool AddressManager::setHost(const QString& host, LookupTrigger trigger, quint16
|
||||||
|
|
||||||
_port = port;
|
_port = port;
|
||||||
|
|
||||||
|
// any host change should clear the shareable place name
|
||||||
|
_shareablePlaceName.clear();
|
||||||
|
|
||||||
if (host != _host) {
|
if (host != _host) {
|
||||||
_host = host;
|
_host = host;
|
||||||
emit hostChanged(_host);
|
emit hostChanged(_host);
|
||||||
|
@ -708,6 +711,59 @@ void AddressManager::copyPath() {
|
||||||
QApplication::clipboard()->setText(currentPath());
|
QApplication::clipboard()->setText(currentPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddressManager::handleShareableNameAPIResponse(QNetworkReply& requestReply) {
|
||||||
|
// make sure that this response is for the domain we're currently connected to
|
||||||
|
auto domainID = DependencyManager::get<NodeList>()->getDomainHandler().getUUID();
|
||||||
|
|
||||||
|
if (requestReply.url().toString().contains(uuidStringWithoutCurlyBraces(domainID))) {
|
||||||
|
// check for a name or default name in the API response
|
||||||
|
|
||||||
|
QJsonObject responseObject = QJsonDocument::fromJson(requestReply.readAll()).object();
|
||||||
|
QJsonObject domainObject = responseObject["domain"].toObject();
|
||||||
|
|
||||||
|
const QString DOMAIN_NAME_KEY = "name";
|
||||||
|
const QString DOMAIN_DEFAULT_PLACE_NAME_KEY = "default_place_name";
|
||||||
|
|
||||||
|
bool shareableNameChanged { false };
|
||||||
|
|
||||||
|
if (domainObject[DOMAIN_NAME_KEY].isString()) {
|
||||||
|
_shareablePlaceName = domainObject[DOMAIN_NAME_KEY].toString();
|
||||||
|
shareableNameChanged = true;
|
||||||
|
} else if (domainObject[DOMAIN_DEFAULT_PLACE_NAME_KEY].isString()) {
|
||||||
|
_shareablePlaceName = domainObject[DOMAIN_DEFAULT_PLACE_NAME_KEY].toString();
|
||||||
|
shareableNameChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shareableNameChanged) {
|
||||||
|
qDebug() << "AddressManager shareable name changed to" << _shareablePlaceName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddressManager::lookupShareableNameForDomainID(const QUuid& domainID) {
|
||||||
|
|
||||||
|
// if we get to a domain via IP/hostname, often the address is only reachable by this client
|
||||||
|
// and not by other clients on the LAN or Internet
|
||||||
|
|
||||||
|
// to work around this we use the ID to lookup the default place name, and if it exists we
|
||||||
|
// then use that for Steam join/invite or copiable address
|
||||||
|
|
||||||
|
// it only makes sense to lookup a shareable default name if we don't have a place name
|
||||||
|
if (_placeName.isEmpty()) {
|
||||||
|
JSONCallbackParameters callbackParams;
|
||||||
|
|
||||||
|
// no error callback handling
|
||||||
|
// in the case of an error we simply assume there is no default place name
|
||||||
|
callbackParams.jsonCallbackReceiver = this;
|
||||||
|
callbackParams.jsonCallbackMethod = "handleShareableNameAPIResponse";
|
||||||
|
|
||||||
|
DependencyManager::get<AccountManager>()->sendRequest(GET_DOMAIN_ID.arg(uuidStringWithoutCurlyBraces(domainID)),
|
||||||
|
AccountManagerAuth::None,
|
||||||
|
QNetworkAccessManager::GetOperation,
|
||||||
|
callbackParams);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AddressManager::addCurrentAddressToHistory(LookupTrigger trigger) {
|
void AddressManager::addCurrentAddressToHistory(LookupTrigger trigger) {
|
||||||
|
|
||||||
// if we're cold starting and this is called for the first address (from settings) we don't do anything
|
// if we're cold starting and this is called for the first address (from settings) we don't do anything
|
||||||
|
|
|
@ -101,6 +101,8 @@ public slots:
|
||||||
void copyAddress();
|
void copyAddress();
|
||||||
void copyPath();
|
void copyPath();
|
||||||
|
|
||||||
|
void lookupShareableNameForDomainID(const QUuid& domainID);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void lookupResultsFinished();
|
void lookupResultsFinished();
|
||||||
void lookupResultIsOffline();
|
void lookupResultIsOffline();
|
||||||
|
@ -124,6 +126,8 @@ private slots:
|
||||||
void handleAPIResponse(QNetworkReply& requestReply);
|
void handleAPIResponse(QNetworkReply& requestReply);
|
||||||
void handleAPIError(QNetworkReply& errorReply);
|
void handleAPIError(QNetworkReply& errorReply);
|
||||||
|
|
||||||
|
void handleShareableNameAPIResponse(QNetworkReply& requestReply);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void goToAddressFromObject(const QVariantMap& addressMap, const QNetworkReply& reply);
|
void goToAddressFromObject(const QVariantMap& addressMap, const QNetworkReply& reply);
|
||||||
|
|
||||||
|
@ -154,6 +158,8 @@ private:
|
||||||
PositionGetter _positionGetter;
|
PositionGetter _positionGetter;
|
||||||
OrientationGetter _orientationGetter;
|
OrientationGetter _orientationGetter;
|
||||||
|
|
||||||
|
QString _shareablePlaceName;
|
||||||
|
|
||||||
QStack<QUrl> _backStack;
|
QStack<QUrl> _backStack;
|
||||||
QStack<QUrl> _forwardStack;
|
QStack<QUrl> _forwardStack;
|
||||||
quint64 _lastBackPush = 0;
|
quint64 _lastBackPush = 0;
|
||||||
|
|
|
@ -539,6 +539,10 @@ void NodeList::processDomainServerList(QSharedPointer<ReceivedMessage> message)
|
||||||
if (!_domainHandler.isConnected()) {
|
if (!_domainHandler.isConnected()) {
|
||||||
_domainHandler.setUUID(domainUUID);
|
_domainHandler.setUUID(domainUUID);
|
||||||
_domainHandler.setIsConnected(true);
|
_domainHandler.setIsConnected(true);
|
||||||
|
|
||||||
|
// in case we didn't use a place name to get to this domain,
|
||||||
|
// give the address manager a chance to lookup a default one now
|
||||||
|
DependencyManager::get<AddressManager>()->lookupShareableNameForDomainID(domainUUID);
|
||||||
} else if (_domainHandler.getUUID() != domainUUID) {
|
} else if (_domainHandler.getUUID() != domainUUID) {
|
||||||
// Recieved packet from different domain.
|
// Recieved packet from different domain.
|
||||||
qWarning() << "IGNORING DomainList packet from" << domainUUID << "while connected to" << _domainHandler.getUUID();
|
qWarning() << "IGNORING DomainList packet from" << domainUUID << "while connected to" << _domainHandler.getUUID();
|
||||||
|
|
Loading…
Reference in a new issue