]> jfr.im git - irc/quakenet/newserv.git/blob - channel/channel.h
Merge
[irc/quakenet/newserv.git] / channel / channel.h
1 /* channel.h */
2
3 #ifndef __CHANNEL_H
4 #define __CHANNEL_H
5
6 #include "../lib/flags.h"
7 #include "../lib/sstring.h"
8 #include "../irc/irc_config.h"
9 #include "../lib/array.h"
10 #include "../lib/sstring.h"
11 #include "../core/hooks.h"
12 #include "../core/error.h"
13 #include "../nick/nick.h"
14
15 #include <time.h>
16 #include <stdlib.h>
17
18 #define CHANMODE_NOEXTMSG 0x0001
19 #define CHANMODE_TOPICLIMIT 0x0002
20 #define CHANMODE_SECRET 0x0004
21 #define CHANMODE_PRIVATE 0x0008
22 #define CHANMODE_INVITEONLY 0x0010
23 #define CHANMODE_LIMIT 0x0020
24 #define CHANMODE_KEY 0x0040
25 #define CHANMODE_MODERATE 0x0080
26 #define CHANMODE_NOCOLOUR 0x0100
27 #define CHANMODE_NOCTCP 0x0200
28 #define CHANMODE_REGONLY 0x0400
29 #define CHANMODE_DELJOINS 0x0800
30 #define CHANMODE_NOQUITMSG 0x1000
31 #define CHANMODE_NONOTICE 0x2000
32 #define CHANMODE_MODNOAUTH 0x4000
33 #define CHANMODE_SINGLETARG 0x8000
34
35 #define CHANMODE_ALL 0xFFFF
36
37 #define CHANBAN_NICKEXACT 0x0001 /* Ban includes an exact nick (no wildcards) */
38 #define CHANBAN_NICKMASK 0x0002 /* Ban includes a nick mask with wildcards */
39 #define CHANBAN_NICKANY 0x0004 /* Ban is *!.. */
40 #define CHANBAN_NICKNULL 0x0008 /* Ban has no nick */
41 #define CHANBAN_USEREXACT 0x0010 /* Ban includes an exact user (no wildcards) */
42 #define CHANBAN_USERMASK 0x0020 /* Ban includes a user mask with wildcards */
43 #define CHANBAN_USERANY 0x0040 /* Ban is ..!*@.. */
44 #define CHANBAN_USERNULL 0x0080 /* Ban has no user */
45 #define CHANBAN_HOSTEXACT 0x0100 /* Ban includes an exact host */
46 #define CHANBAN_HOSTMASK 0x0200 /* Ban includes a host mask */
47 #define CHANBAN_HOSTANY 0x0400 /* Ban is ..@* */
48 #define CHANBAN_HOSTNULL 0x0800 /* Ban has no host */
49 #define CHANBAN_IP 0x1000 /* Ban could match against IP address */
50 #define CHANBAN_CIDR 0x2000 /* Ban includes a CIDR mask (e.g. 192.168.0.0/16 ) */
51 #define CHANBAN_INVALID 0x4000 /* Ban is nonsensical, i.e. has at least one really NULL component*/
52 #define CHANBAN_HIDDENHOST 0x8000 /* Ban could possibly match hidden host */
53
54 #define IsNoExtMsg(x) ((x)->flags & CHANMODE_NOEXTMSG)
55 #define IsTopicLimit(x) ((x)->flags & CHANMODE_TOPICLIMIT)
56 #define IsSecret(x) ((x)->flags & CHANMODE_SECRET)
57 #define IsPrivate(x) ((x)->flags & CHANMODE_PRIVATE)
58 #define IsInviteOnly(x) ((x)->flags & CHANMODE_INVITEONLY)
59 #define IsLimit(x) ((x)->flags & CHANMODE_LIMIT)
60 #define IsKey(x) ((x)->flags & CHANMODE_KEY)
61 #define IsModerated(x) ((x)->flags & CHANMODE_MODERATE)
62 #define IsNoColour(x) ((x)->flags & CHANMODE_NOCOLOUR)
63 #define IsNoCTCP(x) ((x)->flags & CHANMODE_NOCTCP)
64 #define IsRegOnly(x) ((x)->flags & CHANMODE_REGONLY)
65 #define IsDelJoins(x) ((x)->flags & CHANMODE_DELJOINS)
66 #define IsNoQuitMsg(x) ((x)->flags & CHANMODE_NOQUITMSG)
67 #define IsNoNotice(x) ((x)->flags & CHANMODE_NONOTICE)
68 #define IsModNoAuth(x) ((x)->flags & CHANMODE_MODNOAUTH)
69 #define IsSingleTarg(x) ((x)->flags & CHANMODE_SINGLETARG)
70
71 #define SetNoExtMsg(x) ((x)->flags |= CHANMODE_NOEXTMSG)
72 #define SetTopicLimit(x) ((x)->flags |= CHANMODE_TOPICLIMIT)
73 #define SetSecret(x) ((x)->flags |= CHANMODE_SECRET)
74 #define SetPrivate(x) ((x)->flags |= CHANMODE_PRIVATE)
75 #define SetInviteOnly(x) ((x)->flags |= CHANMODE_INVITEONLY)
76 #define SetLimit(x) ((x)->flags |= CHANMODE_LIMIT)
77 #define SetKey(x) ((x)->flags |= CHANMODE_KEY)
78 #define SetModerated(x) ((x)->flags |= CHANMODE_MODERATE)
79 #define SetNoColour(x) ((x)->flags |= CHANMODE_NOCOLOUR)
80 #define SetNoCTCP(x) ((x)->flags |= CHANMODE_NOCTCP)
81 #define SetRegOnly(x) ((x)->flags |= CHANMODE_REGONLY)
82 #define SetDelJoins(x) ((x)->flags |= CHANMODE_DELJOINS)
83 #define SetNoQuitMsg(x) ((x)->flags |= CHANMODE_NOQUITMSG)
84 #define SetNoNotice(x) ((x)->flags |= CHANMODE_NONOTICE)
85 #define SetModNoAuth(x) ((x)->flags |= CHANMODE_MODNOAUTH)
86 #define SetSingleTarg(x) ((x)->flags |= CHANMODE_SINGLETARG)
87
88 #define ClearNoExtMsg(x) ((x)->flags &= ~CHANMODE_NOEXTMSG)
89 #define ClearTopicLimit(x) ((x)->flags &= ~CHANMODE_TOPICLIMIT)
90 #define ClearSecret(x) ((x)->flags &= ~CHANMODE_SECRET)
91 #define ClearPrivate(x) ((x)->flags &= ~CHANMODE_PRIVATE)
92 #define ClearInviteOnly(x) ((x)->flags &= ~CHANMODE_INVITEONLY)
93 #define ClearLimit(x) ((x)->flags &= ~CHANMODE_LIMIT)
94 #define ClearKey(x) ((x)->flags &= ~CHANMODE_KEY)
95 #define ClearModerated(x) ((x)->flags &= ~CHANMODE_MODERATE)
96 #define ClearNoColour(x) ((x)->flags &= ~CHANMODE_NOCOLOUR)
97 #define ClearNoCTCP(x) ((x)->flags &= ~CHANMODE_NOCTCP)
98 #define ClearRegOnly(x) ((x)->flags &= ~CHANMODE_REGONLY)
99 #define ClearDelJoins(x) ((x)->flags &= ~CHANMODE_DELJOINS)
100 #define ClearNoQuitMsg(x) ((x)->flags &= ~CHANMODE_NOQUITMSG)
101 #define ClearNoNotice(x) ((x)->flags &= ~CHANMODE_NONOTICE)
102 #define ClearModNoAuth(x) ((x)->flags &= ~CHANMODE_MODNOAUTH)
103 #define ClearSingleTarg(x) ((x)->flags &= ~CHANMODE_SINGLETARG)
104
105 #define CUMODE_OP 0x80000000
106 #define CUMODE_VOICE 0x40000000
107
108 #define CU_NUMERICMASK 0x3FFFFFFF
109 #define CU_MODEMASK 0xC0000000
110
111 #define CU_NOUSERMASK 0x0003FFFF
112
113 /* Maximum allowed hash search depth */
114
115 #define CUHASH_DEPTH 10
116
117 #define MAGIC_REMOTE_JOIN_TS 1270080000
118
119 #define CHANNELHASHSIZE 60000
120 #define MAXCHANNELEXTS 7
121
122 #define MODECHANGE_MODES 0x00000001
123 #define MODECHANGE_USERS 0x00000002
124 #define MODECHANGE_BANS 0x00000004
125
126 struct channel;
127
128 typedef struct chanindex {
129 sstring *name;
130 struct channel *channel;
131 struct chanindex *next;
132 unsigned int marker;
133 void *exts[MAXCHANNELEXTS];
134 } chanindex;
135
136 typedef struct chanban {
137 flag_t flags;
138 sstring *nick;
139 sstring *user;
140 sstring *host;
141 time_t timeset;
142 struct chanban *next;
143 } chanban;
144
145 typedef struct chanuserhash {
146 unsigned short hashsize;
147 unsigned short totalusers;
148 unsigned long *content;
149 } chanuserhash;
150
151 typedef struct channel {
152 chanindex *index;
153 time_t timestamp;
154 sstring *topic;
155 time_t topictime;
156 flag_t flags;
157 sstring *key;
158 int limit;
159 chanban *bans;
160 chanuserhash *users;
161 } channel;
162
163 extern unsigned long nouser;
164 extern const flag cmodeflags[];
165 extern chanindex *chantable[CHANNELHASHSIZE];
166
167 /* functions from channel.c */
168 int addnicktochannel(channel *cp, long numeric);
169 void delnickfromchannel(channel *cp, long numeric, int updateuser);
170 void delchannel(channel *cp);
171 channel *createchannel(char *name);
172 channel *findchannel(char *name);
173 void addchanneltohash(channel *cp);
174 void removechannelfromhash(channel *cp);
175 void addordelnick(int hooknum, void *arg);
176 void onconnect(int hooknum, void *arg);
177 unsigned int countuniquehosts(channel *cp);
178
179 /* functions from channelhandlers.c */
180 int handleburstmsg(void *source, int cargc, char **cargv);
181 int handlejoinmsg(void *source, int cargc, char **cargv);
182 int handlecreatemsg(void *source, int cargc, char **cargv);
183 int handlepartmsg(void *source, int cargc, char **cargv);
184 int handlekickmsg(void *source, int cargc, char **cargv);
185 int handletopicmsg(void *source, int cargc, char **cargv);
186 int handlemodemsg(void *source, int cargc, char **cargv);
187 int handleclearmodemsg(void *source, int cargc, char **cargv);
188 void handlewhoischannels(int hooknum, void *arg);
189
190 /* functions from chanuserhash.c */
191 void rehashchannel(channel *cp);
192 int addnumerictochanuserhash(chanuserhash *cuh, long numeric);
193 unsigned long *getnumerichandlefromchanhash(chanuserhash *cuh, long numeric);
194
195 /* functions from channelalloc.c */
196 void initchannelalloc();
197 channel *newchan();
198 void freechan(channel *cp);
199 chanuserhash *newchanuserhash(int numbuckets);
200 void freechanuserhash(chanuserhash *cuhp);
201 chanban *getchanban();
202 void freechanban(chanban *cbp);
203 chanindex *getchanindex();
204 void freechanindex(chanindex *cip);
205
206 /* functions from channelbans.c */
207 chanban *makeban(const char *mask);
208 int banoverlap(const chanban *bana, const chanban *banb);
209 int banequal(chanban *bana, chanban *banb);
210 char *bantostring(chanban *bp);
211 char *bantostringdebug(chanban *bp);
212 void setban(channel *cp, const char *ban);
213 int clearban(channel *cp, const char *ban, int optional);
214 void clearallbans(channel *cp);
215 int nickmatchban(nick *np, chanban *bp);
216 int nickbanned(nick *np, channel *cp);
217
218 /* functions from channelindex.c */
219 void initchannelindex();
220 chanindex *findchanindex(const char *name);
221 chanindex *findorcreatechanindex(const char *name);
222 void releasechanindex(chanindex *cip);
223 int registerchanext(const char *name);
224 int findchanext(const char *name);
225 void releasechanext(int index);
226 unsigned int nextchanmarker();
227
228 #endif