]> jfr.im git - irc/quakenet/newserv.git/blame - channel/channel.h
Sigh
[irc/quakenet/newserv.git] / channel / channel.h
CommitLineData
c86edd1d
Q
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
118struct channel;
119
120typedef struct chanindex {
121 sstring *name;
122 struct channel *channel;
123 struct chanindex *next;
124 unsigned int marker;
125 void *exts[MAXCHANNELEXTS];
126} chanindex;
127
128typedef 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
137typedef struct chanuserhash {
138 unsigned short hashsize;
139 unsigned short totalusers;
140 unsigned long *content;
141} chanuserhash;
142
143typedef 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
155extern unsigned long nouser;
156extern const flag cmodeflags[];
157extern chanindex *chantable[CHANNELHASHSIZE];
158
159/* functions from channel.c */
160int addnicktochannel(channel *cp, long numeric);
161void delnickfromchannel(channel *cp, long numeric, int updateuser);
162void delchannel(channel *cp);
163channel *createchannel(char *name);
164channel *findchannel(char *name);
165void addchanneltohash(channel *cp);
166void removechannelfromhash(channel *cp);
167void addordelnick(int hooknum, void *arg);
168void onconnect(int hooknum, void *arg);
169unsigned int countuniquehosts(channel *cp);
170
171/* functions from channelhandlers.c */
172int handleburstmsg(void *source, int cargc, char **cargv);
173int handlejoinmsg(void *source, int cargc, char **cargv);
174int handlecreatemsg(void *source, int cargc, char **cargv);
175int handlepartmsg(void *source, int cargc, char **cargv);
176int handlekickmsg(void *source, int cargc, char **cargv);
177int handletopicmsg(void *source, int cargc, char **cargv);
178int handlemodemsg(void *source, int cargc, char **cargv);
179int handleclearmodemsg(void *source, int cargc, char **cargv);
f2b36aa8 180void handlewhoischannels(int hooknum, void *arg);
c86edd1d
Q
181
182/* functions from chanuserhash.c */
183void rehashchannel(channel *cp);
184int addnumerictochanuserhash(chanuserhash *cuh, long numeric);
185unsigned long *getnumerichandlefromchanhash(chanuserhash *cuh, long numeric);
186
187/* functions from channelalloc.c */
188void initchannelalloc();
189channel *newchan();
190void freechan(channel *cp);
191chanuserhash *newchanuserhash(int numbuckets);
192void freechanuserhash(chanuserhash *cuhp);
193chanban *getchanban();
194void freechanban(chanban *cbp);
195chanindex *getchanindex();
196void freechanindex(chanindex *cip);
197
198/* functions from channelbans.c */
199chanban *makeban(const char *mask);
200int banoverlap(const chanban *bana, const chanban *banb);
201int banequal(chanban *bana, chanban *banb);
202char *bantostring(chanban *bp);
203char *bantostringdebug(chanban *bp);
204void setban(channel *cp, const char *ban);
205int clearban(channel *cp, const char *ban, int optional);
206void clearallbans(channel *cp);
207int nickmatchban(nick *np, chanban *bp);
208int nickbanned(nick *np, channel *cp);
209
210/* functions from channelindex.c */
211void initchannelindex();
212chanindex *findchanindex(const char *name);
213chanindex *findorcreatechanindex(const char *name);
214void releasechanindex(chanindex *cip);
215int registerchanext(const char *name);
216int findchanext(const char *name);
217void releasechanext(int index);
218unsigned int nextchanmarker();
219
220#endif