From 67b1015f4a2b173e06dc1d3ddceab8b0db979acf Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 5 May 2016 14:54:04 -0700 Subject: [PATCH 01/15] re add users to default, default to visible friends only --- interface/src/DiscoverabilityManager.cpp | 2 +- scripts/defaultScripts.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/interface/src/DiscoverabilityManager.cpp b/interface/src/DiscoverabilityManager.cpp index 230f4202c8..46aabe8702 100644 --- a/interface/src/DiscoverabilityManager.cpp +++ b/interface/src/DiscoverabilityManager.cpp @@ -20,7 +20,7 @@ #include "DiscoverabilityManager.h" #include "Menu.h" -const Discoverability::Mode DEFAULT_DISCOVERABILITY_MODE = Discoverability::All; +const Discoverability::Mode DEFAULT_DISCOVERABILITY_MODE = Discoverability::Friends; DiscoverabilityManager::DiscoverabilityManager() : _mode("discoverabilityMode", DEFAULT_DISCOVERABILITY_MODE) diff --git a/scripts/defaultScripts.js b/scripts/defaultScripts.js index ceccf20647..3904d97a91 100644 --- a/scripts/defaultScripts.js +++ b/scripts/defaultScripts.js @@ -8,9 +8,10 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.load("system/away.js"); -Script.load("system/progress.js"); Script.load("system/edit.js"); +Script.load("system/progress.js"); +Script.load("system/away.js"); +Script.load("system/users.js"); Script.load("system/examples.js"); Script.load("system/selectAudioDevice.js"); Script.load("system/notifications.js"); From d1755649b1e0e7129ecf1ef0830fdf194b157d7e Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 5 May 2016 14:55:41 -0700 Subject: [PATCH 02/15] order --- scripts/defaultScripts.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/defaultScripts.js b/scripts/defaultScripts.js index 3904d97a91..9b11fa73cc 100644 --- a/scripts/defaultScripts.js +++ b/scripts/defaultScripts.js @@ -8,11 +8,12 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.load("system/edit.js"); + Script.load("system/progress.js"); Script.load("system/away.js"); Script.load("system/users.js"); Script.load("system/examples.js"); +Script.load("system/edit.js"); Script.load("system/selectAudioDevice.js"); Script.load("system/notifications.js"); Script.load("system/controllers/handControllerGrab.js"); From 97e1621776d5950fc6d8a3afb27a327c81f9a9cd Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 5 May 2016 15:02:16 -0700 Subject: [PATCH 03/15] increase width --- scripts/system/users.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/system/users.js b/scripts/system/users.js index 91d552dd40..9612a19eee 100644 --- a/scripts/system/users.js +++ b/scripts/system/users.js @@ -222,7 +222,7 @@ var usersWindow = (function() { var baseURL = Script.resolvePath("assets/images/tools/"); - var WINDOW_WIDTH = 160, + var WINDOW_WIDTH = 260, WINDOW_MARGIN = 12, WINDOW_BASE_MARGIN = 6, // A little less is needed in order look correct WINDOW_FONT = { From 96174468b3b3ac36d187188cca4f52086a028217 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 5 May 2016 15:27:30 -0700 Subject: [PATCH 04/15] use reliable and ordered packets for avatar identity --- libraries/avatars/src/AvatarData.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 7db55d50e0..fd13f8c370 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -1193,10 +1193,15 @@ void AvatarData::sendIdentityPacket() { QByteArray identityData = identityByteArray(); - auto identityPacket = NLPacket::create(PacketType::AvatarIdentity, identityData.size()); - identityPacket->write(identityData); - - nodeList->broadcastToNodes(std::move(identityPacket), NodeSet() << NodeType::AvatarMixer); + auto packetList = NLPacketList::create(PacketType::AvatarIdentity, QByteArray(), true, true); + packetList->write(identityData); + nodeList->eachMatchingNode( + [&](const SharedNodePointer& node)->bool { + return node->getType() == NodeType::AvatarMixer && node->getActiveSocket(); + }, + [&](const SharedNodePointer& node) { + nodeList->sendPacketList(std::move(packetList), *node); + }); } void AvatarData::sendBillboardPacket() { From 0ea46cb4155cbdae47e854b6eb2fa0146853804b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 5 May 2016 15:35:37 -0700 Subject: [PATCH 05/15] send fallback socket, don't send HB if send usage disabled --- interface/src/DiscoverabilityManager.cpp | 19 +++++++++++++++---- libraries/networking/src/UserActivityLogger.h | 2 ++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/interface/src/DiscoverabilityManager.cpp b/interface/src/DiscoverabilityManager.cpp index 230f4202c8..bc1403aa46 100644 --- a/interface/src/DiscoverabilityManager.cpp +++ b/interface/src/DiscoverabilityManager.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "DiscoverabilityManager.h" @@ -44,6 +45,7 @@ void DiscoverabilityManager::updateLocation() { QJsonObject rootObject; QJsonObject locationObject; + QString pathString = addressManager->currentPath(); @@ -56,13 +58,22 @@ void DiscoverabilityManager::updateLocation() { const QString PLACE_ID_KEY_IN_LOCATION = "place_id"; locationObject.insert(PLACE_ID_KEY_IN_LOCATION, uuidStringWithoutCurlyBraces(addressManager->getRootPlaceID())); - - } else { + } + + if (!domainHandler.getUUID().isNull()) { const QString DOMAIN_ID_KEY_IN_LOCATION = "domain_id"; locationObject.insert(DOMAIN_ID_KEY_IN_LOCATION, uuidStringWithoutCurlyBraces(domainHandler.getUUID())); } - + + // in case the place/domain isn't in the database, we send the network address and port + auto& domainSockAddr = domainHandler.getSockAddr(); + const QString NETWORK_ADRESS_KEY_IN_LOCATION = "network_address"; + locationObject.insert(NETWORK_ADRESS_KEY_IN_LOCATION, domainSockAddr.getAddress().toString()); + + const QString NETWORK_ADDRESS_PORT_IN_LOCATION = "network_port"; + locationObject.insert(NETWORK_ADDRESS_PORT_IN_LOCATION, domainSockAddr.getPort()); + const QString FRIENDS_ONLY_KEY_IN_LOCATION = "friends_only"; locationObject.insert(FRIENDS_ONLY_KEY_IN_LOCATION, (_mode.get() == Discoverability::Friends)); @@ -72,7 +83,7 @@ void DiscoverabilityManager::updateLocation() { QNetworkAccessManager::PutOperation, JSONCallbackParameters(), QJsonDocument(rootObject).toJson()); } - } else { + } else if (UserActivityLogger::getInstance().isEnabled()) { // we still send a heartbeat to the metaverse server for stats collection const QString API_USER_HEARTBEAT_PATH = "/api/v1/user/heartbeat"; accountManager.sendRequest(API_USER_HEARTBEAT_PATH, AccountManagerAuth::Required, QNetworkAccessManager::PutOperation); diff --git a/libraries/networking/src/UserActivityLogger.h b/libraries/networking/src/UserActivityLogger.h index 5c1cb03e3a..c2ab93db2f 100644 --- a/libraries/networking/src/UserActivityLogger.h +++ b/libraries/networking/src/UserActivityLogger.h @@ -28,6 +28,8 @@ public: static UserActivityLogger& getInstance(); public slots: + bool isEnabled() { return !_disabled.get(); } + void disable(bool disable); void logAction(QString action, QJsonObject details = QJsonObject(), JSONCallbackParameters params = JSONCallbackParameters()); From 839c7fb8c2f6cd06d4dc3d74f379d398ab812f20 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 5 May 2016 15:45:11 -0700 Subject: [PATCH 06/15] provide session ID for metaverse heartbeat once received --- interface/src/DiscoverabilityManager.cpp | 28 ++++++++++++++++++- interface/src/DiscoverabilityManager.h | 6 +++- .../networking/src/NetworkingConstants.h | 4 +-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/interface/src/DiscoverabilityManager.cpp b/interface/src/DiscoverabilityManager.cpp index bc1403aa46..4338addb55 100644 --- a/interface/src/DiscoverabilityManager.cpp +++ b/interface/src/DiscoverabilityManager.cpp @@ -31,6 +31,8 @@ DiscoverabilityManager::DiscoverabilityManager() : const QString API_USER_LOCATION_PATH = "/api/v1/user/location"; +const QString SESSION_ID_KEY = "session_id"; + void DiscoverabilityManager::updateLocation() { AccountManager& accountManager = AccountManager::getInstance(); @@ -86,7 +88,31 @@ void DiscoverabilityManager::updateLocation() { } else if (UserActivityLogger::getInstance().isEnabled()) { // we still send a heartbeat to the metaverse server for stats collection const QString API_USER_HEARTBEAT_PATH = "/api/v1/user/heartbeat"; - accountManager.sendRequest(API_USER_HEARTBEAT_PATH, AccountManagerAuth::Required, QNetworkAccessManager::PutOperation); + + JSONCallbackParameters callbackParameters; + callbackParameters.jsonCallbackReceiver = this; + callbackParameters.jsonCallbackMethod = "handleHeartbeatResponse"; + + QJsonObject heartbeatObject; + if (!_sessionID.isEmpty()) { + heartbeatObject[SESSION_ID_KEY] = _sessionID; + } else { + heartbeatObject[SESSION_ID_KEY] = QJsonValue(); + } + + accountManager.sendRequest(API_USER_HEARTBEAT_PATH, AccountManagerAuth::Optional, + QNetworkAccessManager::PutOperation, callbackParameters, + QJsonDocument(heartbeatObject).toJson()); + } +} + +void DiscoverabilityManager::handleHeartbeatResponse(QNetworkReply& requestReply) { + QJsonObject jsonObject = QJsonDocument::fromJson(requestReply.readAll()).object(); + + static const QString STATUS_KEY = "status"; + + if (jsonObject.contains(STATUS_KEY) && jsonObject[STATUS_KEY] == "success") { + _sessionID = jsonObject[SESSION_ID_KEY].toString(); } } diff --git a/interface/src/DiscoverabilityManager.h b/interface/src/DiscoverabilityManager.h index 1b5adcdb5d..94d74b81b9 100644 --- a/interface/src/DiscoverabilityManager.h +++ b/interface/src/DiscoverabilityManager.h @@ -42,10 +42,14 @@ public slots: signals: void discoverabilityModeChanged(Discoverability::Mode discoverabilityMode); +private slots: + void handleHeartbeatResponse(QNetworkReply& requestReply); + private: DiscoverabilityManager(); Setting::Handle _mode; + QString _sessionID; }; -#endif // hifi_DiscoverabilityManager_h \ No newline at end of file +#endif // hifi_DiscoverabilityManager_h diff --git a/libraries/networking/src/NetworkingConstants.h b/libraries/networking/src/NetworkingConstants.h index a1940611bc..d1e0a46c71 100644 --- a/libraries/networking/src/NetworkingConstants.h +++ b/libraries/networking/src/NetworkingConstants.h @@ -15,7 +15,7 @@ #include namespace NetworkingConstants { - const QUrl METAVERSE_SERVER_URL = QUrl("https://metaverse.highfidelity.com"); + const QUrl METAVERSE_SERVER_URL = QUrl("http://localhost:3000"); } -#endif // hifi_NetworkingConstants_h \ No newline at end of file +#endif // hifi_NetworkingConstants_h From a5d09e268d5b0c3132128fae4cc6955c7e451062 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 5 May 2016 15:56:16 -0700 Subject: [PATCH 07/15] fix sessionID pull and re-sent for HB --- interface/src/DiscoverabilityManager.cpp | 8 +++----- libraries/networking/src/AccountManager.cpp | 13 +++++++++++++ libraries/networking/src/AccountManager.h | 2 ++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/interface/src/DiscoverabilityManager.cpp b/interface/src/DiscoverabilityManager.cpp index 4338addb55..db84da55de 100644 --- a/interface/src/DiscoverabilityManager.cpp +++ b/interface/src/DiscoverabilityManager.cpp @@ -107,12 +107,10 @@ void DiscoverabilityManager::updateLocation() { } void DiscoverabilityManager::handleHeartbeatResponse(QNetworkReply& requestReply) { - QJsonObject jsonObject = QJsonDocument::fromJson(requestReply.readAll()).object(); + auto dataObject = AccountManager::dataObjectFromResponse(requestReply); - static const QString STATUS_KEY = "status"; - - if (jsonObject.contains(STATUS_KEY) && jsonObject[STATUS_KEY] == "success") { - _sessionID = jsonObject[SESSION_ID_KEY].toString(); + if (!dataObject.isEmpty()) { + _sessionID = dataObject[SESSION_ID_KEY].toString(); } } diff --git a/libraries/networking/src/AccountManager.cpp b/libraries/networking/src/AccountManager.cpp index e97b077f24..407d7fc605 100644 --- a/libraries/networking/src/AccountManager.cpp +++ b/libraries/networking/src/AccountManager.cpp @@ -66,6 +66,19 @@ JSONCallbackParameters::JSONCallbackParameters(QObject* jsonCallbackReceiver, co } +QJsonObject AccountManager::dataObjectFromResponse(QNetworkReply &requestReply) { + QJsonObject jsonObject = QJsonDocument::fromJson(requestReply.readAll()).object(); + + static const QString STATUS_KEY = "status"; + static const QString DATA_KEY = "data"; + + if (jsonObject.contains(STATUS_KEY) && jsonObject[STATUS_KEY] == "success" && jsonObject.contains(DATA_KEY)) { + return jsonObject[DATA_KEY].toObject(); + } else { + return QJsonObject(); + } +} + AccountManager::AccountManager() : _authURL(), _pendingCallbackMap() diff --git a/libraries/networking/src/AccountManager.h b/libraries/networking/src/AccountManager.h index 0ebefafbed..c374a62515 100644 --- a/libraries/networking/src/AccountManager.h +++ b/libraries/networking/src/AccountManager.h @@ -77,6 +77,8 @@ public: DataServerAccountInfo& getAccountInfo() { return _accountInfo; } + static QJsonObject dataObjectFromResponse(QNetworkReply& requestReply); + public slots: void requestAccessToken(const QString& login, const QString& password); From 6a6d6dd20fee85f77e2ed6ccdcfed268cbd44e3d Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 5 May 2016 16:34:02 -0700 Subject: [PATCH 08/15] Defer mipmap gen to gpu --- libraries/model/src/model/TextureMap.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/libraries/model/src/model/TextureMap.cpp b/libraries/model/src/model/TextureMap.cpp index 349980b702..0fed0b0b4e 100755 --- a/libraries/model/src/model/TextureMap.cpp +++ b/libraries/model/src/model/TextureMap.cpp @@ -171,14 +171,6 @@ gpu::Texture* TextureUsage::process2DTextureColorFromImage(const QImage& srcImag if (generateMips) { theTexture->autoGenerateMips(-1); - auto levels = theTexture->maxMip(); - uvec2 size(image.width(), image.height()); - for (uint8_t i = 1; i <= levels; ++i) { - size >>= 1; - size = glm::max(size, uvec2(1)); - image = image.scaled(size.x, size.y, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - theTexture->assignStoredMip(i, formatMip, image.byteCount(), image.constBits()); - } } } From 7f496ea069e41821a3b76c407196ba50804eaa07 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 5 May 2016 17:54:00 -0700 Subject: [PATCH 09/15] Fix colliding fbx tex names --- .../src/model-networking/ModelCache.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index e4fb5c97f8..24834967d6 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -394,10 +394,20 @@ const QString& NetworkMaterial::getTextureName(MapChannel channel) { return NO_TEXTURE; } -QUrl NetworkMaterial::getTextureUrl(const QUrl& url, const FBXTexture& texture) { - // If content is inline, cache it under the fbx file, not its url - const auto baseUrl = texture.content.isEmpty() ? url : QUrl(url.url() + "/"); - return baseUrl.resolved(QUrl(texture.filename)); +QUrl NetworkMaterial::getTextureUrl(const QUrl& baseUrl, const FBXTexture& texture) { + if (texture.content.isEmpty()) { + // External file: search relative to the baseUrl, in case filename is relative + return baseUrl.resolved(QUrl(texture.filename)); + } else { + // Inlined file: cache under the fbx file to avoid namespace clashes + // NOTE: We cannot resolve the path because filename may be an absolute path + assert(texture.filename.size() > 0); + if (texture.filename.at(0) == '/') { + return baseUrl.toString() + texture.filename; + } else { + return baseUrl.toString() + '/' + texture.filename; + } + } } model::TextureMapPointer NetworkMaterial::fetchTextureMap(const QUrl& baseUrl, const FBXTexture& fbxTexture, From 073d845bb5d1e9a22752ff7adfda343593eca01f Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 5 May 2016 18:33:01 -0700 Subject: [PATCH 10/15] show with debug icons when someone else is the simulation owner --- interface/resources/icons/statusIconAtlas.svg | 83 ++++++++++++------- .../src/RenderableEntityItem.cpp | 4 + .../src/RenderableEntityItem.h | 1 + 3 files changed, 57 insertions(+), 31 deletions(-) diff --git a/interface/resources/icons/statusIconAtlas.svg b/interface/resources/icons/statusIconAtlas.svg index 72f9bc4af7..027102cc69 100644 --- a/interface/resources/icons/statusIconAtlas.svg +++ b/interface/resources/icons/statusIconAtlas.svg @@ -1,31 +1,52 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff --git a/libraries/entities-renderer/src/RenderableEntityItem.cpp b/libraries/entities-renderer/src/RenderableEntityItem.cpp index 25f4052c75..d148145dde 100644 --- a/libraries/entities-renderer/src/RenderableEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableEntityItem.cpp @@ -85,10 +85,14 @@ void makeEntityItemStatusGetters(EntityItemPointer entity, render::Item::Status: auto nodeList = DependencyManager::get(); const QUuid& myNodeID = nodeList->getSessionUUID(); bool weOwnSimulation = entity->getSimulationOwner().matchesValidID(myNodeID); + bool otherOwnSimulation = !weOwnSimulation && !entity->getSimulationOwner().isNull(); if (weOwnSimulation) { return render::Item::Status::Value(1.0f, render::Item::Status::Value::BLUE, (unsigned char)RenderItemStatusIcon::SIMULATION_OWNER); + } else if (otherOwnSimulation) { + return render::Item::Status::Value(1.0f, render::Item::Status::Value::RED, + (unsigned char)RenderItemStatusIcon::OTHER_SIMULATION_OWNER); } return render::Item::Status::Value(0.0f, render::Item::Status::Value::BLUE, (unsigned char)RenderItemStatusIcon::SIMULATION_OWNER); diff --git a/libraries/entities-renderer/src/RenderableEntityItem.h b/libraries/entities-renderer/src/RenderableEntityItem.h index 92bb98ad32..09451e87d4 100644 --- a/libraries/entities-renderer/src/RenderableEntityItem.h +++ b/libraries/entities-renderer/src/RenderableEntityItem.h @@ -25,6 +25,7 @@ enum class RenderItemStatusIcon { PACKET_RECEIVED = 2, SIMULATION_OWNER = 3, HAS_ACTIONS = 4, + OTHER_SIMULATION_OWNER = 5, NONE = 255 }; From 7dd8515bd885f49472a2fc652c22f01d30bbd428 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 6 May 2016 11:50:40 -0700 Subject: [PATCH 11/15] send a simple heartbeat if location has not changed --- interface/src/DiscoverabilityManager.cpp | 31 ++++++++++++++++++------ interface/src/DiscoverabilityManager.h | 1 + 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/interface/src/DiscoverabilityManager.cpp b/interface/src/DiscoverabilityManager.cpp index db84da55de..40186de035 100644 --- a/interface/src/DiscoverabilityManager.cpp +++ b/interface/src/DiscoverabilityManager.cpp @@ -30,6 +30,7 @@ DiscoverabilityManager::DiscoverabilityManager() : } const QString API_USER_LOCATION_PATH = "/api/v1/user/location"; +const QString API_USER_HEARTBEAT_PATH = "/api/v1/user/heartbeat"; const QString SESSION_ID_KEY = "session_id"; @@ -48,7 +49,6 @@ void DiscoverabilityManager::updateLocation() { QJsonObject locationObject; - QString pathString = addressManager->currentPath(); const QString LOCATION_KEY_IN_ROOT = "location"; @@ -78,16 +78,33 @@ void DiscoverabilityManager::updateLocation() { const QString FRIENDS_ONLY_KEY_IN_LOCATION = "friends_only"; locationObject.insert(FRIENDS_ONLY_KEY_IN_LOCATION, (_mode.get() == Discoverability::Friends)); - - rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject); - - accountManager.sendRequest(API_USER_LOCATION_PATH, AccountManagerAuth::Required, + + // if we have a session ID add it now, otherwise add a null value + rootObject[SESSION_ID_KEY] = _sessionID.isEmpty() ? QJsonValue() : _sessionID; + + JSONCallbackParameters callbackParameters; + callbackParameters.jsonCallbackReceiver = this; + callbackParameters.jsonCallbackMethod = "handleHeartbeatResponse"; + + // figure out if we'll send a fresh location or just a simple heartbeat + auto apiPath = API_USER_HEARTBEAT_PATH; + + if (locationObject != _lastLocationObject) { + // we have a changed location, send it now + _lastLocationObject = locationObject; + + rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject); + + apiPath = API_USER_LOCATION_PATH; + } + + accountManager.sendRequest(apiPath, AccountManagerAuth::Required, QNetworkAccessManager::PutOperation, - JSONCallbackParameters(), QJsonDocument(rootObject).toJson()); + callbackParameters, QJsonDocument(rootObject).toJson()); + } } else if (UserActivityLogger::getInstance().isEnabled()) { // we still send a heartbeat to the metaverse server for stats collection - const QString API_USER_HEARTBEAT_PATH = "/api/v1/user/heartbeat"; JSONCallbackParameters callbackParameters; callbackParameters.jsonCallbackReceiver = this; diff --git a/interface/src/DiscoverabilityManager.h b/interface/src/DiscoverabilityManager.h index 94d74b81b9..9a1fa7b39c 100644 --- a/interface/src/DiscoverabilityManager.h +++ b/interface/src/DiscoverabilityManager.h @@ -50,6 +50,7 @@ private: Setting::Handle _mode; QString _sessionID; + QJsonObject _lastLocationObject; }; #endif // hifi_DiscoverabilityManager_h From ed1ddc2a8bd34a73bb56ef0c91c1b97689d4e43b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 6 May 2016 11:54:49 -0700 Subject: [PATCH 12/15] remove code to update/store wallet balance --- interface/src/Application.cpp | 9 -------- .../scripting/AccountScriptingInterface.cpp | 16 -------------- .../src/scripting/AccountScriptingInterface.h | 6 ------ libraries/networking/src/AccountManager.cpp | 20 ------------------ libraries/networking/src/AccountManager.h | 3 --- .../networking/src/DataServerAccountInfo.cpp | 21 ------------------- .../networking/src/DataServerAccountInfo.h | 12 +---------- 7 files changed, 1 insertion(+), 86 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c2a4088dcc..e4f8271368 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -161,7 +161,6 @@ extern "C" { using namespace std; static QTimer locationUpdateTimer; -static QTimer balanceUpdateTimer; static QTimer identityPacketTimer; static QTimer pingTimer; @@ -688,13 +687,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : // connect to appropriate slots on AccountManager AccountManager& accountManager = AccountManager::getInstance(); - const qint64 BALANCE_UPDATE_INTERVAL_MSECS = 5 * MSECS_PER_SEC; - - connect(&balanceUpdateTimer, &QTimer::timeout, &accountManager, &AccountManager::updateBalance); - balanceUpdateTimer.start(BALANCE_UPDATE_INTERVAL_MSECS); - - connect(&accountManager, &AccountManager::balanceChanged, this, &Application::updateWindowTitle); - auto dialogsManager = DependencyManager::get(); connect(&accountManager, &AccountManager::authRequired, dialogsManager.data(), &DialogsManager::showLoginDialog); connect(&accountManager, &AccountManager::usernameChanged, this, &Application::updateWindowTitle); @@ -1197,7 +1189,6 @@ void Application::cleanupBeforeQuit() { // first stop all timers directly or by invokeMethod // depending on what thread they run in locationUpdateTimer.stop(); - balanceUpdateTimer.stop(); identityPacketTimer.stop(); pingTimer.stop(); QMetaObject::invokeMethod(&_settingsTimer, "stop", Qt::BlockingQueuedConnection); diff --git a/interface/src/scripting/AccountScriptingInterface.cpp b/interface/src/scripting/AccountScriptingInterface.cpp index 126cd53003..1b6d52ac2a 100644 --- a/interface/src/scripting/AccountScriptingInterface.cpp +++ b/interface/src/scripting/AccountScriptingInterface.cpp @@ -13,32 +13,16 @@ #include "AccountScriptingInterface.h" -AccountScriptingInterface::AccountScriptingInterface() { - AccountManager& accountManager = AccountManager::getInstance(); - connect(&accountManager, &AccountManager::balanceChanged, this, - &AccountScriptingInterface::updateBalance); -} - AccountScriptingInterface* AccountScriptingInterface::getInstance() { static AccountScriptingInterface sharedInstance; return &sharedInstance; } -float AccountScriptingInterface::getBalance() { - AccountManager& accountManager = AccountManager::getInstance(); - return accountManager.getAccountInfo().getBalanceInSatoshis(); -} - bool AccountScriptingInterface::isLoggedIn() { AccountManager& accountManager = AccountManager::getInstance(); return accountManager.isLoggedIn(); } -void AccountScriptingInterface::updateBalance() { - AccountManager& accountManager = AccountManager::getInstance(); - emit balanceChanged(accountManager.getAccountInfo().getBalanceInSatoshis()); -} - QString AccountScriptingInterface::getUsername() { AccountManager& accountManager = AccountManager::getInstance(); if (accountManager.isLoggedIn()) { diff --git a/interface/src/scripting/AccountScriptingInterface.h b/interface/src/scripting/AccountScriptingInterface.h index 578a9d6728..888149b836 100644 --- a/interface/src/scripting/AccountScriptingInterface.h +++ b/interface/src/scripting/AccountScriptingInterface.h @@ -16,17 +16,11 @@ class AccountScriptingInterface : public QObject { Q_OBJECT - AccountScriptingInterface(); -signals: - void balanceChanged(float newBalance); - public slots: static AccountScriptingInterface* getInstance(); - float getBalance(); QString getUsername(); bool isLoggedIn(); - void updateBalance(); }; #endif // hifi_AccountScriptingInterface_h diff --git a/libraries/networking/src/AccountManager.cpp b/libraries/networking/src/AccountManager.cpp index 407d7fc605..8c23844f4e 100644 --- a/libraries/networking/src/AccountManager.cpp +++ b/libraries/networking/src/AccountManager.cpp @@ -95,8 +95,6 @@ AccountManager::AccountManager() : qRegisterMetaType("QHttpMultiPart*"); qRegisterMetaType(); - - connect(&_accountInfo, &DataServerAccountInfo::balanceChanged, this, &AccountManager::accountInfoBalanceChanged); } const QString DOUBLE_SLASH_SUBSTITUTE = "slashslash"; @@ -105,9 +103,6 @@ void AccountManager::logout() { // a logout means we want to delete the DataServerAccountInfo we currently have for this URL, in-memory and in file _accountInfo = DataServerAccountInfo(); - emit balanceChanged(0); - connect(&_accountInfo, &DataServerAccountInfo::balanceChanged, this, &AccountManager::accountInfoBalanceChanged); - // remove this account from the account settings file removeAccountFromFile(); @@ -116,21 +111,6 @@ void AccountManager::logout() { emit usernameChanged(QString()); } -void AccountManager::updateBalance() { - if (hasValidAccessToken()) { - // ask our auth endpoint for our balance - JSONCallbackParameters callbackParameters; - callbackParameters.jsonCallbackReceiver = &_accountInfo; - callbackParameters.jsonCallbackMethod = "setBalanceFromJSON"; - - sendRequest("/api/v1/wallets/mine", AccountManagerAuth::Required, QNetworkAccessManager::GetOperation, callbackParameters); - } -} - -void AccountManager::accountInfoBalanceChanged(qint64 newBalance) { - emit balanceChanged(newBalance); -} - QString accountFileDir() { return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); } diff --git a/libraries/networking/src/AccountManager.h b/libraries/networking/src/AccountManager.h index c374a62515..108b49f678 100644 --- a/libraries/networking/src/AccountManager.h +++ b/libraries/networking/src/AccountManager.h @@ -87,8 +87,6 @@ public slots: void requestAccessTokenError(QNetworkReply::NetworkError error); void requestProfileError(QNetworkReply::NetworkError error); void logout(); - void updateBalance(); - void accountInfoBalanceChanged(qint64 newBalance); void generateNewUserKeypair() { generateNewKeypair(); } void generateNewDomainKeypair(const QUuid& domainID) { generateNewKeypair(false, domainID); } @@ -100,7 +98,6 @@ signals: void loginComplete(const QUrl& authURL); void loginFailed(); void logoutComplete(); - void balanceChanged(qint64 newBalance); void newKeypair(); private slots: diff --git a/libraries/networking/src/DataServerAccountInfo.cpp b/libraries/networking/src/DataServerAccountInfo.cpp index 9455fb1b88..211bfdccfa 100644 --- a/libraries/networking/src/DataServerAccountInfo.cpp +++ b/libraries/networking/src/DataServerAccountInfo.cpp @@ -31,8 +31,6 @@ DataServerAccountInfo::DataServerAccountInfo(const DataServerAccountInfo& otherI _xmppPassword = otherInfo._xmppPassword; _discourseApiKey = otherInfo._discourseApiKey; _walletID = otherInfo._walletID; - _balance = otherInfo._balance; - _hasBalance = otherInfo._hasBalance; _privateKey = otherInfo._privateKey; _domainID = otherInfo._domainID; } @@ -51,8 +49,6 @@ void DataServerAccountInfo::swap(DataServerAccountInfo& otherInfo) { swap(_xmppPassword, otherInfo._xmppPassword); swap(_discourseApiKey, otherInfo._discourseApiKey); swap(_walletID, otherInfo._walletID); - swap(_balance, otherInfo._balance); - swap(_hasBalance, otherInfo._hasBalance); swap(_privateKey, otherInfo._privateKey); swap(_domainID, otherInfo._domainID); } @@ -87,23 +83,6 @@ void DataServerAccountInfo::setWalletID(const QUuid& walletID) { } } -void DataServerAccountInfo::setBalance(qint64 balance) { - if (!_hasBalance || _balance != balance) { - _balance = balance; - _hasBalance = true; - - emit balanceChanged(_balance); - } -} - -void DataServerAccountInfo::setBalanceFromJSON(QNetworkReply& requestReply) { - QJsonObject jsonObject = QJsonDocument::fromJson(requestReply.readAll()).object(); - if (jsonObject["status"].toString() == "success") { - qint64 balanceInSatoshis = jsonObject["data"].toObject()["wallet"].toObject()["balance"].toDouble(); - setBalance(balanceInSatoshis); - } -} - bool DataServerAccountInfo::hasProfile() const { return _username.length() > 0; } diff --git a/libraries/networking/src/DataServerAccountInfo.h b/libraries/networking/src/DataServerAccountInfo.h index 6223bc008e..6ee726efde 100644 --- a/libraries/networking/src/DataServerAccountInfo.h +++ b/libraries/networking/src/DataServerAccountInfo.h @@ -43,13 +43,6 @@ public: const QUuid& getWalletID() const { return _walletID; } void setWalletID(const QUuid& walletID); - qint64 getBalance() const { return _balance; } - float getBalanceInSatoshis() const { return _balance / SATOSHIS_PER_CREDIT; } - void setBalance(qint64 balance); - bool hasBalance() const { return _hasBalance; } - void setHasBalance(bool hasBalance) { _hasBalance = hasBalance; } - Q_INVOKABLE void setBalanceFromJSON(QNetworkReply& requestReply); - QByteArray getUsernameSignature(const QUuid& connectionToken); bool hasPrivateKey() const { return !_privateKey.isEmpty(); } void setPrivateKey(const QByteArray& privateKey) { _privateKey = privateKey; } @@ -65,8 +58,7 @@ public: friend QDataStream& operator<<(QDataStream &out, const DataServerAccountInfo& info); friend QDataStream& operator>>(QDataStream &in, DataServerAccountInfo& info); -signals: - qint64 balanceChanged(qint64 newBalance); + private: void swap(DataServerAccountInfo& otherInfo); @@ -75,8 +67,6 @@ private: QString _xmppPassword; QString _discourseApiKey; QUuid _walletID; - qint64 _balance { 0 }; - bool _hasBalance { false }; QUuid _domainID; // if this holds account info for a domain, this holds the ID of that domain QByteArray _privateKey; From 258c5308db6303ffdddcdc8d3478e397ce6ec5d3 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 6 May 2016 11:57:25 -0700 Subject: [PATCH 13/15] don't require an active domain connection for location update --- interface/src/DiscoverabilityManager.cpp | 111 +++++++++++------------ 1 file changed, 55 insertions(+), 56 deletions(-) diff --git a/interface/src/DiscoverabilityManager.cpp b/interface/src/DiscoverabilityManager.cpp index 40186de035..e6be7e9034 100644 --- a/interface/src/DiscoverabilityManager.cpp +++ b/interface/src/DiscoverabilityManager.cpp @@ -37,72 +37,71 @@ const QString SESSION_ID_KEY = "session_id"; void DiscoverabilityManager::updateLocation() { AccountManager& accountManager = AccountManager::getInstance(); - if (_mode.get() != Discoverability::None) { + if (_mode.get() != Discoverability::None && accountManager.isLoggedIn()) { auto addressManager = DependencyManager::get(); DomainHandler& domainHandler = DependencyManager::get()->getDomainHandler(); - - if (accountManager.isLoggedIn() && domainHandler.isConnected() - && (!addressManager->getRootPlaceID().isNull() || !domainHandler.getUUID().isNull())) { - - // construct a QJsonObject given the user's current address information - QJsonObject rootObject; - - QJsonObject locationObject; - QString pathString = addressManager->currentPath(); - - const QString LOCATION_KEY_IN_ROOT = "location"; - - const QString PATH_KEY_IN_LOCATION = "path"; - locationObject.insert(PATH_KEY_IN_LOCATION, pathString); - - if (!addressManager->getRootPlaceID().isNull()) { - const QString PLACE_ID_KEY_IN_LOCATION = "place_id"; - locationObject.insert(PLACE_ID_KEY_IN_LOCATION, - uuidStringWithoutCurlyBraces(addressManager->getRootPlaceID())); - } + // construct a QJsonObject given the user's current address information + QJsonObject rootObject; - if (!domainHandler.getUUID().isNull()) { - const QString DOMAIN_ID_KEY_IN_LOCATION = "domain_id"; - locationObject.insert(DOMAIN_ID_KEY_IN_LOCATION, - uuidStringWithoutCurlyBraces(domainHandler.getUUID())); - } + QJsonObject locationObject; - // in case the place/domain isn't in the database, we send the network address and port - auto& domainSockAddr = domainHandler.getSockAddr(); - const QString NETWORK_ADRESS_KEY_IN_LOCATION = "network_address"; - locationObject.insert(NETWORK_ADRESS_KEY_IN_LOCATION, domainSockAddr.getAddress().toString()); + QString pathString = addressManager->currentPath(); - const QString NETWORK_ADDRESS_PORT_IN_LOCATION = "network_port"; - locationObject.insert(NETWORK_ADDRESS_PORT_IN_LOCATION, domainSockAddr.getPort()); + const QString LOCATION_KEY_IN_ROOT = "location"; - const QString FRIENDS_ONLY_KEY_IN_LOCATION = "friends_only"; - locationObject.insert(FRIENDS_ONLY_KEY_IN_LOCATION, (_mode.get() == Discoverability::Friends)); + const QString PATH_KEY_IN_LOCATION = "path"; + locationObject.insert(PATH_KEY_IN_LOCATION, pathString); - // if we have a session ID add it now, otherwise add a null value - rootObject[SESSION_ID_KEY] = _sessionID.isEmpty() ? QJsonValue() : _sessionID; - - JSONCallbackParameters callbackParameters; - callbackParameters.jsonCallbackReceiver = this; - callbackParameters.jsonCallbackMethod = "handleHeartbeatResponse"; - - // figure out if we'll send a fresh location or just a simple heartbeat - auto apiPath = API_USER_HEARTBEAT_PATH; - - if (locationObject != _lastLocationObject) { - // we have a changed location, send it now - _lastLocationObject = locationObject; - - rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject); - - apiPath = API_USER_LOCATION_PATH; - } - - accountManager.sendRequest(apiPath, AccountManagerAuth::Required, - QNetworkAccessManager::PutOperation, - callbackParameters, QJsonDocument(rootObject).toJson()); + const QString CONNECTED_KEY_IN_LOCATION = "connected"; + locationObject.insert(CONNECTED_KEY_IN_LOCATION, domainHandler.isConnected()); + if (!addressManager->getRootPlaceID().isNull()) { + const QString PLACE_ID_KEY_IN_LOCATION = "place_id"; + locationObject.insert(PLACE_ID_KEY_IN_LOCATION, + uuidStringWithoutCurlyBraces(addressManager->getRootPlaceID())); } + + if (!domainHandler.getUUID().isNull()) { + const QString DOMAIN_ID_KEY_IN_LOCATION = "domain_id"; + locationObject.insert(DOMAIN_ID_KEY_IN_LOCATION, + uuidStringWithoutCurlyBraces(domainHandler.getUUID())); + } + + // in case the place/domain isn't in the database, we send the network address and port + auto& domainSockAddr = domainHandler.getSockAddr(); + const QString NETWORK_ADRESS_KEY_IN_LOCATION = "network_address"; + locationObject.insert(NETWORK_ADRESS_KEY_IN_LOCATION, domainSockAddr.getAddress().toString()); + + const QString NETWORK_ADDRESS_PORT_IN_LOCATION = "network_port"; + locationObject.insert(NETWORK_ADDRESS_PORT_IN_LOCATION, domainSockAddr.getPort()); + + const QString FRIENDS_ONLY_KEY_IN_LOCATION = "friends_only"; + locationObject.insert(FRIENDS_ONLY_KEY_IN_LOCATION, (_mode.get() == Discoverability::Friends)); + + // if we have a session ID add it now, otherwise add a null value + rootObject[SESSION_ID_KEY] = _sessionID.isEmpty() ? QJsonValue() : _sessionID; + + JSONCallbackParameters callbackParameters; + callbackParameters.jsonCallbackReceiver = this; + callbackParameters.jsonCallbackMethod = "handleHeartbeatResponse"; + + // figure out if we'll send a fresh location or just a simple heartbeat + auto apiPath = API_USER_HEARTBEAT_PATH; + + if (locationObject != _lastLocationObject) { + // we have a changed location, send it now + _lastLocationObject = locationObject; + + rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject); + + apiPath = API_USER_LOCATION_PATH; + } + + accountManager.sendRequest(apiPath, AccountManagerAuth::Required, + QNetworkAccessManager::PutOperation, + callbackParameters, QJsonDocument(rootObject).toJson()); + } else if (UserActivityLogger::getInstance().isEnabled()) { // we still send a heartbeat to the metaverse server for stats collection From fb09efc0c99e29d0569d0b48b79d6a1e9f7b7b27 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 6 May 2016 12:01:03 -0700 Subject: [PATCH 14/15] send location updates immediately on mode change and startup --- interface/src/Application.cpp | 3 +++ interface/src/DiscoverabilityManager.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e4f8271368..4a829b3191 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -676,6 +676,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : connect(&nodeList->getDomainHandler(), &DomainHandler::connectedToDomain, discoverabilityManager.data(), &DiscoverabilityManager::updateLocation); + // send a location update immediately + discoverabilityManager->updateLocation(); + connect(nodeList.data(), &NodeList::nodeAdded, this, &Application::nodeAdded); connect(nodeList.data(), &NodeList::nodeKilled, this, &Application::nodeKilled); connect(nodeList.data(), &NodeList::nodeActivated, this, &Application::nodeActivated); diff --git a/interface/src/DiscoverabilityManager.cpp b/interface/src/DiscoverabilityManager.cpp index e6be7e9034..b4d0ee9b85 100644 --- a/interface/src/DiscoverabilityManager.cpp +++ b/interface/src/DiscoverabilityManager.cpp @@ -144,6 +144,9 @@ void DiscoverabilityManager::setDiscoverabilityMode(Discoverability::Mode discov if (static_cast(_mode.get()) == Discoverability::None) { // if we just got set to no discoverability, make sure that we delete our location in DB removeLocation(); + } else { + // we have a discoverability mode that says we should send a location, do that right away + updateLocation(); } emit discoverabilityModeChanged(discoverabilityMode); From 6f6221840eb94bd58bae4249cd0819870e8b8773 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 6 May 2016 13:26:23 -0700 Subject: [PATCH 15/15] put back the correct metaverse API url in NetworkingConstants --- libraries/networking/src/NetworkingConstants.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/networking/src/NetworkingConstants.h b/libraries/networking/src/NetworkingConstants.h index d1e0a46c71..a512ae8887 100644 --- a/libraries/networking/src/NetworkingConstants.h +++ b/libraries/networking/src/NetworkingConstants.h @@ -15,7 +15,7 @@ #include namespace NetworkingConstants { - const QUrl METAVERSE_SERVER_URL = QUrl("http://localhost:3000"); + const QUrl METAVERSE_SERVER_URL = QUrl("https://metaverse.highfidelity.com"); } #endif // hifi_NetworkingConstants_h