2019-02-12 13:12:11 +03:00
|
|
|
#ifndef CLIENTPROTOCOL_H
|
|
|
|
#define CLIENTPROTOCOL_H
|
|
|
|
|
|
|
|
#include "clientprotocol_global.h"
|
|
|
|
|
2019-02-13 13:03:40 +03:00
|
|
|
#include <QVariantMap>
|
2019-02-25 21:38:37 +03:00
|
|
|
#include <snakeutils.h>
|
|
|
|
#include "config.h"
|
2019-02-28 10:42:36 +03:00
|
|
|
#include "networkclasses.h"
|
2019-02-13 13:03:40 +03:00
|
|
|
|
2019-02-12 13:12:11 +03:00
|
|
|
namespace ClientProtocol {
|
2019-02-14 13:58:51 +03:00
|
|
|
|
2019-02-13 13:03:40 +03:00
|
|
|
enum Type: unsigned char {
|
|
|
|
Responke = 0,
|
|
|
|
Request = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Command: unsigned char {
|
2019-02-15 23:36:59 +03:00
|
|
|
Undefined = 0x00,
|
|
|
|
Ping = 0x01,
|
|
|
|
Item = 0x02,
|
|
|
|
Login = 0x03,
|
2019-02-26 20:24:05 +03:00
|
|
|
PlayerData = 0x04,
|
|
|
|
ApplyData = 0x05
|
|
|
|
|
2019-02-13 13:03:40 +03:00
|
|
|
};
|
|
|
|
|
2019-02-28 10:42:36 +03:00
|
|
|
int getSize(NetworkClasses::Type type, bool isMax = true);
|
|
|
|
bool isStaticObject(NetworkClasses::Type type, int& max, int &min);
|
|
|
|
bool isValidSize(NetworkClasses::Type type, int size);
|
2019-02-25 21:38:37 +03:00
|
|
|
|
|
|
|
|
2019-02-13 13:03:40 +03:00
|
|
|
/**
|
|
|
|
* @brief The Header struct 1 byte
|
|
|
|
*/
|
2019-02-28 10:42:36 +03:00
|
|
|
struct CLIENTPROTOCOLSHARED_EXPORT Header {
|
2019-02-13 13:03:40 +03:00
|
|
|
/**
|
|
|
|
* @brief size - size of package data (not header)
|
|
|
|
*/
|
2019-02-13 22:03:29 +03:00
|
|
|
unsigned short size: 10;
|
2019-02-13 13:03:40 +03:00
|
|
|
/**
|
|
|
|
* @brief type of package see Type
|
|
|
|
*/
|
|
|
|
unsigned char type: 1;
|
|
|
|
/**
|
|
|
|
* @brief command of pacage see Command
|
|
|
|
*/
|
|
|
|
unsigned char command: 3;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Header default constructor
|
|
|
|
*/
|
|
|
|
Header();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief isValid
|
|
|
|
* @return true if header is valid
|
|
|
|
*/
|
|
|
|
bool isValid() const;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief reset - reset all data and set for header invalid status
|
|
|
|
*/
|
|
|
|
void reset();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The Package struct
|
|
|
|
*/
|
2019-02-28 10:42:36 +03:00
|
|
|
struct CLIENTPROTOCOLSHARED_EXPORT Package {
|
2019-02-13 13:03:40 +03:00
|
|
|
/**
|
|
|
|
* @brief hdr - header of package
|
|
|
|
*/
|
|
|
|
Header hdr;
|
|
|
|
/**
|
|
|
|
* @brief data - source data of package
|
|
|
|
*/
|
|
|
|
QByteArray data;
|
|
|
|
|
|
|
|
Package();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief isValid
|
|
|
|
* @return true if package is valid
|
|
|
|
*/
|
|
|
|
bool isValid() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief parse
|
|
|
|
* @return Qmap of package (default key if "value")
|
|
|
|
*/
|
2019-02-15 23:36:59 +03:00
|
|
|
bool parse(QVariantMap &res) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief create - fill package
|
|
|
|
* @param data - data of filled
|
|
|
|
* @return true if all done
|
|
|
|
*/
|
|
|
|
bool create(const QVariantMap &data);
|
2019-02-13 13:03:40 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief toBytes
|
|
|
|
* @return bytes array of packag
|
|
|
|
*/
|
|
|
|
QByteArray toBytes() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief reset - reset all data and set for package invalid status
|
|
|
|
*/
|
|
|
|
void reset();
|
2019-02-12 13:12:11 +03:00
|
|
|
|
2019-02-13 13:03:40 +03:00
|
|
|
};
|
2019-02-15 23:36:59 +03:00
|
|
|
|
2019-02-12 13:12:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // CLIENTPROTOCOL_H
|