blob: 4a03e952898655efb4533d2f62aec9b0d3224231 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
//
// parser.h
// mcc@exe
//
// Created by Finn Behrens on 19.02.21.
//
#ifndef parser_h
#define parser_h
#include <stdio.h>
#include <event2/buffer.h>
#include <stdbool.h>
#include <unistd.h>
#include "protocol.h"
#include "package.h"
/**
* A struct for client specific data.
*
* @field fd of the client
*
* @field bufferevent ev-buffer to write data to
*
* @field compression_threshold when to start compressing packages
*
* @field state protocoll state of the client
*
* @field user the user associated to the client
*
* TODO: add crypto and compression parsing
*/
typedef struct {
/* The clients socket. */
int fd;
/* The bufferedevent for this client. */
struct bufferevent *buf_ev;
/* negative means no compression */
int compression_threshold;
enum mc_state state;
mc_play_user_t *user;
// TODO: encrpytion
} client_t;
int parse_packet(client_t *client, uint8_t *buffer);
static inline void mc_close_user(client_t *client) {
bufferevent_free(client->buf_ev);
close(client->fd);
if (client->user != NULL)
free(client->user);
free(client);
}
struct mc_package_op {
int (*doit) (client_t *client, mc_package_header_t *header);
int cmd;
enum mc_direction direction;
enum mc_state state;
};
#endif /* parser_h */
|