Esempio n. 1
0
void XMLHttpRequestClass::open(const QString& method, const QString& url, bool async, const QString& username,
                               const QString& password) {
    if (_readyState == UNSENT) {
        _method = method;
        _url.setUrl(url);
        _async = async;

        if (url.toLower().left(METAVERSE_API_URL.length()) == METAVERSE_API_URL) {
            auto accountManager = DependencyManager::get<AccountManager>();
                
            if (accountManager->hasValidAccessToken()) {
                static const QString HTTP_AUTHORIZATION_HEADER = "Authorization";
                QString bearerString = "Bearer " + accountManager->getAccountInfo().getAccessToken().token;
                _request.setRawHeader(HTTP_AUTHORIZATION_HEADER.toLocal8Bit(), bearerString.toLocal8Bit());
            }
        }

        if (!username.isEmpty()) {
            _url.setUserName(username);
        }
        if (!password.isEmpty()) {
            _url.setPassword(password);
        }
        _request.setUrl(_url);
        setReadyState(OPENED);
    }
}
void XMLHttpRequestClass::open(const QString& method, const QString& url, bool async, const QString& username,
                               const QString& password) {
    if (_readyState == UNSENT) {
        _method = method;
        _url.setUrl(url);
        _async = async;

        if (url.toLower().left(METAVERSE_API_URL.length()) == METAVERSE_API_URL) {
            auto accountManager = DependencyManager::get<AccountManager>();
                
            if (accountManager->hasValidAccessToken()) {
                QUrlQuery urlQuery(_url.query());
                urlQuery.addQueryItem("access_token", accountManager->getAccountInfo().getAccessToken().token);
                _url.setQuery(urlQuery);
            }
                
        }
        if (!username.isEmpty()) {
            _url.setUserName(username);
        }
        if (!password.isEmpty()) {
            _url.setPassword(password);
        }
        _request.setUrl(_url);
        setReadyState(OPENED);
    }
}
Esempio n. 3
0
QNetworkRequest createNetworkRequest() {

    QNetworkRequest request;

    QUrl requestURL = NetworkingConstants::METAVERSE_SERVER_URL();
    requestURL.setPath(USER_ACTIVITY_URL);

    request.setUrl(requestURL);

    auto accountManager = DependencyManager::get<AccountManager>();

    if (accountManager->hasValidAccessToken()) {
        request.setRawHeader(ACCESS_TOKEN_AUTHORIZATION_HEADER,
                             accountManager->getAccountInfo().getAccessToken().authorizationHeaderValue());
    }

    request.setRawHeader(METAVERSE_SESSION_ID_HEADER,
                         uuidStringWithoutCurlyBraces(accountManager->getSessionID()).toLocal8Bit());

    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");

    request.setPriority(QNetworkRequest::HighPriority);

    return request;
}
Esempio n. 4
0
QNetworkReply* OAuthNetworkAccessManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest& req,
                                                        QIODevice* outgoingData) {
    auto accountManager = DependencyManager::get<AccountManager>();
    
    if (accountManager->hasValidAccessToken()
        && req.url().host() == NetworkingConstants::METAVERSE_SERVER_URL.host()) {
        QNetworkRequest authenticatedRequest(req);
        authenticatedRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
        authenticatedRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
        authenticatedRequest.setRawHeader(ACCESS_TOKEN_AUTHORIZATION_HEADER,
                                          accountManager->getAccountInfo().getAccessToken().authorizationHeaderValue());
        
        return QNetworkAccessManager::createRequest(op, authenticatedRequest, outgoingData);
    } else {
        return QNetworkAccessManager::createRequest(op, req, outgoingData);
    }
}
Esempio n. 5
0
void LoginDialog::toggleAction() {
    auto accountManager = DependencyManager::get<AccountManager>();
    QAction* loginAction = Menu::getInstance()->getActionForOption(MenuOption::Login);
    Q_CHECK_PTR(loginAction);
    static QMetaObject::Connection connection;
    if (connection) {
        disconnect(connection);
    }

    if (accountManager->isLoggedIn()) {
        // change the menu item to logout
        loginAction->setText("Logout " + accountManager->getAccountInfo().getUsername());
        connection = connect(loginAction, &QAction::triggered, accountManager.data(), &AccountManager::logout);
    } else {
        // change the menu item to login
        loginAction->setText("Log In / Sign Up");
        connection = connect(loginAction, &QAction::triggered, [] { LoginDialog::showWithSelection(); });
    }
}
bool Bitmaszyna::getfunds()
{    
    struct json_object *json,*jtmp,*jtmp2;

    curl_mutex.lock();
    if (makeApiCall("funds",&json,string("nonce=")+to_stringl(getctime()).toStdString()))
    {
        if (!fetchData(&json,&jtmp)) return(false);
        log(string(chunk.memory)+"\n");
        json_object_object_get_ex(json,"funds",&jtmp);
        json_object_object_get_ex(jtmp,"available_btc",&jtmp2);
        balance.balance[BTC]=json_object_get_double(jtmp2);
        json_object_object_get_ex(jtmp,"blocked_btc",&jtmp2);
        balance.blocked[BTC]=json_object_get_double(jtmp2);
        json_object_object_get_ex(jtmp,"available_ltc",&jtmp2);
        balance.balance[LTC]=json_object_get_double(jtmp2);
        json_object_object_get_ex(jtmp,"blocked_ltc",&jtmp2);
        balance.blocked[LTC]=json_object_get_double(jtmp2);
        json_object_object_get_ex(jtmp,"available_kbm",&jtmp2);
        balance.balance[KBM]=json_object_get_double(jtmp2);
        json_object_object_get_ex(jtmp,"blocked_kbm",&jtmp2);
        balance.blocked[KBM]=json_object_get_double(jtmp2);
        json_object_object_get_ex(jtmp,"available_pln",&jtmp2);
        balance.balance[PLN]=json_object_get_double(jtmp2);
        json_object_object_get_ex(jtmp,"blocked_pln",&jtmp2);
        balance.blocked[PLN]=json_object_get_double(jtmp2);
        json_object_object_get_ex(jtmp,"takerfee",&jtmp2);
        fees.taker=json_object_get_double(jtmp2);
        json_object_object_get_ex(jtmp,"makerfee",&jtmp2);
        fees.maker=json_object_get_double(jtmp2);
        json_object_put(json);
        logged=true;
        curl_mutex.unlock();
        return(getAccountInfo());
    }
    curl_mutex.unlock();
    return(false);
}
Esempio n. 7
0
QString keyFilePath() {
    auto accountManager = DependencyManager::get<AccountManager>();
    return PathUtils::getAppDataFilePath(QString("%1.%2").arg(accountManager->getAccountInfo().getUsername(), KEY_FILE));
}
Esempio n. 8
0
JNIEXPORT jstring JNICALL
Java_io_highfidelity_hifiinterface_fragment_FriendsFragment_nativeGetAccessToken(JNIEnv *env, jobject instance) {
    auto accountManager = DependencyManager::get<AccountManager>();
    return env->NewStringUTF(accountManager->getAccountInfo().getAccessToken().token.toLatin1().data());
}
Esempio n. 9
0
ATPClientApp::ATPClientApp(int argc, char* argv[]) :
    QCoreApplication(argc, argv)
{
    // parse command-line
    QCommandLineParser parser;
    parser.setApplicationDescription("High Fidelity ATP-Client");

    const QCommandLineOption helpOption = parser.addHelpOption();

    const QCommandLineOption verboseOutput("v", "verbose output");
    parser.addOption(verboseOutput);

    const QCommandLineOption uploadOption("T", "upload local file", "local-file-to-send");
    parser.addOption(uploadOption);

    const QCommandLineOption authOption("u", "set usename and pass", "username:password");
    parser.addOption(authOption);

    const QCommandLineOption outputFilenameOption("o", "output filename", "output-file-name");
    parser.addOption(outputFilenameOption);

    const QCommandLineOption domainAddressOption("d", "domain-server address", "127.0.0.1");
    parser.addOption(domainAddressOption);

    const QCommandLineOption listenPortOption("listenPort", "listen port", QString::number(INVALID_PORT));
    parser.addOption(listenPortOption);

    if (!parser.parse(QCoreApplication::arguments())) {
        qCritical() << parser.errorText() << endl;
        parser.showHelp();
        Q_UNREACHABLE();
    }

    if (parser.isSet(helpOption)) {
        parser.showHelp();
        Q_UNREACHABLE();
    }

    _verbose = parser.isSet(verboseOutput);
    if (!_verbose) {
        QLoggingCategory::setFilterRules("qt.network.ssl.warning=false");

        const_cast<QLoggingCategory*>(&networking())->setEnabled(QtDebugMsg, false);
        const_cast<QLoggingCategory*>(&networking())->setEnabled(QtInfoMsg, false);
        const_cast<QLoggingCategory*>(&networking())->setEnabled(QtWarningMsg, false);

        const_cast<QLoggingCategory*>(&shared())->setEnabled(QtDebugMsg, false);
        const_cast<QLoggingCategory*>(&shared())->setEnabled(QtInfoMsg, false);
        const_cast<QLoggingCategory*>(&shared())->setEnabled(QtWarningMsg, false);
    }

    QStringList posArgs = parser.positionalArguments();
    if (posArgs.size() != 1) {
        qDebug() << "give remote url argument";
        parser.showHelp();
        Q_UNREACHABLE();
    }

    _url = QUrl(posArgs[0]);
    if (_url.scheme() != "atp") {
        qDebug() << "url should start with atp:";
        parser.showHelp();
        Q_UNREACHABLE();
    }

    int domainPort = 40103;
    if (_url.port() != -1) {
        domainPort = _url.port();
    }

    if (parser.isSet(outputFilenameOption)) {
        _localOutputFile = parser.value(outputFilenameOption);
    }

    if (parser.isSet(uploadOption)) {
        _localUploadFile = parser.value(uploadOption);
    }

    if (parser.isSet(authOption)) {
        QStringList pieces = parser.value(authOption).split(":");
        if (pieces.size() != 2) {
            qDebug() << "-u should be followed by username:password";
            parser.showHelp();
            Q_UNREACHABLE();
        }

        _username = pieces[0];
        _password = pieces[1];
        _waitingForLogin = true;
    }

    if (parser.isSet(listenPortOption)) {
        _listenPort = parser.value(listenPortOption).toInt();
    }

    _domainServerAddress = QString("127.0.0.1") + ":" + QString::number(domainPort);
    if (parser.isSet(domainAddressOption)) {
        _domainServerAddress = parser.value(domainAddressOption);
    } else if (!_url.host().isEmpty()) {
        QUrl domainURL;
        domainURL.setScheme("hifi");
        domainURL.setHost(_url.host());
        _domainServerAddress = domainURL.toString();
    }

    DependencyManager::registerInheritance<LimitedNodeList, NodeList>();

    DependencyManager::set<StatTracker>();
    DependencyManager::set<AccountManager>([&]{ return QString(HIGH_FIDELITY_ATP_CLIENT_USER_AGENT); });
    DependencyManager::set<AddressManager>();
    DependencyManager::set<NodeList>(NodeType::Agent, _listenPort);

    auto accountManager = DependencyManager::get<AccountManager>();
    accountManager->setIsAgent(true);
    accountManager->setAuthURL(NetworkingConstants::METAVERSE_SERVER_URL());

    auto nodeList = DependencyManager::get<NodeList>();

    // setup a timer for domain-server check ins
    _domainCheckInTimer = new QTimer(nodeList.data());
    connect(_domainCheckInTimer, &QTimer::timeout, nodeList.data(), &NodeList::sendDomainServerCheckIn);
    _domainCheckInTimer->start(DOMAIN_SERVER_CHECK_IN_MSECS);

    // start the nodeThread so its event loop is running
    // (must happen after the checkin timer is created with the nodelist as it's parent)
    nodeList->startThread();

    const DomainHandler& domainHandler = nodeList->getDomainHandler();
    connect(&domainHandler, SIGNAL(hostnameChanged(const QString&)), SLOT(domainChanged(const QString&)));
    connect(&domainHandler, &DomainHandler::domainConnectionRefused, this, &ATPClientApp::domainConnectionRefused);

    connect(nodeList.data(), &NodeList::nodeAdded, this, &ATPClientApp::nodeAdded);
    connect(nodeList.data(), &NodeList::nodeKilled, this, &ATPClientApp::nodeKilled);
    connect(nodeList.data(), &NodeList::nodeActivated, this, &ATPClientApp::nodeActivated);
    connect(nodeList.data(), &NodeList::packetVersionMismatch, this, &ATPClientApp::notifyPacketVersionMismatch);
    nodeList->addSetOfNodeTypesToNodeInterestSet(NodeSet() << NodeType::AudioMixer << NodeType::AvatarMixer
                                                 << NodeType::EntityServer << NodeType::AssetServer << NodeType::MessagesMixer);

    if (_verbose) {
        QString username = accountManager->getAccountInfo().getUsername();
        qDebug() << "cached username is" << username << ", isLoggedIn =" << accountManager->isLoggedIn();
    }

    if (!_username.isEmpty()) {

        connect(accountManager.data(), &AccountManager::newKeypair, this, [&](){
            if (_verbose) {
                qDebug() << "new keypair has been created.";
            }
        });

        connect(accountManager.data(), &AccountManager::loginComplete, this, [&](){
            if (_verbose) {
                qDebug() << "login successful";
            }
            _waitingForLogin = false;
            go();
        });
        connect(accountManager.data(), &AccountManager::loginFailed, this, [&](){
            qDebug() << "login failed.";
            _waitingForLogin = false;
            go();
        });
        accountManager->requestAccessToken(_username, _password);
    }

    auto assetClient = DependencyManager::set<AssetClient>();
    assetClient->init();

    if (_verbose) {
        qDebug() << "domain-server address is" << _domainServerAddress;
    }

    DependencyManager::get<AddressManager>()->handleLookupString(_domainServerAddress, false);

    QTimer* _timeoutTimer = new QTimer(this);
    _timeoutTimer->setSingleShot(true);
    connect(_timeoutTimer, &QTimer::timeout, this, &ATPClientApp::timedOut);
    _timeoutTimer->start(TIMEOUT_MILLISECONDS);
}
Esempio n. 10
0
ACClientApp::ACClientApp(int argc, char* argv[]) :
    QCoreApplication(argc, argv)
{
    // parse command-line
    QCommandLineParser parser;
    parser.setApplicationDescription("High Fidelity AC client");

    const QCommandLineOption helpOption = parser.addHelpOption();

    const QCommandLineOption verboseOutput("v", "verbose output");
    parser.addOption(verboseOutput);

    const QCommandLineOption authOption("u", "set usename and pass", "username:password");
    parser.addOption(authOption);

    const QCommandLineOption domainAddressOption("d", "domain-server address", "127.0.0.1");
    parser.addOption(domainAddressOption);

    const QCommandLineOption cacheSTUNOption("s", "cache stun-server response");
    parser.addOption(cacheSTUNOption);

    const QCommandLineOption listenPortOption("listenPort", "listen port", QString::number(INVALID_PORT));
    parser.addOption(listenPortOption);

    if (!parser.parse(QCoreApplication::arguments())) {
        qCritical() << parser.errorText() << endl;
        parser.showHelp();
        Q_UNREACHABLE();
    }

    if (parser.isSet(helpOption)) {
        parser.showHelp();
        Q_UNREACHABLE();
    }

    _verbose = parser.isSet(verboseOutput);
    if (!_verbose) {
        QLoggingCategory::setFilterRules("qt.network.ssl.warning=false");

        const_cast<QLoggingCategory*>(&networking())->setEnabled(QtDebugMsg, false);
        const_cast<QLoggingCategory*>(&networking())->setEnabled(QtInfoMsg, false);
        const_cast<QLoggingCategory*>(&networking())->setEnabled(QtWarningMsg, false);

        const_cast<QLoggingCategory*>(&shared())->setEnabled(QtDebugMsg, false);
        const_cast<QLoggingCategory*>(&shared())->setEnabled(QtInfoMsg, false);
        const_cast<QLoggingCategory*>(&shared())->setEnabled(QtWarningMsg, false);
    }
    

    QString domainServerAddress = "127.0.0.1:40103";
    if (parser.isSet(domainAddressOption)) {
        domainServerAddress = parser.value(domainAddressOption);
    }

    if (_verbose) {
        qDebug() << "domain-server address is" << domainServerAddress;
    }

    int listenPort = INVALID_PORT;
    if (parser.isSet(listenPortOption)) {
        listenPort = parser.value(listenPortOption).toInt();
    }

    if (parser.isSet(authOption)) {
        QStringList pieces = parser.value(authOption).split(":");
        if (pieces.size() != 2) {
            qDebug() << "-u should be followed by username:password";
            parser.showHelp();
            Q_UNREACHABLE();
        }

        _username = pieces[0];
        _password = pieces[1];
    }

    DependencyManager::registerInheritance<LimitedNodeList, NodeList>();

    DependencyManager::set<AccountManager>([&]{ return QString("Mozilla/5.0 (HighFidelityACClient)"); });
    DependencyManager::set<AddressManager>();
    DependencyManager::set<NodeList>(NodeType::Agent, listenPort);

    auto accountManager = DependencyManager::get<AccountManager>();
    accountManager->setIsAgent(true);
    accountManager->setAuthURL(NetworkingConstants::METAVERSE_SERVER_URL());

    auto nodeList = DependencyManager::get<NodeList>();

    // setup a timer for domain-server check ins
    QTimer* domainCheckInTimer = new QTimer(nodeList.data());
    connect(domainCheckInTimer, &QTimer::timeout, nodeList.data(), &NodeList::sendDomainServerCheckIn);
    domainCheckInTimer->start(DOMAIN_SERVER_CHECK_IN_MSECS);

    // start the nodeThread so its event loop is running
    // (must happen after the checkin timer is created with the nodelist as it's parent)
    nodeList->startThread();

    const DomainHandler& domainHandler = nodeList->getDomainHandler();
    connect(&domainHandler, SIGNAL(domainURLChanged(QUrl)), SLOT(domainChanged(QUrl)));
    connect(&domainHandler, &DomainHandler::domainConnectionRefused, this, &ACClientApp::domainConnectionRefused);

    connect(nodeList.data(), &NodeList::nodeAdded, this, &ACClientApp::nodeAdded);
    connect(nodeList.data(), &NodeList::nodeKilled, this, &ACClientApp::nodeKilled);
    connect(nodeList.data(), &NodeList::nodeActivated, this, &ACClientApp::nodeActivated);
    connect(nodeList.data(), &NodeList::packetVersionMismatch, this, &ACClientApp::notifyPacketVersionMismatch);
    nodeList->addSetOfNodeTypesToNodeInterestSet(NodeSet() << NodeType::AudioMixer << NodeType::AvatarMixer
                                                 << NodeType::EntityServer << NodeType::AssetServer << NodeType::MessagesMixer);

    if (_verbose) {
        QString username = accountManager->getAccountInfo().getUsername();
        qDebug() << "cached username is" << username << ", isLoggedIn =" << accountManager->isLoggedIn();
    }

    if (!_username.isEmpty()) {

        connect(accountManager.data(), &AccountManager::newKeypair, this, [&](){
            if (_verbose) {
                qDebug() << "new keypair has been created.";
            }
        });

        connect(accountManager.data(), &AccountManager::loginComplete, this, [&](){
            if (_verbose) {
                qDebug() << "login successful";
            }
        });
        connect(accountManager.data(), &AccountManager::loginFailed, this, [&](){
            qDebug() << "login failed.";
        });
        accountManager->requestAccessToken(_username, _password);
    }

    DependencyManager::get<AddressManager>()->handleLookupString(domainServerAddress, false);

    QTimer* doTimer = new QTimer(this);
    doTimer->setSingleShot(true);
    connect(doTimer, &QTimer::timeout, this, &ACClientApp::timedOut);
    doTimer->start(4000);
}