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