Snake/SnakeServer/ServerProtocol/serverprotocol.h

45 lines
659 B
C
Raw Normal View History

2019-01-02 14:19:39 +03:00
#ifndef SERVERPROTOCOL_H
#define SERVERPROTOCOL_H
#include "serverprotocol_global.h"
#include <QVariantMap>
2019-01-02 14:19:39 +03:00
#define DEFAULT_PORT 9200
#define DEFAULT_GAME_PORT 7777
namespace ServerProtocol {
enum Type: unsigned char {
Responke = 0,
Request = 1
};
2019-01-02 14:19:39 +03:00
enum Command: unsigned char {
undefined = 0x00,
ping = 0x01,
2019-01-02 14:19:39 +03:00
};
struct Header {
unsigned char size: 4;
unsigned char type: 1;
unsigned char command: 3;
Header();
bool isValid() const;
};
struct Package {
Header hdr;
QByteArray data;
bool isValid() const;
QVariantMap parse() const;
QByteArray toBytes() const;
};
}
2019-01-02 14:19:39 +03:00
#endif // SERVERPROTOCOL_H