mirror of
https://github.com/QuasarApp/Hanoi-Towers.git
synced 2025-05-14 02:19:33 +00:00
fix default data base
This commit is contained in:
parent
ce0493b53d
commit
6e0f5a794d
@ -1 +1 @@
|
||||
Subproject commit 40c203dc1e67574978b637538b4d1a75a2587873
|
||||
Subproject commit ccda548d948e7690e5fddc61d6efdd10f8881eb0
|
@ -1 +1 @@
|
||||
Subproject commit ce8e1688b39bff7ceb3af5d5cf73cef365dab069
|
||||
Subproject commit 3d36acb3f287e0fc7e0889ca4c34a04742681db9
|
@ -17,7 +17,6 @@
|
||||
constexpr unsigned char currentVersion = 6;
|
||||
|
||||
#define DEFAULT_USER "User"
|
||||
#define CURRENT_PROFILE_KEY "currentProfile"
|
||||
#define FIRST_RUN_KEY "isFirstStart"
|
||||
#define LVL_KEY "lvl"
|
||||
#define ANIMATION_KEY "animation"
|
||||
@ -39,9 +38,19 @@ BackEnd::BackEnd(QQmlApplicationEngine *engine):
|
||||
connect(&_client, &HanoiClient::statusChanged,
|
||||
this, &BackEnd::handleLogined);
|
||||
|
||||
_loginModel = new LoginView::LVMainModel("UserLogin");
|
||||
_loginModel = new LoginView::LVMainModel("userLogin");
|
||||
_loginModel->setComponents(LoginView::Nickname);
|
||||
_loginModel->init(engine);
|
||||
|
||||
connect(_loginModel , &LoginView::LVMainModel::sigLoginRequest,
|
||||
this, &BackEnd::handleOnlineRequest);
|
||||
|
||||
connect(_loginModel , &LoginView::LVMainModel::sigRegisterRequest,
|
||||
this, &BackEnd::handleOnlineRequest);
|
||||
|
||||
connect(&_client , &HanoiClient::requestError,
|
||||
this, &BackEnd::handleOnlineRequestError);
|
||||
|
||||
}
|
||||
|
||||
void BackEnd::reset(){
|
||||
@ -133,7 +142,8 @@ ProfileData* BackEnd::addProfile(const QString &userName, bool isOnlineuser) {
|
||||
profile = new ProfileData(userName);
|
||||
|
||||
connect(profile, &ProfileData::onlineRequest,
|
||||
this, &BackEnd::handleOnlineRequest);
|
||||
this, &BackEnd::handleOnlineRequestfromProfile);
|
||||
|
||||
|
||||
profile->setOnline(isOnlineuser);
|
||||
|
||||
@ -180,14 +190,21 @@ void BackEnd::removeLocalUserData(const QString& name) {
|
||||
|
||||
}
|
||||
|
||||
void BackEnd::handleOnlineRequest() {
|
||||
|
||||
auto _profile = dynamic_cast<ProfileData*>(sender());
|
||||
|
||||
if (!_profile)
|
||||
void BackEnd::handleOnlineRequestfromProfile(const QString &name) {
|
||||
if (name != _profile) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_client.login(_profile->name(), "")) {
|
||||
LoginView::UserData data;
|
||||
data.setNickname(name);
|
||||
_loginModel->setData(data);
|
||||
|
||||
emit showOnlinePage();
|
||||
}
|
||||
|
||||
void BackEnd::handleOnlineRequest(const LoginView::UserData & user) {
|
||||
|
||||
if (!_client.login(user.nickname(), user.rawPassword().toLatin1())) {
|
||||
QmlNotificationService::NotificationService::getService()->setNotify(
|
||||
tr("Register online error"), tr("Failed to register this account, if this account was created by you, try to restore it."), "",
|
||||
QmlNotificationService::NotificationData::Error);
|
||||
@ -195,18 +212,15 @@ void BackEnd::handleOnlineRequest() {
|
||||
|
||||
}
|
||||
|
||||
void BackEnd::handleRemoveRequest() {
|
||||
// not supported
|
||||
QmlNotificationService::NotificationService::getService()->setNotify(
|
||||
tr("Remove online error"), tr("not Supported"), "",
|
||||
QmlNotificationService::NotificationData::Warning);
|
||||
void BackEnd::handleOnlineRequestError(const QString &) {
|
||||
emit handleOnlineRequestfromProfile(_profile);
|
||||
}
|
||||
|
||||
void BackEnd::handleLogined(int state) {
|
||||
|
||||
if (state == 2) {
|
||||
auto logineduser = _client.user();
|
||||
_profileList[logineduser->mail()]->update(*logineduser.data());
|
||||
_profileList[logineduser->mail()]->update(logineduser.data());
|
||||
}
|
||||
}
|
||||
|
||||
@ -305,12 +319,7 @@ void BackEnd::removeUser(const QString &name) {
|
||||
if (!profile) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (profile->isOnline()) {
|
||||
handleRemoveRequest();
|
||||
} else {
|
||||
removeLocalUserData(name);
|
||||
}
|
||||
removeLocalUserData(name);
|
||||
|
||||
}
|
||||
|
||||
@ -328,6 +337,20 @@ void BackEnd::setProfile(QString profile) {
|
||||
return;
|
||||
|
||||
_profile = profile;
|
||||
|
||||
auto profileData = dynamic_cast<ProfileData*>(profileObject());
|
||||
|
||||
if (profileData->isOnline()) {
|
||||
_client.setUser(profileData->userData());
|
||||
if (!_client.login()) {
|
||||
QmlNotificationService::NotificationService::getService()->setNotify(
|
||||
tr("Login failed"),
|
||||
tr("Failed to login %0, if this account was created by you, try to restore it.").arg(_profile),
|
||||
"",
|
||||
QmlNotificationService::NotificationData::Warning);
|
||||
}
|
||||
}
|
||||
|
||||
emit profileChanged(_profile);
|
||||
}
|
||||
|
||||
@ -341,3 +364,15 @@ void BackEnd::setReward(int revard) {
|
||||
profile->setRecord(revard);
|
||||
}
|
||||
}
|
||||
|
||||
void BackEnd::removeOnlineProfile(QString) {
|
||||
// not supported
|
||||
|
||||
if (!_client.removeProfile()) {
|
||||
|
||||
QmlNotificationService::NotificationService::getService()->setNotify(
|
||||
tr("Remove online error"), tr("current profile not online!"), "",
|
||||
QmlNotificationService::NotificationData::Warning);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
namespace LoginView {
|
||||
class LVMainModel;
|
||||
class UserData;
|
||||
}
|
||||
class QQmlApplicationEngine;
|
||||
|
||||
@ -55,8 +56,10 @@ private:
|
||||
HanoiClient _client;
|
||||
|
||||
private slots:
|
||||
void handleOnlineRequest();
|
||||
void handleRemoveRequest();
|
||||
void handleOnlineRequestfromProfile(const QString&);
|
||||
void handleOnlineRequest(const LoginView::UserData&);
|
||||
void handleOnlineRequestError(const QString&Errr);
|
||||
|
||||
void handleLogined(int);
|
||||
|
||||
public:
|
||||
@ -153,6 +156,8 @@ public slots:
|
||||
|
||||
void setReward(int);
|
||||
|
||||
void removeOnlineProfile(QString profile);
|
||||
|
||||
signals:
|
||||
void firstChanged();
|
||||
void animationChanged();
|
||||
@ -161,6 +166,8 @@ signals:
|
||||
void profileChanged(QString profile);
|
||||
|
||||
void usersListModelChanged(QObject* usersListModel);
|
||||
void showOnlinePage();
|
||||
|
||||
};
|
||||
|
||||
#endif // SAVER_H
|
||||
|
@ -6,8 +6,21 @@
|
||||
*/
|
||||
|
||||
#include "hanoiclient.h"
|
||||
#include <qmlnotifyservice.h>
|
||||
#include <userdatarequest.h>
|
||||
|
||||
HanoiClient::HanoiClient():
|
||||
NP::Client(REMOTE_HOST, REMOTE_PORT) {
|
||||
connectClient();
|
||||
|
||||
connect(this, &HanoiClient::requestError,
|
||||
this, &HanoiClient::handleError);
|
||||
}
|
||||
|
||||
void HanoiClient::handleError(const QString &error) {
|
||||
QmlNotificationService::NotificationService::getService()->setNotify(
|
||||
tr("Jnline error"), error, "",
|
||||
QmlNotificationService::NotificationData::Error);
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,6 +20,9 @@ class HanoiClient: public NP::Client
|
||||
{
|
||||
public:
|
||||
HanoiClient();
|
||||
|
||||
private slots:
|
||||
void handleError(const QString& error);
|
||||
};
|
||||
|
||||
#endif // HANOICLIENT_H
|
||||
|
@ -11,6 +11,7 @@ import QtQuick.Layouts 1.3
|
||||
import QtQuick.Controls 2.13
|
||||
import QtQuick.Controls.Material 2.13
|
||||
import "./../base" as Base
|
||||
import LoginViewModule 1.0
|
||||
|
||||
Item {
|
||||
id:menuPage
|
||||
@ -78,4 +79,19 @@ Item {
|
||||
|
||||
}
|
||||
|
||||
LoginViewDialog {
|
||||
|
||||
id: loginPopUp
|
||||
lognViewModel: userLogin // exampleLogin - this is inited model in main.cpp
|
||||
|
||||
Connections {
|
||||
target: backEnd;
|
||||
onShowOnlinePage :{
|
||||
loginPopUp.open();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,12 +8,10 @@
|
||||
#include "profiledata.h"
|
||||
|
||||
void ProfileData::setOnline(bool onlineProfile) {
|
||||
if (onlineProfile != isOnline()) {
|
||||
if (onlineProfile) {
|
||||
emit onlineRequest();
|
||||
} else {
|
||||
emit onlineChanged(onlineProfile);
|
||||
}
|
||||
if (onlineProfile) {
|
||||
emit onlineRequest(name());
|
||||
} else {
|
||||
emit onlineChanged(onlineProfile);
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,11 +23,13 @@ void ProfileData::setRecord(int rec) {
|
||||
emit recordChanged(rec);
|
||||
}
|
||||
|
||||
void ProfileData::handleServerResponce(const NP::UserData& data) {
|
||||
if (_userData.token() != data.token()) {
|
||||
_userData = data;
|
||||
emit onlineChanged(isOnline());
|
||||
}
|
||||
const NP::UserData *ProfileData::userData() const {
|
||||
return &_userData;
|
||||
}
|
||||
|
||||
void ProfileData::handleServerResponce(const NP::UserData &data) {
|
||||
_userData = data;
|
||||
emit onlineChanged(isOnline());
|
||||
}
|
||||
|
||||
ProfileData::ProfileData(const QString &name):
|
||||
@ -52,11 +52,11 @@ int ProfileData::record() const {
|
||||
}
|
||||
|
||||
bool ProfileData::isOnline() const {
|
||||
return _userData.token().isValid();
|
||||
return _userData.token().toBytes().size();
|
||||
}
|
||||
|
||||
void ProfileData::update(const NP::UserData &newData) {
|
||||
_userData.copyFrom(&newData);
|
||||
void ProfileData::update(const NP::UserData *newData) {
|
||||
_userData.copyFrom(newData);
|
||||
}
|
||||
|
||||
QDataStream &ProfileData::fromStream(QDataStream &stream) {
|
||||
|
@ -8,8 +8,7 @@
|
||||
#ifndef PROFILEDATA_H
|
||||
#define PROFILEDATA_H
|
||||
#include "gamestate.h"
|
||||
|
||||
#include <userdata.h>
|
||||
#include "userdata.h"
|
||||
|
||||
class ProfileData : public QObject, public NP::StreamBase
|
||||
{
|
||||
@ -37,12 +36,14 @@ public:
|
||||
Q_INVOKABLE int record() const;
|
||||
Q_INVOKABLE bool isOnline() const;
|
||||
|
||||
void update(const NP::UserData& newData);
|
||||
void update(const NP::UserData *newData);
|
||||
|
||||
// StreamBase interface
|
||||
QDataStream &fromStream(QDataStream &stream) override;
|
||||
QDataStream &toStream(QDataStream &stream) const override;
|
||||
|
||||
const NP::UserData *userData() const;
|
||||
|
||||
public slots:
|
||||
void setOnline(bool onlineUser);
|
||||
void setRecord(int record);
|
||||
@ -50,7 +51,7 @@ public slots:
|
||||
signals:
|
||||
void gameStateChanged(QObject* gameState);
|
||||
void onlineChanged(bool onlineUser);
|
||||
void onlineRequest();
|
||||
void onlineRequest(const QString& name);
|
||||
void recordChanged(int record);
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user