mirror of
https://github.com/QuasarApp/Hanoi-Towers.git
synced 2025-05-13 18:09:33 +00:00
update server
This commit is contained in:
parent
4bc80e4582
commit
5d45ee287b
2
HanoiTowers/Protockol/src/onlinerating.cpp
Normal file
2
HanoiTowers/Protockol/src/onlinerating.cpp
Normal file
@ -0,0 +1,2 @@
|
||||
#include "onlinerating.h"
|
||||
|
20
HanoiTowers/Protockol/src/onlinerating.h
Normal file
20
HanoiTowers/Protockol/src/onlinerating.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef ONLINERATING_H
|
||||
#define ONLINERATING_H
|
||||
|
||||
#include <dbobject.h>
|
||||
#include "hanoitowersprotockol_global.h"
|
||||
|
||||
|
||||
class HANOITOWERSPROTOCOL_EXPORT OnlineRating: public QH::PKG::DBObject
|
||||
{
|
||||
public:
|
||||
OnlineRating();
|
||||
|
||||
// DBObject interface
|
||||
QH::PKG::DBObject *createDBObject() const override;
|
||||
|
||||
protected:
|
||||
QString primaryKey() const override;
|
||||
};
|
||||
|
||||
#endif // ONLINERATING_H
|
@ -27,10 +27,15 @@ bool UserData::copyFrom(const QH::PKG::AbstractData *other) {
|
||||
|
||||
_userData = otherObject->_userData;
|
||||
_updateTime = otherObject->_updateTime;
|
||||
_token = otherObject->_token;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const QH::AccessToken &UserData::getSignToken() const {
|
||||
return _token;
|
||||
}
|
||||
|
||||
void UserData::setName(const QString &name) {
|
||||
_userData._name = name;
|
||||
}
|
||||
@ -66,6 +71,7 @@ QDataStream &UserData::fromStream(QDataStream &stream) {
|
||||
DBObject::fromStream(stream);
|
||||
stream >> _userData;
|
||||
stream >> _updateTime;
|
||||
stream >> _token;
|
||||
|
||||
return stream;
|
||||
}
|
||||
@ -74,6 +80,7 @@ QDataStream &UserData::toStream(QDataStream &stream) const {
|
||||
DBObject::toStream(stream);
|
||||
stream << _userData;
|
||||
stream << _updateTime;
|
||||
stream << _token;
|
||||
|
||||
return stream;
|
||||
}
|
||||
@ -91,6 +98,10 @@ QString UserData::primaryKey() const {
|
||||
return "id";
|
||||
}
|
||||
|
||||
void UserData::setToken(const QH::AccessToken &token) {
|
||||
_token = token;
|
||||
}
|
||||
|
||||
int UserData::updateTime() const {
|
||||
return _updateTime;
|
||||
}
|
||||
|
@ -3,10 +3,11 @@
|
||||
#include "profiledata.h"
|
||||
|
||||
#include <dbobject.h>
|
||||
#include <itoken.h>
|
||||
|
||||
using namespace QH::PKG;
|
||||
|
||||
class HANOITOWERSPROTOCOL_EXPORT UserData: public DBObject
|
||||
class HANOITOWERSPROTOCOL_EXPORT UserData: public DBObject, public QH::IToken
|
||||
{
|
||||
public:
|
||||
UserData();
|
||||
@ -23,6 +24,8 @@ public:
|
||||
bool isValid() const override;
|
||||
bool copyFrom(const AbstractData *other) override;
|
||||
|
||||
const QH::AccessToken &getSignToken() const override;
|
||||
|
||||
void setName(const QString& name);
|
||||
QString name() const;
|
||||
|
||||
@ -32,6 +35,8 @@ public:
|
||||
int updateTime() const;
|
||||
void setUpdateTime(int updateTime);
|
||||
|
||||
void setToken(const QH::AccessToken &token);
|
||||
|
||||
protected:
|
||||
QDataStream &fromStream(QDataStream &stream) override;
|
||||
QDataStream &toStream(QDataStream &stream) const override;
|
||||
@ -40,8 +45,10 @@ protected:
|
||||
|
||||
private:
|
||||
ProfileData _userData;
|
||||
QH::AccessToken _token;
|
||||
int _updateTime;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // USERDATA_H
|
||||
|
39
HanoiTowers/Protockol/src/world.cpp
Normal file
39
HanoiTowers/Protockol/src/world.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include "world.h"
|
||||
|
||||
World::World():
|
||||
QH::PKG::DBObjectSet("UsersData") {
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool World::fromSqlRecord(const QSqlRecord &q) {
|
||||
UserPreview data;
|
||||
data.id = q.value("userID").toString();
|
||||
|
||||
data.userName = q.value("userName").toString();
|
||||
data.record = q.value("points").toInt();
|
||||
|
||||
_data.push_back(data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QH::PKG::DBObject *World::createDBObject() const {
|
||||
|
||||
}
|
||||
|
||||
void World::clear() {
|
||||
|
||||
}
|
||||
|
||||
bool World::isValid() const {
|
||||
|
||||
}
|
||||
|
||||
QH::PKG::DBVariantMap World::variantMap() const {
|
||||
|
||||
}
|
||||
|
||||
QString World::condition() const {
|
||||
|
||||
}
|
34
HanoiTowers/Protockol/src/world.h
Normal file
34
HanoiTowers/Protockol/src/world.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2021 QuasarApp.
|
||||
* Distributed under the lgplv3 software license, see the accompanying
|
||||
* Everyone is permitted to copy and distribute verbatim copies
|
||||
* of this license document, but changing it is not allowed.
|
||||
*/
|
||||
|
||||
#ifndef WORLD_H
|
||||
#define WORLD_H
|
||||
|
||||
#include "userpreview.h"
|
||||
|
||||
#include <dbobjectset.h>
|
||||
|
||||
class World: public QH::PKG::DBObjectSet
|
||||
{
|
||||
public:
|
||||
World();
|
||||
|
||||
bool fromSqlRecord(const QSqlRecord &q) override;
|
||||
QH::PKG::DBObject *createDBObject() const override;
|
||||
void clear() override;
|
||||
bool isValid() const override;
|
||||
|
||||
protected:
|
||||
QH::PKG::DBVariantMap variantMap() const override;
|
||||
QString condition() const override;
|
||||
|
||||
private:
|
||||
QList<UserPreview> _data;
|
||||
|
||||
};
|
||||
|
||||
#endif // WORLD_H
|
@ -1,5 +1,7 @@
|
||||
CREATE TABLE IF NOT EXISTS UsersData (
|
||||
id INTEGER NOT NULL UNIQUE,
|
||||
id VARCHAR(64) NOT NULL UNIQUE,
|
||||
|
||||
--General user name, it is not userID of local user. for get userId see NetworkMembers.userName of the UserDB.sql
|
||||
userName VARCHAR(64) default NULL,
|
||||
|
||||
--Profile data
|
||||
@ -9,7 +11,7 @@ CREATE TABLE IF NOT EXISTS UsersData (
|
||||
updateTime INTEGER default 0,
|
||||
userAvatar BLOB default NULL,
|
||||
|
||||
FOREIGN KEY(id) REFERENCES NetworkMembers(userName)
|
||||
FOREIGN KEY(id) REFERENCES NetworkMembers(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
);
|
||||
|
@ -435,6 +435,10 @@ void BackEnd::setOnlineStatus(QH::ClientStatus onlineStatus) {
|
||||
if (_onlineStatus == static_cast<OnlineStatus>(onlineStatus))
|
||||
return;
|
||||
|
||||
if (_profile.isOnline() && onlineStatus == QH::ClientStatus::Connected) {
|
||||
_client->login(DataConverter::toUserMember(_profile));
|
||||
}
|
||||
|
||||
_onlineStatus = static_cast<OnlineStatus>(onlineStatus);
|
||||
emit onlineStatusChanged(static_cast<int>(_onlineStatus));
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ UserData DataConverter::toUserData(const QSharedPointer<LocalUser> &input) {
|
||||
|
||||
UserData DataConverter::toUserData(const LocalUser &input) {
|
||||
UserData result;
|
||||
result.setId(input.getId());
|
||||
result.setUpdateTime(input.updateTime());
|
||||
result.setUserData(*input.userData());
|
||||
|
||||
@ -59,7 +60,7 @@ QH::PKG::UserMember DataConverter::toUserMember(const QSharedPointer<LocalUser>
|
||||
|
||||
QH::PKG::UserMember DataConverter::toUserMember(const LocalUser &input) {
|
||||
QH::PKG::UserMember result;
|
||||
result.setName(input.getId().toString());
|
||||
result.setId(input.getId());
|
||||
result.setToken(input.token());
|
||||
result.setAuthenticationData(input.hashPassword());
|
||||
|
||||
|
@ -82,7 +82,7 @@ void HanoiClient::incomingData(AbstractData *pkg, const QH::AbstractNodeInfo *se
|
||||
Q_UNUSED(sender);
|
||||
|
||||
if (pkg->cmd() == H_16<UserMember>()) {
|
||||
if (auto user = getLocalUser(static_cast<UserMember*>(pkg)->name())) {
|
||||
if (auto user = getLocalUser(static_cast<UserMember*>(pkg)->getId().toString())) {
|
||||
user->setToken(static_cast<UserMember*>(pkg)->token());
|
||||
user->setOnline(true);
|
||||
|
||||
@ -124,6 +124,7 @@ QSharedPointer<LocalUser> HanoiClient::getLocalUser(const QString &userId) const
|
||||
}
|
||||
|
||||
bool HanoiClient::sendUserData(QSharedPointer<UserData> data) {
|
||||
data->setToken(getMember().token());
|
||||
return sendData(data.data(), serverAddress());
|
||||
}
|
||||
|
||||
@ -166,9 +167,7 @@ bool HanoiClient::setNewAvatar(const QString &userId, const QByteArray &image) {
|
||||
obj->setAvatar(image);
|
||||
|
||||
if (isOnlineAndLoginned(obj)) {
|
||||
auto userData = DataConverter::toUserDataPtr(obj);
|
||||
userData->setId(getMember().getId());
|
||||
return sendUserData(userData);
|
||||
return sendUserData(DataConverter::toUserDataPtr(obj));
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -231,9 +230,7 @@ bool HanoiClient::updateProfile(const LocalUser& user) {
|
||||
}
|
||||
|
||||
if (isOnlineAndLoginned(localUser)) {
|
||||
auto userData = DataConverter::toUserDataPtr(localUser);
|
||||
userData->setId(getMember().getId());
|
||||
return sendUserData(userData);
|
||||
return sendUserData(DataConverter::toUserDataPtr(localUser));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
2
Heart
2
Heart
@ -1 +1 @@
|
||||
Subproject commit 8aa4b4bfeff92b4a6648aead6085ef7d2e22cde6
|
||||
Subproject commit 2dae30332c70d3d56acd49b74a53d76e27e0e2ca
|
Loading…
x
Reference in New Issue
Block a user