]>
Commit | Line | Data |
---|---|---|
a87bc2c2 | 1 | Add welcome message functionality. |
2 | ||
3 | client commands: | |
4 | user: | |
5 | /WELCOME | |
6 | shows welcome messages set, same is shown on connect | |
7 | ||
8 | oper: | |
9 | /WELCOME [<target>] [[!]<name> :<message>] | |
10 | to view welcome messages from a remote server | |
11 | to set a local welcome message on this server or a remote server | |
12 | set a global welcome message (target *) | |
13 | the ! prefix makes the server annouce the welcome message to its clients when setting | |
14 | ||
15 | server: | |
cb0b5df1 | 16 | :<source> WE <target> [[!]<name> <timestamp> <who> :<text>] |
a87bc2c2 | 17 | who is who set the message, the server puts in the opername when a client sets it. |
cb0b5df1 | 18 | :<name> is a number 1 to WELCOME_MAX_ENTRIES - currently set at 10 (should be more than we ever need) |
a87bc2c2 | 19 | that means there is room for 10 local and 10 global entries |
a87bc2c2 | 20 | |
cb0b5df1 | 21 | STATS W/welcome (/STATS w/userload made case sensitive) |
a87bc2c2 | 22 | :server 230 nick W Name Target Who Timestamp :Message |
23 | :server 227 nick W 1 * opername 1233072583 :Latest news: testing this welcome patch :) | |
24 | :server 227 nick W 2 * opername 1233072583 : | |
25 | :server 227 nick W 1 servername opername 1233072590 :This is a test server, expect restarts. | |
26 | :server 219 nick W :End of /STATS report | |
27 | ||
28 | listing welcomes or on connect: | |
29 | :server NOTICE nick :[QuakeNet] Latest news: testing this welcome patch :) | |
30 | :server NOTICE nick :[server] This is a test server, expect restarts. | |
31 | ||
32 | announcement is done by a notice by the local server to $* with the same message | |
33 | format as for listing welcome messages. | |
34 | :server NOTICE $* :[QuakeNet] Latest news: testing this welcome patch :) | |
35 | :server NOTICE $* :[server] This is a test server, expect restarts. | |
36 | ||
37 | ||
38 | Files: | |
39 | ||
40 | include/handlers.h | |
41 | add m_welcome mo_welcome ms_welcome mh_welcome functions | |
42 | ||
43 | include/features.h | |
44 | ircd/features.c | |
45 | add features FEAT_WELCOME and FEAT_HIS_STATS_W | |
46 | ||
47 | include/msg.h | |
48 | add MSG_WELCOME TOK_WELCOME CMD_WELCOME | |
49 | ||
50 | ircd/parse.c | |
51 | add welcome message functions | |
52 | ||
53 | include/numeric.h | |
54 | ircd/s_err.c | |
55 | add RPL_STATSWELCOME ERR_NOSUCHWELCOME | |
56 | ||
57 | include/welcome.h | |
58 | ircd/welcome.c | |
59 | ircd/m_welcome.c | |
60 | new | |
61 | ||
62 | ircd/Makefile.in | |
63 | add welcome.c and m_welcome.c files | |
64 | ||
a87bc2c2 | 65 | ircd/s_serv.c |
66 | add burst welcome message | |
67 | ||
68 | ircd/s_stats.c | |
69 | add /STATS W/welcome | |
70 | ||
71 | ircd/s_user.c | |
72 | add showing of welcome messages on connect | |
73 | ||
db0ccf80 | 74 | include/client.h |
75 | ircd/client.c | |
76 | ircd/ircd_lexer.l | |
77 | ircd/ircd_parser.y | |
78 | add PRIV_LOCAL_WELCOME PRIV_WELCOME | |
79 | ||
182f0f64 | 80 | diff -r 211f48754a7f include/client.h |
5632b943 | 81 | --- a/include/client.h |
82 | +++ b/include/client.h | |
308d3fca | 83 | @@ -142,6 +142,8 @@ |
84 | PRIV_USER_PRIVACY, /* oper can bypass user privacy +x etc gives i.e. see real ip's */ | |
85 | PRIV_CHANNEL_PRIVACY, /* oper can bypass channel privacy i.e. can see modes on channels they are not on and channel keys */ | |
86 | PRIV_SERVERINFO, /* oper can use /get, /stats, /hash, retrieve remote information */ | |
4e89d808 | 87 | + PRIV_WELCOME, /* oper can WELCOME */ |
88 | + PRIV_LOCAL_WELCOME, /* oper can local WELCOME */ | |
89 | PRIV_LAST_PRIV /**< number of privileges */ | |
90 | }; | |
91 | ||
182f0f64 | 92 | diff -r 211f48754a7f include/handlers.h |
5632b943 | 93 | --- a/include/handlers.h |
94 | +++ b/include/handlers.h | |
f0f686d6 | 95 | @@ -138,6 +138,7 @@ |
cddf800b | 96 | extern int m_version(struct Client*, struct Client*, int, char*[]); |
97 | extern int m_wallchops(struct Client*, struct Client*, int, char*[]); | |
98 | extern int m_wallvoices(struct Client*, struct Client*, int, char*[]); | |
99 | +extern int m_welcome(struct Client*, struct Client*, int, char*[]); | |
100 | extern int m_who(struct Client*, struct Client*, int, char*[]); | |
101 | extern int m_whois(struct Client*, struct Client*, int, char*[]); | |
102 | extern int m_whowas(struct Client*, struct Client*, int, char*[]); | |
f0f686d6 | 103 | @@ -172,6 +173,7 @@ |
cddf800b | 104 | extern int mo_version(struct Client*, struct Client*, int, char*[]); |
105 | extern int mo_wallops(struct Client*, struct Client*, int, char*[]); | |
106 | extern int mo_wallusers(struct Client*, struct Client*, int, char*[]); | |
107 | +extern int mo_welcome(struct Client*, struct Client*, int, char*[]); | |
308d3fca | 108 | extern int mo_xquery(struct Client*, struct Client*, int, char*[]); |
cddf800b | 109 | extern int mr_error(struct Client*, struct Client*, int, char*[]); |
110 | extern int mr_error(struct Client*, struct Client*, int, char*[]); | |
f0f686d6 | 111 | @@ -230,6 +232,7 @@ |
cddf800b | 112 | extern int ms_wallops(struct Client*, struct Client*, int, char*[]); |
113 | extern int ms_wallusers(struct Client*, struct Client*, int, char*[]); | |
114 | extern int ms_wallvoices(struct Client*, struct Client*, int, char*[]); | |
115 | +extern int ms_welcome(struct Client*, struct Client*, int, char*[]); | |
116 | extern int ms_whois(struct Client*, struct Client*, int, char*[]); | |
308d3fca | 117 | extern int ms_xquery(struct Client*, struct Client*, int, char*[]); |
118 | extern int ms_xreply(struct Client*, struct Client*, int, char*[]); | |
182f0f64 | 119 | diff -r 211f48754a7f include/ircd_features.h |
5632b943 | 120 | --- a/include/ircd_features.h |
121 | +++ b/include/ircd_features.h | |
a87bc2c2 | 122 | @@ -101,6 +101,7 @@ |
123 | FEAT_IRCD_RES_TIMEOUT, | |
124 | FEAT_AUTH_TIMEOUT, | |
125 | FEAT_ANNOUNCE_INVITES, | |
126 | + FEAT_WELCOME, | |
127 | ||
128 | /* features that affect all operators */ | |
129 | FEAT_EXTENDED_CHECKCMD, | |
308d3fca | 130 | @@ -142,6 +143,7 @@ |
a87bc2c2 | 131 | FEAT_HIS_STATS_u, |
132 | FEAT_HIS_STATS_U, | |
133 | FEAT_HIS_STATS_v, | |
134 | + FEAT_HIS_STATS_W, | |
135 | FEAT_HIS_STATS_w, | |
136 | FEAT_HIS_STATS_x, | |
137 | FEAT_HIS_STATS_y, | |
182f0f64 | 138 | diff -r 211f48754a7f include/msg.h |
5632b943 | 139 | --- a/include/msg.h |
140 | +++ b/include/msg.h | |
308d3fca | 141 | @@ -196,6 +196,10 @@ |
cddf800b | 142 | #define TOK_NOTICE "O" |
143 | #define CMD_NOTICE MSG_NOTICE, TOK_NOTICE | |
100a7f47 | 144 | |
cddf800b | 145 | +#define MSG_WELCOME "WELCOME" /* WELC */ |
146 | +#define TOK_WELCOME "WE" | |
147 | +#define CMD_WELCOME MSG_WELCOME, TOK_WELCOME | |
100a7f47 | 148 | + |
cddf800b | 149 | #define MSG_WALLCHOPS "WALLCHOPS" /* WC */ |
150 | #define TOK_WALLCHOPS "WC" | |
100a7f47 | 151 | #define CMD_WALLCHOPS MSG_WALLCHOPS, TOK_WALLCHOPS |
182f0f64 | 152 | diff -r 211f48754a7f include/numeric.h |
5632b943 | 153 | --- a/include/numeric.h |
154 | +++ b/include/numeric.h | |
a87bc2c2 | 155 | @@ -116,6 +116,7 @@ |
156 | RPL_STATSGLINE 227 Dalnet | |
157 | RPL_STATSVLINE 227 unreal */ | |
158 | #define RPL_STATSALINE 226 /* Hybrid, Undernet */ | |
159 | +#define RPL_STATSWELCOME 227 /* QuakeNet extension */ | |
160 | #define RPL_STATSQLINE 228 /* Undernet extension */ | |
a87bc2c2 | 161 | |
308d3fca | 162 | /* RPL_SERVICEINFO 231 unused */ |
163 | @@ -440,6 +441,8 @@ | |
a87bc2c2 | 164 | /* ERR_GHOSTEDCLIENT 503 efnet */ |
165 | /* ERR_VWORLDWARN 503 austnet */ | |
166 | ||
167 | +#define ERR_NOSUCHWELCOME 509 /* QuakeNet extension */ | |
168 | + | |
169 | #define ERR_SILELISTFULL 511 /* Undernet extension */ | |
170 | /* ERR_NOTIFYFULL 512 aircd */ | |
171 | /* ERR_TOOMANYWATCH 512 Numeric List: Dalnet */ | |
182f0f64 | 172 | diff -r 211f48754a7f include/welcome.h |
5632b943 | 173 | --- /dev/null |
174 | +++ b/include/welcome.h | |
6dd3e24f | 175 | @@ -0,0 +1,60 @@ |
cddf800b | 176 | +#ifndef INCLUDED_welcome_h |
177 | +#define INCLUDED_welcome_h | |
178 | +/* | |
179 | + * IRC - Internet Relay Chat, include/welcome.h | |
180 | + * Copyright (C) 1990 Jarkko Oikarinen and | |
181 | + * University of Oulu, Computing Center | |
182 | + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu> | |
183 | + * | |
184 | + * This program is free software; you can redistribute it and/or modify | |
185 | + * it under the terms of the GNU General Public License as published by | |
186 | + * the Free Software Foundation; either version 2, or (at your option) | |
187 | + * any later version. | |
188 | + * | |
189 | + * This program is distributed in the hope that it will be useful, | |
190 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
191 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
192 | + * GNU General Public License for more details. | |
193 | + * | |
194 | + * You should have received a copy of the GNU General Public License | |
195 | + * along with this program; if not, write to the Free Software | |
196 | + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
197 | + */ | |
198 | +/** @file | |
a87bc2c2 | 199 | + * @brief Interface and declarations for welcome message handling. |
cddf800b | 200 | + */ |
201 | +#ifndef INCLUDED_sys_types_h | |
202 | +#include <sys/types.h> | |
203 | +#define INCLUDED_sys_types_h | |
204 | +#endif | |
205 | + | |
a87bc2c2 | 206 | +struct Client; |
207 | +struct StatDesc; | |
208 | + | |
cb0b5df1 | 209 | +/* Maximum number of welcome entries (per type; X global, X local) */ |
6dd3e24f | 210 | +#define WELCOME_MAX_ENTRIES 10 |
211 | +/* Maximum timestamp drift in seconds allowed ahead of our idea of nettime | |
212 | + * before we throw a warning to ops | |
213 | + */ | |
214 | +#define WELCOME_MAX_DRIFT 600 | |
a87bc2c2 | 215 | + |
216 | +/* Describes a Welcome message entry. */ | |
217 | +struct Welcome { | |
6dd3e24f | 218 | + time_t timestamp; /**< Timestamp of the welcome */ |
219 | + char text[TOPICLEN + 1]; /**< Message */ | |
220 | + char who[ACCOUNTLEN + 1]; /**< Who set it */ | |
a87bc2c2 | 221 | +}; |
222 | + | |
cb0b5df1 | 223 | +/** Welcome type flags */ |
a87bc2c2 | 224 | +#define WELCOME_LOCAL 0x01 /**< welcome is local */ |
225 | +/** Welcome action flags */ | |
226 | +#define WELCOME_ANNOUNCE 0x02 /**< announce change to users */ | |
227 | + | |
a87bc2c2 | 228 | +extern int welcome_do(struct Client *cptr, struct Client *sptr, char *name, char *text, |
229 | + char *who, time_t timestamp, unsigned int flags); | |
cb0b5df1 | 230 | +extern void welcome_announce(int name); |
cddf800b | 231 | +extern void welcome_burst(struct Client *cptr); |
a87bc2c2 | 232 | +extern int welcome_list(struct Client *sptr, int connect); |
233 | +extern void welcome_stats(struct Client *sptr, const struct StatDesc *sd, char *param); | |
cddf800b | 234 | + |
235 | +#endif /* INCLUDED_welcome_h */ | |
182f0f64 | 236 | diff -r 211f48754a7f ircd/Makefile.in |
5632b943 | 237 | --- a/ircd/Makefile.in |
238 | +++ b/ircd/Makefile.in | |
308d3fca | 239 | @@ -186,6 +186,7 @@ |
a87bc2c2 | 240 | m_wallops.c \ |
241 | m_wallusers.c \ | |
242 | m_wallvoices.c \ | |
243 | + m_welcome.c \ | |
244 | m_who.c \ | |
245 | m_whois.c \ | |
246 | m_whowas.c \ | |
dcd0ea31 | 247 | @@ -215,6 +216,7 @@ |
a87bc2c2 | 248 | send.c \ |
249 | uping.c \ | |
250 | userload.c \ | |
251 | + welcome.c \ | |
252 | whocmds.c \ | |
253 | whowas.c \ | |
254 | y.tab.c | |
308d3fca | 255 | @@ -1161,6 +1163,11 @@ |
a87bc2c2 | 256 | ../include/ircd_reply.h ../include/ircd_string.h \ |
257 | ../include/ircd_chattr.h ../include/msg.h ../include/numeric.h \ | |
258 | ../include/numnicks.h ../include/s_user.h ../include/send.h | |
259 | +m_welcome.o: m_welcome.c ../config.h ../include/channel.h \ | |
260 | + ../include/client.h ../include/hash.h ../include/ircd.h ../include/ircd_log.h \ | |
261 | + ../include/ircd_reply.h ../include/ircd_string.h ../include/msg.h \ | |
262 | + ../include/numeric.h ../include/numnicks.h ../include/s_user.h \ | |
263 | + ../include/send.h ../include/welcome.h | |
264 | m_who.o: m_who.c ../config.h ../include/channel.h ../include/ircd_defs.h \ | |
265 | ../include/res.h ../config.h ../include/client.h ../include/dbuf.h \ | |
266 | ../include/msgq.h ../include/ircd_events.h ../include/ircd_handler.h \ | |
308d3fca | 267 | @@ -1422,6 +1429,13 @@ |
a87bc2c2 | 268 | ../include/numnicks.h ../include/querycmds.h ../include/ircd_features.h \ |
269 | ../include/s_misc.h ../include/s_stats.h ../include/send.h \ | |
270 | ../include/struct.h ../include/sys.h | |
271 | +welcome.o: welcome.c ../config.h ../include/client.h \ | |
272 | + ../include/hash.h ../include/ircd.h ../include/ircd_alloc.h \ | |
273 | + ../include/ircd_features.h ../include/ircd_log.h ../include/ircd_reply.h \ | |
274 | + ../include/match.h ../include/msg.h ../include/numeric.h \ | |
275 | + ../include/numnicks.h ../include/s_debug.h ../include/s_bsd.h \ | |
276 | + ../include/s_misc.h ../include/send.h ../include/struct.h \ | |
277 | + ../include/sys.h ../include/welcome.h | |
278 | whocmds.o: whocmds.c ../config.h ../include/whocmds.h \ | |
279 | ../include/channel.h ../include/ircd_defs.h ../include/res.h \ | |
280 | ../config.h ../include/client.h ../include/dbuf.h ../include/msgq.h \ | |
182f0f64 | 281 | diff -r 211f48754a7f ircd/client.c |
5632b943 | 282 | --- a/ircd/client.c |
283 | +++ b/ircd/client.c | |
308d3fca | 284 | @@ -177,6 +177,7 @@ |
4e89d808 | 285 | FlagSet(&privs_local, PRIV_WHOX); |
286 | FlagSet(&privs_local, PRIV_DISPLAY); | |
287 | FlagSet(&privs_local, PRIV_FORCE_LOCAL_OPMODE); | |
288 | + FlagSet(&privs_local, PRIV_LOCAL_WELCOME); | |
308d3fca | 289 | |
290 | privs_defaults_set = 1; | |
291 | } | |
292 | @@ -223,6 +224,7 @@ | |
293 | ClrPriv(client, PRIV_JUPE); | |
4e89d808 | 294 | ClrPriv(client, PRIV_OPMODE); |
4e89d808 | 295 | ClrPriv(client, PRIV_BADCHAN); |
296 | + ClrPriv(client, PRIV_WELCOME); | |
297 | } | |
308d3fca | 298 | } |
299 | ||
300 | @@ -244,7 +246,7 @@ | |
301 | P(CHANSERV), P(XTRA_OPER), P(NOIDLE), P(FREEFORM), | |
302 | P(PARANOID), P(CHECK), P(WALL), P(CLOSE), | |
303 | P(ROUTE), P(ROUTEINFO), P(SERVERINFO), P(CHANNEL_PRIVACY), | |
304 | - P(USER_PRIVACY), | |
305 | + P(USER_PRIVACY), P(WELCOME), P(LOCAL_WELCOME), | |
4e89d808 | 306 | #undef P |
307 | { 0, 0 } | |
308 | }; | |
182f0f64 | 309 | diff -r 211f48754a7f ircd/ircd_features.c |
5632b943 | 310 | --- a/ircd/ircd_features.c |
311 | +++ b/ircd/ircd_features.c | |
e721b9bb | 312 | @@ -366,6 +366,7 @@ |
a87bc2c2 | 313 | F_I(IRCD_RES_TIMEOUT, 0, 4, 0), |
314 | F_I(AUTH_TIMEOUT, 0, 9, 0), | |
315 | F_B(ANNOUNCE_INVITES, 0, 0, 0), | |
316 | + F_B(WELCOME, 0, 1, 0), | |
317 | ||
318 | /* features that affect all operators */ | |
319 | F_B(EXTENDED_CHECKCMD, 0, 0, 0), | |
308d3fca | 320 | @@ -407,6 +408,7 @@ |
a87bc2c2 | 321 | F_B(HIS_STATS_u, 0, 1, 0), |
322 | F_B(HIS_STATS_U, 0, 1, 0), | |
323 | F_B(HIS_STATS_v, 0, 1, 0), | |
324 | + F_B(HIS_STATS_W, 0, 1, 0), | |
325 | F_B(HIS_STATS_w, 0, 1, 0), | |
326 | F_B(HIS_STATS_x, 0, 1, 0), | |
327 | F_B(HIS_STATS_y, 0, 1, 0), | |
182f0f64 | 328 | diff -r 211f48754a7f ircd/ircd_lexer.l |
5632b943 | 329 | --- a/ircd/ircd_lexer.l |
330 | +++ b/ircd/ircd_lexer.l | |
308d3fca | 331 | @@ -166,6 +166,8 @@ |
332 | { "serverinfo", TPRIV_SERVERINFO }, | |
333 | { "user_privacy", TPRIV_USER_PRIVACY }, | |
334 | { "channel_privacy", TPRIV_CHANNEL_PRIVACY }, | |
4e89d808 | 335 | + { "local_welcome", TPRIV_LOCAL_WELCOME }, |
336 | + { "welcome", TPRIV_WELCOME }, | |
337 | { NULL, 0 } | |
338 | }; | |
339 | static int ntokens; | |
182f0f64 | 340 | diff -r 211f48754a7f ircd/ircd_parser.y |
5632b943 | 341 | --- a/ircd/ircd_parser.y |
342 | +++ b/ircd/ircd_parser.y | |
308d3fca | 343 | @@ -189,6 +189,7 @@ |
344 | %token TPRIV_CHANSERV TPRIV_XTRA_OPER TPRIV_NOIDLE TPRIV_FREEFORM TPRIV_PARANOID | |
345 | %token TPRIV_CHECK TPRIV_WALL TPRIV_CLOSE TPRIV_ROUTE TPRIV_ROUTEINFO TPRIV_SERVERINFO | |
346 | %token TPRIV_CHANNEL_PRIVACY TPRIV_USER_PRIVACY TPRIV_LIST_CHAN | |
dcd0ea31 | 347 | +%token TPRIV_LOCAL_WELCOME TPRIV_WELCOME |
4e89d808 | 348 | /* and some types... */ |
349 | %type <num> sizespec | |
350 | %type <num> timespec timefactor factoredtimes factoredtime | |
308d3fca | 351 | @@ -703,6 +704,8 @@ |
352 | TPRIV_SERVERINFO { $$ = PRIV_SERVERINFO ; } | | |
353 | TPRIV_CHANNEL_PRIVACY { $$ = PRIV_CHANNEL_PRIVACY ; } | | |
354 | TPRIV_USER_PRIVACY { $$ = PRIV_USER_PRIVACY ; } | | |
4e89d808 | 355 | + TPRIV_LOCAL_WELCOME { $$ = PRIV_LOCAL_WELCOME; } | |
356 | + TPRIV_WELCOME { $$ = PRIV_WELCOME; } | | |
357 | TPRIV_PARANOID { $$ = PRIV_PARANOID; } ; | |
358 | yesorno: YES { $$ = 1; } | NO { $$ = 0; }; | |
359 | ||
182f0f64 | 360 | diff -r 211f48754a7f ircd/m_welcome.c |
5632b943 | 361 | --- /dev/null |
362 | +++ b/ircd/m_welcome.c | |
d2e4469e | 363 | @@ -0,0 +1,284 @@ |
cddf800b | 364 | +/* |
365 | + * IRC - Internet Relay Chat, ircd/m_welcome.c | |
366 | + * Copyright (C) 1990 Jarkko Oikarinen and | |
367 | + * University of Oulu, Computing Center | |
368 | + * | |
369 | + * See file AUTHORS in IRC package for additional names of | |
370 | + * the programmers. | |
371 | + * | |
372 | + * This program is free software; you can redistribute it and/or modify | |
373 | + * it under the terms of the GNU General Public License as published by | |
374 | + * the Free Software Foundation; either version 1, or (at your option) | |
375 | + * any later version. | |
376 | + * | |
377 | + * This program is distributed in the hope that it will be useful, | |
378 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
379 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
380 | + * GNU General Public License for more details. | |
381 | + * | |
382 | + * You should have received a copy of the GNU General Public License | |
383 | + * along with this program; if not, write to the Free Software | |
384 | + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
385 | + * | |
cddf800b | 386 | + */ |
387 | + | |
388 | +/* | |
389 | + * m_functions execute protocol messages on this server: | |
390 | + * | |
391 | + * cptr is always NON-NULL, pointing to a *LOCAL* client | |
392 | + * structure (with an open socket connected!). This | |
393 | + * identifies the physical socket where the message | |
394 | + * originated (or which caused the m_function to be | |
395 | + * executed--some m_functions may call others...). | |
396 | + * | |
397 | + * sptr is the source of the message, defined by the | |
398 | + * prefix part of the message if present. If not | |
399 | + * or prefix not found, then sptr==cptr. | |
400 | + * | |
401 | + * (!IsServer(cptr)) => (cptr == sptr), because | |
402 | + * prefixes are taken *only* from servers... | |
403 | + * | |
404 | + * (IsServer(cptr)) | |
405 | + * (sptr == cptr) => the message didn't | |
406 | + * have the prefix. | |
407 | + * | |
408 | + * (sptr != cptr && IsServer(sptr) means | |
409 | + * the prefix specified servername. (?) | |
410 | + * | |
411 | + * (sptr != cptr && !IsServer(sptr) means | |
412 | + * that message originated from a remote | |
413 | + * user (not local). | |
414 | + * | |
415 | + * combining | |
416 | + * | |
417 | + * (!IsServer(sptr)) means that, sptr can safely | |
418 | + * taken as defining the target structure of the | |
419 | + * message in this server. | |
420 | + * | |
421 | + * *Always* true (if 'parse' and others are working correct): | |
422 | + * | |
423 | + * 1) sptr->from == cptr (note: cptr->from == cptr) | |
424 | + * | |
425 | + * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr | |
426 | + * *cannot* be a local connection, unless it's | |
427 | + * actually cptr!). [MyConnect(x) should probably | |
428 | + * be defined as (x == x->from) --msa ] | |
429 | + * | |
430 | + * parc number of variable parameter strings (if zero, | |
431 | + * parv is allowed to be NULL) | |
432 | + * | |
433 | + * parv a NULL terminated list of parameter pointers, | |
434 | + * | |
435 | + * parv[0], sender (prefix string), if not present | |
436 | + * this points to an empty string. | |
437 | + * parv[1]...parv[parc-1] | |
438 | + * pointers to additional parameters | |
439 | + * parv[parc] == NULL, *always* | |
440 | + * | |
441 | + * note: it is guaranteed that parv[0]..parv[parc-1] are all | |
442 | + * non-NULL pointers. | |
443 | + */ | |
444 | +#include "config.h" | |
445 | + | |
446 | +#include "channel.h" | |
447 | +#include "client.h" | |
448 | +#include "hash.h" | |
449 | +#include "ircd.h" | |
a87bc2c2 | 450 | +#include "ircd_features.h" |
cddf800b | 451 | +#include "ircd_log.h" |
452 | +#include "ircd_reply.h" | |
5bb41778 | 453 | +#include "ircd_snprintf.h" |
cddf800b | 454 | +#include "ircd_string.h" |
455 | +#include "msg.h" | |
456 | +#include "numeric.h" | |
457 | +#include "numnicks.h" | |
458 | +#include "s_user.h" | |
459 | +#include "send.h" | |
a87bc2c2 | 460 | +#include "welcome.h" |
cddf800b | 461 | + |
462 | +/* #include <assert.h> -- Now using assert in ircd_log.h */ | |
463 | + | |
464 | +/* | |
465 | + * m_welcome - local generic message handler | |
466 | + * | |
467 | + * parv[0] = Send prefix | |
6dd3e24f | 468 | + * parv[1] = [remote server to query] |
cddf800b | 469 | + */ |
470 | +int m_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) | |
471 | +{ | |
a87bc2c2 | 472 | + /* feature disabled */ |
473 | + if (!feature_bool(FEAT_WELCOME)) | |
474 | + return send_reply(sptr, ERR_DISABLED, "WELCOME"); | |
6dd3e24f | 475 | + |
476 | + /* only opers can set the welcome messages */ | |
477 | + if (parc > 2) | |
478 | + return send_reply(sptr, ERR_NOPRIVILEGES); | |
479 | + | |
480 | + /* remote listing request, see if it is for me or a remote server | |
481 | + * check FEAT_HIS_REMOTE to decide if an ordinary user can do this | |
482 | + */ | |
5632b943 | 483 | + if ((parc > 1) && (hunt_server_cmd(sptr, CMD_WELCOME, cptr, feature_int(FEAT_HIS_REMOTE), |
484 | + "%C", 1, parc, parv) != HUNTED_ISME)) | |
485 | + return 0; | |
6dd3e24f | 486 | + |
5632b943 | 487 | + /* local listing */ |
a87bc2c2 | 488 | + return welcome_list(sptr, 0); |
cddf800b | 489 | +} |
490 | + | |
491 | + | |
492 | +/* | |
493 | + * mo_welcome - oper message handler | |
494 | + * | |
495 | + * listing: | |
496 | + * parv[0] = Send prefix | |
497 | + * | |
498 | + * remote listing: | |
499 | + * parv[0] = Send prefix | |
500 | + * parv[1] = Target | |
501 | + * | |
502 | + * set global or on remote server: | |
503 | + * parv[0] = Send prefix | |
6dd3e24f | 504 | + * parv[1] = Target: server or * for global (or left out for this server) |
a87bc2c2 | 505 | + * parv[2] = Name |
506 | + * parv[3] = Text | |
cddf800b | 507 | + */ |
508 | +int mo_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) | |
509 | +{ | |
cb0b5df1 | 510 | + char *target, *name, *who, *text, pattern[BUFSIZE]; |
a87bc2c2 | 511 | + time_t timestamp; |
512 | + unsigned int flags = 0; | |
6dd3e24f | 513 | + int local = 0; |
a87bc2c2 | 514 | + |
515 | + /* feature disabled */ | |
516 | + if (!feature_bool(FEAT_WELCOME)) | |
517 | + return send_reply(sptr, ERR_DISABLED, "WELCOME"); | |
518 | + | |
4e89d808 | 519 | + /* TODO: move feature check here? */ |
a87bc2c2 | 520 | + /* remote listing request, see if it is for me or a remote server */ |
5632b943 | 521 | + if ((parc == 2) && (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C", 1, parc, parv) != HUNTED_ISME)) |
522 | + return 0; | |
523 | + | |
524 | + /* local listing */ | |
525 | + if (parc <= 2) | |
a87bc2c2 | 526 | + return welcome_list(sptr, 0); |
4e89d808 | 527 | + |
528 | + /* check PRIVS */ | |
529 | + /* local - need PRIV LOCAL_WELCOME or WELCOME */ | |
530 | + if (parc == 3 && !HasPriv(sptr,PRIV_LOCAL_WELCOME) && !HasPriv(sptr,PRIV_WELCOME)) | |
531 | + return send_reply(sptr, ERR_NOPRIVILEGES); | |
532 | + | |
533 | + /* global or remote - need PRIV WELCOME */ | |
534 | + if (parc >= 4 && !HasPriv(sptr,PRIV_WELCOME)) | |
535 | + return send_reply(sptr, ERR_NOPRIVILEGES); | |
536 | + | |
a87bc2c2 | 537 | + /* set the parameters */ |
6dd3e24f | 538 | + |
539 | + /* target not given, only name - setting local welcome */ | |
a87bc2c2 | 540 | + if (parc < 4) { |
541 | + local++; | |
542 | + target = cli_name(&me); | |
543 | + name = parv[1]; | |
544 | + flags |= WELCOME_LOCAL; | |
6dd3e24f | 545 | + |
546 | + /* target and name given */ | |
547 | + } else { | |
a87bc2c2 | 548 | + target = parv[1]; |
549 | + name = parv[2]; | |
550 | + } | |
551 | + timestamp = TStime(); | |
552 | + who = cli_user(sptr)->opername; | |
553 | + text = parv[parc - 1]; | |
554 | + | |
555 | + /* target is not global */ | |
556 | + if (!(target[0] == '*' && target[1] == '\0') && !local) { | |
6dd3e24f | 557 | + |
a87bc2c2 | 558 | + /* build a pattern for hunt_server_cmd since we do not have all we need in parv */ |
559 | + ircd_snprintf(0, pattern, sizeof(pattern), "%s %s %Tu %s :%s", "%C", name, timestamp, who, text); | |
560 | + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, pattern, 1, 2, parv) != HUNTED_ISME) | |
561 | + return 0; | |
6dd3e24f | 562 | + |
563 | + /* else it is a local welcome, for me */ | |
564 | + flags |= WELCOME_LOCAL; | |
a87bc2c2 | 565 | + } |
566 | + | |
cb0b5df1 | 567 | + /* TODO: disallow global announcement from oper? |
568 | + * as PRIVMSG/NOTICE to $* is not allowed either by the ircd | |
569 | + * when PRIV for that is added, use that here? PRIV_BROADCAST or something | |
4e89d808 | 570 | + * |
571 | + * change prefix to $ ? | |
cb0b5df1 | 572 | + */ |
a87bc2c2 | 573 | + /* check for anounce prefix */ |
574 | + if (*name == '!') { | |
575 | + name++; | |
576 | + flags |= WELCOME_ANNOUNCE; | |
577 | + } | |
578 | + | |
579 | + /* and do it */ | |
580 | + return welcome_do(cptr, sptr, name, text, who, timestamp, flags); | |
cddf800b | 581 | +} |
582 | + | |
583 | + | |
584 | +/* | |
585 | + * ms_welcome - server message handler | |
586 | + * | |
587 | + * parv[0] = Send prefix | |
588 | + * parv[1] = Target: server numeric or * for global | |
a87bc2c2 | 589 | + * parv[2] = Name |
590 | + * parv[3] = Timestamp | |
591 | + * parv[4] = Who | |
592 | + * parv[5] = Text | |
cddf800b | 593 | + */ |
594 | +int ms_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) | |
595 | +{ | |
cb0b5df1 | 596 | + char *target, *name, *who, *text; |
a87bc2c2 | 597 | + time_t timestamp; |
598 | + unsigned int flags = 0; | |
599 | + | |
6dd3e24f | 600 | + /* not enough - complain */ |
601 | + if (parc < 2) { | |
602 | + protocol_violation(sptr, "Too few parameters for WELCOME (got %d - need 2)", parc); | |
a87bc2c2 | 603 | + return need_more_params(sptr, "WELCOME"); |
6dd3e24f | 604 | + } |
a87bc2c2 | 605 | + |
606 | + /* remote listing request, see if it is for me or a remote server */ | |
607 | + if (parc == 2) { | |
d2e4469e | 608 | + if (IsServer(sptr)) |
609 | + return protocol_violation(cptr, "WELCOME listing request from server %C", sptr); | |
6dd3e24f | 610 | + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C", 1, parc, parv) != HUNTED_ISME) |
611 | + return 0; | |
612 | + return welcome_list(sptr, 0); | |
a87bc2c2 | 613 | + } |
614 | + | |
6dd3e24f | 615 | + /* we need at least 6 parameters to continue - complain */ |
616 | + if (parc < 6) { | |
617 | + protocol_violation(sptr, "Too few parameters for WELCOME (got %d - need 6)", parc); | |
a87bc2c2 | 618 | + return need_more_params(sptr, "WELCOME"); |
6dd3e24f | 619 | + } |
a87bc2c2 | 620 | + |
621 | + /* set the parameters */ | |
622 | + target = parv[1]; | |
623 | + name = parv[2]; | |
624 | + timestamp = atoi(parv[3]); | |
625 | + who = parv[4]; | |
6dd3e24f | 626 | + text = parv[parc - 1]; /* parse reason as last parameter */ |
a87bc2c2 | 627 | + |
628 | + /* target is not global */ | |
629 | + if (!(target[0] == '*' && target[1] == '\0')) { | |
6dd3e24f | 630 | + |
a87bc2c2 | 631 | + /* not for me, and forward it */ |
632 | + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C %s %s %s :%s", 1, parc, parv) != HUNTED_ISME) | |
633 | + return 0; | |
6dd3e24f | 634 | + |
635 | + /* local welcome for me */ | |
636 | + flags |= WELCOME_LOCAL; | |
a87bc2c2 | 637 | + } |
638 | + | |
639 | + /* check for anounce prefix */ | |
640 | + if (*name == '!') { | |
641 | + name++; | |
642 | + flags |= WELCOME_ANNOUNCE; | |
643 | + } | |
644 | + | |
645 | + /* and do it */ | |
646 | + return welcome_do(cptr, sptr, name, text, who, timestamp, flags); | |
647 | +} | |
182f0f64 | 648 | diff -r 211f48754a7f ircd/parse.c |
5632b943 | 649 | --- a/ircd/parse.c |
650 | +++ b/ircd/parse.c | |
f0f686d6 | 651 | @@ -661,6 +661,15 @@ |
652 | /* UNREG, CLIENT, SERVER, OPER, SERVICE */ | |
653 | { m_unregistered, m_not_oper, ms_check, mo_check, m_ignore } | |
cddf800b | 654 | }, |
655 | + | |
656 | + /* add command for WELCOME */ | |
657 | + { | |
658 | + MSG_WELCOME, | |
659 | + TOK_WELCOME, | |
660 | + 0, MAXPARA, MFLG_SLOW, 0, NULL, | |
a87bc2c2 | 661 | + /* UNREG, CLIENT, SERVER, OPER, SERVICE, HELP */ |
308d3fca | 662 | + { m_unregistered, m_welcome, ms_welcome, mo_welcome, m_ignore } |
cddf800b | 663 | + }, |
664 | ||
665 | /* This command is an alias for QUIT during the unregistered part of | |
666 | * of the server. This is because someone jumping via a broken web | |
182f0f64 | 667 | diff -r 211f48754a7f ircd/s_err.c |
5632b943 | 668 | --- a/ircd/s_err.c |
669 | +++ b/ircd/s_err.c | |
a87bc2c2 | 670 | @@ -486,7 +486,7 @@ |
671 | /* 226 */ | |
672 | { RPL_STATSALINE, "%s", "226" }, | |
673 | /* 227 */ | |
674 | - { 0 }, | |
675 | + { RPL_STATSWELCOME, "W %d %s %s %Tu :%s", "227" }, | |
676 | /* 228 */ | |
677 | { RPL_STATSQLINE, "Q %s :%s", "228" }, | |
678 | /* 229 */ | |
679 | @@ -1050,7 +1050,7 @@ | |
680 | /* 508 */ | |
681 | { 0 }, | |
682 | /* 509 */ | |
683 | - { 0 }, | |
684 | + { ERR_NOSUCHWELCOME, "%s :No such welcome", "509" }, | |
685 | /* 510 */ | |
686 | { 0 }, | |
687 | /* 511 */ | |
182f0f64 | 688 | diff -r 211f48754a7f ircd/s_serv.c |
5632b943 | 689 | --- a/ircd/s_serv.c |
690 | +++ b/ircd/s_serv.c | |
a87bc2c2 | 691 | @@ -57,6 +57,7 @@ |
692 | #include "struct.h" | |
693 | #include "sys.h" | |
694 | #include "userload.h" | |
695 | +#include "welcome.h" | |
696 | ||
697 | /* #include <assert.h> -- Now using assert in ircd_log.h */ | |
698 | #include <stdlib.h> | |
699 | @@ -196,6 +197,7 @@ | |
700 | */ | |
701 | gline_burst(cptr); | |
702 | jupe_burst(cptr); | |
703 | + welcome_burst(cptr); | |
704 | ||
705 | /* | |
706 | * Pass on my client information to the new server | |
182f0f64 | 707 | diff -r 211f48754a7f ircd/s_stats.c |
5632b943 | 708 | --- a/ircd/s_stats.c |
709 | +++ b/ircd/s_stats.c | |
a87bc2c2 | 710 | @@ -54,6 +54,7 @@ |
711 | #include "send.h" | |
712 | #include "struct.h" | |
713 | #include "userload.h" | |
714 | +#include "welcome.h" | |
715 | ||
716 | #include <stdio.h> | |
717 | #include <stdlib.h> | |
308d3fca | 718 | @@ -654,9 +655,12 @@ |
a87bc2c2 | 719 | { 'V', "vserversmach", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS), FEAT_HIS_STATS_v, |
720 | stats_servers_verbose, 0, | |
721 | "Verbose server information." }, | |
722 | - { 'w', "userload", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_w, | |
723 | + { 'w', "userload", STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS, FEAT_HIS_STATS_w, | |
724 | calc_load, 0, | |
725 | "Userload statistics." }, | |
726 | + { 'W', "welcome", STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS, FEAT_HIS_STATS_W, | |
727 | + welcome_stats, 0, | |
728 | + "Welcome messages." }, | |
729 | { 'x', "memusage", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_x, | |
730 | stats_meminfo, 0, | |
731 | "List usage information." }, | |
182f0f64 | 732 | diff -r 211f48754a7f ircd/s_user.c |
5632b943 | 733 | --- a/ircd/s_user.c |
734 | +++ b/ircd/s_user.c | |
a87bc2c2 | 735 | @@ -63,6 +63,7 @@ |
736 | #include "userload.h" | |
737 | #include "version.h" | |
738 | #include "whowas.h" | |
739 | +#include "welcome.h" | |
740 | ||
741 | #include "handlers.h" /* m_motd and m_lusers */ | |
742 | ||
f0f686d6 | 743 | @@ -410,6 +411,9 @@ |
a87bc2c2 | 744 | cli_info(sptr), NumNick(cptr) /* two %s's */); |
745 | ||
746 | IPcheck_connect_succeeded(sptr); | |
747 | + | |
748 | + if (feature_bool(FEAT_WELCOME)) | |
749 | + welcome_list(sptr, 1); | |
750 | } | |
751 | else { | |
752 | struct Client *acptr = user->server; | |
182f0f64 | 753 | diff -r 211f48754a7f ircd/welcome.c |
5632b943 | 754 | --- /dev/null |
755 | +++ b/ircd/welcome.c | |
6c894401 | 756 | @@ -0,0 +1,371 @@ |
cddf800b | 757 | +/* |
a87bc2c2 | 758 | + * IRC - Internet Relay Chat, ircd/welcome.c |
cddf800b | 759 | + * Copyright (C) 1990 Jarkko Oikarinen and |
760 | + * University of Oulu, Finland | |
761 | + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu> | |
762 | + * | |
763 | + * This program is free software; you can redistribute it and/or modify | |
764 | + * it under the terms of the GNU General Public License as published by | |
765 | + * the Free Software Foundation; either version 1, or (at your option) | |
766 | + * any later version. | |
767 | + * | |
768 | + * This program is distributed in the hope that it will be useful, | |
769 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
770 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
771 | + * GNU General Public License for more details. | |
772 | + * | |
773 | + * You should have received a copy of the GNU General Public License | |
774 | + * along with this program; if not, write to the Free Software | |
775 | + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
776 | + */ | |
777 | +/** @file | |
a87bc2c2 | 778 | + * @brief Implementation of welcome message handling functions. |
cddf800b | 779 | + */ |
780 | +#include "config.h" | |
781 | + | |
782 | +#include "client.h" | |
783 | +#include "hash.h" | |
784 | +#include "ircd.h" | |
785 | +#include "ircd_alloc.h" | |
786 | +#include "ircd_features.h" | |
787 | +#include "ircd_log.h" | |
788 | +#include "ircd_reply.h" | |
789 | +#include "ircd_string.h" | |
790 | +#include "match.h" | |
791 | +#include "msg.h" | |
792 | +#include "numeric.h" | |
793 | +#include "numnicks.h" | |
794 | +#include "s_bsd.h" | |
a87bc2c2 | 795 | +#include "s_debug.h" |
cddf800b | 796 | +#include "s_misc.h" |
797 | +#include "send.h" | |
798 | +#include "struct.h" | |
799 | +#include "sys.h" /* FALSE bleah */ | |
800 | +#include "welcome.h" | |
801 | + | |
802 | +/* #include <assert.h> -- Now using assert in ircd_log.h */ | |
803 | +#include <string.h> | |
804 | + | |
cddf800b | 805 | + |
cb0b5df1 | 806 | +/** List of welcome messages - first MAX for global, second MAX for local */ |
6dd3e24f | 807 | +static struct Welcome WelcomeArray[WELCOME_MAX_ENTRIES * 2] = { { 0 } }; |
cddf800b | 808 | + |
cddf800b | 809 | + |
a87bc2c2 | 810 | +/** Allocate a new welcome with the given parameters. |
811 | + * @param[in] name Name of the welcome message. | |
812 | + * @param[in] text The welcome message. | |
813 | + * @param[in] who Who set it. | |
814 | + * @param[in] timestamp When it was set. | |
cb0b5df1 | 815 | + * @return name Array number of the welcome set. |
cddf800b | 816 | + */ |
cb0b5df1 | 817 | +static int |
818 | +welcome_make(int name, char *text, char *who, time_t timestamp) | |
cddf800b | 819 | +{ |
cb0b5df1 | 820 | + /* range 0 to 2 * max - 1 */ |
821 | + assert(name >= 0 && name <= 2 * WELCOME_MAX_ENTRIES - 1); | |
822 | + | |
823 | + /* store it */ | |
824 | + ircd_strncpy(WelcomeArray[name].text, text, TOPICLEN); | |
825 | + ircd_strncpy(WelcomeArray[name].who, who, ACCOUNTLEN); | |
826 | + WelcomeArray[name].timestamp = timestamp; | |
827 | + | |
828 | + return name; | |
cddf800b | 829 | +} |
830 | + | |
cddf800b | 831 | + |
a87bc2c2 | 832 | +/** Change a welcome message. |
833 | + * @param[in] cptr Local client that sent us the welcome. | |
834 | + * @param[in] sptr Originator of the welcome. | |
835 | + * @param[in] name Name of the message. | |
836 | + * @param[in] text The welcome message. | |
837 | + * @param[in] timestamp Timestamp of when the message was set. | |
838 | + * @param[in] flags Flags to set on welcome. | |
839 | + * @return Zero | |
cddf800b | 840 | + */ |
841 | +int | |
a87bc2c2 | 842 | +welcome_do(struct Client *cptr, struct Client *sptr, char *name, char *text, |
843 | + char *who, time_t timestamp, unsigned int flags) | |
cddf800b | 844 | +{ |
cb0b5df1 | 845 | + int nameint = atoi(name); /* transform to int */ |
846 | + int namearray = nameint - 1; /* used to test the array element */ | |
6dd3e24f | 847 | + char oldtext[TOPICLEN + 1]; /* save old text when unsetting */ |
848 | + static time_t rate; | |
849 | + | |
850 | + assert(NULL != cptr); | |
851 | + assert(NULL != sptr); | |
852 | + assert(NULL != name); | |
853 | + assert(NULL != text); | |
854 | + assert(NULL != who); | |
a87bc2c2 | 855 | + |
cb0b5df1 | 856 | + /* debug */ |
a87bc2c2 | 857 | + Debug((DEBUG_DEBUG, "welcome_do(\"%s\", \"%s\", \"%s\", \"%s\" \"%s\", %Tu, 0x%04x)", |
858 | + cli_name(cptr), cli_name(sptr), name, text, who, timestamp, flags)); | |
859 | + | |
860 | + /* check name */ | |
cb0b5df1 | 861 | + if (nameint < 1 || nameint > WELCOME_MAX_ENTRIES) { |
a87bc2c2 | 862 | + if (IsUser(sptr)) |
863 | + sendcmdto_one(&me, CMD_NOTICE, sptr, | |
864 | + "%C :WELCOME: Invalid message number %s - should between 1 and %d", | |
6c894401 | 865 | + sptr, name, WELCOME_MAX_ENTRIES); |
866 | + else | |
867 | + protocol_violation(cptr, "WELCOME: Invalid message number %s from %C", name, sptr); | |
cddf800b | 868 | + return 0; |
869 | + } | |
870 | + | |
cb0b5df1 | 871 | + /* correct namearray for local offset */ |
872 | + if (flags & WELCOME_LOCAL) | |
873 | + namearray += WELCOME_MAX_ENTRIES; | |
a87bc2c2 | 874 | + |
875 | + /* cannot unset welcome that is not set */ | |
6dd3e24f | 876 | + if (WelcomeArray[namearray].timestamp == 0 && EmptyString(text)) { |
877 | + | |
a87bc2c2 | 878 | + /* from user, throw error */ |
879 | + if (IsUser(sptr)) | |
880 | + return send_reply(sptr, ERR_NOSUCHWELCOME, name); | |
6dd3e24f | 881 | + |
882 | + /* new local welcome from server, but empty - ignore | |
883 | + * we do accept a new global welcome message that is empty | |
884 | + */ | |
a87bc2c2 | 885 | + if (flags & WELCOME_LOCAL) |
886 | + return 0; | |
a87bc2c2 | 887 | + } |
cddf800b | 888 | + |
a87bc2c2 | 889 | + /* check if there is something to change */ |
6dd3e24f | 890 | + /* we got a record for it */ |
891 | + if (WelcomeArray[namearray].timestamp != 0) { | |
892 | + | |
893 | + /* global */ | |
182f0f64 | 894 | + if (!(flags & WELCOME_LOCAL)) { |
6dd3e24f | 895 | + |
896 | + /* netburst and we got the same or a newer one | |
897 | + * | |
898 | + * we only use the timestamp for resolving conflicts in net burst | |
899 | + * outside of netburst, we simply parse whatever we get | |
900 | + * this way we will not get stuck with a welcome message set by a server | |
901 | + * running ahead with the time | |
902 | + */ | |
903 | + if (IsBurstOrBurstAck(cptr) && timestamp <= WelcomeArray[namearray].timestamp) | |
a87bc2c2 | 904 | + return 0; |
6dd3e24f | 905 | + |
906 | + /* local welcome - we use our idea of the time */ | |
cb0b5df1 | 907 | + } else |
a87bc2c2 | 908 | + timestamp = TStime(); |
cb0b5df1 | 909 | + |
a87bc2c2 | 910 | + /* compare new message with old message */ |
cb0b5df1 | 911 | + if (ircd_strcmp(text, WelcomeArray[namearray].text) == 0) { |
a87bc2c2 | 912 | + if (IsUser(sptr)) |
913 | + sendcmdto_one(&me, CMD_NOTICE, sptr, | |
4e94a910 | 914 | + "%C :WELCOME: Cannot change %s message for %s - nothing to change.", |
915 | + sptr, (flags & WELCOME_LOCAL) ? "local" : "global", name); | |
a87bc2c2 | 916 | + return 0; |
917 | + } | |
918 | + } | |
cddf800b | 919 | + |
6dd3e24f | 920 | + /* TODO: rate limited for what? max 10 welcome messages..? */ |
921 | + /* possible timestamp drift - warn ops */ | |
922 | + if (timestamp - TStime() > WELCOME_MAX_DRIFT) { | |
923 | + sendto_opmask_butone_ratelimited(0, SNO_NETWORK, &rate, | |
924 | + "Possible timestamp drift from %C; timestamp in WELCOME message is %is ahead of time", | |
925 | + IsServer(sptr) ? sptr : cli_user(sptr)->server, timestamp - TStime()); | |
926 | + | |
927 | + /* warn remote oper too */ | |
928 | + if (IsUser(sptr)) | |
929 | + sendcmdto_one(&me, CMD_NOTICE, sptr, | |
930 | + "%C :Possible timestamp drift from %C; timestamp in WELCOME message is %is ahead of time", | |
931 | + sptr, cli_user(sptr)->server, timestamp - TStime()); | |
932 | + } | |
933 | + | |
934 | + /* unsetting - do not announce, save text */ | |
935 | + if (EmptyString(text)) { | |
936 | + flags &= ~WELCOME_ANNOUNCE; | |
937 | + ircd_strncpy(oldtext, WelcomeArray[namearray].text, TOPICLEN); | |
938 | + } | |
939 | + | |
cb0b5df1 | 940 | + /* update */ |
941 | + welcome_make(namearray, text, who, timestamp); | |
942 | + | |
cb0b5df1 | 943 | + /* inform ops */ |
4e94a910 | 944 | + sendto_opmask_butone(0, SNO_OLDSNO, "%s %s%s%s WELCOME %d \"%s\" [%Tu]", |
a87bc2c2 | 945 | + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ? |
946 | + get_client_name_and_opername(sptr) : cli_name((cli_user(sptr))->server), | |
6dd3e24f | 947 | + EmptyString(text) ? "unsetting" : "changing", |
948 | + (flags & WELCOME_ANNOUNCE) ? " and announcing " : " ", | |
4e94a910 | 949 | + (flags & WELCOME_LOCAL) ? "local" : "global", |
6dd3e24f | 950 | + nameint, |
951 | + EmptyString(text) ? oldtext : WelcomeArray[namearray].text, | |
952 | + WelcomeArray[namearray].timestamp); | |
a87bc2c2 | 953 | + |
954 | + /* log it */ | |
4e94a910 | 955 | + log_write(LS_NETWORK, L_INFO, LOG_NOSNOTICE, "%#C (%s) %s%s%s WELCOME %d \"%s\" [%Tu]", |
6dd3e24f | 956 | + sptr, WelcomeArray[namearray].who, |
957 | + EmptyString(text) ? "unsetting" : "changing", | |
958 | + (flags & WELCOME_ANNOUNCE) ? " and announcing " : " ", | |
4e94a910 | 959 | + (flags & WELCOME_LOCAL) ? "local" : "global", |
6dd3e24f | 960 | + nameint, |
961 | + EmptyString(text) ? oldtext : WelcomeArray[namearray].text, | |
cb0b5df1 | 962 | + WelcomeArray[namearray].timestamp); |
a87bc2c2 | 963 | + |
964 | + /* welcome set by remote user, inform oper of success */ | |
6dd3e24f | 965 | + if ((flags & WELCOME_LOCAL) && IsUser(sptr) && !MyUser(sptr)) { |
966 | + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s %s%s local WELCOME %d \"%s\" [%Tu]", | |
967 | + sptr, get_client_name_and_opername(sptr), | |
968 | + EmptyString(text) ? "unsetting" : "changing", | |
969 | + (flags & WELCOME_ANNOUNCE) ? " and announcing" : "", | |
970 | + nameint, | |
971 | + EmptyString(text) ? oldtext : WelcomeArray[namearray].text, | |
972 | + WelcomeArray[namearray].timestamp); | |
973 | + | |
974 | + /* TODO: wallops all local changes, by both local and remote opers? */ | |
975 | + /* tell all opers about the local message being set remotely */ | |
976 | + sendwallto_group_butone(&me, WALL_WALLOPS, 0, | |
977 | + "%s %s%s local WELCOME %d \"%s\" [%Tu]", | |
978 | + get_client_name_and_opername(sptr), | |
979 | + EmptyString(text) ? "unsetting" : "changing", | |
980 | + (flags & WELCOME_ANNOUNCE) ? " and announcing" : "", | |
981 | + nameint, | |
982 | + EmptyString(text) ? oldtext : WelcomeArray[namearray].text, | |
983 | + WelcomeArray[namearray].timestamp); | |
984 | + } | |
cddf800b | 985 | + |
cb0b5df1 | 986 | + /* propagate it */ |
a87bc2c2 | 987 | + if (!(flags & WELCOME_LOCAL)) |
988 | + sendcmdto_serv_butone(sptr, CMD_WELCOME, cptr, "* %s%d %Tu %s :%s", | |
cb0b5df1 | 989 | + (flags & WELCOME_ANNOUNCE) ? "!" : "", nameint, |
990 | + WelcomeArray[namearray].timestamp, WelcomeArray[namearray].who, | |
991 | + WelcomeArray[namearray].text); | |
cddf800b | 992 | + |
a87bc2c2 | 993 | + /* announce it */ |
6dd3e24f | 994 | + if (flags & WELCOME_ANNOUNCE) |
cb0b5df1 | 995 | + welcome_announce(namearray); |
a87bc2c2 | 996 | + |
997 | + return 0; | |
cddf800b | 998 | +} |
999 | + | |
a87bc2c2 | 1000 | + |
1001 | +/** Announce a welcome message to local clients. | |
cb0b5df1 | 1002 | + * @param[in] name Welcome message to announce. |
cddf800b | 1003 | + */ |
a87bc2c2 | 1004 | +void |
cb0b5df1 | 1005 | +welcome_announce(int name) |
cddf800b | 1006 | +{ |
a87bc2c2 | 1007 | + struct Client *acptr; |
1008 | + struct MsgBuf *msgbuf; | |
6dd3e24f | 1009 | + int i; |
a87bc2c2 | 1010 | + |
cb0b5df1 | 1011 | + /* range 0 to 2 * max - 1 */ |
1012 | + assert(name >= 0 && name <= 2 * WELCOME_MAX_ENTRIES - 1); | |
a87bc2c2 | 1013 | + |
cb0b5df1 | 1014 | + /* TODO: target is $* as if it were a global broadcast |
1015 | + * could make it $servername for local message announcement | |
1016 | + * but the type is shown between [ ] already | |
1017 | + * either [Network] or [servername] - using $* is just shorter. | |
1018 | + */ | |
a87bc2c2 | 1019 | + /* build msgbuf */ |
1020 | + msgbuf = msgq_make(0, ":%C %s $* :[%s] %s", &me, MSG_NOTICE, | |
cb0b5df1 | 1021 | + name >= WELCOME_MAX_ENTRIES ? cli_name(&me) : feature_str(FEAT_NETWORK), |
1022 | + WelcomeArray[name].text); | |
a87bc2c2 | 1023 | + |
6dd3e24f | 1024 | + /* go over local clients */ |
1025 | + for (i = HighestFd; i > 0; --i) { | |
cb0b5df1 | 1026 | + |
6dd3e24f | 1027 | + /* skip unregistered clients - they see the message during login |
1028 | + * skip servers | |
a87bc2c2 | 1029 | + */ |
6dd3e24f | 1030 | + if (!(acptr = LocalClientArray[i]) || !IsRegistered(acptr) || IsServer(acptr)) |
a87bc2c2 | 1031 | + continue; |
cb0b5df1 | 1032 | + |
6dd3e24f | 1033 | + /* send it away */ |
a87bc2c2 | 1034 | + send_buffer(acptr, msgbuf, 0); |
cddf800b | 1035 | + } |
cddf800b | 1036 | +} |
1037 | + | |
a87bc2c2 | 1038 | + |
a87bc2c2 | 1039 | +/** Send the full list of welcome message to \a cptr. |
1040 | + * @param[in] cptr Local server to send welcomes to. | |
cddf800b | 1041 | + */ |
1042 | +void | |
a87bc2c2 | 1043 | +welcome_burst(struct Client *cptr) |
cddf800b | 1044 | +{ |
cb0b5df1 | 1045 | + int name; |
a87bc2c2 | 1046 | + |
6dd3e24f | 1047 | + assert(NULL != cptr); |
1048 | + | |
cb0b5df1 | 1049 | + /* loop over global entries - 0 to max - 1*/ |
1050 | + for (name = 0; name <= WELCOME_MAX_ENTRIES - 1; name++) { | |
1051 | + if (WelcomeArray[name].timestamp != 0) | |
a87bc2c2 | 1052 | + sendcmdto_one(&me, CMD_WELCOME, cptr, "* %d %Tu %s :%s", |
cb0b5df1 | 1053 | + name + 1, WelcomeArray[name].timestamp, WelcomeArray[name].who, |
1054 | + WelcomeArray[name].text); | |
cddf800b | 1055 | + } |
1056 | +} | |
1057 | + | |
a87bc2c2 | 1058 | + |
a87bc2c2 | 1059 | +/** List welcome messages. |
1060 | + * @param[in] sptr Client requesting the listing. | |
1061 | + * @param[in] connect When non zero do not report no welcome is set | |
cddf800b | 1062 | + * @return Zero. |
1063 | + */ | |
1064 | +int | |
a87bc2c2 | 1065 | +welcome_list(struct Client *sptr, int connect) |
cddf800b | 1066 | +{ |
cb0b5df1 | 1067 | + int found = 0, local = 0, name; |
a87bc2c2 | 1068 | + |
6dd3e24f | 1069 | + assert(NULL != sptr); |
1070 | + | |
cb0b5df1 | 1071 | + /* loop over all entries - range 0 to 2 * max - 1 */ |
1072 | + for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) { | |
a87bc2c2 | 1073 | + |
cb0b5df1 | 1074 | + /* local entries now */ |
1075 | + if (name == WELCOME_MAX_ENTRIES) | |
1076 | + local = 1; | |
a87bc2c2 | 1077 | + |
cb0b5df1 | 1078 | + /* not set or empty - skip */ |
6dd3e24f | 1079 | + /* TODO: EmptyString? */ |
cb0b5df1 | 1080 | + if (WelcomeArray[name].timestamp == 0 || *WelcomeArray[name].text == 0) |
a87bc2c2 | 1081 | + continue; |
cb0b5df1 | 1082 | + |
1083 | + /* got one */ | |
a87bc2c2 | 1084 | + found++; |
cb0b5df1 | 1085 | + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :[%s] %s", |
1086 | + sptr, local ? cli_name(&me) : feature_str(FEAT_NETWORK), WelcomeArray[name].text); | |
a87bc2c2 | 1087 | + } |
cb0b5df1 | 1088 | + |
1089 | + /* nothing set */ | |
a87bc2c2 | 1090 | + if (!found && !connect) |
cb0b5df1 | 1091 | + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :No welcome message set.", sptr); |
1092 | + | |
a87bc2c2 | 1093 | + return 0; |
1094 | +} | |
cddf800b | 1095 | + |
cddf800b | 1096 | + |
a87bc2c2 | 1097 | +/** Statistics callback to list Welcome messages. |
1098 | + * @param[in] sptr Client requesting statistics. | |
1099 | + * @param[in] sd Stats descriptor for request (ignored). | |
1100 | + * @param[in] param Extra parameter from user (ignored). | |
1101 | + */ | |
1102 | +void | |
1103 | +welcome_stats(struct Client *sptr, const struct StatDesc *sd, char *param) | |
1104 | +{ | |
cb0b5df1 | 1105 | + int name, local = 0; |
a87bc2c2 | 1106 | + |
6dd3e24f | 1107 | + assert(NULL != sptr); |
1108 | + | |
cb0b5df1 | 1109 | + /* loop over all entries - range 0 to 2 * max - 1*/ |
1110 | + for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) { | |
cddf800b | 1111 | + |
cb0b5df1 | 1112 | + /* local entries now */ |
1113 | + if (name == WELCOME_MAX_ENTRIES) | |
1114 | + local = 1; | |
a87bc2c2 | 1115 | + |
cb0b5df1 | 1116 | + /* not set */ |
1117 | + if (WelcomeArray[name].timestamp == 0) | |
1118 | + continue; | |
cddf800b | 1119 | + |
cb0b5df1 | 1120 | + /* send it */ |
1121 | + send_reply(sptr, RPL_STATSWELCOME, | |
6dd3e24f | 1122 | + local ? name + 1 - WELCOME_MAX_ENTRIES : name + 1, |
1123 | + local ? cli_name(&me) : "*", | |
cb0b5df1 | 1124 | + WelcomeArray[name].who, WelcomeArray[name].timestamp, |
6dd3e24f | 1125 | + EmptyString(WelcomeArray[name].text) ? "<Empty>" : WelcomeArray[name].text); |
cddf800b | 1126 | + } |
cddf800b | 1127 | +} |