]> jfr.im git - irc/evilnet/x3.git/blob - src/hash.h
Fix for <trigger>shoot telling you to use .roulette instead of <trigger>roulette
[irc/evilnet/x3.git] / src / hash.h
1 /* hash.h - IRC network state database
2 * Copyright 2000-2004 srvx Development Team
3 *
4 * This file is part of x3.
5 *
6 * x3 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 3 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 0x00000001 /* +o USER */
29 #define MODE_VOICE 0x00000002 /* +v USER */
30 #define MODE_PRIVATE 0x00000004 /* +p */
31 #define MODE_SECRET 0x00000008 /* +s */
32 #define MODE_MODERATED 0x00000010 /* +m */
33 #define MODE_TOPICLIMIT 0x00000020 /* +t */
34 #define MODE_INVITEONLY 0x00000040 /* +i */
35 #define MODE_NOPRIVMSGS 0x00000080 /* +n */
36 #define MODE_KEY 0x00000100 /* +k KEY */
37 #define MODE_BAN 0x00000200 /* +b BAN */
38 #define MODE_LIMIT 0x00000400 /* +l LIMIT */
39 #define MODE_DELAYJOINS 0x00000800 /* +D */
40 #define MODE_REGONLY 0x00001000 /* ircu +r */
41 #define MODE_NOCOLORS 0x00002000 /* +c */
42 #define MODE_NOCTCPS 0x00004000 /* +C */
43 #define MODE_REGISTERED 0x00008000 /* Bahamut +r */
44 #define MODE_STRIPCOLOR 0x00010000 /* +S Strip mirc color codes */
45 #define MODE_MODUNREG 0x00020000 /* +M mod unregister */
46 #define MODE_NONOTICE 0x00040000 /* +N no notices */
47 #define MODE_OPERSONLY 0x00080000 /* +O Opers only */
48 #define MODE_NOQUITMSGS 0x00100000 /* +Q suppress messages from quit notices */
49 #define MODE_NOAMSG 0x00200000 /* +T no multi-target messages */
50 #define MODE_SSLONLY 0x00400000 /* +Z ssl only */
51 #define MODE_HALFOP 0x00800000 /* +h USER */
52 #define MODE_EXEMPT 0x01000000 /* +e exempt */
53 #define MODE_HIDEMODE 0x02000000 /* +L hide modes */
54 #define MODE_APASS 0x04000000 /* +A adminpass */
55 #define MODE_UPASS 0x08000000 /* +U userpass */
56 #define MODE_REMOVE 0x80000000
57
58 #define FLAGS_OPER 0x000001 /* Operator +O */
59 #define FLAGS_LOCOP 0x000002 /* Local operator +o */
60 #define FLAGS_INVISIBLE 0x000004 /* invisible +i */
61 #define FLAGS_WALLOP 0x000008 /* receives wallops +w */
62 #define FLAGS_SERVNOTICE 0x000010 /* receives server notices +s */
63 #define FLAGS_DEAF 0x000020 /* deaf +d */
64 #define FLAGS_SERVICE 0x000040 /* cannot be kicked, killed or deoped +k */
65 #define FLAGS_GLOBAL 0x000080 /* receives global messages +g */
66 #define FLAGS_SETHOST 0x000100 /* sethost +h */
67 #define FLAGS_PERSISTENT 0x000200 /* for reserved nicks, this isn't just one-shot */
68 #define FLAGS_GAGGED 0x000400 /* for gagged users */
69 #define FLAGS_AWAY 0x000800 /* for away users */
70 #define FLAGS_STAMPED 0x001000 /* for users who have been stamped */
71 #define FLAGS_HIDDEN_HOST 0x002000 /* user's host is masked by their account */
72 #define FLAGS_REGNICK 0x004000 /* user owns their current nick */
73 #define FLAGS_REGISTERING 0x008000 /* user has issued account register command, is waiting for email cookie */
74 #define FLAGS_BOT 0x010000 /* Bot +B */
75 #define FLAGS_HIDECHANS 0x020000 /* Hidden channels +n */
76 #define FLAGS_HIDEIDLE 0x040000 /* Hidden idle time +I */
77 #define FLAGS_XTRAOP 0x080000 /* Hidden idle time */
78 #define FLAGS_CLOAKHOST 0x100000 /* user has cloaked host */
79 #define FLAGS_CLOAKIP 0x200000 /* user has cloaked ip */
80
81 #define IsOper(x) ((x)->modes & FLAGS_OPER)
82 #define IsService(x) ((x)->modes & FLAGS_SERVICE)
83 #define IsDeaf(x) ((x)->modes & FLAGS_DEAF)
84 #define IsInvisible(x) ((x)->modes & FLAGS_INVISIBLE)
85 #define IsGlobal(x) ((x)->modes & FLAGS_GLOBAL)
86 #define IsWallOp(x) ((x)->modes & FLAGS_WALLOP)
87 #define IsServNotice(x) ((x)->modes & FLAGS_SERVNOTICE)
88 #define IsBotM(x) ((x)->modes & FLAGS_BOT)
89 #define IsHideChans(x) ((x)->modes & FLAGS_HIDECHANS)
90 #define IsHideIdle(x) ((x)->modes & FLAGS_HIDEIDLE)
91 #define IsXtraOp(x) ((x)->modes & FLAGS_XTRAOP)
92 #define IsSetHost(x) ((x)->modes & FLAGS_SETHOST)
93 #define IsGagged(x) ((x)->modes & FLAGS_GAGGED)
94 #define IsPersistent(x) ((x)->modes & FLAGS_PERSISTENT)
95 #define IsAway(x) ((x)->modes & FLAGS_AWAY)
96 #define IsStamped(x) ((x)->modes & FLAGS_STAMPED)
97 #define IsHiddenHost(x) ((x)->modes & FLAGS_HIDDEN_HOST)
98 #define IsReggedNick(x) ((x)->modes & FLAGS_REGNICK)
99 #define IsRegistering(x) ((x)->modes & FLAGS_REGISTERING)
100 #define IsFakeHost(x) ((x)->fakehost[0] != '\0')
101 #define IsLocal(x) ((x)->uplink == self)
102
103 #define NICKLEN 30
104 #define USERLEN 10
105 #define HOSTLEN 63
106 #define SOCKIPLEN 45
107 #define ACCOUNTLEN 15
108 #define REALLEN 50
109 #define TOPICLEN 250
110 #define CHANNELLEN 200
111 #define MARKLEN 200
112 #define MAXOPLEVEL 999
113
114 #define MAXMODEPARAMS 6
115 #define MAXBANS 128
116 #define MAXEXEMPTS 45
117
118 /* IDLEN is 6 because it takes 5.33 Base64 digits to store 32 bytes. */
119 #define IDLEN 6
120
121 /** Operator privileges. */
122 enum Priv {
123 PRIV_CHAN_LIMIT, /**< no channel limit on oper */
124 PRIV_MODE_LCHAN, /**< oper can mode local chans */
125 PRIV_WALK_LCHAN, /**< oper can walk through local modes */
126 PRIV_DEOP_LCHAN, /**< no deop oper on local chans */
127 PRIV_SHOW_INVIS, /**< show local invisible users */
128 PRIV_SHOW_ALL_INVIS, /**< show all invisible users */
129 PRIV_UNLIMIT_QUERY, /**< unlimit who queries */
130 PRIV_KILL, /**< oper can KILL */
131 PRIV_LOCAL_KILL, /**< oper can local KILL */
132 PRIV_REHASH, /**< oper can REHASH */
133 PRIV_REMOTEREHASH, /**< oper can remote REHASH */
134 PRIV_RESTART, /**< oper can RESTART */
135 PRIV_DIE, /**< oper can DIE */
136 PRIV_ZLINE, /**< oper can ZLINE */
137 PRIV_LOCAL_ZLINE, /**< oper can local ZLINE */
138 PRIV_GLINE, /**< oper can GLINE */
139 PRIV_LOCAL_GLINE, /**< oper can local GLINE */
140 PRIV_SHUN, /**< oper can SHUN */
141 PRIV_LOCAL_SHUN, /**< oper can local SHUN */
142 PRIV_JUPE, /**< oper can JUPE */
143 PRIV_LOCAL_JUPE, /**< oper can local JUPE */
144 PRIV_OPMODE, /**< oper can OP/CLEARMODE */
145 PRIV_LOCAL_OPMODE, /**< oper can local OP/CLEARMODE */
146 PRIV_SET, /**< oper can SET */
147 PRIV_WHOX, /**< oper can use /who x */
148 PRIV_BADCHAN, /**< oper can BADCHAN */
149 PRIV_LOCAL_BADCHAN, /**< oper can local BADCHAN */
150 PRIV_SEE_CHAN, /**< oper can see in secret chans */
151 PRIV_PROPAGATE, /**< propagate oper status */
152 PRIV_DISPLAY, /**< "Is an oper" displayed */
153 PRIV_SEE_OPERS, /**< display hidden opers */
154 PRIV_WIDE_GLINE, /**< oper can set wider G-lines */
155 PRIV_WIDE_ZLINE, /**< oper can set wider Z-Lines */
156 PRIV_WIDE_SHUN, /**< oper can set wider G-lines */
157 PRIV_LIST_CHAN, /**< oper can list secret channels */
158 PRIV_FORCE_OPMODE, /**< can hack modes on quarantined channels */
159 PRIV_FORCE_LOCAL_OPMODE, /**< can hack modes on quarantined local channels */
160 PRIV_CHECK, /**< oper can use CHECK */
161 PRIV_SEE_SECRET_CHAN, /**< oper can see +s channels in whois */
162 PRIV_WHOIS_NOTICE, /**< oper can set/unset user mode +W */
163 PRIV_HIDE_IDLE, /**< oper can set/unset user mode +I */
164 PRIV_XTRAOP, /**< oper can set/unset user mode +X */
165 PRIV_HIDE_CHANNELS, /**< oper can set/unset user mode +n */
166 PRIV_LAST_PRIV /**< number of privileges */
167 };
168
169 /** Number of bits */
170 #define _PRIV_NBITS (8 * sizeof(unsigned long))
171 /** Element number for priv \a priv. */
172 #define _PRIV_IDX(priv) ((priv) / _PRIV_NBITS)
173 /** Element bit for priv \a priv. */
174 #define _PRIV_BIT(priv) (1UL << ((priv) % _PRIV_NBITS))
175
176 /** Operator privileges. */
177 struct Privs {
178 unsigned long priv_mask[(PRIV_LAST_PRIV + _PRIV_NBITS - 1) / _PRIV_NBITS];
179 };
180
181 DECLARE_LIST(userList, struct userNode*);
182 DECLARE_LIST(modeList, struct modeNode*);
183 DECLARE_LIST(banList, struct banNode*);
184 DECLARE_LIST(exemptList, struct exemptNode*);
185 DECLARE_LIST(channelList, struct chanNode*);
186 DECLARE_LIST(serverList, struct server*);
187
188 struct userNode {
189 char *nick; /* Unique name of the client, nick or host */
190 char ident[USERLEN + 1]; /* Per-host identification for user */
191 char info[REALLEN + 1]; /* Free form additional client information */
192 char hostname[HOSTLEN + 1]; /* DNS name or IP address */
193 char fakehost[HOSTLEN + 1]; /* Assigned fake host */
194 char crypthost[HOSTLEN + 30]; /* Crypted hostname */
195 char cryptip[SOCKIPLEN + 30]; /* Crypted IP */
196 #ifdef WITH_PROTOCOL_P10
197 char numeric[COMBO_NUMERIC_LEN+1];
198 unsigned int num_local : 18;
199 #endif
200 unsigned int loc; /* Is user connecting via LOC? */
201 unsigned int no_notice; /* Does the users client not see notices? */
202 unsigned int dead : 1; /* Is user waiting to be recycled? */
203 irc_in_addr_t ip; /* User's IP address */
204 long modes; /* user flags +isw etc... */
205
206 // sethost - reed/apples
207 char sethost[USERLEN + HOSTLEN + 2]; /* 1 for '\0' and 1 for @ = 2 */
208
209 /* GeoIP Data */
210 char *country_name;
211
212 /* GeoIP City Data */
213 char *country_code;
214 char *city;
215 char *region;
216 char *postal_code;
217 float latitude;
218 float longitude;
219 int dma_code;
220 int area_code;
221
222 char *mark; /* only filled if they are marked */
223 char *version_reply; /* only filled in if a version query was triggered */
224
225 time_t timestamp; /* Time of last nick change */
226 struct server *uplink; /* Server that user is connected to */
227 struct modeList channels; /* Vector of channels user is in */
228 struct Privs privs;
229
230 /* from nickserv */
231 struct handle_info *handle_info;
232 struct userNode *next_authed;
233 struct policer auth_policer;
234 };
235
236 #define privs(cli) ((cli)->privs)
237 #define PrivSet(pset, priv) ((pset)->priv_mask[_PRIV_IDX(priv)] |= \
238 _PRIV_BIT(priv))
239 #define PrivClr(pset, priv) ((pset)->priv_mask[_PRIV_IDX(priv)] &= \
240 ~(_PRIV_BIT(priv)))
241 #define PrivHas(pset, priv) ((pset)->priv_mask[_PRIV_IDX(priv)] & \
242 _PRIV_BIT(priv))
243
244 #define PRIV_ADD 1
245 #define PRIV_DEL 0
246
247 #define GrantPriv(cli, priv) (PrivSet(&(privs(cli)), priv))
248 #define RevokePriv(cli, priv) (PrivClr(&(privs(cli)), priv))
249 #define HasPriv(cli, priv) (PrivHas(&(privs(cli)), priv))
250
251 struct chanNode {
252 chan_mode_t modes;
253 unsigned int limit, locks;
254 char key[KEYLEN + 1];
255 char upass[KEYLEN + 1];
256 char apass[KEYLEN + 1];
257 time_t timestamp; /* creation time */
258
259 char topic[TOPICLEN + 1];
260 char topic_nick[NICKLEN + 1];
261 time_t topic_time;
262
263 struct modeList members;
264 struct banList banlist;
265 struct exemptList exemptlist;
266 struct policer join_policer;
267 unsigned int join_flooded : 1;
268 unsigned int bad_channel : 1;
269
270 struct chanData *channel_info;
271 struct channel_help *channel_help;
272 char name[1];
273 };
274
275 struct banNode {
276 char ban[NICKLEN + USERLEN + HOSTLEN + 3]; /* 1 for '\0', 1 for ! and 1 for @ = 3 */
277 char who[NICKLEN + 1]; /* who set ban */
278 time_t set; /* time ban was set */
279 };
280
281 struct exemptNode {
282 char exempt[NICKLEN + USERLEN + HOSTLEN + 3]; /* 1 for '\0', 1 for ! and 1 for @ = 3 */
283 char who[NICKLEN + 1]; /* who set exempt */
284 time_t set; /* time exempt was set */
285 };
286
287 struct modeNode {
288 struct chanNode *channel;
289 struct userNode *user;
290 long modes;
291 short oplevel;
292 time_t idle_since;
293 };
294
295 #define SERVERNAMEMAX 64
296 #define SERVERDESCRIPTMAX 128
297
298 struct server {
299 char name[SERVERNAMEMAX+1];
300 time_t boot;
301 time_t link;
302 char description[SERVERDESCRIPTMAX+1];
303 #ifdef WITH_PROTOCOL_P10
304 char numeric[COMBO_NUMERIC_LEN+1];
305 unsigned int num_mask;
306 #endif
307 unsigned int hops, clients, max_clients;
308 unsigned int burst : 1, self_burst : 1;
309 struct server *uplink;
310 #ifdef WITH_PROTOCOL_P10
311 struct userNode **users; /* flat indexed by numeric */
312 #else
313 dict_t users; /* indexed by nick */
314 #endif
315 struct serverList children;
316 };
317
318 struct waitingConnection {
319 char *server;
320 char *target;
321 };
322
323 struct routingPlan {
324 dict_t servers;
325 };
326
327 struct routingPlanServer {
328 char *uplink;
329 char *secondaryuplink;
330 unsigned int port;
331 int karma;
332 int offline;
333 };
334
335 /* Ported from X2 */
336 struct routeList {
337 char* server; /* Name of the server */
338 unsigned int port; /* connection port */
339 char *uplink; /* Server its linked to (towards us) */
340 char *secondaryuplink;
341 int outsideness; /* 0 means leaf, 1 second layer, etc. my uplink is highest */
342 struct routeList *next;
343 };
344
345 /* Ported from X2 */
346 struct route {
347 int count; /* how many servers we have */
348 int maxdepth; /* biggest outsideness value */
349 int centered; /* set to TRUE when changerouteUplinks is run */
350 struct routeList *servers;
351 };
352
353
354 extern struct server *self;
355 extern dict_t channels;
356 extern dict_t clients;
357 extern dict_t servers;
358 extern unsigned int max_clients, invis_clients;
359 extern time_t max_clients_time;
360 extern struct userList curr_opers, curr_helpers;
361
362 struct server* GetServerH(const char *name); /* using full name */
363 struct userNode* GetUserH(const char *nick); /* using nick */
364 struct chanNode* GetChannel(const char *name);
365 struct modeNode* GetUserMode(struct chanNode* channel, struct userNode* user);
366
367 typedef void (*server_link_func_t) (struct server *server);
368 void reg_server_link_func(server_link_func_t handler);
369
370 typedef int (*new_user_func_t) (struct userNode *user);
371 void reg_new_user_func(new_user_func_t handler);
372 typedef void (*del_user_func_t) (struct userNode *user, struct userNode *killer, const char *why);
373 void reg_del_user_func(del_user_func_t handler);
374 void unreg_del_user_func(del_user_func_t handler);
375 void ReintroduceUser(struct userNode* user);
376 typedef void (*nick_change_func_t)(struct userNode *user, const char *old_nick);
377 void reg_nick_change_func(nick_change_func_t handler);
378 void NickChange(struct userNode* user, const char *new_nick, int no_announce);
379 void SVSNickChange(struct userNode* user, const char *new_nick);
380
381 typedef void (*account_func_t) (struct userNode *user, const char *stamp);
382 void reg_account_func(account_func_t handler);
383 void call_account_func(struct userNode *user, const char *stamp);
384 void StampUser(struct userNode *user, const char *stamp, time_t timestamp);
385 void assign_fakehost(struct userNode *user, const char *host, int announce);
386 void set_geoip_info(struct userNode *user);
387
388 typedef void (*new_channel_func_t) (struct chanNode *chan);
389 void reg_new_channel_func(new_channel_func_t handler);
390 typedef int (*join_func_t) (struct modeNode *mNode);
391 void reg_join_func(join_func_t handler);
392 typedef void (*del_channel_func_t) (struct chanNode *chan);
393 void reg_del_channel_func(del_channel_func_t handler);
394
395 struct chanNode* AddChannel(const char *name, time_t time_, const char *modes, char *banlist, char *exemptlist);
396 void LockChannel(struct chanNode *channel);
397 void UnlockChannel(struct chanNode *channel);
398
399 struct modeNode* AddChannelUser(struct userNode* user, struct chanNode* channel);
400
401 typedef void (*part_func_t) (struct modeNode *mn, const char *reason);
402 void reg_part_func(part_func_t handler);
403 void unreg_part_func(part_func_t handler);
404 void DelChannelUser(struct userNode* user, struct chanNode* channel, const char *reason, int deleting);
405 void KickChannelUser(struct userNode* target, struct chanNode* channel, struct userNode *kicker, const char *why);
406
407 typedef void (*kick_func_t) (struct userNode *kicker, struct userNode *user, struct chanNode *chan);
408 void reg_kick_func(kick_func_t handler);
409 void ChannelUserKicked(struct userNode* kicker, struct userNode* victim, struct chanNode* channel);
410
411 int ChannelBanExists(struct chanNode *channel, const char *ban);
412 int ChannelExemptExists(struct chanNode *channel, const char *exempt);
413
414 typedef int (*topic_func_t)(struct userNode *who, struct chanNode *chan, const char *old_topic);
415 void reg_topic_func(topic_func_t handler);
416 void SetChannelTopic(struct chanNode *channel, struct userNode *service, struct userNode *user, const char *topic, int announce);
417 struct userNode *IsInChannel(struct chanNode *channel, struct userNode *user);
418
419 void init_structs(void);
420
421 #endif