53 lines
1.3 KiB
C
53 lines
1.3 KiB
C
#ifndef MAZE32_PROTOCOL_H
|
|
#define MAZE32_PROTOCOL_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#include "maze32_lobby.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define MAZE32_PROTOCOL_VERSION 1U
|
|
#define MAZE32_PROTOCOL_MESSAGE_LIMIT 512U
|
|
#define MAZE32_REQUEST_ID_MAX_BYTES 32U
|
|
|
|
typedef enum {
|
|
MAZE32_MESSAGE_INVALID = 0,
|
|
MAZE32_MESSAGE_JOIN,
|
|
MAZE32_MESSAGE_RESTORE,
|
|
MAZE32_MESSAGE_START,
|
|
MAZE32_MESSAGE_HEARTBEAT,
|
|
MAZE32_MESSAGE_SUGGEST_NAME,
|
|
} maze32_message_type_t;
|
|
|
|
typedef enum {
|
|
MAZE32_PROTOCOL_OK = 0,
|
|
MAZE32_PROTOCOL_MALFORMED,
|
|
MAZE32_PROTOCOL_TOO_LARGE,
|
|
MAZE32_PROTOCOL_UNSUPPORTED_VERSION,
|
|
MAZE32_PROTOCOL_UNKNOWN_TYPE,
|
|
MAZE32_PROTOCOL_INVALID_PAYLOAD,
|
|
} maze32_protocol_result_t;
|
|
|
|
typedef struct {
|
|
maze32_message_type_t type;
|
|
uint32_t sequence;
|
|
char request_id[MAZE32_REQUEST_ID_MAX_BYTES + 1U];
|
|
maze32_role_t role;
|
|
char name[MAZE32_PLAYER_NAME_MAX_BYTES + 1U];
|
|
char token[MAZE32_SESSION_TOKEN_HEX_LENGTH + 1U];
|
|
} maze32_client_message_t;
|
|
|
|
maze32_protocol_result_t maze32_protocol_parse(const char* data, size_t length,
|
|
maze32_client_message_t* message);
|
|
const char* maze32_protocol_result_name(maze32_protocol_result_t result);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|