diff --git a/src/GUI/private/mainmodel.cpp b/src/GUI/private/mainmodel.cpp index 42092e7..07086e6 100644 --- a/src/GUI/private/mainmodel.cpp +++ b/src/GUI/private/mainmodel.cpp @@ -370,12 +370,15 @@ void MainModel::initCardsListModels() { connect(_cardsListModel, &CardsListModel::sigRemoveRequest, this, &MainModel::handleRemoveRequest); - connect(_ownCardsListModel, &CardsListModel::sigEditFinished, - this, &MainModel::handleCardEditFinished); - connect(_cardsListModel, &CardsListModel::sigEditFinished, this, &MainModel::saveCard); + connect(_cardsListModel, &CardsListModel::sigResetCardModel, + this, &MainModel::handleResetCardModel); + + connect(_ownCardsListModel, &CardsListModel::sigEditFinished, + this, &MainModel::handleCardEditFinished); + connect(_ownCardsListModel, &CardsListModel::sigRemoveRequest, this, &MainModel::handleRemoveRequest); @@ -385,9 +388,6 @@ void MainModel::initCardsListModels() { connect(_ownCardsListModel, &CardsListModel::sigCardSelectedForStatistic, this, &MainModel::handleCardSelectedForStatistic); - connect(_cardsListModel, &CardsListModel::sigResetCardModel, - this, &MainModel::handleResetCardModel); - connect(_ownCardsListModel, &CardsListModel::sigResetCardModel, this, &MainModel::handleResetCardModel); } @@ -779,15 +779,24 @@ void RC::MainModel::saveCard(const QSharedPointer& card) { card->setCardVersion(VERSION_CARD_USER); } else { card->setCardVersion(card->getCardVersion() + 1); - } _db->insertIfExistsUpdateObject(card); // send notification about updates to server - if (!fClient) { - auto seller = _backEndModel.staticCast(); - seller->cardUpdated(card->cardId(), card->getCardVersion()); + auto currentUserId = _currentUser->userId(); + if (card->isOvner(currentUserId)) { + + auto seller = _backEndModel.dynamicCast(); + if (!seller) + return; + + auto header = _currentUser->getHelloPackage(); + + seller->setPurchase(header, + card->cardId(), + 0); + } } @@ -801,7 +810,8 @@ void MainModel::handleCardEditFinished(const QSharedPointer& card) { return; } - auto listOfUsers = _backEndModel->getAllUserFromCard(card->cardId()); + auto listOfUsers = _backEndModel->getAllUserFromCard(card->cardId(), + _currentUser->userId()); if (localCard && listOfUsers.size() && localCard->getFreeIndex() != card->getFreeIndex()) { @@ -871,7 +881,9 @@ void MainModel::handleRemoveRequest(const QSharedPointer &card) { }; if (getMode()) { - auto listOfUsers = _backEndModel->getAllActiveUserFromCard(card->cardId()); + auto listOfUsers = _backEndModel->getAllActiveUserFromCard(card->cardId(), + ACTIVE_USER_TIME_LIMIT, + _currentUser->userId()); if (listOfUsers.size()) { service->setNotify(tr("Operation not permitted"), @@ -906,7 +918,7 @@ void MainModel::handleCardSelectedForWork(const QSharedPointer &card) } void MainModel::handleCardSelectedForStatistic(const QSharedPointer &card) { - auto usersList = _backEndModel->getAllUserFromCard(card->card()->cardId()); + auto usersList = _backEndModel->getAllUserFromCard(card->card()->cardId(), _currentUser->userId()); auto usersDataList = _backEndModel->getAllUserDataFromCard(card->card()->cardId()); _statisticModel->setDataList(card, usersList, usersDataList); diff --git a/src/GUI/private/usermodel.h b/src/GUI/private/usermodel.h index 9777d19..a1676d5 100644 --- a/src/GUI/private/usermodel.h +++ b/src/GUI/private/usermodel.h @@ -64,6 +64,7 @@ class UserModel: public QObject, public QuasarAppUtils::SettingsListner Q_INVOKABLE QString userBackUpData() const; int userId() const; + API::UserHeader getHelloPackage() const; signals: void objChanged(); @@ -74,7 +75,6 @@ class UserModel: public QObject, public QuasarAppUtils::SettingsListner protected: void setSessinon(long long newSessinon); - API::UserHeader getHelloPackage() const; void handleSettingsChanged(const QString& key, const QVariant& value) override; private: diff --git a/src/RC/CheatCard/api/apiobjectsfactory.h b/src/RC/CheatCard/api/apiobjectsfactory.h index 483d76f..742a376 100644 --- a/src/RC/CheatCard/api/apiobjectsfactory.h +++ b/src/RC/CheatCard/api/apiobjectsfactory.h @@ -70,11 +70,17 @@ class APIObjectsFactory: public IAPIObjectsFactory }; template - QList > getAllUserFromCardImpl(unsigned int cardId) const { + QList > getAllUserFromCardImpl(unsigned int cardId, + unsigned int ignoreUserId = 0) const { check_type(UsersCards); - QString where = QString("card=%0").arg(cardId); + QString where; + if (ignoreUserId) { + where = QString("card=%0 AND user!=%1").arg(cardId).arg(ignoreUserId); + } else { + where = QString("card=%0").arg(cardId); + } QH::PKG::DBObjectsRequest request("UsersCards", where); @@ -89,14 +95,21 @@ class APIObjectsFactory: public IAPIObjectsFactory template QList > getAllActiveUserFromCardImpl(unsigned int cardId, - int unixTimeRange = ACTIVE_USER_TIME_LIMIT) const { + int unixTimeRange = ACTIVE_USER_TIME_LIMIT, + unsigned int ignoreUserId = 0) const { check_type(UsersCards); int timePoint = time(0) - unixTimeRange; - QString where = QString("card=%0 AND time>%1"). - arg(cardId).arg(timePoint); + QString where; + if (ignoreUserId) { + where = QString("card=%0 AND time>%1 AND user!=%2"). + arg(cardId).arg(timePoint).arg(ignoreUserId); + } else { + where = QString("card=%0 AND time>%1") + .arg(cardId).arg(timePoint); + } QH::PKG::DBObjectsRequest request("UsersCards", where); @@ -111,14 +124,21 @@ class APIObjectsFactory: public IAPIObjectsFactory template QList > getAllPassiveUserFromCardImpl(unsigned int cardId, - int unixTimeRange = ACTIVE_USER_TIME_LIMIT) const { + int unixTimeRange = ACTIVE_USER_TIME_LIMIT, + unsigned int ignoreUserId = 0) const { check_type(UsersCards); int timePoint = time(0) - unixTimeRange; - QString where = QString("card=%0 AND time<%1"). - arg(cardId).arg(timePoint); + QString where; + if (ignoreUserId) { + where = QString("card=%0 AND time<%1 AND user!=%2"). + arg(cardId).arg(timePoint).arg(ignoreUserId); + } else { + where = QString("card=%0 AND time<%1") + .arg(cardId).arg(timePoint); + } QH::PKG::DBObjectsRequest request("UsersCards", where); diff --git a/src/RC/CheatCard/api/apiobjectsfactoryv0.cpp b/src/RC/CheatCard/api/apiobjectsfactoryv0.cpp index 92bf9e6..c82b5e7 100644 --- a/src/RC/CheatCard/api/apiobjectsfactoryv0.cpp +++ b/src/RC/CheatCard/api/apiobjectsfactoryv0.cpp @@ -38,22 +38,24 @@ APIObjectsFactoryV0::getUserCardData(unsigned int userId, unsigned int cardId) c } QList > -APIObjectsFactoryV0::getAllUserFromCard(unsigned int cardId) const { - return getAllUserFromCardImpl(cardId); +APIObjectsFactoryV0::getAllUserFromCard(unsigned int cardId, unsigned int ignore) const { + return getAllUserFromCardImpl(cardId, ignore); } QList > APIObjectsFactoryV0::getAllPassiveUserFromCard(unsigned int cardId, - int unixTimeRange) const { - return getAllPassiveUserFromCardImpl(cardId, unixTimeRange); + int unixTimeRange, + unsigned int ignoreUserId) const { + return getAllPassiveUserFromCardImpl(cardId, unixTimeRange, ignoreUserId); } QList > APIObjectsFactoryV0::getAllActiveUserFromCard(unsigned int cardId, - int unixTimeRange) const { - return getAllActiveUserFromCardImpl(cardId, unixTimeRange); + int unixTimeRange, + unsigned int ignoreUserId) const { + return getAllActiveUserFromCardImpl(cardId, unixTimeRange, ignoreUserId); } QList > diff --git a/src/RC/CheatCard/api/apiobjectsfactoryv0.h b/src/RC/CheatCard/api/apiobjectsfactoryv0.h index 946d7a6..48212d2 100644 --- a/src/RC/CheatCard/api/apiobjectsfactoryv0.h +++ b/src/RC/CheatCard/api/apiobjectsfactoryv0.h @@ -24,11 +24,13 @@ class APIObjectsFactoryV0 : public APIObjectsFactory QSharedPointer getUser(unsigned int userId) const override; QList > getAllUserData(unsigned int userId) const override; QSharedPointer getUserCardData(unsigned int userId, unsigned int cardId) const override; - QList > getAllUserFromCard(unsigned int cardId) const override; + QList > getAllUserFromCard(unsigned int cardId, unsigned int ignore = 0) const override; QList > getAllPassiveUserFromCard(unsigned int cardId, - int unixTimeRange = ACTIVE_USER_TIME_LIMIT) const override; + int unixTimeRange = ACTIVE_USER_TIME_LIMIT, + unsigned int ignoreUserId = 0) const override; QList > getAllActiveUserFromCard(unsigned int cardId, - int unixTimeRange = ACTIVE_USER_TIME_LIMIT) const override; + int unixTimeRange = ACTIVE_USER_TIME_LIMIT, + unsigned int ignoreUserId = 0) const override; QList > getAllUserDataFromCard(unsigned int cardId) const override; QList> getAllUserWithPrivateKeys() const override;; diff --git a/src/RC/CheatCard/api/apiobjectsfactoryv1-5.cpp b/src/RC/CheatCard/api/apiobjectsfactoryv1-5.cpp index 5508499..f7fbfa2 100644 --- a/src/RC/CheatCard/api/apiobjectsfactoryv1-5.cpp +++ b/src/RC/CheatCard/api/apiobjectsfactoryv1-5.cpp @@ -32,25 +32,27 @@ APIObjectsFactoryV1_5::getUserCardData(unsigned int userId, unsigned int cardId) } QList > -APIObjectsFactoryV1_5::getAllUserFromCard(unsigned int cardId) const { - return getAllUserFromCardImpl(cardId); +APIObjectsFactoryV1_5::getAllUserFromCard(unsigned int cardId, unsigned int ignoreuser) const { + return getAllUserFromCardImpl(cardId, ignoreuser); } QList > APIObjectsFactoryV1_5::getAllPassiveUserFromCard(unsigned int cardId, - int unixTimeRange) const { - return getAllPassiveUserFromCardImpl(cardId, unixTimeRange); + int unixTimeRange, + unsigned int ignoreuser) const { + return getAllPassiveUserFromCardImpl(cardId, unixTimeRange, ignoreuser); } QList > APIObjectsFactoryV1_5::getAllActiveUserFromCard(unsigned int cardId, - int unixTimeRange) const { - return getAllActiveUserFromCardImpl(cardId, unixTimeRange); + int unixTimeRange, + unsigned int ignoreuser) const { + return getAllActiveUserFromCardImpl(cardId, unixTimeRange, ignoreuser); } QList > APIObjectsFactoryV1_5::getAllUserCardsData(const QByteArray &userKey, - const QList> &childs) { + const QList> &childs) { QList keys; diff --git a/src/RC/CheatCard/api/apiobjectsfactoryv1-5.h b/src/RC/CheatCard/api/apiobjectsfactoryv1-5.h index 6bd3b4c..f10d8e3 100644 --- a/src/RC/CheatCard/api/apiobjectsfactoryv1-5.h +++ b/src/RC/CheatCard/api/apiobjectsfactoryv1-5.h @@ -22,11 +22,14 @@ class APIObjectsFactoryV1_5: public APIObjectsFactoryV1 QList > getAllUserData(unsigned int userId) const override; QSharedPointer getUserCardData(unsigned int userId, unsigned int cardId) const override; - QList > getAllUserFromCard(unsigned int cardId) const override; + QList > getAllUserFromCard(unsigned int cardId, + unsigned int ignoreuser = 0) const override; QList > getAllPassiveUserFromCard(unsigned int cardId, - int unixTimeRange = ACTIVE_USER_TIME_LIMIT) const override; + int unixTimeRange = ACTIVE_USER_TIME_LIMIT, + unsigned int ignoreuser = 0) const override; QList > getAllActiveUserFromCard(unsigned int cardId, - int unixTimeRange = ACTIVE_USER_TIME_LIMIT) const override; + int unixTimeRange = ACTIVE_USER_TIME_LIMIT, + unsigned int ignoreuser = 0) const override; QList > getAllUserCardsData(const QByteArray &userKey, const QList > &childs) override; diff --git a/src/RC/CheatCard/api/apiobjectsfactoryv1.cpp b/src/RC/CheatCard/api/apiobjectsfactoryv1.cpp index 8325e48..c7622e3 100644 --- a/src/RC/CheatCard/api/apiobjectsfactoryv1.cpp +++ b/src/RC/CheatCard/api/apiobjectsfactoryv1.cpp @@ -35,20 +35,22 @@ APIObjectsFactoryV1::getUserCardData(unsigned int userId, unsigned int cardId) c } QList > -APIObjectsFactoryV1::getAllUserFromCard(unsigned int cardId) const { - return getAllUserFromCardImpl(cardId); +APIObjectsFactoryV1::getAllUserFromCard(unsigned int cardId, unsigned int ignoreuser) const { + return getAllUserFromCardImpl(cardId, ignoreuser); } QList > APIObjectsFactoryV1::getAllPassiveUserFromCard(unsigned int cardId, - int unixTimeRange) const { - return getAllPassiveUserFromCardImpl(cardId, unixTimeRange); + int unixTimeRange, + unsigned int ignoreuser) const { + return getAllPassiveUserFromCardImpl(cardId, unixTimeRange, ignoreuser); } QList > APIObjectsFactoryV1::getAllActiveUserFromCard(unsigned int cardId, - int unixTimeRange) const { - return getAllActiveUserFromCardImpl(cardId, unixTimeRange); + int unixTimeRange, + unsigned int ignoreuser) const { + return getAllActiveUserFromCardImpl(cardId, unixTimeRange, ignoreuser); } QSharedPointer diff --git a/src/RC/CheatCard/api/apiobjectsfactoryv1.h b/src/RC/CheatCard/api/apiobjectsfactoryv1.h index 5dccd38..cf46250 100644 --- a/src/RC/CheatCard/api/apiobjectsfactoryv1.h +++ b/src/RC/CheatCard/api/apiobjectsfactoryv1.h @@ -22,11 +22,14 @@ class APIObjectsFactoryV1: public APIObjectsFactoryV0 QList > getAllUserData(unsigned int userId) const override; QSharedPointer getUserCardData(unsigned int userId, unsigned int cardId) const override; - QList > getAllUserFromCard(unsigned int cardId) const override; + QList > getAllUserFromCard(unsigned int cardId, + unsigned int ignoreuser = 0) const override; QList > getAllPassiveUserFromCard(unsigned int cardId, - int unixTimeRange = ACTIVE_USER_TIME_LIMIT) const override; + int unixTimeRange = ACTIVE_USER_TIME_LIMIT, + unsigned int ignoreuser = 0) const override; QList > getAllActiveUserFromCard(unsigned int cardId, - int unixTimeRange = ACTIVE_USER_TIME_LIMIT) const override; + int unixTimeRange = ACTIVE_USER_TIME_LIMIT, + unsigned int ignoreuser = 0) const override; QSharedPointer getCard(unsigned int cardId) override; QList > getAllUserCards(const QByteArray &userKey, bool restOf, const QList> &childs) override; diff --git a/src/RC/CheatCard/api/apiv1-5.cpp b/src/RC/CheatCard/api/apiv1-5.cpp index 21b068b..146405d 100644 --- a/src/RC/CheatCard/api/apiv1-5.cpp +++ b/src/RC/CheatCard/api/apiv1-5.cpp @@ -214,7 +214,9 @@ bool ApiV1_5::processDeleteCardRequest(const QSharedPointergetAllActiveUserFromCard(request->card()); + auto userKey = API::User::makeKey(request->secret()); + auto userId = API::User::makeId(userKey); + auto listOfUsers = node()->getAllActiveUserFromCard(request->card(), ACTIVE_USER_TIME_LIMIT, userId); if (listOfUsers.size()) { return false; diff --git a/src/RC/CheatCard/api/iapiobjectsfactory.h b/src/RC/CheatCard/api/iapiobjectsfactory.h index 63b7c74..f75a836 100644 --- a/src/RC/CheatCard/api/iapiobjectsfactory.h +++ b/src/RC/CheatCard/api/iapiobjectsfactory.h @@ -34,9 +34,12 @@ class IAPIObjectsFactory virtual QSharedPointer getUserCardData(unsigned int userId, unsigned int cardId) const = 0; - virtual QList> getAllUserFromCard(unsigned int cardId) const = 0; - virtual QList> getAllActiveUserFromCard(unsigned int cardId, int unixTimeRange) const = 0; - virtual QList> getAllPassiveUserFromCard(unsigned int cardId, int unixTimeRange) const = 0; + virtual QList> getAllUserFromCard(unsigned int cardId, + unsigned int ignoreUserId = 0) const = 0; + virtual QList> getAllActiveUserFromCard(unsigned int cardId, int unixTimeRange, + unsigned int ignoreUserId = 0) const = 0; + virtual QList> getAllPassiveUserFromCard(unsigned int cardId, int unixTimeRange, + unsigned int ignoreUserId = 0) const = 0; virtual QList> getAllUserDataFromCard(unsigned int cardId) const = 0; virtual QList> getAllUserWithPrivateKeys() const = 0; diff --git a/src/RC/CheatCard/dataconvertor.cpp b/src/RC/CheatCard/dataconvertor.cpp index 1e2c085..cdb6246 100644 --- a/src/RC/CheatCard/dataconvertor.cpp +++ b/src/RC/CheatCard/dataconvertor.cpp @@ -18,11 +18,19 @@ DataConvertor::DataConvertor() } QSharedPointer DataConvertor::toUser(const QSharedPointer &userHeader) { + + if (!userHeader) + return nullptr; + + return toUser(*userHeader); +} + +QSharedPointer DataConvertor::toUser(const API::UserHeader &userHeader) { auto result = QSharedPointer::create(); - result->setKey(userHeader->token()); - result->setId(userHeader->getUserId()); - result->setName(userHeader->userName()); + result->setKey(userHeader.token()); + result->setId(userHeader.getUserId()); + result->setName(userHeader.userName()); result->setSecret(""); return result; diff --git a/src/RC/CheatCard/dataconvertor.h b/src/RC/CheatCard/dataconvertor.h index 283b889..80d061a 100644 --- a/src/RC/CheatCard/dataconvertor.h +++ b/src/RC/CheatCard/dataconvertor.h @@ -26,6 +26,8 @@ class CHEATCARD_CORE_EXPORT DataConvertor DataConvertor(); static QSharedPointer toUser(const QSharedPointer& userHeader); + static QSharedPointer toUser(const RC::API::UserHeader& userHeader); + static QSharedPointer toUserHeader(const QSharedPointer &user); }; diff --git a/src/RC/CheatCard/seller.cpp b/src/RC/CheatCard/seller.cpp index 2480399..ae8e61f 100644 --- a/src/RC/CheatCard/seller.cpp +++ b/src/RC/CheatCard/seller.cpp @@ -62,16 +62,16 @@ bool Seller::incrementPurchases(const QSharedPointer &usersCard } QSharedPointer -Seller::prepareData(const QSharedPointer &userHeaderData, +Seller::prepareData(const API::UserHeader &userHeaderData, unsigned int cardId) { - if (!userHeaderData->isValid()) + if (!userHeaderData.isValid()) return nullptr; auto session = QSharedPointer::create(); - session->setSessionId(userHeaderData->getSessionId()); - session->setUsercardId(API::UsersCards::genId(userHeaderData->getUserId(), cardId)); + session->setSessionId(userHeaderData.getSessionId()); + session->setUsercardId(API::UsersCards::genId(userHeaderData.getUserId(), cardId)); if (!session->isValid()) { return nullptr; @@ -83,7 +83,7 @@ Seller::prepareData(const QSharedPointer &userHeaderData, _lastRequested[session->getSessionId()] = session; API::User userrquest; - userrquest.setId(userHeaderData->getUserId()); + userrquest.setId(userHeaderData.getUserId()); auto dbUser = DataConvertor::toUser(userHeaderData); @@ -96,10 +96,10 @@ Seller::prepareData(const QSharedPointer &userHeaderData, } - auto userCardsData = getUserCardData(userHeaderData->getUserId(), cardId); + auto userCardsData = getUserCardData(userHeaderData.getUserId(), cardId); if (!userCardsData) { userCardsData = QSharedPointer::create(); - userCardsData->setUser(userHeaderData->getUserId()); + userCardsData->setUser(userHeaderData.getUserId()); userCardsData->setPurchasesNumber(0); userCardsData->setCard(cardId); } @@ -144,7 +144,7 @@ bool Seller::incrementPurchase(const QSharedPointer &userHeader } // code for old api - auto usersCardsData = prepareData(userHeaderData, cardId); + auto usersCardsData = prepareData(*userHeaderData, cardId); if (!usersCardsData) return false; @@ -162,6 +162,25 @@ bool Seller::incrementPurchase(const QSharedPointer &userHeader return sendDataPrivate(domain, port); } + +bool Seller::setPurchase(const API::UserHeader &userHeaderData, + unsigned int cardId, int purchasesCount, + const QString &domain, int port) { + + // code for old api + auto usersCardsData = prepareData(userHeaderData, cardId); + if (!usersCardsData) + return false; + + usersCardsData->setPurchasesNumber(purchasesCount); + + if (!db()->insertIfExistsUpdateObject(usersCardsData)) { + return false; + } + + return sendDataPrivate(domain, port); +} + bool Seller::sentDataToServerReceive(const QSharedPointer &userHeaderData, unsigned int cardId, int receiveCount, @@ -183,7 +202,7 @@ bool Seller::sentDataToServerReceive(const QSharedPointer &user // code for old api - auto usersCardsData = prepareData(userHeaderData, cardId); + auto usersCardsData = prepareData(*userHeaderData, cardId); if (!usersCardsData) return false; diff --git a/src/RC/CheatCard/seller.h b/src/RC/CheatCard/seller.h index 2a30cd9..f3d58e7 100644 --- a/src/RC/CheatCard/seller.h +++ b/src/RC/CheatCard/seller.h @@ -41,6 +41,10 @@ class CHEATCARD_CORE_EXPORT Seller: public BaseNode NodeType nodeType() const override; + bool setPurchase(const RC::API::UserHeader &userHeaderData, + unsigned int cardId, int purchasesCount, + const QString& domain = "", + int port = DEFAULT_CHEAT_CARD_PORT_SSL); protected: void nodeConnected(QH::AbstractNodeInfo *node) override; void nodeConfirmend(QH::AbstractNodeInfo *node) override; @@ -48,7 +52,7 @@ class CHEATCARD_CORE_EXPORT Seller: public BaseNode int purchasesCount); private: - QSharedPointer prepareData(const QSharedPointer &userHeaderData, + QSharedPointer prepareData(const RC::API::UserHeader &userHeaderData, unsigned int cardId); bool sendDataPrivate(const QString &domain, int port);