Suppress pointless display of oplevels in ?chaninfo.
[srvx.git] / src / hash.h
1 /* hash.h - IRC network state database
2  * Copyright 2000-2006 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 HASH_H
22 #define HASH_H
23
24 #include "common.h"
25 #include "dict.h"
26 #include "policer.h"
27
28 #define MODE_CHANOP         0x0001 /* +o USER */
29 #define MODE_VOICE          0x0002 /* +v USER */
30 #define MODE_PRIVATE        0x0004 /* +p */
31 #define MODE_SECRET         0x0008 /* +s */
32 #define MODE_MODERATED      0x0010 /* +m */
33 #define MODE_TOPICLIMIT     0x0020 /* +t */
34 #define MODE_INVITEONLY     0x0040 /* +i */
35 #define MODE_NOPRIVMSGS     0x0080 /* +n */
36 #define MODE_KEY            0x0100 /* +k KEY */
37 #define MODE_BAN            0x0200 /* +b BAN */
38 #define MODE_LIMIT          0x0400 /* +l LIMIT */
39 #define MODE_DELAYJOINS     0x0800 /* +D */
40 #define MODE_REGONLY        0x1000 /* ircu +r, Bahamut +R */
41 #define MODE_NOCOLORS       0x2000 /* +c */
42 #define MODE_NOCTCPS        0x4000 /* +C */
43 #define MODE_REGISTERED     0x8000 /* Bahamut +r */
44 #define MODE_APASS          0x10000 /* +A adminpass */
45 #define MODE_UPASS          0x20000 /* +U userpass */
46 #define MODE_REMOVE         0x80000000
47
48 #define FLAGS_OPER          0x0001 /* global operator +o */
49 #define FLAGS_INVISIBLE     0x0004 /* invisible +i */
50 #define FLAGS_WALLOP        0x0008 /* receives wallops +w */
51 #define FLAGS_DEAF          0x0020 /* deaf +d */
52 #define FLAGS_SERVICE       0x0040 /* cannot be kicked, killed or deoped +k */
53 #define FLAGS_GLOBAL        0x0080 /* receives global messages +g */
54 #define FLAGS_NOCHAN        0x0100 /* hide channels in whois +n */
55 #define FLAGS_PERSISTENT    0x0200 /* for reserved nicks, this isn't just one-shot */
56 #define FLAGS_GAGGED        0x0400 /* for gagged users */
57 #define FLAGS_AWAY          0x0800 /* for away users */
58 #define FLAGS_STAMPED       0x1000 /* for users who have been stamped */
59 #define FLAGS_HIDDEN_HOST   0x2000 /* user's host is masked by their account */
60 #define FLAGS_REGNICK       0x4000 /* user owns their current nick */
61 #define FLAGS_REGISTERING   0x8000 /* user has issued account register command, is waiting for email cookie */
62 #define FLAGS_DUMMY         0x10000 /* user is not announced to other servers */
63 #define FLAGS_NOIDLE        0x20000 /* hide idle time in whois +I */
64
65 #define IsOper(x)               ((x)->modes & FLAGS_OPER)
66 #define IsService(x)            ((x)->modes & FLAGS_SERVICE)
67 #define IsDeaf(x)               ((x)->modes & FLAGS_DEAF)
68 #define IsInvisible(x)          ((x)->modes & FLAGS_INVISIBLE)
69 #define IsGlobal(x)             ((x)->modes & FLAGS_GLOBAL)
70 #define IsNoChan(x)             ((x)->modes & FLAGS_NOCHAN)
71 #define IsWallOp(x)             ((x)->modes & FLAGS_WALLOP)
72 #define IsGagged(x)             ((x)->modes & FLAGS_GAGGED)
73 #define IsPersistent(x)         ((x)->modes & FLAGS_PERSISTENT)
74 #define IsAway(x)               ((x)->modes & FLAGS_AWAY)
75 #define IsStamped(x)            ((x)->modes & FLAGS_STAMPED)
76 #define IsHiddenHost(x)         ((x)->modes & FLAGS_HIDDEN_HOST)
77 #define IsReggedNick(x)         ((x)->modes & FLAGS_REGNICK)
78 #define IsRegistering(x)        ((x)->modes & FLAGS_REGISTERING)
79 #define IsDummy(x)              ((x)->modes & FLAGS_DUMMY)
80 #define IsNoIdle(x)             ((x)->modes & FLAGS_NOIDLE)
81 #define IsFakeHost(x)           ((x)->fakehost[0] != '\0')
82 #define IsFakeIdent(x)          ((x)->fakeident[0] != '\0')
83 #define IsLocal(x)              ((x)->uplink == self)
84
85 #define NICKLEN         30
86 #define USERLEN         10
87 #define HOSTLEN         63
88 #define REALLEN         50
89 #define TOPICLEN        250
90 #define CHANNELLEN      200
91 #define MAXOPLEVEL      999
92
93 #define MAXMODEPARAMS   6
94 #define MAXBANS         45
95
96 /* IDLEN is 6 because it takes 5.33 Base64 digits to store 32 bytes. */
97 #define IDLEN           6
98
99 DECLARE_LIST(userList, struct userNode*);
100 DECLARE_LIST(modeList, struct modeNode*);
101 DECLARE_LIST(banList, struct banNode*);
102 DECLARE_LIST(channelList, struct chanNode*);
103 DECLARE_LIST(serverList, struct server*);
104
105 struct userNode {
106     char *nick;                   /* Unique name of the client, nick or host */
107     char ident[USERLEN + 1];      /* Per-host identification for user */
108     char info[REALLEN + 1];       /* Free form additional client information */
109     char hostname[HOSTLEN + 1];   /* DNS name or IP address */
110     char fakehost[HOSTLEN + 1];   /* Assigned fake host */
111     char fakeident[USERLEN + 1];  /* Assigned fake ident */
112 #ifdef WITH_PROTOCOL_P10
113     char numeric[COMBO_NUMERIC_LEN+1];
114     unsigned int num_local : 18;
115 #endif
116     unsigned int dead : 1;        /* Is user waiting to be recycled? */
117     irc_in_addr_t ip;             /* User's IP address */
118     long modes;                   /* user flags +isw etc... */
119
120     unsigned long   timestamp;    /* Time of last nick change */
121     unsigned long   idle_since;   /* Last time user did something on or to a channel */
122     struct server   *uplink;      /* Server that user is connected to */
123     struct modeList channels;     /* Vector of channels user is in */
124
125     /* from nickserv */
126     struct handle_info *handle_info;
127     struct userNode *next_authed;
128     struct policer auth_policer;
129 };
130
131 struct chanNode {
132     chan_mode_t modes;
133     unsigned int limit;
134     unsigned int locks;
135     char key[KEYLEN + 1];
136     char upass[KEYLEN + 1];
137     char apass[KEYLEN + 1];
138     unsigned long timestamp; /* creation time */
139
140     char topic[TOPICLEN + 1];
141     char topic_nick[NICKLEN + 1];
142     unsigned long topic_time;
143
144     struct modeList members;
145     struct banList banlist;
146     struct policer join_policer;
147     unsigned int join_flooded : 1;
148     unsigned int bad_channel : 1;
149
150     struct chanData *channel_info;
151     struct channel_help *channel_help;
152     char name[1];
153 };
154
155 struct banNode {
156     char ban[NICKLEN + USERLEN + HOSTLEN + 3]; /* 1 for '\0', 1 for ! and 1 for @ = 3 */
157     char who[NICKLEN + 1]; /* who set ban */
158     unsigned long set; /* time ban was set */
159 };
160
161 struct modeNode {
162     struct chanNode *channel;
163     struct userNode *user;
164     unsigned short modes;
165     short oplevel;
166     unsigned long idle_since;
167 };
168
169 #define SERVERNAMEMAX 64
170 #define SERVERDESCRIPTMAX 128
171
172 struct server {
173     char name[SERVERNAMEMAX+1];
174     unsigned long boot;
175     unsigned long link_time;
176     char description[SERVERDESCRIPTMAX+1];
177 #ifdef WITH_PROTOCOL_P10
178     char numeric[COMBO_NUMERIC_LEN+1];
179     unsigned int num_mask;
180 #endif
181     unsigned int hops, clients, max_clients;
182     unsigned int burst : 1, self_burst : 1;
183     struct server *uplink;
184 #ifdef WITH_PROTOCOL_P10
185     struct userNode **users; /* flat indexed by numeric */
186 #else
187     dict_t users; /* indexed by nick */
188 #endif
189     struct serverList children;
190 };
191
192 extern struct server *self;
193 extern dict_t channels;
194 extern dict_t clients;
195 extern dict_t servers;
196 extern unsigned int max_clients, invis_clients;
197 extern unsigned long max_clients_time;
198 extern struct userList curr_opers, curr_helpers;
199
200 struct server* GetServerH(const char *name); /* using full name */
201 struct userNode* GetUserH(const char *nick);   /* using nick */
202 struct chanNode* GetChannel(const char *name);
203 struct modeNode* GetUserMode(struct chanNode* channel, struct userNode* user);
204
205 int userList_contains(struct userList *list, struct userNode *user);
206
207 typedef void (*server_link_func_t) (struct server *server);
208 void reg_server_link_func(server_link_func_t handler);
209
210 typedef void (*new_user_func_t) (struct userNode *user);
211 void reg_new_user_func(new_user_func_t handler);
212 typedef void (*del_user_func_t) (struct userNode *user, struct userNode *killer, const char *why);
213 void reg_del_user_func(del_user_func_t handler);
214 void unreg_del_user_func(del_user_func_t handler);
215 void ReintroduceUser(struct userNode* user);
216 typedef void (*nick_change_func_t)(struct userNode *user, const char *old_nick);
217 void reg_nick_change_func(nick_change_func_t handler);
218 void NickChange(struct userNode* user, const char *new_nick, int no_announce);
219
220 typedef void (*account_func_t) (struct userNode *user, const char *stamp, unsigned long timestamp, unsigned long serial);
221 void reg_account_func(account_func_t handler);
222 void call_account_func(struct userNode *user, const char *stamp, unsigned long timestamp, unsigned long serial);
223 void StampUser(struct userNode *user, const char *stamp, unsigned long timestamp, unsigned long serial);
224 void assign_fakehost(struct userNode *user, const char *host, const char *ident, int force, int announce);
225
226 typedef void (*new_channel_func_t) (struct chanNode *chan);
227 void reg_new_channel_func(new_channel_func_t handler);
228 typedef int (*join_func_t) (struct modeNode *mNode);
229 void reg_join_func(join_func_t handler);
230 typedef void (*del_channel_func_t) (struct chanNode *chan);
231 void reg_del_channel_func(del_channel_func_t handler);
232
233 struct chanNode* AddChannel(const char *name, unsigned long time_, const char *modes, char *banlist);
234 void LockChannel(struct chanNode *channel);
235 void UnlockChannel(struct chanNode *channel);
236
237 struct modeNode* AddChannelUser(struct userNode* user, struct chanNode* channel);
238
239 int modeNode_sort(const void *pa, const void *pb);
240 typedef void (*part_func_t) (struct modeNode *mn, const char *reason);
241 void reg_part_func(part_func_t handler);
242 void unreg_part_func(part_func_t handler);
243 void DelChannelUser(struct userNode* user, struct chanNode* channel, const char *reason, int deleting);
244 void KickChannelUser(struct userNode* target, struct chanNode* channel, struct userNode *kicker, const char *why);
245
246 typedef void (*kick_func_t) (struct userNode *kicker, struct userNode *user, struct chanNode *chan);
247 void reg_kick_func(kick_func_t handler);
248 void ChannelUserKicked(struct userNode* kicker, struct userNode* victim, struct chanNode* channel);
249
250 int ChannelBanExists(struct chanNode *channel, const char *ban);
251
252 typedef int (*topic_func_t)(struct userNode *who, struct chanNode *chan, const char *old_topic);
253 void reg_topic_func(topic_func_t handler);
254 void SetChannelTopic(struct chanNode *channel, struct userNode *user, const char *topic, int announce);
255
256 void init_structs(void);
257
258 #endif