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 {
|
2019-03-05 00:48:32 +03:00
|
|
|
Undefined = 0x00,
|
|
|
|
Responke = 0x01,
|
|
|
|
Request = 0x02,
|
|
|
|
Stream = 0x03,
|
2019-02-13 13:03:40 +03:00
|
|
|
};
|
|
|
|
|
2019-03-05 00:48:32 +03:00
|
|
|
//enum class Command: unsigned char {
|
|
|
|
// Undefined = 0x00,
|
|
|
|
// Ping = 0x01,
|
|
|
|
// Item = 0x02,
|
|
|
|
// Login = 0x03,
|
|
|
|
// PlayerData = 0x04,
|
|
|
|
// SaveData = 0x05
|
2019-02-26 20:24:05 +03:00
|
|
|
|
2019-03-05 00:48:32 +03:00
|
|
|
//};
|
2019-02-13 13:03:40 +03:00
|
|
|
|
2019-03-05 00:48:32 +03:00
|
|
|
unsigned int getSize(NetworkClasses::Type type, bool isMax = false);
|
|
|
|
bool isStaticObject(NetworkClasses::Type type, unsigned int &max, unsigned int &min);
|
|
|
|
bool isValidSize(NetworkClasses::Type type, unsigned int size);
|
2019-02-25 21:38:37 +03:00
|
|
|
|
|
|
|
|
2019-02-13 13:03:40 +03:00
|
|
|
/**
|
2019-03-05 00:48:32 +03:00
|
|
|
* @brief The Header struct 8 byte
|
2019-02-13 13:03:40 +03:00
|
|
|
*/
|
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-03-05 00:48:32 +03:00
|
|
|
unsigned int size: 32;
|
2019-02-13 13:03:40 +03:00
|
|
|
/**
|
|
|
|
* @brief type of package see Type
|
|
|
|
*/
|
2019-03-05 00:48:32 +03:00
|
|
|
unsigned char type: 8;
|
2019-02-13 13:03:40 +03:00
|
|
|
/**
|
|
|
|
* @brief command of pacage see Command
|
|
|
|
*/
|
2019-03-05 00:48:32 +03:00
|
|
|
unsigned short command: 16;
|
2019-02-13 13:03:40 +03:00
|
|
|
|
2019-02-28 18:06:13 +03:00
|
|
|
/**
|
|
|
|
* @brief sig
|
|
|
|
* signed of package (package number)
|
|
|
|
*/
|
2019-03-02 13:29:21 +03:00
|
|
|
unsigned char sig : 8;
|
2019-02-28 18:06:13 +03:00
|
|
|
|
|
|
|
|
2019-02-13 13:03:40 +03:00
|
|
|
/**
|
|
|
|
* @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-03-02 16:47:26 +03:00
|
|
|
bool parse(QVariantMap &res) const;
|
2019-02-15 23:36:59 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief create - fill package
|
|
|
|
* @param data - data of filled
|
|
|
|
* @return true if all done
|
|
|
|
*/
|
2019-03-05 00:48:32 +03:00
|
|
|
bool create(const QVariantMap &data, Type type);
|
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
|