120 lines
2.7 KiB
C
Raw Normal View History

2019-02-13 13:03:40 +03:00
#ifndef CLIENT_CP_H
#define CLIENT_CP_H
#include "clientprotocol_global.h"
#include "clientprotocol.h"
#include <QObject>
class QTcpSocket;
2019-02-13 14:28:42 +03:00
class Player;
class BaseItem;
2019-03-02 00:10:43 +03:00
class testSankeServer;
2019-02-13 13:03:40 +03:00
namespace ClientProtocol {
class CLIENTPROTOCOLSHARED_EXPORT Client: public QObject
{
Q_OBJECT
private:
QTcpSocket *_destination;
Package _downloadPackage;
bool _online = false;
2019-06-13 12:53:35 +03:00
bool _logined = false;
QByteArray _token;
2019-06-13 12:53:35 +03:00
QByteArray _rsaKey;
2019-03-01 15:26:45 +03:00
int currentIndex = 0;
2019-03-02 13:29:21 +03:00
QHash<unsigned char, QVariantMap> _requestsMap;
/**
* @brief checkCommand - return old sendet command if commnad not valid return undefined command
* @param sig - sig package
* @param reqCmd - reqCmd of package
* @param type - type of package
* @return if commnad not valid return undefined command
*/
Command checkCommand(int sig, Command reqCmd, Type type);
2019-04-29 14:39:48 +03:00
bool receiveData(const QByteArray &obj, Header hdr);
2019-06-13 12:53:35 +03:00
bool setRSAKey(const QByteArray &key);
2019-06-13 12:53:35 +03:00
void setLoginStatus(bool newStatus);
void setOnlineStatus(bool newStatus);
2019-03-02 13:29:21 +03:00
bool sendPackage(Package &pkg);
2019-03-02 13:29:21 +03:00
inline unsigned char nextIndex();
2019-03-02 00:10:43 +03:00
2019-03-05 00:48:32 +03:00
bool ping();
2019-06-22 15:52:07 +03:00
QByteArray generateHash(const QByteArray &pass) const;
2019-02-13 13:03:40 +03:00
void updateStatuses(Command extCmd, Command cmd, Type type, const QByteArray &obj);
2019-02-13 13:03:40 +03:00
private slots:
void incommingData();
void handleDisconnected();
2019-02-13 13:03:40 +03:00
public:
2019-05-26 13:52:16 +03:00
explicit Client(const QString& addrress = LOCAL_SNAKE_SERVER,
unsigned short port = DEFAULT_SNAKE_PORT,
QObject * ptr = nullptr);
2019-02-13 14:28:42 +03:00
/**
* @brief login - register or login a user
* @param gmail - gmail of user
* @param pass - hash of pass of user
* @param error - error ( if all good this variable is empty)
2019-02-15 23:36:59 +03:00
* @return
2019-02-13 14:28:42 +03:00
*/
2019-02-15 23:36:59 +03:00
bool login(const QString& gmail, const QByteArray &pass);
2019-02-13 14:28:42 +03:00
2019-06-17 18:09:06 +03:00
void loginOut();
2019-02-13 14:28:42 +03:00
/**
* @brief updateData
* @return true if refresh seсcessfully completed
*/
bool updateData();
/**
* @brief savedata
* @param gameData - data of lvl
* @return true if all good
*/
2019-03-05 00:48:32 +03:00
bool savaData(const QList<int> &gameData);
2019-02-13 14:28:42 +03:00
/**
* @brief getItem
* @param id of item
* @return item data
*/
bool getItem(int id);
2019-02-13 14:28:42 +03:00
/**
* @brief isOnline
2019-06-13 12:53:35 +03:00
* @return true if client is connected to server and get rsapub key
*/
const bool &isOnline() const;
/**
* @brief isLogin
* @return true if player is online
*/
2019-06-13 12:53:35 +03:00
const bool &isLogin() const;
2019-03-02 00:10:43 +03:00
friend class ::testSankeServer;
2019-02-13 13:03:40 +03:00
signals:
2019-04-29 14:39:48 +03:00
void sigIncommingData(Command cmd, const QByteArray& obj);
void onlineChanged(bool);
2019-06-13 12:53:35 +03:00
void loginChanged(bool);
2019-02-13 13:03:40 +03:00
};
}
#endif // CLIENT_CP_H