87 lines
1.8 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;
QByteArray _token;
2019-03-01 15:26:45 +03:00
int currentIndex = 0;
2019-03-02 13:29:21 +03:00
QHash<unsigned char, QVariantMap> _requestsMap;
2019-04-29 14:39:48 +03:00
bool receiveData(const QByteArray &obj, Header hdr);
2019-03-01 07:56:15 +03:00
void setOnline(bool newStatus);
2019-03-02 13:29:21 +03:00
bool sendPackage(Package &pkg);
inline unsigned char nextIndex();
2019-03-02 00:10:43 +03:00
2019-03-05 00:48:32 +03:00
bool ping();
2019-02-13 13:03:40 +03:00
private slots:
void incommingData();
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
/**
* @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
* @return true if player online
*/
bool isOnline() 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-02-13 13:03:40 +03:00
};
}
#endif // CLIENT_CP_H