-
Notifications
You must be signed in to change notification settings - Fork 7
/
server.h
106 lines (85 loc) · 3.04 KB
/
server.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* soliloque-server, an open source implementation of the TeamSpeak protocol.
* Copyright (C) 2009 Hugo Camboulive <hugo.camboulive AT gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SERVER_H__
#define __SERVER_H__
#include "ban.h"
#include "channel.h"
#include "player.h"
#include "array.h"
#include "server_privileges.h"
#include <pthread.h>
#include <poll.h>
#include <semaphore.h>
#define ERROR_IF(cond) \
if(cond) { \
printf("(EE) %s", strerror(errno)); \
exit(1); \
}
#define WARNING_IF(cond) \
if(cond) { \
printf("(WW) %s", strerror(errno)); \
}
struct server {
uint32_t id;
struct array *chans;
struct array *players;
struct array *leaving_players;
struct array *bans;
struct array *regs;
struct server_stat *stats;
char password[30];
char server_name[30];
char machine[30];
char welcome_msg[256];
uint16_t version[4]/* = {2,0,20,1}*/;
int socket_desc;
int port;
int codecs;
struct server_privileges *privileges;
struct pollfd socket_poll;
pthread_t main_thread;
struct config *conf;
sem_t send_packets;
pthread_t packet_sender;
};
struct server *new_server(void);
/* Server - channel functions */
struct channel *get_channel_by_id(struct server *serv, uint32_t id);
struct channel *get_channel_by_db_id(struct server *s, uint32_t db_id);
int add_channel(struct server *serv, struct channel *chan);
int destroy_channel_by_id(struct server *serv, uint32_t id);
struct channel *get_default_channel(struct server *serv);
/* Server - player functions */
struct player *get_player_by_ids(struct server *s, uint32_t pub_id, uint32_t priv_id);
struct player *get_leaving_player_by_ids(struct server *s, uint32_t pub_id, uint32_t priv_id);
struct player *get_player_by_public_id(struct server *s, uint32_t pub_id);
int add_player(struct server *serv, struct player *pl);
void remove_player(struct server *s, struct player *p);
int move_player(struct player *p, struct channel *to);
/* Server - ban functions */
int add_ban(struct server *s, struct ban *b);
void remove_ban(struct server *s, struct ban *b);
struct ban *get_ban_by_id(struct server *s, uint16_t id);
struct ban *get_ban_by_ip(struct server *s, struct in_addr ip);
/* Server - registration functions */
struct registration *get_registration(struct server *s, char *login, char *pass);
int add_registration(struct server *s, struct registration *r);
void print_server(struct server *s);
void server_start(struct server *s);
void server_stop(struct server *s);
#endif