29cd337697c6e5347640b0c2d6d17cd63ce288d9
[NeonServV5.git] / src / tools.h
1 /* tools.h - NeonServ v5.3
2  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
3  * 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License 
15  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
16  */
17 #ifndef _tools_h
18 #define _tools_h
19
20 #include "main.h"
21
22 #define TABLE_FLAG_USE_POINTER  0x01
23 #define TABLE_FLAG_COL_BOLD     0x02
24 #define TABLE_FLAG_COL_CONTENTS 0x04
25
26 struct ClientSocket;
27 struct UserNode;
28 struct ChanNode;
29
30 struct Table {
31     char ***contents;
32     int length;
33     int width;
34     int flags;
35     int *col_flags;
36     
37     int entrys;
38     int *maxwidth;
39     
40     char **table_lines; //we just store this to free it in table_free
41 };
42
43 struct ModeBuffer {
44     struct ClientSocket *client;
45     struct ChanNode *chan;
46     char addModes[MAXMODES];
47     char delModes[MAXMODES];
48     char *addModesParams[MAXMODES];
49     char *delModesParams[MAXMODES];
50     int addCount;
51     int delCount;
52 };
53
54 int match(const char *mask, const char *name);
55
56 struct Table *table_init(int width, int length, int flags);
57 int table_add(struct Table *table, char **entry);
58 int table_change(struct Table *table, int row, char **entry);
59 int table_change_field(struct Table *table, int row, int col, char *entry);
60 int table_set_bold(struct Table *table, int collum, int bold);
61 char **table_end(struct Table *table);
62 void table_free(struct Table *table);
63
64 char* timeToStr(struct UserNode *user, int seconds, int items, char *buf);
65 int strToTime(struct UserNode *user, char *str);
66
67 struct ModeBuffer* initModeBuffer(struct ClientSocket *client, struct ChanNode *chan);
68 #define modeBufferSimpleMode(MODEBUF,ADD,MODE) modeBufferSet(MODEBUF, ADD, MODE, NULL) 
69 #define modeBufferOp(MODEBUF,USER) modeBufferSet(MODEBUF, 1, 'o', USER)
70 #define modeBufferDeop(MODEBUF,USER) modeBufferSet(MODEBUF, 0, 'o', USER) 
71 #define modeBufferVoice(MODEBUF,USER) modeBufferSet(MODEBUF, 1, 'v', USER)
72 #define modeBufferDevoice(MODEBUF,USER) modeBufferSet(MODEBUF, 0, 'v', USER) 
73 #define modeBufferBan(MODEBUF,MASK) modeBufferSet(MODEBUF, 1, 'b', MASK) 
74 #define modeBufferUnban(MODEBUF,MASK) modeBufferSet(MODEBUF, 0, 'b', MASK) 
75 void modeBufferSet(struct ModeBuffer *modeBuf, int add, char mode, char *param);
76 void flushModeBuffer(struct ModeBuffer *modeBuf);
77 void freeModeBuffer(struct ModeBuffer *modeBuf);
78
79 int is_ircmask(const char *text);
80
81 char* generate_banmask(struct UserNode *user, char *buffer); 
82 char* make_banmask(char *input, char* buffer);
83 int isFakeHost(char *host);
84
85 int mask_match(char *mask, struct UserNode *user);
86
87 unsigned long crc32(const char *text);
88
89 void init_tools();
90
91 #endif