22fb7173c86ee88d90c5c77a4c7b19d3ccb62e9e
[srvx.git] / src / chanserv.h
1 /* chanserv.h - Channel service bot
2  * Copyright 2000-2004 srvx Development Team
3  *
4  * This file is part of srvx.
5  *
6  * srvx is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with srvx; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
19  */
20
21 #ifndef _chanserv_h
22 #define _chanserv_h
23
24 #include "nickserv.h"
25
26 enum UL_ALIASES {
27     UL_PEON = 100,
28     UL_OP = 200,
29     UL_MASTER = 300,
30     UL_PRESENT = UL_MASTER,
31     UL_COOWNER = 400,
32     UL_OWNER = 500,
33     UL_HELPER = 600,
34 };
35
36 enum levelOption {
37     lvlGiveVoice,
38     lvlGiveOps,
39     lvlEnfOps,
40     lvlEnfModes,
41     lvlEnfTopic,
42     lvlPubCmd,
43     lvlSetters,
44     lvlCTCPUsers,
45     lvlUserInfo,
46     lvlInviteMe,
47     lvlTopicSnarf,
48     lvlVote,
49     NUM_LEVEL_OPTIONS
50 };
51
52 enum charOption {
53     chProtect,
54     chToys,
55     chTopicRefresh,
56     chCTCPReaction,
57     NUM_CHAR_OPTIONS
58 };
59
60 #define CHANNEL_NODELETE    0x00000001 /* (1 << 0) */
61 #define CHANNEL_SUSPENDED   0x00000002 /* (1 << 1) */
62 #define CHANNEL_INFO_LINES  0x00000004 /* (1 << 2) - DEPRECATED */
63 #define CHANNEL_VOICE_ALL   0x00000008 /* (1 << 3) - DEPRECATED */
64 /* No longer used. */                      /* (1 << 4) */
65 #define CHANNEL_DYNAMIC_LIMIT   0x00000020 /* (1 << 5) */
66 #define CHANNEL_TOPIC_SNARF     0x00000040 /* (1 << 6) - DEPRECATED */
67 #define CHANNEL_PEON_INVITE     0x00000080 /* (1 << 7) - DEPRECATED */
68 #define CHANNEL_OFFCHANNEL      0x00000100 /* (1 << 8) */
69 #define CHANNEL_UNREVIEWED      0x00000200 /* (1 << 9) */
70 /* Flags with values over 0x20000000 or (1 << 29) will not work
71  * because chanData.flags is a 30-bit field.
72  */
73
74 #define IsProtected(x)  ((x)->flags & CHANNEL_NODELETE)
75 #define IsSuspended(x)  ((x)->flags & CHANNEL_SUSPENDED)
76 #define IsOffChannel(x) (((x)->flags & CHANNEL_OFFCHANNEL) && (off_channel > 1))
77
78 struct chanData
79 {
80     struct chanNode     *channel;
81     struct mod_chanmode modes;
82
83     unsigned long       registered;
84     unsigned long       visited;
85     unsigned long       limitAdjusted;
86     unsigned long       ownerTransfer;
87     unsigned long       expiry;
88
89     char    *topic;
90     char    *greeting;
91     char    *user_greeting;
92     char    *registrar;
93     char    *topic_mask;
94
95     char          *vote;
96     unsigned int  vote_start;
97     dict_t        vote_options;
98
99     unsigned int        flags : 30;
100     unsigned int        may_opchan : 1;
101     unsigned int        max;
102     unsigned int        max_time;
103     unsigned int        last_refresh;
104     unsigned short      banCount;
105     unsigned short      userCount;
106     unsigned short      lvlOpts[NUM_LEVEL_OPTIONS];
107     unsigned char       chOpts[NUM_CHAR_OPTIONS];
108
109     struct userData     *users;
110     struct banData      *bans;
111     struct dict         *notes;
112     struct suspended    *suspended;
113     struct chanData     *prev;
114     struct chanData     *next;
115 };
116
117 #define USER_AUTO_OP            0x00000001
118 #define USER_SUSPENDED          0x00000002
119 #define USER_AUTO_INVITE        0x00000004
120 #define USER_FLAGS_SIZE         7
121
122 #define IsUserAutoOp(USER)      (!((USER)->flags & USER_AUTO_OP))
123 #define IsUserSuspended(USER)   ((USER)->flags & USER_SUSPENDED)
124 #define IsUserAutoInvite(USER)  ((USER)->flags & USER_AUTO_INVITE)
125
126 struct userData
127 {
128     struct handle_info  *handle;
129     struct chanData     *channel;
130
131     char                *info;
132     unsigned long       seen;
133     unsigned short      access;
134     unsigned int        present : 1;
135     unsigned int        flags : USER_FLAGS_SIZE;
136
137     unsigned short      voted;
138     unsigned int        votefor;
139
140     /* linked list of userDatas for a chanData */
141     struct userData     *prev;
142     struct userData     *next;
143     /* linked list of userDatas for a handle_info */
144     struct userData     *u_prev;
145     struct userData     *u_next;
146 };
147
148 struct banData
149 {
150     char            mask[NICKLEN + USERLEN + HOSTLEN + 3];
151     char            owner[NICKLEN+1];
152     struct chanData *channel;
153
154     unsigned long   set;
155     unsigned long   triggered;
156     unsigned long   expires;
157
158     char            *reason;
159
160     struct banData  *prev;
161     struct banData  *next;
162 };
163
164 struct suspended
165 {
166     struct chanData     *cData;
167     char                *suspender;
168     char                *reason;
169     unsigned long       issued;
170     unsigned long       expires;
171     unsigned long       revoked;
172     struct suspended    *previous;
173 };
174
175 struct vote_option
176 {
177     char                *name;
178     unsigned int        option_id;
179     char                *option_str;
180     unsigned int        voted;
181 };
182
183 struct do_not_register
184 {
185     char   chan_name[CHANNELLEN+1];
186     char   setter[NICKSERV_HANDLE_LEN+1];
187     unsigned long set;
188     unsigned long expires;
189     char   reason[1];
190 };
191
192 #define GetChannelUser(channel, handle) _GetChannelUser(channel, handle, 1, 0)
193 struct userData *_GetChannelUser(struct chanData *channel, struct handle_info *handle, int override, int allow_suspended);
194 struct banData *add_channel_ban(struct chanData *channel, const char *mask, char *owner, unsigned long set, unsigned long triggered, unsigned long expires, char *reason);
195 void init_chanserv(const char *nick);
196 void del_channel_user(struct userData *user, int do_gc);
197 struct channelList *chanserv_support_channels(void);
198 unsigned short user_level_from_name(const char *name, unsigned short clamp_level);
199 struct do_not_register *chanserv_is_dnr(const char *chan_name, struct handle_info *handle);
200 int check_user_level(struct chanNode *channel, struct userNode *user, enum levelOption opt, int allow_override, int exempt_owner);
201 struct mod_chanmode *find_matching_bans(struct banList *bans, struct userNode *actee, const char *mask);
202 void handle_new_channel_created(char *chan, struct userNode *user);
203
204 #endif