]> jfr.im git - irc/quakenet/snircd-patchqueue.git/blob - welcome.patch
094222c727d4f45c94b7fa4dac697e23fb545a0b
[irc/quakenet/snircd-patchqueue.git] / welcome.patch
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:
16 :<source> WE <target> [[!]<name> <timestamp> <who> :<text>]
17 who is who set the message, the server puts in the opername when a client sets it.
18 :<name> is a number 1 to WELCOME_MAX_ENTRIES - currently set at 10 (should be more than we ever need)
19 that means there is room for 10 local and 10 global entries
20
21 STATS W/welcome (/STATS w/userload made case sensitive)
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
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
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
80 diff -r a9b437e961ec include/client.h
81 --- a/include/client.h
82 +++ b/include/client.h
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 */
87 + PRIV_WELCOME, /* oper can WELCOME */
88 + PRIV_LOCAL_WELCOME, /* oper can local WELCOME */
89 PRIV_LAST_PRIV /**< number of privileges */
90 };
91
92 diff -r a9b437e961ec include/handlers.h
93 --- a/include/handlers.h
94 +++ b/include/handlers.h
95 @@ -138,6 +138,7 @@
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*[]);
103 @@ -172,6 +173,7 @@
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*[]);
108 extern int mo_xquery(struct Client*, struct Client*, int, char*[]);
109 extern int mr_error(struct Client*, struct Client*, int, char*[]);
110 extern int mr_error(struct Client*, struct Client*, int, char*[]);
111 @@ -230,6 +232,7 @@
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*[]);
117 extern int ms_xquery(struct Client*, struct Client*, int, char*[]);
118 extern int ms_xreply(struct Client*, struct Client*, int, char*[]);
119 diff -r a9b437e961ec include/ircd_features.h
120 --- a/include/ircd_features.h
121 +++ b/include/ircd_features.h
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,
130 @@ -142,6 +143,7 @@
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,
138 diff -r a9b437e961ec include/msg.h
139 --- a/include/msg.h
140 +++ b/include/msg.h
141 @@ -196,6 +196,10 @@
142 #define TOK_NOTICE "O"
143 #define CMD_NOTICE MSG_NOTICE, TOK_NOTICE
144
145 +#define MSG_WELCOME "WELCOME" /* WELC */
146 +#define TOK_WELCOME "WE"
147 +#define CMD_WELCOME MSG_WELCOME, TOK_WELCOME
148 +
149 #define MSG_WALLCHOPS "WALLCHOPS" /* WC */
150 #define TOK_WALLCHOPS "WC"
151 #define CMD_WALLCHOPS MSG_WALLCHOPS, TOK_WALLCHOPS
152 diff -r a9b437e961ec include/numeric.h
153 --- a/include/numeric.h
154 +++ b/include/numeric.h
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 */
161
162 /* RPL_SERVICEINFO 231 unused */
163 @@ -440,6 +441,8 @@
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 */
172 diff -r a9b437e961ec include/welcome.h
173 --- /dev/null
174 +++ b/include/welcome.h
175 @@ -0,0 +1,66 @@
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
199 + * @brief Interface and declarations for welcome message handling.
200 + */
201 +#ifndef INCLUDED_sys_types_h
202 +#include <sys/types.h>
203 +#define INCLUDED_sys_types_h
204 +#endif
205 +
206 +struct Client;
207 +struct StatDesc;
208 +
209 +/* Maximum number of welcome entries (per type; X global, X local) */
210 +#define WELCOME_MAX_ENTRIES 10
211 +/* Maximum length of a welcome message */
212 +#define WELCOMELEN TOPICLEN
213 +/* Maximum timestamp drift in seconds allowed ahead of our idea of nettime
214 + * before we throw a warning to ops
215 + */
216 +#define WELCOME_MAX_DRIFT 600
217 +
218 +/* test if a welcome entry is in a valid range */
219 +#define WelcomeIsValid(x) ((x) >= 0 && (x) <= 2 * WELCOME_MAX_ENTRIES - 1)
220 +
221 +/* Describes a Welcome message entry. */
222 +struct Welcome {
223 + time_t timestamp; /**< Timestamp of the welcome */
224 + char text[WELCOMELEN + 1]; /**< Message */
225 + char who[ACCOUNTLEN + 1]; /**< Who set it */
226 +};
227 +
228 +/** Welcome type flags */
229 +#define WELCOME_LOCAL 0x01 /**< welcome is local */
230 +/** Welcome action flags */
231 +#define WELCOME_ANNOUNCE 0x02 /**< announce change to users */
232 +#define WELCOME_INSERT 0x04 /**< insert welcome message, move down all others one place */
233 +
234 +extern int welcome_do(struct Client *cptr, struct Client *sptr, char *name,
235 + time_t timestamp, char *who, char *text, unsigned int flags);
236 +extern void welcome_announce(int name);
237 +extern void welcome_burst(struct Client *cptr);
238 +extern int welcome_list(struct Client *sptr, int connect);
239 +extern void welcome_stats(struct Client *sptr, const struct StatDesc *sd, char *param);
240 +
241 +#endif /* INCLUDED_welcome_h */
242 diff -r a9b437e961ec ircd/Makefile.in
243 --- a/ircd/Makefile.in
244 +++ b/ircd/Makefile.in
245 @@ -186,6 +186,7 @@
246 m_wallops.c \
247 m_wallusers.c \
248 m_wallvoices.c \
249 + m_welcome.c \
250 m_who.c \
251 m_whois.c \
252 m_whowas.c \
253 @@ -215,6 +216,7 @@
254 send.c \
255 uping.c \
256 userload.c \
257 + welcome.c \
258 whocmds.c \
259 whowas.c \
260 y.tab.c
261 @@ -1161,6 +1163,11 @@
262 ../include/ircd_reply.h ../include/ircd_string.h \
263 ../include/ircd_chattr.h ../include/msg.h ../include/numeric.h \
264 ../include/numnicks.h ../include/s_user.h ../include/send.h
265 +m_welcome.o: m_welcome.c ../config.h ../include/channel.h \
266 + ../include/client.h ../include/hash.h ../include/ircd.h ../include/ircd_log.h \
267 + ../include/ircd_reply.h ../include/ircd_string.h ../include/msg.h \
268 + ../include/numeric.h ../include/numnicks.h ../include/s_user.h \
269 + ../include/send.h ../include/welcome.h
270 m_who.o: m_who.c ../config.h ../include/channel.h ../include/ircd_defs.h \
271 ../include/res.h ../config.h ../include/client.h ../include/dbuf.h \
272 ../include/msgq.h ../include/ircd_events.h ../include/ircd_handler.h \
273 @@ -1422,6 +1429,13 @@
274 ../include/numnicks.h ../include/querycmds.h ../include/ircd_features.h \
275 ../include/s_misc.h ../include/s_stats.h ../include/send.h \
276 ../include/struct.h ../include/sys.h
277 +welcome.o: welcome.c ../config.h ../include/client.h \
278 + ../include/hash.h ../include/ircd.h ../include/ircd_alloc.h \
279 + ../include/ircd_features.h ../include/ircd_log.h ../include/ircd_reply.h \
280 + ../include/match.h ../include/msg.h ../include/numeric.h \
281 + ../include/numnicks.h ../include/s_debug.h ../include/s_bsd.h \
282 + ../include/s_misc.h ../include/send.h ../include/struct.h \
283 + ../include/sys.h ../include/welcome.h
284 whocmds.o: whocmds.c ../config.h ../include/whocmds.h \
285 ../include/channel.h ../include/ircd_defs.h ../include/res.h \
286 ../config.h ../include/client.h ../include/dbuf.h ../include/msgq.h \
287 diff -r a9b437e961ec ircd/client.c
288 --- a/ircd/client.c
289 +++ b/ircd/client.c
290 @@ -177,6 +177,7 @@
291 FlagSet(&privs_local, PRIV_WHOX);
292 FlagSet(&privs_local, PRIV_DISPLAY);
293 FlagSet(&privs_local, PRIV_FORCE_LOCAL_OPMODE);
294 + FlagSet(&privs_local, PRIV_LOCAL_WELCOME);
295
296 privs_defaults_set = 1;
297 }
298 @@ -223,6 +224,7 @@
299 ClrPriv(client, PRIV_JUPE);
300 ClrPriv(client, PRIV_OPMODE);
301 ClrPriv(client, PRIV_BADCHAN);
302 + ClrPriv(client, PRIV_WELCOME);
303 }
304 }
305
306 @@ -244,7 +246,7 @@
307 P(CHANSERV), P(XTRA_OPER), P(NOIDLE), P(FREEFORM),
308 P(PARANOID), P(CHECK), P(WALL), P(CLOSE),
309 P(ROUTE), P(ROUTEINFO), P(SERVERINFO), P(CHANNEL_PRIVACY),
310 - P(USER_PRIVACY),
311 + P(USER_PRIVACY), P(WELCOME), P(LOCAL_WELCOME),
312 #undef P
313 { 0, 0 }
314 };
315 diff -r a9b437e961ec ircd/ircd_features.c
316 --- a/ircd/ircd_features.c
317 +++ b/ircd/ircd_features.c
318 @@ -366,6 +366,7 @@
319 F_I(IRCD_RES_TIMEOUT, 0, 4, 0),
320 F_I(AUTH_TIMEOUT, 0, 9, 0),
321 F_B(ANNOUNCE_INVITES, 0, 0, 0),
322 + F_B(WELCOME, 0, 1, 0),
323
324 /* features that affect all operators */
325 F_B(EXTENDED_CHECKCMD, 0, 0, 0),
326 @@ -407,6 +408,7 @@
327 F_B(HIS_STATS_u, 0, 1, 0),
328 F_B(HIS_STATS_U, 0, 1, 0),
329 F_B(HIS_STATS_v, 0, 1, 0),
330 + F_B(HIS_STATS_W, 0, 1, 0),
331 F_B(HIS_STATS_w, 0, 1, 0),
332 F_B(HIS_STATS_x, 0, 1, 0),
333 F_B(HIS_STATS_y, 0, 1, 0),
334 diff -r a9b437e961ec ircd/ircd_lexer.l
335 --- a/ircd/ircd_lexer.l
336 +++ b/ircd/ircd_lexer.l
337 @@ -166,6 +166,8 @@
338 { "serverinfo", TPRIV_SERVERINFO },
339 { "user_privacy", TPRIV_USER_PRIVACY },
340 { "channel_privacy", TPRIV_CHANNEL_PRIVACY },
341 + { "local_welcome", TPRIV_LOCAL_WELCOME },
342 + { "welcome", TPRIV_WELCOME },
343 { NULL, 0 }
344 };
345 static int ntokens;
346 diff -r a9b437e961ec ircd/ircd_parser.y
347 --- a/ircd/ircd_parser.y
348 +++ b/ircd/ircd_parser.y
349 @@ -189,6 +189,7 @@
350 %token TPRIV_CHANSERV TPRIV_XTRA_OPER TPRIV_NOIDLE TPRIV_FREEFORM TPRIV_PARANOID
351 %token TPRIV_CHECK TPRIV_WALL TPRIV_CLOSE TPRIV_ROUTE TPRIV_ROUTEINFO TPRIV_SERVERINFO
352 %token TPRIV_CHANNEL_PRIVACY TPRIV_USER_PRIVACY TPRIV_LIST_CHAN
353 +%token TPRIV_LOCAL_WELCOME TPRIV_WELCOME
354 /* and some types... */
355 %type <num> sizespec
356 %type <num> timespec timefactor factoredtimes factoredtime
357 @@ -703,6 +704,8 @@
358 TPRIV_SERVERINFO { $$ = PRIV_SERVERINFO ; } |
359 TPRIV_CHANNEL_PRIVACY { $$ = PRIV_CHANNEL_PRIVACY ; } |
360 TPRIV_USER_PRIVACY { $$ = PRIV_USER_PRIVACY ; } |
361 + TPRIV_LOCAL_WELCOME { $$ = PRIV_LOCAL_WELCOME; } |
362 + TPRIV_WELCOME { $$ = PRIV_WELCOME; } |
363 TPRIV_PARANOID { $$ = PRIV_PARANOID; } ;
364 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
365
366 diff -r a9b437e961ec ircd/m_welcome.c
367 --- /dev/null
368 +++ b/ircd/m_welcome.c
369 @@ -0,0 +1,296 @@
370 +/*
371 + * IRC - Internet Relay Chat, ircd/m_welcome.c
372 + * Copyright (C) 1990 Jarkko Oikarinen and
373 + * University of Oulu, Computing Center
374 + *
375 + * See file AUTHORS in IRC package for additional names of
376 + * the programmers.
377 + *
378 + * This program is free software; you can redistribute it and/or modify
379 + * it under the terms of the GNU General Public License as published by
380 + * the Free Software Foundation; either version 1, or (at your option)
381 + * any later version.
382 + *
383 + * This program is distributed in the hope that it will be useful,
384 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
385 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
386 + * GNU General Public License for more details.
387 + *
388 + * You should have received a copy of the GNU General Public License
389 + * along with this program; if not, write to the Free Software
390 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
391 + *
392 + */
393 +
394 +/*
395 + * m_functions execute protocol messages on this server:
396 + *
397 + * cptr is always NON-NULL, pointing to a *LOCAL* client
398 + * structure (with an open socket connected!). This
399 + * identifies the physical socket where the message
400 + * originated (or which caused the m_function to be
401 + * executed--some m_functions may call others...).
402 + *
403 + * sptr is the source of the message, defined by the
404 + * prefix part of the message if present. If not
405 + * or prefix not found, then sptr==cptr.
406 + *
407 + * (!IsServer(cptr)) => (cptr == sptr), because
408 + * prefixes are taken *only* from servers...
409 + *
410 + * (IsServer(cptr))
411 + * (sptr == cptr) => the message didn't
412 + * have the prefix.
413 + *
414 + * (sptr != cptr && IsServer(sptr) means
415 + * the prefix specified servername. (?)
416 + *
417 + * (sptr != cptr && !IsServer(sptr) means
418 + * that message originated from a remote
419 + * user (not local).
420 + *
421 + * combining
422 + *
423 + * (!IsServer(sptr)) means that, sptr can safely
424 + * taken as defining the target structure of the
425 + * message in this server.
426 + *
427 + * *Always* true (if 'parse' and others are working correct):
428 + *
429 + * 1) sptr->from == cptr (note: cptr->from == cptr)
430 + *
431 + * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
432 + * *cannot* be a local connection, unless it's
433 + * actually cptr!). [MyConnect(x) should probably
434 + * be defined as (x == x->from) --msa ]
435 + *
436 + * parc number of variable parameter strings (if zero,
437 + * parv is allowed to be NULL)
438 + *
439 + * parv a NULL terminated list of parameter pointers,
440 + *
441 + * parv[0], sender (prefix string), if not present
442 + * this points to an empty string.
443 + * parv[1]...parv[parc-1]
444 + * pointers to additional parameters
445 + * parv[parc] == NULL, *always*
446 + *
447 + * note: it is guaranteed that parv[0]..parv[parc-1] are all
448 + * non-NULL pointers.
449 + */
450 +#include "config.h"
451 +
452 +#include "channel.h"
453 +#include "client.h"
454 +#include "hash.h"
455 +#include "ircd.h"
456 +#include "ircd_features.h"
457 +#include "ircd_log.h"
458 +#include "ircd_reply.h"
459 +#include "ircd_snprintf.h"
460 +#include "ircd_string.h"
461 +#include "msg.h"
462 +#include "numeric.h"
463 +#include "numnicks.h"
464 +#include "s_user.h"
465 +#include "send.h"
466 +#include "welcome.h"
467 +
468 +/* #include <assert.h> -- Now using assert in ircd_log.h */
469 +
470 +/*
471 + * m_welcome - local generic message handler
472 + *
473 + * parv[0] = Send prefix
474 + * parv[1] = [remote server to query]
475 + */
476 +int m_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
477 +{
478 + /* feature disabled */
479 + if (!feature_bool(FEAT_WELCOME))
480 + return send_reply(sptr, ERR_DISABLED, "WELCOME");
481 +
482 + /* only opers can set the welcome messages */
483 + if (parc > 2)
484 + return send_reply(sptr, ERR_NOPRIVILEGES);
485 +
486 + /* remote listing request, see if it is for me or a remote server
487 + * check FEAT_HIS_REMOTE to decide if an ordinary user can do this
488 + */
489 + if ((parc > 1) && (hunt_server_cmd(sptr, CMD_WELCOME, cptr, feature_int(FEAT_HIS_REMOTE),
490 + "%C", 1, parc, parv) != HUNTED_ISME))
491 + return 0;
492 +
493 + /* local listing */
494 + return welcome_list(sptr, 0);
495 +}
496 +
497 +
498 +/*
499 + * mo_welcome - oper message handler
500 + *
501 + * listing:
502 + * parv[0] = Send prefix
503 + *
504 + * remote listing:
505 + * parv[0] = Send prefix
506 + * parv[1] = Target
507 + *
508 + * set global or on remote server:
509 + * parv[0] = Send prefix
510 + * parv[1] = Target: server or * for global (or left out for this server)
511 + * parv[2] = Name
512 + * parv[3] = Text
513 + */
514 +int mo_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
515 +{
516 + char *target, *name, *who, *text, pattern[BUFSIZE];
517 + time_t timestamp;
518 + unsigned int flags = 0;
519 + int local = 0;
520 +
521 + /* feature disabled */
522 + if (!feature_bool(FEAT_WELCOME))
523 + return send_reply(sptr, ERR_DISABLED, "WELCOME");
524 +
525 + /* TODO: move feature check here? */
526 + /* remote listing request, see if it is for me or a remote server */
527 + if ((parc == 2) && (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C", 1, parc, parv) != HUNTED_ISME))
528 + return 0;
529 +
530 + /* local listing */
531 + if (parc <= 2)
532 + return welcome_list(sptr, 0);
533 +
534 + /* check PRIVS */
535 + /* local - need PRIV LOCAL_WELCOME or WELCOME */
536 + if (parc == 3 && !HasPriv(sptr,PRIV_LOCAL_WELCOME) && !HasPriv(sptr,PRIV_WELCOME))
537 + return send_reply(sptr, ERR_NOPRIVILEGES);
538 +
539 + /* global or remote - need PRIV WELCOME */
540 + if (parc >= 4 && !HasPriv(sptr,PRIV_WELCOME))
541 + return send_reply(sptr, ERR_NOPRIVILEGES);
542 +
543 + /* set the parameters */
544 +
545 + /* target not given, only name - setting local welcome */
546 + if (parc < 4) {
547 + local++;
548 + target = cli_name(&me);
549 + name = parv[1];
550 + flags |= WELCOME_LOCAL;
551 +
552 + /* target and name given */
553 + } else {
554 + target = parv[1];
555 + name = parv[2];
556 + }
557 + timestamp = TStime();
558 + who = cli_user(sptr)->opername;
559 + text = parv[parc - 1];
560 +
561 + /* target is not global */
562 + if (!(target[0] == '*' && target[1] == '\0') && !local) {
563 +
564 + /* build a pattern for hunt_server_cmd since we do not have all we need in parv */
565 + ircd_snprintf(0, pattern, sizeof(pattern), "%s %s %Tu %s :%s", "%C", name, timestamp, who, text);
566 + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, pattern, 1, 2, parv) != HUNTED_ISME)
567 + return 0;
568 +
569 + /* else it is a local welcome, for me */
570 + flags |= WELCOME_LOCAL;
571 + }
572 +
573 + /* TODO: disallow global announcement from oper?
574 + * as PRIVMSG/NOTICE to $* is not allowed either by the ircd
575 + * when PRIV for that is added, use that here? PRIV_BROADCAST or something
576 + *
577 + * change prefix to $ ?
578 + */
579 + /* check for anounce prefix */
580 + if (*name == '!') {
581 + name++;
582 + flags |= WELCOME_ANNOUNCE;
583 + }
584 +
585 + /* check for insert prefix */
586 + if (*name == '+') {
587 + name++;
588 + flags |= WELCOME_INSERT;
589 + }
590 +
591 + /* and do it */
592 + return welcome_do(cptr, sptr, name, timestamp, who, text, flags);
593 +}
594 +
595 +
596 +/*
597 + * ms_welcome - server message handler
598 + *
599 + * parv[0] = Send prefix
600 + * parv[1] = Target: server numeric or * for global
601 + * parv[2] = Name
602 + * parv[3] = Timestamp
603 + * parv[4] = Who
604 + * parv[5] = Text
605 + */
606 +int ms_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
607 +{
608 + char *target, *name, *who, *text;
609 + time_t timestamp;
610 + unsigned int flags = 0;
611 +
612 + /* not enough - complain */
613 + if (parc < 2) {
614 + protocol_violation(sptr, "Too few parameters for WELCOME (got %d - need 2)", parc);
615 + return need_more_params(sptr, "WELCOME");
616 + }
617 +
618 + /* remote listing request, see if it is for me or a remote server */
619 + if (parc == 2) {
620 + if (IsServer(sptr))
621 + return protocol_violation(cptr, "WELCOME listing request from server %C", sptr);
622 + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C", 1, parc, parv) != HUNTED_ISME)
623 + return 0;
624 + return welcome_list(sptr, 0);
625 + }
626 +
627 + /* we need at least 6 parameters to continue - complain */
628 + if (parc < 6) {
629 + protocol_violation(sptr, "Too few parameters for WELCOME (got %d - need 6)", parc);
630 + return need_more_params(sptr, "WELCOME");
631 + }
632 +
633 + /* set the parameters */
634 + target = parv[1];
635 + name = parv[2];
636 + timestamp = atoi(parv[3]);
637 + who = parv[4];
638 + text = parv[parc - 1]; /* parse reason as last parameter */
639 +
640 + /* target is not global */
641 + if (!(target[0] == '*' && target[1] == '\0')) {
642 +
643 + /* not for me, and forward it */
644 + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C %s %s %s :%s", 1, parc, parv) != HUNTED_ISME)
645 + return 0;
646 +
647 + /* local welcome for me */
648 + flags |= WELCOME_LOCAL;
649 + }
650 +
651 + /* check for anounce prefix */
652 + if (*name == '!') {
653 + name++;
654 + flags |= WELCOME_ANNOUNCE;
655 + }
656 +
657 + /* check for insert prefix */
658 + if (*name == '+') {
659 + name++;
660 + flags |= WELCOME_INSERT;
661 + }
662 +
663 + /* and do it */
664 + return welcome_do(cptr, sptr, name, timestamp, who, text, flags);
665 +}
666 diff -r a9b437e961ec ircd/parse.c
667 --- a/ircd/parse.c
668 +++ b/ircd/parse.c
669 @@ -661,6 +661,15 @@
670 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
671 { m_unregistered, m_not_oper, ms_check, mo_check, m_ignore }
672 },
673 +
674 + /* add command for WELCOME */
675 + {
676 + MSG_WELCOME,
677 + TOK_WELCOME,
678 + 0, MAXPARA, MFLG_SLOW, 0, NULL,
679 + /* UNREG, CLIENT, SERVER, OPER, SERVICE, HELP */
680 + { m_unregistered, m_welcome, ms_welcome, mo_welcome, m_ignore }
681 + },
682
683 /* This command is an alias for QUIT during the unregistered part of
684 * of the server. This is because someone jumping via a broken web
685 diff -r a9b437e961ec ircd/s_err.c
686 --- a/ircd/s_err.c
687 +++ b/ircd/s_err.c
688 @@ -486,7 +486,7 @@
689 /* 226 */
690 { RPL_STATSALINE, "%s", "226" },
691 /* 227 */
692 - { 0 },
693 + { RPL_STATSWELCOME, "W %d %s %s %Tu :%s", "227" },
694 /* 228 */
695 { RPL_STATSQLINE, "Q %s :%s", "228" },
696 /* 229 */
697 @@ -1050,7 +1050,7 @@
698 /* 508 */
699 { 0 },
700 /* 509 */
701 - { 0 },
702 + { ERR_NOSUCHWELCOME, "%s :No such welcome", "509" },
703 /* 510 */
704 { 0 },
705 /* 511 */
706 diff -r a9b437e961ec ircd/s_serv.c
707 --- a/ircd/s_serv.c
708 +++ b/ircd/s_serv.c
709 @@ -57,6 +57,7 @@
710 #include "struct.h"
711 #include "sys.h"
712 #include "userload.h"
713 +#include "welcome.h"
714
715 /* #include <assert.h> -- Now using assert in ircd_log.h */
716 #include <stdlib.h>
717 @@ -196,6 +197,7 @@
718 */
719 gline_burst(cptr);
720 jupe_burst(cptr);
721 + welcome_burst(cptr);
722
723 /*
724 * Pass on my client information to the new server
725 diff -r a9b437e961ec ircd/s_stats.c
726 --- a/ircd/s_stats.c
727 +++ b/ircd/s_stats.c
728 @@ -54,6 +54,7 @@
729 #include "send.h"
730 #include "struct.h"
731 #include "userload.h"
732 +#include "welcome.h"
733
734 #include <stdio.h>
735 #include <stdlib.h>
736 @@ -654,9 +655,12 @@
737 { 'V', "vserversmach", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS), FEAT_HIS_STATS_v,
738 stats_servers_verbose, 0,
739 "Verbose server information." },
740 - { 'w', "userload", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_w,
741 + { 'w', "userload", STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS, FEAT_HIS_STATS_w,
742 calc_load, 0,
743 "Userload statistics." },
744 + { 'W', "welcome", STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS, FEAT_HIS_STATS_W,
745 + welcome_stats, 0,
746 + "Welcome messages." },
747 { 'x', "memusage", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_x,
748 stats_meminfo, 0,
749 "List usage information." },
750 diff -r a9b437e961ec ircd/s_user.c
751 --- a/ircd/s_user.c
752 +++ b/ircd/s_user.c
753 @@ -63,6 +63,7 @@
754 #include "userload.h"
755 #include "version.h"
756 #include "whowas.h"
757 +#include "welcome.h"
758
759 #include "handlers.h" /* m_motd and m_lusers */
760
761 @@ -410,6 +411,9 @@
762 cli_info(sptr), NumNick(cptr) /* two %s's */);
763
764 IPcheck_connect_succeeded(sptr);
765 +
766 + if (feature_bool(FEAT_WELCOME))
767 + welcome_list(sptr, 1);
768 }
769 else {
770 struct Client *acptr = user->server;
771 diff -r a9b437e961ec ircd/welcome.c
772 --- /dev/null
773 +++ b/ircd/welcome.c
774 @@ -0,0 +1,596 @@
775 +/*
776 + * IRC - Internet Relay Chat, ircd/welcome.c
777 + * Copyright (C) 1990 Jarkko Oikarinen and
778 + * University of Oulu, Finland
779 + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
780 + *
781 + * This program is free software; you can redistribute it and/or modify
782 + * it under the terms of the GNU General Public License as published by
783 + * the Free Software Foundation; either version 1, or (at your option)
784 + * any later version.
785 + *
786 + * This program is distributed in the hope that it will be useful,
787 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
788 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
789 + * GNU General Public License for more details.
790 + *
791 + * You should have received a copy of the GNU General Public License
792 + * along with this program; if not, write to the Free Software
793 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
794 + */
795 +/** @file
796 + * @brief Implementation of welcome message handling functions.
797 + */
798 +#include "config.h"
799 +
800 +#include "client.h"
801 +#include "hash.h"
802 +#include "ircd.h"
803 +#include "ircd_alloc.h"
804 +#include "ircd_features.h"
805 +#include "ircd_log.h"
806 +#include "ircd_reply.h"
807 +#include "ircd_string.h"
808 +#include "match.h"
809 +#include "msg.h"
810 +#include "numeric.h"
811 +#include "numnicks.h"
812 +#include "s_bsd.h"
813 +#include "s_debug.h"
814 +#include "s_misc.h"
815 +#include "send.h"
816 +#include "struct.h"
817 +#include "sys.h" /* FALSE bleah */
818 +#include "welcome.h"
819 +
820 +/* #include <assert.h> -- Now using assert in ircd_log.h */
821 +#include <string.h>
822 +
823 +
824 +/** List of welcome messages - first MAX for global, second MAX for local */
825 +static struct Welcome WelcomeArray[WELCOME_MAX_ENTRIES * 2] = { { 0 } };
826 +
827 +
828 +/** Allocate a new welcome with the given parameters.
829 + * @param[in] name Name of the welcome message.
830 + * @param[in] text The welcome message.
831 + * @param[in] who Who set it.
832 + * @param[in] timestamp When it was set.
833 + * @return name Array number of the welcome set.
834 + */
835 +static int
836 +welcome_make(int name, char *text, char *who, time_t timestamp)
837 +{
838 + /* valid range */
839 + assert(WelcomeIsValid(name));
840 +
841 + /* store it */
842 + ircd_strncpy(WelcomeArray[name].text, text, WELCOMELEN);
843 + ircd_strncpy(WelcomeArray[name].who, who, ACCOUNTLEN);
844 + WelcomeArray[name].timestamp = timestamp;
845 +
846 + return name;
847 +}
848 +
849 +
850 +/** Propagate a welcome message.
851 + * @param[in] cptr Local client that sent us the welcome.
852 + * @param[in] sptr Originator of the welcome.
853 + * @param[in] nameint Name of the message.
854 + * @param[in] timestamp Timestamp of when the message was set.
855 + * @param[in] who Who set this message.
856 + * @param[in] text The welcome message.
857 + * @param[in] flags Flags to set on welcome.
858 + * @return Zero
859 + */
860 +int
861 +welcome_propagate(struct Client *cptr, struct Client *sptr, int nameint,
862 + time_t timestamp, char *who, char *text, unsigned int flags)
863 +{
864 + /* must be global */
865 + assert(!(flags & WELCOME_LOCAL));
866 +
867 + sendcmdto_serv_butone(sptr, CMD_WELCOME, cptr, "* %s%s%d %Tu %s :%s",
868 + (flags & WELCOME_ANNOUNCE) ? "!" : "", (flags & WELCOME_INSERT) ? "+" : "",
869 + nameint, timestamp, who, text);
870 +
871 + return 0;
872 +}
873 +
874 +
875 +/** Log a welcome message.
876 + * @param[in] sptr Originator of the welcome.
877 + * @param[in] msg The message to show.
878 + * @param[in] flags Flags to set on welcome.
879 + * @return Zero
880 + */
881 +int
882 +welcome_log(struct Client *sptr, char *msg, unsigned int flags)
883 +{
884 +
885 + /* inform ops */
886 + sendto_opmask_butone(0, SNO_OLDSNO, "%s %s",
887 + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
888 + get_client_name_and_opername(sptr) : cli_name((cli_user(sptr))->server), msg);
889 +
890 + /* log it */
891 + log_write(LS_NETWORK, L_INFO, LOG_NOSNOTICE, "%s %s", get_client_name_and_opername(sptr), msg);
892 +
893 + /* welcome by remote user, inform oper of success */
894 + if ((flags & WELCOME_LOCAL) && IsUser(sptr) && !MyUser(sptr)) {
895 + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s %s",
896 + sptr, get_client_name_and_opername(sptr), msg);
897 +
898 + /* TODO: wallops all local changes, by both local and remote opers? */
899 + /* tell all opers about the local message being set remotely */
900 + sendwallto_group_butone(&me, WALL_WALLOPS, 0, "%s %s", get_client_name_and_opername(sptr), msg);
901 + }
902 +
903 + return 0;
904 +}
905 +
906 +
907 +/** Set a welcome message.
908 + * @param[in] cptr Local client that sent us the welcome.
909 + * @param[in] sptr Originator of the welcome.
910 + * @param[in] nameint Name of the message.
911 + * @param[in] namearray Array entry.
912 + * @param[in] timestamp Timestamp of when the message was set.
913 + * @param[in] who Who set this message.
914 + * @param[in] text The message.
915 + * @param[in] flags Flags to set on welcome.
916 + * @return Zero
917 + */
918 +int
919 +welcome_set(struct Client *cptr, struct Client *sptr, int nameint,
920 + int namearray, time_t timestamp, char *who, char *text, unsigned int flags)
921 +{
922 + char msg[BUFSIZE]; /* msg for logging */
923 + int new = 0;
924 +
925 + /* debug */
926 + Debug((DEBUG_DEBUG, "welcome_set(\"%s\", \"%s\", %d, %d, %Tu, \"%s\", \"%s\", 0x%04x)",
927 + cli_name(cptr), cli_name(sptr), nameint, namearray, timestamp, who, text, flags));
928 +
929 + /* not set */
930 + if (*WelcomeArray[namearray].text == 0)
931 + new = 1;
932 +
933 + /* update */
934 + welcome_make(namearray, text, who, timestamp);
935 +
936 + /* create msg for log */
937 + ircd_snprintf(0, msg, 0, "%s%s%s WELCOME %d \"%s\" %s [%Tu]",
938 + new ? "setting" : "changing",
939 + (flags & WELCOME_ANNOUNCE) ? " and announcing " : " ",
940 + (flags & WELCOME_LOCAL) ? "local" : "global",
941 + nameint, text, who, timestamp);
942 +
943 + /* log it */
944 + welcome_log(sptr, msg, flags);
945 +
946 + /* propagate it */
947 + if (!(flags & WELCOME_LOCAL))
948 + welcome_propagate(cptr, sptr, nameint, timestamp, who, text, flags);
949 +
950 + /* announce it */
951 + if (flags & WELCOME_ANNOUNCE)
952 + welcome_announce(namearray);
953 +
954 + return 0;
955 +}
956 +
957 +
958 +/** Unset a welcome message.
959 + * @param[in] cptr Local client that sent us the welcome.
960 + * @param[in] sptr Originator of the welcome.
961 + * @param[in] nameint Name of the message.
962 + * @param[in] namearray Array entry.
963 + * @param[in] timestamp Timestamp of when the message was set.
964 + * @param[in] who Who set this message.
965 + * @param[in] flags Flags to set on welcome.
966 + * @return Zero
967 + */
968 +int
969 +welcome_unset(struct Client *cptr, struct Client *sptr, int nameint,
970 + int namearray, time_t timestamp, char *who, unsigned int flags)
971 +{
972 + char msg[BUFSIZE]; /* msg for logging */
973 + char text[WELCOMELEN + 1]; /* save old text */
974 + int i; /* loop variable */
975 + int empty = namearray; /* first empty spot in array after arrayname */
976 + int end = WELCOME_MAX_ENTRIES -1; /* last element to check in array */
977 +
978 + /* debug */
979 + Debug((DEBUG_DEBUG, "welcome_unset(\"%s\", \"%s\", %d, %d, %Tu, \"%s\", 0x%04x)",
980 + cli_name(cptr), cli_name(sptr), nameint, namearray, timestamp, who, flags));
981 +
982 + /* save text */
983 + ircd_strncpy(text, WelcomeArray[namearray].text, WELCOMELEN);
984 +
985 + /* update */
986 + welcome_make(namearray, "", who, timestamp);
987 +
988 + /* create msg for log */
989 + ircd_snprintf(0, msg, 0, "unsetting %s WELCOME %d \"%s\" %s [%Tu]",
990 + (flags & WELCOME_LOCAL) ? "local" : "global", nameint, text, who, timestamp);
991 +
992 + /* log it */
993 + welcome_log(sptr, msg, flags);
994 +
995 + /* propagate it, but not when inserting */
996 + if (!(flags & (WELCOME_LOCAL|WELCOME_INSERT)))
997 + welcome_propagate(cptr, sptr, nameint, timestamp, who, "", flags);
998 +
999 + /* correct end for local offset */
1000 + if (flags & WELCOME_LOCAL)
1001 + end += WELCOME_MAX_ENTRIES;
1002 +
1003 + /* move entries up, update timestamp */
1004 + for (i = namearray; i < end; i++)
1005 + welcome_make(i, WelcomeArray[i+1].text, WelcomeArray[i+1].who, timestamp);
1006 +
1007 + /* clear last entry, update timestamp */
1008 + welcome_make(end, "", who, timestamp);
1009 +
1010 + return 0;
1011 +}
1012 +
1013 +
1014 +/** Insert a welcome message.
1015 + * @param[in] cptr Local client that sent us the welcome.
1016 + * @param[in] sptr Originator of the welcome.
1017 + * @param[in] nameint Name of the message.
1018 + * @param[in] namearray Array entry.
1019 + * @param[in] timestamp Timestamp of when the message was set.
1020 + * @param[in] who Who set this message.
1021 + * @param[in] text The welcome message.
1022 + * @param[in] flags Flags to set on welcome.
1023 + * @return Zero
1024 + */
1025 +int
1026 +welcome_insert(struct Client *cptr, struct Client *sptr, int nameint,
1027 + int namearray, time_t timestamp, char *who, char *text, unsigned int flags)
1028 +{
1029 + char msg[BUFSIZE]; /* msg for logging */
1030 + int i; /* loop variable */
1031 + int empty = -1; /* first empty spot in array after arrayname */
1032 + int end = WELCOME_MAX_ENTRIES -1; /* last element to check in array */
1033 + int last = end; /* last welcome message to feed to welcome_unset */
1034 +
1035 + /* debug */
1036 + Debug((DEBUG_DEBUG, "welcome_insert(\"%s\", \"%s\", %d, %d, %Tu, \"%s\", \"%s\", 0x%04x)",
1037 + cli_name(cptr), cli_name(sptr), nameint, namearray, timestamp, who, text, flags));
1038 +
1039 + /* correct end for local offset */
1040 + if (flags & WELCOME_LOCAL)
1041 + end += WELCOME_MAX_ENTRIES;
1042 +
1043 + /* find first empty spot */
1044 + for (i = namearray; i <= end; i++) {
1045 + if (*WelcomeArray[i].text == 0) {
1046 + empty = i;
1047 + break;
1048 + }
1049 + }
1050 +
1051 + /* no empty spot, need to unset last */
1052 + if (empty == -1) {
1053 + welcome_unset(cptr, sptr, end, namearray, timestamp, who, flags);
1054 + empty = end;
1055 + }
1056 +
1057 + /* move entries down, update timestamp */
1058 + for (i = empty; i > namearray; i--)
1059 + welcome_make(i, WelcomeArray[i-1].text, WelcomeArray[i-1].who, timestamp);
1060 +
1061 + /* correct empty for local offset */
1062 + if (flags & WELCOME_LOCAL)
1063 + empty -= WELCOME_MAX_ENTRIES;
1064 +
1065 + /* create msg for log */
1066 + if (nameint == empty)
1067 + ircd_snprintf(0, msg, 0, "moving %s WELCOME message %d one place down",
1068 + (flags & WELCOME_LOCAL) ? "local" : "global", nameint);
1069 + else
1070 + ircd_snprintf(0, msg, 0, "moving %s WELCOME message %d %s %d one place down",
1071 + (flags & WELCOME_LOCAL) ? "local" : "global", nameint, (empty - nameint > 1) ? "to" : "and" , empty);
1072 +
1073 + /* log it */
1074 + welcome_log(sptr, msg, flags);
1075 +
1076 + /* set it */
1077 + welcome_set(cptr, sptr, nameint, namearray, timestamp, who, text, flags);
1078 +
1079 + return 0;
1080 +}
1081 +
1082 +
1083 +/** Change a welcome message.
1084 + * @param[in] cptr Local client that sent us the welcome.
1085 + * @param[in] sptr Originator of the welcome.
1086 + * @param[in] name Name of the message.
1087 + * @param[in] timestamp Timestamp of when the message was set.
1088 + * @param[in] who Who set this message.
1089 + * @param[in] text The welcome message.
1090 + * @param[in] flags Flags to set on welcome.
1091 + * @return Zero
1092 + */
1093 +int
1094 +welcome_do(struct Client *cptr, struct Client *sptr, char *name,
1095 + time_t timestamp, char *who, char *text, unsigned int flags)
1096 +{
1097 + int nameint = atoi(name); /* transform to int */
1098 + int namearray = nameint - 1; /* used to test the array element */
1099 + int max = WELCOME_MAX_ENTRIES; /* max number of entries */
1100 + static time_t rate; /* rate limit snomask message */
1101 +
1102 + assert(NULL != cptr);
1103 + assert(NULL != sptr);
1104 + assert(NULL != name);
1105 + assert(NULL != text);
1106 + assert(NULL != who);
1107 +
1108 + /* debug */
1109 + Debug((DEBUG_DEBUG, "welcome_do(\"%s\", \"%s\", \"%s\", %Tu, \"%s\", \"%s\", 0x%04x)",
1110 + cli_name(cptr), cli_name(sptr), name, timestamp, who, text, flags));
1111 +
1112 + /* if for some reason timestamp is 0, increase it */
1113 + if (timestamp == 0)
1114 + timestamp++;
1115 +
1116 + /* name empty after taking off the prefixes? */
1117 + if (EmptyString(name)) {
1118 + if (IsUser(sptr))
1119 + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :WELCOME: No message number given", sptr);
1120 + else
1121 + protocol_violation(cptr, "WELCOME: No message number given by %C", sptr);
1122 + return 0;
1123 + }
1124 +
1125 + /* check name */
1126 + if (!WelcomeIsValid(namearray)) {
1127 + if (IsUser(sptr))
1128 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1129 + "%C :WELCOME: Invalid message number %s - should between 1 and %d",
1130 + sptr, name, max);
1131 + else {
1132 + protocol_violation(cptr, "WELCOME: Invalid message number %s from %C - should be between 1 and %d",
1133 + name, sptr, max);
1134 + /* nameint greater than max, perhaps we are upgrading, but used extra slots too soon?
1135 + * propagate it manually
1136 + * TODO: cant do announce here?
1137 + */
1138 + if (nameint > max && !(flags & WELCOME_LOCAL))
1139 + welcome_propagate(cptr, sptr, nameint, timestamp, who, text, flags);
1140 + }
1141 + return 0;
1142 + }
1143 +
1144 + /* source is user, and is myuser or welcome is local, check length of the message */
1145 + if ((IsUser(sptr)) && ((MyUser(sptr)) || (flags & WELCOME_LOCAL)) && (strlen(text) > WELCOMELEN)) {
1146 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1147 + "%C :WELCOME: The message is too long with %d chars - max is %d chars",
1148 + sptr, strlen(text), WELCOMELEN);
1149 + ircd_strncpy(text, text, WELCOMELEN);
1150 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1151 + "%C :WELCOME: Change or truncate the message to: \"%s\"", sptr, text);
1152 + return 0;
1153 + }
1154 +
1155 + /* correct namearray for local offset */
1156 + if (flags & WELCOME_LOCAL)
1157 + namearray += WELCOME_MAX_ENTRIES;
1158 +
1159 + /* must be true by now */
1160 + assert(WelcomeIsValid(namearray));
1161 +
1162 + /* cannot unset welcome that is not set */
1163 + if (WelcomeArray[namearray].timestamp == 0 && EmptyString(text)) {
1164 +
1165 + /* from user, throw error */
1166 + if (IsUser(sptr))
1167 + return send_reply(sptr, ERR_NOSUCHWELCOME, name);
1168 +
1169 + /* new local welcome from server, but empty - ignore
1170 + * we do accept a new global welcome message that is empty
1171 + */
1172 + if (flags & WELCOME_LOCAL)
1173 + return 0;
1174 + }
1175 +
1176 + /* check if there is something to change */
1177 + /* we got a record for it */
1178 + if (WelcomeArray[namearray].timestamp != 0) {
1179 +
1180 + /* global */
1181 + if (!(flags & WELCOME_LOCAL)) {
1182 +
1183 + /* netburst and we got the same or a newer one
1184 + *
1185 + * we only use the timestamp for resolving conflicts in net burst
1186 + * outside of netburst, we simply parse whatever we get
1187 + * this way we will not get stuck with a welcome message set by a server
1188 + * running ahead with the time
1189 + */
1190 + if (IsBurstOrBurstAck(cptr) && timestamp <= WelcomeArray[namearray].timestamp)
1191 + return 0;
1192 +
1193 + /* local welcome - we use our idea of the time */
1194 + } else
1195 + timestamp = TStime();
1196 +
1197 + /* compare new message with old message */
1198 + if (ircd_strcmp(text, WelcomeArray[namearray].text) == 0) {
1199 + if (IsUser(sptr))
1200 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1201 + "%C :WELCOME: Cannot change %s message for %s - nothing to change.",
1202 + sptr, (flags & WELCOME_LOCAL) ? "local" : "global", name);
1203 + return 0;
1204 + }
1205 + }
1206 +
1207 + /* do not insert for last global/local entry and when not set yet */
1208 + if ((flags & WELCOME_INSERT) && ((WelcomeArray[namearray].timestamp == 0) || (nameint == max)))
1209 + flags &= ~WELCOME_INSERT;
1210 +
1211 + /* TODO: rate limited for what? max 10 welcome messages..? */
1212 + /* possible timestamp drift - warn ops */
1213 + if (timestamp - TStime() > WELCOME_MAX_DRIFT) {
1214 + sendto_opmask_butone_ratelimited(0, SNO_NETWORK, &rate,
1215 + "Possible timestamp drift from %C; timestamp in WELCOME message is %is ahead of time",
1216 + IsServer(sptr) ? sptr : cli_user(sptr)->server, timestamp - TStime());
1217 +
1218 + /* warn remote oper too */
1219 + if (IsUser(sptr))
1220 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1221 + "%C :Possible timestamp drift from %C; timestamp in WELCOME message is %is ahead of time",
1222 + sptr, cli_user(sptr)->server, timestamp - TStime());
1223 + }
1224 +
1225 + /* unset */
1226 + if (EmptyString(text)) {
1227 + /* clear insert flag,
1228 + * when this flag is set, welcome_unset() assumes it is being called from welcome_insert()
1229 + * and wont propagate the change
1230 + */
1231 + flags &= ~WELCOME_INSERT;
1232 + return welcome_unset(cptr, sptr, nameint, namearray, timestamp, who, flags);
1233 + }
1234 +
1235 + /* insert */
1236 + if (flags & WELCOME_INSERT)
1237 + return welcome_insert(cptr, sptr, nameint, namearray, timestamp, who, text, flags);
1238 +
1239 + /* new or change */
1240 + return welcome_set(cptr, sptr, nameint, namearray, timestamp, who, text, flags);
1241 +}
1242 +
1243 +
1244 +/** Announce a welcome message to local clients.
1245 + * @param[in] name Welcome message to announce.
1246 + */
1247 +void
1248 +welcome_announce(int name)
1249 +{
1250 + struct Client *acptr;
1251 + struct MsgBuf *msgbuf;
1252 + int i;
1253 +
1254 + /* valid range */
1255 + assert(WelcomeIsValid(name));
1256 +
1257 + /* TODO: target is $* as if it were a global broadcast
1258 + * could make it $servername for local message announcement
1259 + * but the type is shown between [ ] already
1260 + * either [Network] or [servername] - using $* is just shorter.
1261 + */
1262 + /* build msgbuf */
1263 + msgbuf = msgq_make(0, ":%C %s $* :[%s] %s", &me, MSG_NOTICE,
1264 + name >= WELCOME_MAX_ENTRIES ? cli_name(&me) : feature_str(FEAT_NETWORK),
1265 + WelcomeArray[name].text);
1266 +
1267 + /* go over local clients */
1268 + for (i = HighestFd; i > 0; --i) {
1269 +
1270 + /* skip unregistered clients - they see the message during login
1271 + * skip servers
1272 + */
1273 + if (!(acptr = LocalClientArray[i]) || !IsRegistered(acptr) || IsServer(acptr))
1274 + continue;
1275 +
1276 + /* send it away */
1277 + send_buffer(acptr, msgbuf, 0);
1278 + }
1279 +}
1280 +
1281 +
1282 +/** Send the full list of welcome message to \a cptr.
1283 + * @param[in] cptr Local server to send welcomes to.
1284 + */
1285 +void
1286 +welcome_burst(struct Client *cptr)
1287 +{
1288 + int name;
1289 +
1290 + assert(NULL != cptr);
1291 +
1292 + /* loop over global entries - 0 to max - 1*/
1293 + for (name = 0; name <= WELCOME_MAX_ENTRIES - 1; name++) {
1294 + if (WelcomeArray[name].timestamp != 0)
1295 + sendcmdto_one(&me, CMD_WELCOME, cptr, "* %d %Tu %s :%s",
1296 + name + 1, WelcomeArray[name].timestamp, WelcomeArray[name].who,
1297 + WelcomeArray[name].text);
1298 + }
1299 +}
1300 +
1301 +
1302 +/** List welcome messages.
1303 + * @param[in] sptr Client requesting the listing.
1304 + * @param[in] connect When non zero do not report no welcome is set
1305 + * @return Zero.
1306 + */
1307 +int
1308 +welcome_list(struct Client *sptr, int connect)
1309 +{
1310 + int found = 0, local = 0, name;
1311 +
1312 + assert(NULL != sptr);
1313 +
1314 + /* loop over all entries - range 0 to 2 * max - 1 */
1315 + for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) {
1316 +
1317 + /* local entries now */
1318 + if (name == WELCOME_MAX_ENTRIES)
1319 + local = 1;
1320 +
1321 + /* not set or empty - skip */
1322 + /* TODO: EmptyString? */
1323 + if (WelcomeArray[name].timestamp == 0 || *WelcomeArray[name].text == 0)
1324 + continue;
1325 +
1326 + /* got one */
1327 + found++;
1328 + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :[%s] %s",
1329 + sptr, local ? cli_name(&me) : feature_str(FEAT_NETWORK), WelcomeArray[name].text);
1330 + }
1331 +
1332 + /* nothing set */
1333 + if (!found && !connect)
1334 + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :No welcome message set.", sptr);
1335 +
1336 + return 0;
1337 +}
1338 +
1339 +
1340 +/** Statistics callback to list Welcome messages.
1341 + * @param[in] sptr Client requesting statistics.
1342 + * @param[in] sd Stats descriptor for request (ignored).
1343 + * @param[in] param Extra parameter from user (ignored).
1344 + */
1345 +void
1346 +welcome_stats(struct Client *sptr, const struct StatDesc *sd, char *param)
1347 +{
1348 + int name, local = 0;
1349 +
1350 + assert(NULL != sptr);
1351 +
1352 + /* loop over all entries - range 0 to 2 * max - 1*/
1353 + for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) {
1354 +
1355 + /* local entries now */
1356 + if (name == WELCOME_MAX_ENTRIES)
1357 + local = 1;
1358 +
1359 + /* not set */
1360 + if (WelcomeArray[name].timestamp == 0)
1361 + continue;
1362 +
1363 + /* send it */
1364 + send_reply(sptr, RPL_STATSWELCOME,
1365 + local ? name + 1 - WELCOME_MAX_ENTRIES : name + 1,
1366 + local ? cli_name(&me) : "*",
1367 + WelcomeArray[name].who, WelcomeArray[name].timestamp,
1368 + EmptyString(WelcomeArray[name].text) ? "<Empty>" : WelcomeArray[name].text);
1369 + }
1370 +}