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