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>
|
|
|
|
|
|
|
|
#define DEFAULT_SNAKE_SERVER "127.0.0.1"
|
|
|
|
#define LOCAL_SNAKE_SERVER "127.0.0.1"
|
|
|
|
|
|
|
|
#define DEFAULT_SNAKE_PORT 7777
|
|
|
|
|
2019-02-12 13:12:11 +03:00
|
|
|
namespace ClientProtocol {
|
2019-02-14 13:58:51 +03:00
|
|
|
|
|
|
|
enum Class: unsigned char {
|
|
|
|
SnakeData = 0
|
|
|
|
};
|
|
|
|
|
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,
|
|
|
|
PlayerData = 0x04
|
2019-02-13 13:03:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The Header struct 1 byte
|
|
|
|
*/
|
|
|
|
struct Header {
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
struct Package {
|
|
|
|
/**
|
|
|
|
* @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
|