1 /* hash.h - IRC network state database
2 * Copyright 2000-2006 srvx Development Team
4 * This file is part of srvx.
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.
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.
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.
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_NONOTICES 0x40000 /* +N */
47 #define MODE_NOAMSGS 0x80000 /* +M */
48 #define MODE_ALTCHAN 0x100000 /* +F */
49 #define MODE_ACCESS 0x200000 /* +a */
50 #define MODE_NOFLOOD 0x400000 /* +f */
51 #define MODE_AUDITORIUM 0x800000 /* +u */
52 #define MODE_REMOVE 0x80000000
54 #define FLAGS_OPER 0x0001 /* +o global operator */
55 #define FLAGS_INVISIBLE 0x0004 /* +i invisible */
56 #define FLAGS_WALLOP 0x0008 /* +w receives wallops */
57 #define FLAGS_DEAF 0x0020 /* +d deaf */
58 #define FLAGS_SERVICE 0x0040 /* +k cannot be kicked, killed or deoped */
59 #define FLAGS_GLOBAL 0x0080 /* +g receives global messages */
60 #define FLAGS_NOCHAN 0x0100 /* +n hide channels in whois */
61 #define FLAGS_PERSISTENT 0x0200 /* for reserved nicks, this isn't just one-shot */
62 #define FLAGS_GAGGED 0x0400 /* for gagged users */
63 #define FLAGS_AWAY 0x0800 /* for away users */
64 #define FLAGS_STAMPED 0x1000 /* for users who have been stamped */
65 #define FLAGS_HIDDEN_HOST 0x2000 /* +x user's host is masked by their account */
66 #define FLAGS_REGNICK 0x4000 /* +r user owns their current nick */
67 #define FLAGS_REGISTERING 0x8000 /* user has issued account register command, is waiting for email cookie */
68 #define FLAGS_DUMMY 0x10000 /* user is not announced to other servers */
69 #define FLAGS_NOIDLE 0x20000 /* +I hide idle time in whois */
70 #define FLAGS_NETSERV 0x40000 /* +S */
71 #define FLAGS_SECURITYSERV 0x80000 /* +D */
72 #define FLAGS_XTRAOP 0x100000 /* +X */
73 #define FLAGS_HIDDENOPER 0x200000 /* +H */
74 #define FLAGS_SERVERNOTICE 0x400000 /* +s */
75 #define FLAGS_SEENOIDLE 0x800000 /* +t */
77 #define IsOper(x) ((x)->modes & FLAGS_OPER)
78 #define IsService(x) ((x)->modes & FLAGS_SERVICE)
79 #define IsDeaf(x) ((x)->modes & FLAGS_DEAF)
80 #define IsInvisible(x) ((x)->modes & FLAGS_INVISIBLE)
81 #define IsGlobal(x) ((x)->modes & FLAGS_GLOBAL)
82 #define IsNoChan(x) ((x)->modes & FLAGS_NOCHAN)
83 #define IsWallOp(x) ((x)->modes & FLAGS_WALLOP)
84 #define IsGagged(x) ((x)->modes & FLAGS_GAGGED)
85 #define IsPersistent(x) ((x)->modes & FLAGS_PERSISTENT)
86 #define IsAway(x) ((x)->modes & FLAGS_AWAY)
87 #define IsStamped(x) ((x)->modes & FLAGS_STAMPED)
88 #define IsHiddenHost(x) ((x)->modes & FLAGS_HIDDEN_HOST)
89 #define IsReggedNick(x) ((x)->modes & FLAGS_REGNICK)
90 #define IsRegistering(x) ((x)->modes & FLAGS_REGISTERING)
91 #define IsDummy(x) ((x)->modes & FLAGS_DUMMY)
92 #define IsNoIdle(x) ((x)->modes & FLAGS_NOIDLE)
93 #define IsSecurityServ(x) ((x)->modes & FLAGS_SECURITYSERV)
94 #define IsNetServ(x) ((x)->modes & FLAGS_NETSERV)
95 #define IsXtraOp(x) ((x)->modes & FLAGS_XTRAOP)
96 #define IsServerNotice(x) ((x)->modes & FLAGS_SERVERNOTICE)
97 #define IsHiddenOper(x) ((x)->modes & FLAGS_HIDDENOPER)
98 #define IsSeeNoIdle(x) ((x)->modes & FLAGS_SEENOIDLE)
99 #define IsFakeHost(x) ((x)->fakehost[0] != '\0')
100 #define IsFakeIdent(x) ((x)->fakeident[0] != '\0')
101 #define IsLocal(x) ((x)->uplink == self)
103 #define NOFLOODLEN 15
109 #define CHANNELLEN 200
110 #define MAXOPLEVEL 999
112 #define MAXMODEPARAMS 6
115 /* IDLEN is 6 because it takes 5.33 Base64 digits to store 32 bytes. */
118 DECLARE_LIST(userList, struct userNode*);
119 DECLARE_LIST(modeList, struct modeNode*);
120 DECLARE_LIST(banList, struct banNode*);
121 DECLARE_LIST(channelList, struct chanNode*);
122 DECLARE_LIST(serverList, struct server*);
125 char *nick; /* Unique name of the client, nick or host */
126 char ident[USERLEN + 1]; /* Per-host identification for user */
127 char info[REALLEN + 1]; /* Free form additional client information */
128 char hostname[HOSTLEN + 1]; /* DNS name or IP address */
129 char fakehost[HOSTLEN + 1]; /* Assigned fake host */
130 char fakeident[USERLEN + 1]; /* Assigned fake ident */
131 #ifdef WITH_PROTOCOL_P10
132 char numeric[COMBO_NUMERIC_LEN+1];
133 unsigned int num_local : 18;
135 unsigned int dead : 1; /* Is user waiting to be recycled? */
136 irc_in_addr_t ip; /* User's IP address */
137 long modes; /* user flags +isw etc... */
139 unsigned long timestamp; /* Time of last nick change */
140 unsigned long idle_since; /* Last time user did something on or to a channel */
141 struct server *uplink; /* Server that user is connected to */
142 struct modeList channels; /* Vector of channels user is in */
145 struct handle_info *handle_info;
146 struct userNode *next_authed;
147 struct policer auth_policer;
155 char key[KEYLEN + 1];
156 char altchan[CHANNELLEN + 1];
157 char noflood[NOFLOODLEN + 1];
158 char upass[KEYLEN + 1];
159 char apass[KEYLEN + 1];
160 unsigned long timestamp; /* creation time */
162 char topic[TOPICLEN + 1];
163 char topic_nick[NICKLEN + 1];
164 unsigned long topic_time;
166 struct modeList members;
167 struct banList banlist;
168 struct policer join_policer;
169 struct userList invited;
170 unsigned int join_flooded : 1;
171 unsigned int bad_channel : 1;
173 struct chanData *channel_info;
174 struct channel_help *channel_help;
179 char ban[NICKLEN + USERLEN + HOSTLEN + 3]; /* 1 for '\0', 1 for ! and 1 for @ = 3 */
180 char who[NICKLEN + 1]; /* who set ban */
181 unsigned long set; /* time ban was set */
185 struct chanNode *channel;
186 struct userNode *user;
187 unsigned short modes;
189 unsigned long idle_since;
192 #define SERVERNAMEMAX 64
193 #define SERVERDESCRIPTMAX 128
196 char name[SERVERNAMEMAX+1];
198 unsigned long link_time;
199 char description[SERVERDESCRIPTMAX+1];
200 #ifdef WITH_PROTOCOL_P10
201 char numeric[COMBO_NUMERIC_LEN+1];
202 unsigned int num_mask;
204 unsigned int hops, clients, max_clients;
205 unsigned int burst : 1, self_burst : 1;
206 struct server *uplink;
207 #ifdef WITH_PROTOCOL_P10
208 struct userNode **users; /* flat indexed by numeric */
210 dict_t users; /* indexed by nick */
212 struct serverList children;
215 extern struct server *self;
216 extern dict_t channels;
217 extern dict_t clients;
218 extern dict_t servers;
219 extern unsigned int max_clients, invis_clients;
220 extern unsigned long max_clients_time;
221 extern struct userList curr_opers, curr_helpers;
223 struct server* GetServerH(const char *name); /* using full name */
224 struct userNode* GetUserH(const char *nick); /* using nick */
225 struct chanNode* GetChannel(const char *name);
226 struct modeNode* GetUserMode(struct chanNode* channel, struct userNode* user);
228 int userList_contains(struct userList *list, struct userNode *user);
230 typedef void (*server_link_func_t) (struct server *server);
231 void reg_server_link_func(server_link_func_t handler);
233 typedef void (*new_user_func_t) (struct userNode *user);
234 void reg_new_user_func(new_user_func_t handler);
235 typedef void (*del_user_func_t) (struct userNode *user, struct userNode *killer, const char *why);
236 void reg_del_user_func(del_user_func_t handler);
237 void unreg_del_user_func(del_user_func_t handler);
238 void ReintroduceUser(struct userNode* user);
239 typedef void (*nick_change_func_t)(struct userNode *user, const char *old_nick);
240 void reg_nick_change_func(nick_change_func_t handler);
241 void NickChange(struct userNode* user, const char *new_nick, int no_announce);
243 typedef void (*account_func_t) (struct userNode *user, const char *stamp, unsigned long timestamp, unsigned long serial);
244 void reg_account_func(account_func_t handler);
245 void call_account_func(struct userNode *user, const char *stamp, unsigned long timestamp, unsigned long serial);
246 void StampUser(struct userNode *user, const char *stamp, unsigned long timestamp, unsigned long serial);
247 void assign_fakehost(struct userNode *user, const char *host, const char *ident, int force, int announce);
249 typedef void (*new_channel_func_t) (struct chanNode *chan);
250 void reg_new_channel_func(new_channel_func_t handler);
251 typedef int (*join_func_t) (struct modeNode *mNode);
252 void reg_join_func(join_func_t handler);
253 typedef void (*del_channel_func_t) (struct chanNode *chan);
254 void reg_del_channel_func(del_channel_func_t handler);
256 struct chanNode* AddChannel(const char *name, unsigned long time_, const char *modes, char *banlist);
257 void LockChannel(struct chanNode *channel);
258 void UnlockChannel(struct chanNode *channel);
260 struct modeNode* AddChannelUser(struct userNode* user, struct chanNode* channel);
262 int modeNode_sort(const void *pa, const void *pb);
263 typedef void (*part_func_t) (struct modeNode *mn, const char *reason);
264 void reg_part_func(part_func_t handler);
265 void unreg_part_func(part_func_t handler);
266 void DelChannelUser(struct userNode* user, struct chanNode* channel, const char *reason, int deleting);
267 void KickChannelUser(struct userNode* target, struct chanNode* channel, struct userNode *kicker, const char *why);
269 typedef void (*kick_func_t) (struct userNode *kicker, struct userNode *user, struct chanNode *chan);
270 void reg_kick_func(kick_func_t handler);
271 void ChannelUserKicked(struct userNode* kicker, struct userNode* victim, struct chanNode* channel);
273 int ChannelBanExists(struct chanNode *channel, const char *ban);
275 typedef int (*topic_func_t)(struct userNode *who, struct chanNode *chan, const char *old_topic);
276 void reg_topic_func(topic_func_t handler);
277 void SetChannelTopic(struct chanNode *channel, struct userNode *user, const char *topic, int announce);
279 void init_structs(void);