]>
Commit | Line | Data |
---|---|---|
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 AS |
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 | ||
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 */ | |
40 | #define MODE_REGONLY 0x00001000 /* ircu +r, Bahamut +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 */ | |
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 */ |
d76ed9a9 AS |
54 | #define MODE_REMOVE 0x80000000 |
55 | ||
56 | #define FLAGS_OPER 0x0001 /* Operator +O */ | |
57 | #define FLAGS_LOCOP 0x0002 /* Local operator +o */ | |
58 | #define FLAGS_INVISIBLE 0x0004 /* invisible +i */ | |
59 | #define FLAGS_WALLOP 0x0008 /* receives wallops +w */ | |
60 | #define FLAGS_SERVNOTICE 0x0010 /* receives server notices +s */ | |
61 | #define FLAGS_DEAF 0x0020 /* deaf +d */ | |
62 | #define FLAGS_SERVICE 0x0040 /* cannot be kicked, killed or deoped +k */ | |
63 | #define FLAGS_GLOBAL 0x0080 /* receives global messages +g */ | |
182dd032 AS |
64 | |
65 | // sethost - reed/apples | |
66 | // #define FLAGS_HELPER 0x0100 /* (network?) helper +h */ | |
67 | #define FLAGS_SETHOST 0x0100 /* sethost +h */ | |
68 | ||
d76ed9a9 AS |
69 | #define FLAGS_PERSISTENT 0x0200 /* for reserved nicks, this isn't just one-shot */ |
70 | #define FLAGS_GAGGED 0x0400 /* for gagged users */ | |
71 | #define FLAGS_AWAY 0x0800 /* for away users */ | |
72 | #define FLAGS_STAMPED 0x1000 /* for users who have been stamped */ | |
73 | #define FLAGS_HIDDEN_HOST 0x2000 /* user's host is masked by their account */ | |
74 | #define FLAGS_REGNICK 0x4000 /* user owns their current nick */ | |
75 | #define FLAGS_REGISTERING 0x8000 /* user has issued account register command, is waiting for email cookie */ | |
76 | ||
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 IsWallOp(x) ((x)->modes & FLAGS_WALLOP) | |
83 | #define IsServNotice(x) ((x)->modes & FLAGS_SERVNOTICE) | |
182dd032 AS |
84 | |
85 | // sethost - reed/apples | |
86 | // #define IsHelperIrcu(x) ((x)->modes & FLAGS_HELPER) | |
87 | #define IsSetHost(x) ((x)->modes & FLAGS_SETHOST) | |
88 | ||
d76ed9a9 AS |
89 | #define IsGagged(x) ((x)->modes & FLAGS_GAGGED) |
90 | #define IsPersistent(x) ((x)->modes & FLAGS_PERSISTENT) | |
91 | #define IsAway(x) ((x)->modes & FLAGS_AWAY) | |
92 | #define IsStamped(x) ((x)->modes & FLAGS_STAMPED) | |
93 | #define IsHiddenHost(x) ((x)->modes & FLAGS_HIDDEN_HOST) | |
94 | #define IsReggedNick(x) ((x)->modes & FLAGS_REGNICK) | |
95 | #define IsRegistering(x) ((x)->modes & FLAGS_REGISTERING) | |
96 | #define IsFakeHost(x) ((x)->fakehost[0] != '\0') | |
97 | #define IsLocal(x) ((x)->uplink == self) | |
98 | ||
99 | #define NICKLEN 30 | |
100 | #define USERLEN 10 | |
101 | #define HOSTLEN 63 | |
a32da4c7 | 102 | #define ACCOUNTLEN 15 |
d76ed9a9 AS |
103 | #define REALLEN 50 |
104 | #define TOPICLEN 250 | |
105 | #define CHANNELLEN 200 | |
106 | ||
107 | #define MAXMODEPARAMS 6 | |
ac3bdc8d | 108 | #define MAXBANS 128 |
2aef5f4b | 109 | #define MAXEXEMPTS 45 |
d76ed9a9 AS |
110 | |
111 | /* IDLEN is 6 because it takes 5.33 Base64 digits to store 32 bytes. */ | |
112 | #define IDLEN 6 | |
113 | ||
114 | DECLARE_LIST(userList, struct userNode*); | |
115 | DECLARE_LIST(modeList, struct modeNode*); | |
116 | DECLARE_LIST(banList, struct banNode*); | |
2aef5f4b | 117 | DECLARE_LIST(exemptList, struct exemptNode*); |
d76ed9a9 AS |
118 | DECLARE_LIST(channelList, struct chanNode*); |
119 | DECLARE_LIST(serverList, struct server*); | |
120 | ||
121 | struct userNode { | |
122 | char *nick; /* Unique name of the client, nick or host */ | |
123 | char ident[USERLEN + 1]; /* Per-host identification for user */ | |
124 | char info[REALLEN + 1]; /* Free form additional client information */ | |
125 | char hostname[HOSTLEN + 1]; /* DNS name or IP address */ | |
126 | char fakehost[HOSTLEN + 1]; /* Assigned fake host */ | |
127 | #ifdef WITH_PROTOCOL_P10 | |
128 | char numeric[COMBO_NUMERIC_LEN+1]; | |
129 | unsigned int num_local : 18; | |
130 | #endif | |
131 | unsigned int dead : 1; /* Is user waiting to be recycled? */ | |
132 | struct in_addr ip; /* User's IP address */ | |
133 | long modes; /* user flags +isw etc... */ | |
134 | ||
182dd032 AS |
135 | // sethost - reed/apples |
136 | char sethost[USERLEN + HOSTLEN + 2]; /* 1 for '\0' and 1 for @ = 2 */ | |
137 | ||
d76ed9a9 AS |
138 | time_t timestamp; /* Time of last nick change */ |
139 | struct server *uplink; /* Server that user is connected to */ | |
140 | struct modeList channels; /* Vector of channels user is in */ | |
141 | ||
142 | /* from nickserv */ | |
143 | struct handle_info *handle_info; | |
144 | struct userNode *next_authed; | |
145 | struct policer auth_policer; | |
146 | }; | |
147 | ||
148 | struct chanNode { | |
149 | chan_mode_t modes; | |
150 | unsigned int limit, locks; | |
151 | char key[KEYLEN + 1]; | |
152 | time_t timestamp; /* creation time */ | |
153 | ||
154 | char topic[TOPICLEN + 1]; | |
155 | char topic_nick[NICKLEN + 1]; | |
156 | time_t topic_time; | |
157 | ||
158 | struct modeList members; | |
159 | struct banList banlist; | |
2aef5f4b | 160 | struct exemptList exemptlist; |
d76ed9a9 AS |
161 | struct policer join_policer; |
162 | unsigned int join_flooded : 1; | |
163 | unsigned int bad_channel : 1; | |
164 | ||
165 | struct chanData *channel_info; | |
166 | struct channel_help *channel_help; | |
167 | char name[1]; | |
168 | }; | |
169 | ||
170 | struct banNode { | |
171 | char ban[NICKLEN + USERLEN + HOSTLEN + 3]; /* 1 for '\0', 1 for ! and 1 for @ = 3 */ | |
172 | char who[NICKLEN + 1]; /* who set ban */ | |
173 | time_t set; /* time ban was set */ | |
174 | }; | |
175 | ||
2aef5f4b | 176 | struct exemptNode { |
177 | char exempt[NICKLEN + USERLEN + HOSTLEN + 3]; /* 1 for '\0', 1 for ! and 1 for @ = 3 */ | |
178 | char who[NICKLEN + 1]; /* who set exempt */ | |
179 | time_t set; /* time exempt was set */ | |
180 | }; | |
181 | ||
d76ed9a9 AS |
182 | struct modeNode { |
183 | struct chanNode *channel; | |
184 | struct userNode *user; | |
185 | long modes; | |
186 | time_t idle_since; | |
187 | }; | |
188 | ||
189 | #define SERVERNAMEMAX 64 | |
190 | #define SERVERDESCRIPTMAX 128 | |
191 | ||
192 | struct server { | |
193 | char name[SERVERNAMEMAX+1]; | |
194 | time_t boot; | |
195 | time_t link; | |
196 | char description[SERVERDESCRIPTMAX+1]; | |
197 | #ifdef WITH_PROTOCOL_P10 | |
198 | char numeric[COMBO_NUMERIC_LEN+1]; | |
199 | unsigned int num_mask; | |
200 | #endif | |
201 | unsigned int hops, clients, max_clients; | |
202 | unsigned int burst : 1, self_burst : 1; | |
203 | struct server *uplink; | |
204 | #ifdef WITH_PROTOCOL_P10 | |
205 | struct userNode **users; /* flat indexed by numeric */ | |
206 | #else | |
207 | dict_t users; /* indexed by nick */ | |
208 | #endif | |
209 | struct serverList children; | |
210 | }; | |
211 | ||
212 | extern struct server *self; | |
213 | extern dict_t channels; | |
214 | extern dict_t clients; | |
215 | extern dict_t servers; | |
216 | extern unsigned int max_clients, invis_clients; | |
217 | extern time_t max_clients_time; | |
218 | extern struct userList curr_opers, curr_helpers; | |
219 | ||
220 | struct server* GetServerH(const char *name); /* using full name */ | |
221 | struct userNode* GetUserH(const char *nick); /* using nick */ | |
222 | struct chanNode* GetChannel(const char *name); | |
223 | struct modeNode* GetUserMode(struct chanNode* channel, struct userNode* user); | |
224 | ||
225 | typedef void (*server_link_func_t) (struct server *server); | |
226 | void reg_server_link_func(server_link_func_t handler); | |
227 | ||
228 | typedef int (*new_user_func_t) (struct userNode *user); | |
229 | void reg_new_user_func(new_user_func_t handler); | |
230 | typedef void (*del_user_func_t) (struct userNode *user, struct userNode *killer, const char *why); | |
231 | void reg_del_user_func(del_user_func_t handler); | |
232 | void unreg_del_user_func(del_user_func_t handler); | |
233 | void ReintroduceUser(struct userNode* user); | |
234 | typedef void (*nick_change_func_t)(struct userNode *user, const char *old_nick); | |
235 | void reg_nick_change_func(nick_change_func_t handler); | |
236 | void NickChange(struct userNode* user, const char *new_nick, int no_announce); | |
237 | ||
238 | typedef void (*account_func_t) (struct userNode *user, const char *stamp); | |
239 | void reg_account_func(account_func_t handler); | |
240 | void call_account_func(struct userNode *user, const char *stamp); | |
b21e2cfe | 241 | void StampUser(struct userNode *user, const char *stamp, time_t timestamp); |
d76ed9a9 AS |
242 | void assign_fakehost(struct userNode *user, const char *host, int announce); |
243 | ||
244 | typedef void (*new_channel_func_t) (struct chanNode *chan); | |
245 | void reg_new_channel_func(new_channel_func_t handler); | |
246 | typedef int (*join_func_t) (struct modeNode *mNode); | |
247 | void reg_join_func(join_func_t handler); | |
248 | typedef void (*del_channel_func_t) (struct chanNode *chan); | |
249 | void reg_del_channel_func(del_channel_func_t handler); | |
250 | ||
2aef5f4b | 251 | struct chanNode* AddChannel(const char *name, time_t time_, const char *modes, char *banlist, char *exemptlist); |
d76ed9a9 AS |
252 | void LockChannel(struct chanNode *channel); |
253 | void UnlockChannel(struct chanNode *channel); | |
254 | ||
255 | struct modeNode* AddChannelUser(struct userNode* user, struct chanNode* channel); | |
256 | ||
257 | typedef void (*part_func_t) (struct modeNode *mn, const char *reason); | |
258 | void reg_part_func(part_func_t handler); | |
259 | void unreg_part_func(part_func_t handler); | |
260 | void DelChannelUser(struct userNode* user, struct chanNode* channel, const char *reason, int deleting); | |
261 | void KickChannelUser(struct userNode* target, struct chanNode* channel, struct userNode *kicker, const char *why); | |
262 | ||
263 | typedef void (*kick_func_t) (struct userNode *kicker, struct userNode *user, struct chanNode *chan); | |
264 | void reg_kick_func(kick_func_t handler); | |
265 | void ChannelUserKicked(struct userNode* kicker, struct userNode* victim, struct chanNode* channel); | |
266 | ||
267 | int ChannelBanExists(struct chanNode *channel, const char *ban); | |
2aef5f4b | 268 | int ChannelExemptExists(struct chanNode *channel, const char *exempt); |
d76ed9a9 AS |
269 | |
270 | typedef int (*topic_func_t)(struct userNode *who, struct chanNode *chan, const char *old_topic); | |
271 | void reg_topic_func(topic_func_t handler); | |
272 | void SetChannelTopic(struct chanNode *channel, struct userNode *user, const char *topic, int announce); | |
ac3bdc8d | 273 | struct userNode *IsInChannel(struct chanNode *channel, struct userNode *user); |
d76ed9a9 AS |
274 | |
275 | void init_structs(void); | |
276 | ||
277 | #endif |