-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.h
67 lines (51 loc) · 1.5 KB
/
client.h
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
#ifndef CLIENT_H
#define CLIENT_H
#include <stdbool.h>
#include <netinet/in.h>
#include <pthread.h>
#include "hook.h"
#include "list.h"
#include "packet.h"
struct packet_t;
struct player_t;
struct client_t
{
int sock;
bool writable;
bool close;
bool waiting_for_level;
bool sending_level;
bool hidden;
struct sockaddr_storage sin;
char ip[INET6_ADDRSTRLEN];
char *close_reason;
struct packet_t *packet_recv;
struct packet_t *packet_send;
struct packet_t **packet_send_end;
struct player_t *player;
pthread_mutex_t packet_send_mutex;
int packet_send_count;
int inuse;
};
static inline bool client_t_compare(struct client_t **a, struct client_t **b)
{
return (*a) == (*b);
}
LIST(client, struct client_t *, client_t_compare)
extern struct client_list_t s_clients;
extern pthread_mutex_t s_client_list_mutex;
struct client_t *client_get_by_player(struct player_t *p);
void client_add_packet(struct client_t *c, struct packet_t *p);
void client_process(struct client_t *c, char *message);
void client_send_spawn(struct client_t *c, bool hiding);
void client_send_despawn(struct client_t *c, bool hiding);
void client_spawn_players(struct client_t *c);
void client_despawn_players(struct client_t *c);
void client_notify(struct client_t *c, const char *message);
void client_notify_file(struct client_t *c, const char *filename);
static inline bool client_is_valid(struct client_t *c)
{
return client_list_contains(&s_clients, c);
}
bool client_inuse(struct client_t *c, bool inuse);
#endif /* CLIENT_H */