1 Add welcome message functionality.
6 shows welcome messages set, same is shown on connect
7 feature HIS_REMOTE controls whether ordinary users can request a listing from a remote server
10 /WELCOME [<server>] [[$][+]<N> :<message>]
11 to view welcome messages from a remote server
12 to set a local welcome message on this server or a remote server
13 set a global welcome message (server *)
14 the $ prefix makes the server annouce the welcome message to its clients when setting
15 the + prefix moves message in N and all after that one spot down, and inserts the new message
16 in spot N, if there is no room, the last entry is deleted
17 when an entry is cleared (no text), then all entries after it are moved on place up, so all empty
21 :<source> WE <target> [[$][+]<N> <timestamp> <who> :<text>]
22 who is who set the message, the server puts in the opername when a client sets it.
23 :<N> is a number 1 to WELCOME_MAX_ENTRIES - currently set at 10 (should be more than we ever need)
24 that means there is room for 10 local and 10 global entries
26 STATS W/welcome (/STATS w/userload made case sensitive)
27 :server 230 nick W Name Target Who Timestamp :Message
28 :server 227 nick W 1 * opername 1233072583 :Latest news: testing this welcome patch :)
29 :server 227 nick W 2 * opername 1233072583 :
30 :server 227 nick W 1 servername opername 1233072590 :This is a test server, expect restarts.
31 :server 219 nick W :End of /STATS report
33 listing welcomes or on connect:
34 :server NOTICE nick :[QuakeNet] Latest news: testing this welcome patch :)
35 :server NOTICE nick :[server] This is a test server, expect restarts.
37 announcement is done by a notice by the local server to $* ($servername for local) with the same message
38 format as for listing welcome messages.
39 :server NOTICE $* :[QuakeNet] Latest news: testing this welcome patch :)
40 :server NOTICE $server :[server] This is a test server, expect restarts.
46 add m_welcome mo_welcome ms_welcome functions
50 add features FEAT_WELCOME and FEAT_HIS_STATS_W
53 add MSG_WELCOME TOK_WELCOME CMD_WELCOME
56 add welcome message functions
60 add RPL_STATSWELCOME ERR_NOSUCHWELCOME
68 add welcome.c and m_welcome.c files
71 add burst welcome message
77 add showing of welcome messages on connect
80 add count and memusage of welcome messages
86 add PRIV_LOCAL_WELCOME PRIV_WELCOME
88 diff -r 8bf1b05cdfe7 include/client.h
89 --- a/include/client.h
90 +++ b/include/client.h
92 PRIV_USER_PRIVACY, /* oper can bypass user privacy +x etc gives i.e. see real ip's */
93 PRIV_CHANNEL_PRIVACY, /* oper can bypass channel privacy i.e. can see modes on channels they are not on and channel keys */
94 PRIV_SERVERINFO, /* oper can use /get, /stats, /hash, retrieve remote information */
95 + PRIV_WELCOME, /* oper can WELCOME */
96 + PRIV_LOCAL_WELCOME, /* oper can local WELCOME */
97 PRIV_LAST_PRIV /**< number of privileges */
100 diff -r 8bf1b05cdfe7 include/handlers.h
101 --- a/include/handlers.h
102 +++ b/include/handlers.h
104 extern int m_version(struct Client*, struct Client*, int, char*[]);
105 extern int m_wallchops(struct Client*, struct Client*, int, char*[]);
106 extern int m_wallvoices(struct Client*, struct Client*, int, char*[]);
107 +extern int m_welcome(struct Client*, struct Client*, int, char*[]);
108 extern int m_who(struct Client*, struct Client*, int, char*[]);
109 extern int m_whois(struct Client*, struct Client*, int, char*[]);
110 extern int m_whowas(struct Client*, struct Client*, int, char*[]);
112 extern int mo_version(struct Client*, struct Client*, int, char*[]);
113 extern int mo_wallops(struct Client*, struct Client*, int, char*[]);
114 extern int mo_wallusers(struct Client*, struct Client*, int, char*[]);
115 +extern int mo_welcome(struct Client*, struct Client*, int, char*[]);
116 extern int mo_xquery(struct Client*, struct Client*, int, char*[]);
117 extern int mr_error(struct Client*, struct Client*, int, char*[]);
118 extern int mr_error(struct Client*, struct Client*, int, char*[]);
120 extern int ms_wallops(struct Client*, struct Client*, int, char*[]);
121 extern int ms_wallusers(struct Client*, struct Client*, int, char*[]);
122 extern int ms_wallvoices(struct Client*, struct Client*, int, char*[]);
123 +extern int ms_welcome(struct Client*, struct Client*, int, char*[]);
124 extern int ms_whois(struct Client*, struct Client*, int, char*[]);
125 extern int ms_xquery(struct Client*, struct Client*, int, char*[]);
126 extern int ms_xreply(struct Client*, struct Client*, int, char*[]);
127 diff -r 8bf1b05cdfe7 include/ircd_features.h
128 --- a/include/ircd_features.h
129 +++ b/include/ircd_features.h
131 FEAT_IRCD_RES_TIMEOUT,
133 FEAT_ANNOUNCE_INVITES,
136 /* features that affect all operators */
137 FEAT_EXTENDED_CHECKCMD,
146 diff -r 8bf1b05cdfe7 include/msg.h
150 #define TOK_NOTICE "O"
151 #define CMD_NOTICE MSG_NOTICE, TOK_NOTICE
153 +#define MSG_WELCOME "WELCOME" /* WELC */
154 +#define TOK_WELCOME "WE"
155 +#define CMD_WELCOME MSG_WELCOME, TOK_WELCOME
157 #define MSG_WALLCHOPS "WALLCHOPS" /* WC */
158 #define TOK_WALLCHOPS "WC"
159 #define CMD_WALLCHOPS MSG_WALLCHOPS, TOK_WALLCHOPS
160 diff -r 8bf1b05cdfe7 include/numeric.h
161 --- a/include/numeric.h
162 +++ b/include/numeric.h
164 RPL_STATSGLINE 227 Dalnet
165 RPL_STATSVLINE 227 unreal */
166 #define RPL_STATSALINE 226 /* Hybrid, Undernet */
167 +#define RPL_STATSWELCOME 227 /* QuakeNet extension */
168 #define RPL_STATSQLINE 228 /* Undernet extension */
170 /* RPL_SERVICEINFO 231 unused */
172 /* ERR_GHOSTEDCLIENT 503 efnet */
173 /* ERR_VWORLDWARN 503 austnet */
175 +#define ERR_NOSUCHWELCOME 509 /* QuakeNet extension */
177 #define ERR_SILELISTFULL 511 /* Undernet extension */
178 /* ERR_NOTIFYFULL 512 aircd */
179 /* ERR_TOOMANYWATCH 512 Numeric List: Dalnet */
180 diff -r 8bf1b05cdfe7 include/welcome.h
182 +++ b/include/welcome.h
184 +#ifndef INCLUDED_welcome_h
185 +#define INCLUDED_welcome_h
187 + * IRC - Internet Relay Chat, include/welcome.h
188 + * Copyright (C) 1990 Jarkko Oikarinen and
189 + * University of Oulu, Computing Center
190 + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
192 + * This program is free software; you can redistribute it and/or modify
193 + * it under the terms of the GNU General Public License as published by
194 + * the Free Software Foundation; either version 2, or (at your option)
195 + * any later version.
197 + * This program is distributed in the hope that it will be useful,
198 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
199 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
200 + * GNU General Public License for more details.
202 + * You should have received a copy of the GNU General Public License
203 + * along with this program; if not, write to the Free Software
204 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
207 + * @brief Interface and declarations for welcome message handling.
213 +/* Maximum number of welcome entries (per type; X global, X local) */
214 +#define WELCOME_MAX_ENTRIES 10
215 +/* Maximum length of a welcome message */
216 +#define WELCOMELEN TOPICLEN
219 +/* Test if a welcome entry is in a valid range */
220 +#define WelcomeArrayIsValid(x) ((unsigned) (x) <= 2 * WELCOME_MAX_ENTRIES -1)
221 +/* Test if a welcome name is in a valid range */
222 +#define WelcomeNameIsValid(x) ((unsigned) (x) <= WELCOME_MAX_ENTRIES)
223 +/* Test if a welcome entry is set */
224 +#define WelcomeIsSet(x) (WelcomeArray[(x)].lastmod > 0)
225 +/* Test if a welcome entry is empty */
226 +#define WelcomeIsEmpty(x) (*WelcomeArray[(x)].text == 0)
228 +/* Get welcome create timestamp */
229 +#define WelcomeCreate(x) (WelcomeArray[(x)].create)
230 +/* Get welcome lastmod timestamp */
231 +#define WelcomeLastMod(x) (WelcomeArray[(x)].lastmod)
232 +/* Get welcome who info */
233 +#define WelcomeWho(x) (WelcomeArray[(x)].who)
234 +/* Get welcome text */
235 +#define WelcomeText(x) (WelcomeArray[(x)].text)
238 +/* Describes a Welcome message entry. */
240 + time_t create; /**< When it was set */
241 + time_t lastmod; /**< Last modification timestamp (used for resolving conflicts in burst) */
242 + char text[WELCOMELEN + 1]; /**< Message */
243 + char who[ACCOUNTLEN + 1]; /**< Who set it */
246 +/** Welcome type flags */
247 +#define WELCOME_LOCAL 0x01 /**< welcome is local */
248 +/** Welcome action flags */
249 +#define WELCOME_ANNOUNCE 0x02 /**< announce new welcome to users */
250 +#define WELCOME_INSERT 0x04 /**< insert welcome message, move down all others one place */
251 +#define WELCOME_DELETE 0x08 /**< delete welcome message, move up all others one place */
252 +#define WELCOME_INCLASTMOD 0x10 /**< increase lastmod if needed */
254 +extern int welcome_do(struct Client *cptr, struct Client *sptr, char *name,
255 + time_t create, time_t lastmod, char *who, char *text, unsigned int flags);
256 +extern void welcome_burst(struct Client *cptr);
257 +extern int welcome_list(struct Client *sptr, int connect);
258 +extern void welcome_stats(struct Client *sptr, const struct StatDesc *sd, char *param);
259 +extern int welcome_memory_count(size_t *we_size);
261 +#endif /* INCLUDED_welcome_h */
262 diff -r 8bf1b05cdfe7 ircd/Makefile.in
263 --- a/ircd/Makefile.in
264 +++ b/ircd/Makefile.in
281 @@ -1161,6 +1163,11 @@
282 ../include/ircd_reply.h ../include/ircd_string.h \
283 ../include/ircd_chattr.h ../include/msg.h ../include/numeric.h \
284 ../include/numnicks.h ../include/s_user.h ../include/send.h
285 +m_welcome.o: m_welcome.c ../config.h ../include/channel.h \
286 + ../include/client.h ../include/hash.h ../include/ircd.h ../include/ircd_log.h \
287 + ../include/ircd_reply.h ../include/ircd_string.h ../include/msg.h \
288 + ../include/numeric.h ../include/numnicks.h ../include/s_user.h \
289 + ../include/send.h ../include/welcome.h
290 m_who.o: m_who.c ../config.h ../include/channel.h ../include/ircd_defs.h \
291 ../include/res.h ../config.h ../include/client.h ../include/dbuf.h \
292 ../include/msgq.h ../include/ircd_events.h ../include/ircd_handler.h \
293 @@ -1422,6 +1429,13 @@
294 ../include/numnicks.h ../include/querycmds.h ../include/ircd_features.h \
295 ../include/s_misc.h ../include/s_stats.h ../include/send.h \
296 ../include/struct.h ../include/sys.h
297 +welcome.o: welcome.c ../config.h ../include/client.h \
298 + ../include/hash.h ../include/ircd.h ../include/ircd_alloc.h \
299 + ../include/ircd_features.h ../include/ircd_log.h ../include/ircd_reply.h \
300 + ../include/match.h ../include/msg.h ../include/numeric.h \
301 + ../include/numnicks.h ../include/s_debug.h ../include/s_bsd.h \
302 + ../include/s_misc.h ../include/send.h ../include/struct.h \
303 + ../include/sys.h ../include/welcome.h
304 whocmds.o: whocmds.c ../config.h ../include/whocmds.h \
305 ../include/channel.h ../include/ircd_defs.h ../include/res.h \
306 ../config.h ../include/client.h ../include/dbuf.h ../include/msgq.h \
307 diff -r 8bf1b05cdfe7 ircd/client.c
311 FlagSet(&privs_local, PRIV_WHOX);
312 FlagSet(&privs_local, PRIV_DISPLAY);
313 FlagSet(&privs_local, PRIV_FORCE_LOCAL_OPMODE);
314 + FlagSet(&privs_local, PRIV_LOCAL_WELCOME);
316 privs_defaults_set = 1;
319 ClrPriv(client, PRIV_JUPE);
320 ClrPriv(client, PRIV_OPMODE);
321 ClrPriv(client, PRIV_BADCHAN);
322 + ClrPriv(client, PRIV_WELCOME);
327 P(CHANSERV), P(XTRA_OPER), P(NOIDLE), P(FREEFORM),
328 P(PARANOID), P(CHECK), P(WALL), P(CLOSE),
329 P(ROUTE), P(ROUTEINFO), P(SERVERINFO), P(CHANNEL_PRIVACY),
331 + P(USER_PRIVACY), P(WELCOME), P(LOCAL_WELCOME),
335 diff -r 8bf1b05cdfe7 ircd/ircd_features.c
336 --- a/ircd/ircd_features.c
337 +++ b/ircd/ircd_features.c
339 F_I(IRCD_RES_TIMEOUT, 0, 4, 0),
340 F_I(AUTH_TIMEOUT, 0, 9, 0),
341 F_B(ANNOUNCE_INVITES, 0, 0, 0),
342 + F_B(WELCOME, 0, 1, 0),
344 /* features that affect all operators */
345 F_B(EXTENDED_CHECKCMD, 0, 0, 0),
347 F_B(HIS_STATS_u, 0, 1, 0),
348 F_B(HIS_STATS_U, 0, 1, 0),
349 F_B(HIS_STATS_v, 0, 1, 0),
350 + F_B(HIS_STATS_W, 0, 1, 0),
351 F_B(HIS_STATS_w, 0, 1, 0),
352 F_B(HIS_STATS_x, 0, 1, 0),
353 F_B(HIS_STATS_y, 0, 1, 0),
354 diff -r 8bf1b05cdfe7 ircd/ircd_lexer.l
355 --- a/ircd/ircd_lexer.l
356 +++ b/ircd/ircd_lexer.l
358 { "serverinfo", TPRIV_SERVERINFO },
359 { "user_privacy", TPRIV_USER_PRIVACY },
360 { "channel_privacy", TPRIV_CHANNEL_PRIVACY },
361 + { "local_welcome", TPRIV_LOCAL_WELCOME },
362 + { "welcome", TPRIV_WELCOME },
366 diff -r 8bf1b05cdfe7 ircd/ircd_parser.y
367 --- a/ircd/ircd_parser.y
368 +++ b/ircd/ircd_parser.y
370 %token TPRIV_CHANSERV TPRIV_XTRA_OPER TPRIV_NOIDLE TPRIV_FREEFORM TPRIV_PARANOID
371 %token TPRIV_CHECK TPRIV_WALL TPRIV_CLOSE TPRIV_ROUTE TPRIV_ROUTEINFO TPRIV_SERVERINFO
372 %token TPRIV_CHANNEL_PRIVACY TPRIV_USER_PRIVACY TPRIV_LIST_CHAN
373 +%token TPRIV_LOCAL_WELCOME TPRIV_WELCOME
374 /* and some types... */
376 %type <num> timespec timefactor factoredtimes factoredtime
378 TPRIV_SERVERINFO { $$ = PRIV_SERVERINFO ; } |
379 TPRIV_CHANNEL_PRIVACY { $$ = PRIV_CHANNEL_PRIVACY ; } |
380 TPRIV_USER_PRIVACY { $$ = PRIV_USER_PRIVACY ; } |
381 + TPRIV_LOCAL_WELCOME { $$ = PRIV_LOCAL_WELCOME; } |
382 + TPRIV_WELCOME { $$ = PRIV_WELCOME; } |
383 TPRIV_PARANOID { $$ = PRIV_PARANOID; } ;
384 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
386 diff -r 8bf1b05cdfe7 ircd/m_welcome.c
388 +++ b/ircd/m_welcome.c
391 + * IRC - Internet Relay Chat, ircd/m_welcome.c
392 + * Copyright (C) 1990 Jarkko Oikarinen and
393 + * University of Oulu, Computing Center
395 + * See file AUTHORS in IRC package for additional names of
398 + * This program is free software; you can redistribute it and/or modify
399 + * it under the terms of the GNU General Public License as published by
400 + * the Free Software Foundation; either version 1, or (at your option)
401 + * any later version.
403 + * This program is distributed in the hope that it will be useful,
404 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
405 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
406 + * GNU General Public License for more details.
408 + * You should have received a copy of the GNU General Public License
409 + * along with this program; if not, write to the Free Software
410 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
415 + * m_functions execute protocol messages on this server:
417 + * cptr is always NON-NULL, pointing to a *LOCAL* client
418 + * structure (with an open socket connected!). This
419 + * identifies the physical socket where the message
420 + * originated (or which caused the m_function to be
421 + * executed--some m_functions may call others...).
423 + * sptr is the source of the message, defined by the
424 + * prefix part of the message if present. If not
425 + * or prefix not found, then sptr==cptr.
427 + * (!IsServer(cptr)) => (cptr == sptr), because
428 + * prefixes are taken *only* from servers...
431 + * (sptr == cptr) => the message didn't
434 + * (sptr != cptr && IsServer(sptr) means
435 + * the prefix specified servername. (?)
437 + * (sptr != cptr && !IsServer(sptr) means
438 + * that message originated from a remote
439 + * user (not local).
443 + * (!IsServer(sptr)) means that, sptr can safely
444 + * taken as defining the target structure of the
445 + * message in this server.
447 + * *Always* true (if 'parse' and others are working correct):
449 + * 1) sptr->from == cptr (note: cptr->from == cptr)
451 + * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
452 + * *cannot* be a local connection, unless it's
453 + * actually cptr!). [MyConnect(x) should probably
454 + * be defined as (x == x->from) --msa ]
456 + * parc number of variable parameter strings (if zero,
457 + * parv is allowed to be NULL)
459 + * parv a NULL terminated list of parameter pointers,
461 + * parv[0], sender (prefix string), if not present
462 + * this points to an empty string.
463 + * parv[1]...parv[parc-1]
464 + * pointers to additional parameters
465 + * parv[parc] == NULL, *always*
467 + * note: it is guaranteed that parv[0]..parv[parc-1] are all
468 + * non-NULL pointers.
473 +#include "ircd_features.h"
475 +#include "numeric.h"
477 +#include "welcome.h"
481 + * m_welcome - local generic message handler
487 + * parv[0] = Send prefix
490 + * WELCOME [<server>]
493 + * parv[0] = Send prefix
497 +int m_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
499 + /* feature disabled */
500 + if (!feature_bool(FEAT_WELCOME))
501 + return send_reply(sptr, ERR_DISABLED, "WELCOME");
503 + /* only opers can set the welcome messages */
505 + return send_reply(sptr, ERR_NOPRIVILEGES);
507 + /* remote listing request, see if it is for me or a remote server
508 + * check FEAT_HIS_REMOTE to decide if an ordinary user can do this
510 + if ((parc > 1) && (hunt_server_cmd(sptr, CMD_WELCOME, cptr, feature_int(FEAT_HIS_REMOTE),
511 + "%C", 1, parc, parv) != HUNTED_ISME))
514 + /* local listing */
515 + return welcome_list(sptr, 0);
520 + * mo_welcome - oper message handler
526 + * parv[0] = Send prefix
532 + * parv[0] = Send prefix
536 + * WELCOME <server> <name> :<text>
538 + * set global or on remote server:
539 + * parv[0] = Send prefix
540 + * parv[1] = Target: server or * for global (or left out for this server)
545 +int mo_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
547 + char *target, *name, *who, *text, pattern[BUFSIZE];
548 + time_t create, lastmod;
549 + unsigned int flags = 0;
552 + /* feature disabled */
553 + if (!feature_bool(FEAT_WELCOME))
554 + return send_reply(sptr, ERR_DISABLED, "WELCOME");
556 + /* TODO: move feature check here? */
557 + /* remote listing request, see if it is for me or a remote server */
558 + if ((parc == 2) && (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C", 1, parc, parv) != HUNTED_ISME))
561 + /* local listing */
563 + return welcome_list(sptr, 0);
566 + /* local - need PRIV LOCAL_WELCOME or WELCOME */
567 + if (parc == 3 && !HasPriv(sptr,PRIV_LOCAL_WELCOME) && !HasPriv(sptr,PRIV_WELCOME))
568 + return send_reply(sptr, ERR_NOPRIVILEGES);
570 + /* global or remote - need PRIV WELCOME */
571 + if (parc >= 4 && !HasPriv(sptr,PRIV_WELCOME))
572 + return send_reply(sptr, ERR_NOPRIVILEGES);
574 + /* set the parameters */
576 + /* target not given, only name - setting local welcome */
579 + target = cli_name(&me);
581 + flags |= WELCOME_LOCAL;
583 + /* target and name given */
589 + lastmod = TStime();
590 + who = cli_user(sptr)->opername;
591 + text = parv[parc - 1];
593 + /* target is not global */
594 + if (!(target[0] == '*' && target[1] == '\0') && !local) {
596 + /* build a pattern for hunt_server_cmd since we do not have all we need in parv */
597 + ircd_snprintf(0, pattern, sizeof(pattern), "%s %s %Tu %Tu %s :%s", "%C", name, create, lastmod, who, text);
598 + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, pattern, 1, 2, parv) != HUNTED_ISME)
601 + /* else it is a local welcome, for me */
602 + flags |= WELCOME_LOCAL;
605 + /* check for anounce prefix */
606 + if (*name == '$') {
608 + /* only allow announce by oper for local welcome */
609 + if (flags & WELCOME_LOCAL)
610 + flags |= WELCOME_ANNOUNCE;
613 + /* check for insert prefix */
614 + if (*name == '+') {
616 + flags |= WELCOME_INSERT;
619 + /* check for delete prefix */
620 + else if (*name == '-') {
622 + flags |= WELCOME_DELETE;
625 + /* empty text, set WELCOME_DELETE flag */
627 + flags |= WELCOME_DELETE;
630 + return welcome_do(cptr, sptr, name, create, lastmod, who, text, flags);
635 + * ms_welcome - server message handler
638 + * <source> WE <target>
641 + * parv[0] = Send prefix
642 + * parv[1] = Target: server numeric or * for global
645 + * <source> WE <target> <name> <create> <lastmod> <who> :<text>
647 + * set global or on remote server:
648 + * parv[0] = Send prefix
649 + * parv[1] = Target: server numeric or * for global
652 + * parv[4] = LastMod
657 +int ms_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
659 + char *target, *name, *who, *text;
660 + time_t create, lastmod;
661 + unsigned int flags = 0;
663 + /* not enough - complain */
665 + protocol_violation(cptr, "Received too few parameters for WELCOME from %C (got %d - need 2)", sptr, parc);
666 + return need_more_params(sptr, "WELCOME");
669 + /* remote listing request, see if it is for me or a remote server */
671 + if (IsServer(sptr))
672 + return protocol_violation(cptr, "Received WELCOME listing request from server %C", sptr);
673 + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C", 1, parc, parv) != HUNTED_ISME)
675 + return welcome_list(sptr, 0);
678 + /* we need at least 7 parameters to continue - complain */
680 + protocol_violation(cptr, "Received too few parameters for WELCOME from %C (got %d - need 7)", sptr, parc);
681 + return need_more_params(sptr, "WELCOME");
684 + /* set the parameters */
687 + create = atoi(parv[3]);
688 + lastmod = atoi(parv[4]);
690 + text = parv[parc - 1]; /* parse reason as last parameter */
692 + /* target is not global */
693 + if (!(target[0] == '*' && target[1] == '\0')) {
695 + /* not for me, and forward it */
696 + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C %s %s %s %s :%s", 1, parc, parv) != HUNTED_ISME)
699 + /* local welcome for me */
700 + flags |= WELCOME_LOCAL;
703 + /* check for anounce prefix */
704 + if (*name == '$') {
706 + flags |= WELCOME_ANNOUNCE;
709 + /* check for insert prefix */
710 + if (*name == '+') {
712 + flags |= WELCOME_INSERT;
715 + /* check for delete prefix */
716 + else if (*name == '-') {
718 + flags |= WELCOME_DELETE;
722 + return welcome_do(cptr, sptr, name, create, lastmod, who, text, flags);
724 diff -r 8bf1b05cdfe7 ircd/parse.c
728 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
729 { m_unregistered, m_not_oper, ms_check, mo_check, m_ignore }
732 + /* add command for WELCOME */
736 + 0, MAXPARA, MFLG_SLOW, 0, NULL,
737 + /* UNREG, CLIENT, SERVER, OPER, SERVICE, HELP */
738 + { m_unregistered, m_welcome, ms_welcome, mo_welcome, m_ignore }
741 /* This command is an alias for QUIT during the unregistered part of
742 * of the server. This is because someone jumping via a broken web
743 diff -r 8bf1b05cdfe7 ircd/s_debug.c
750 +#include "welcome.h"
753 /* #include <assert.h> -- Now using assert in ircd_log.h */
755 aw = 0, /* aways set */
756 wwa = 0, /* whowas aways */
758 - ju = 0; /* jupes */
759 + ju = 0, /* jupes */
760 + we = 0; /* welcomes */
762 size_t chm = 0, /* memory used by channels */
763 chbm = 0, /* memory used by channel bans */
765 wwm = 0, /* whowas array memory used */
766 glm = 0, /* memory used by glines */
767 jum = 0, /* memory used by jupes */
768 + wem = 0, /* memory used by welcomes */
769 com = 0, /* memory used by conf lines */
770 dbufs_allocated = 0, /* memory used by dbufs */
771 dbufs_used = 0, /* memory used by dbufs */
773 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
774 ":Glines %d(%zu) Jupes %d(%zu)", gl, glm, ju, jum);
776 + we = welcome_memory_count(&wem);
777 + send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
778 + ":Welcomes %d(%zu)", we, wem);
780 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
781 ":Hash: client %d(%zu), chan is the same", HASHSIZE,
782 sizeof(void *) * HASHSIZE);
783 diff -r 8bf1b05cdfe7 ircd/s_err.c
788 { RPL_STATSALINE, "%s", "226" },
791 + { RPL_STATSWELCOME, "W %d %s %s %Tu %Tu :%s", "227" },
793 { RPL_STATSQLINE, "Q %s :%s", "228" },
795 @@ -1050,7 +1050,7 @@
800 + { ERR_NOSUCHWELCOME, "%s :No such welcome", "509" },
804 diff -r 8bf1b05cdfe7 ircd/s_serv.c
810 #include "userload.h"
811 +#include "welcome.h"
813 /* #include <assert.h> -- Now using assert in ircd_log.h */
819 + welcome_burst(cptr);
822 * Pass on my client information to the new server
823 diff -r 8bf1b05cdfe7 ircd/s_stats.c
829 #include "userload.h"
830 +#include "welcome.h"
835 { 'V', "vserversmach", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS), FEAT_HIS_STATS_v,
836 stats_servers_verbose, 0,
837 "Verbose server information." },
838 - { 'w', "userload", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_w,
839 + { 'w', "userload", STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS, FEAT_HIS_STATS_w,
841 "Userload statistics." },
842 + { 'W', "welcome", STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS, FEAT_HIS_STATS_W,
844 + "Welcome messages." },
845 { 'x', "memusage", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_x,
847 "List usage information." },
848 diff -r 8bf1b05cdfe7 ircd/s_user.c
852 #include "userload.h"
855 +#include "welcome.h"
857 #include "handlers.h" /* m_motd and m_lusers */
861 IPcheck_connect_succeeded(sptr);
864 + if (feature_bool(FEAT_WELCOME))
865 + welcome_list(sptr, 1);
868 /* apply auto sethost if needed */
869 apply_spoofblock(sptr);
870 diff -r 8bf1b05cdfe7 ircd/welcome.c
875 + * IRC - Internet Relay Chat, ircd/welcome.c
876 + * Copyright (C) 1990 Jarkko Oikarinen and
877 + * University of Oulu, Finland
878 + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
880 + * This program is free software; you can redistribute it and/or modify
881 + * it under the terms of the GNU General Public License as published by
882 + * the Free Software Foundation; either version 1, or (at your option)
883 + * any later version.
885 + * This program is distributed in the hope that it will be useful,
886 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
887 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
888 + * GNU General Public License for more details.
890 + * You should have received a copy of the GNU General Public License
891 + * along with this program; if not, write to the Free Software
892 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
895 + * @brief Implementation of welcome message handling functions.
900 +#include "ircd_features.h"
901 +#include "ircd_log.h"
902 +#include "ircd_reply.h"
903 +#include "ircd_string.h"
905 +#include "numeric.h"
907 +#include "s_debug.h"
909 +#include "welcome.h"
912 +/** List of welcome messages - first MAX for global, second MAX for local */
913 +static struct Welcome WelcomeArray[WELCOME_MAX_ENTRIES * 2] = { { 0 } };
916 +/** Allocate a new welcome with the given parameters.
917 + * @param[in] name Name of the welcome message.
918 + * @param[in] text The welcome message.
919 + * @param[in] who Who set it.
920 + * @param[in] create When it was set.
921 + * @param[in] lastmod Last modification timestamp.
922 + * @return name Array number of the welcome set.
925 +welcome_make(int name, char *text, char *who, time_t create, time_t lastmod, unsigned int flags)
929 + assert(WelcomeArrayIsValid(name));
930 + assert(NULL != text);
931 + assert(NULL != who);
932 + assert(lastmod > 0); /* lastmod must not be 0 */
933 + assert(!(flags & WELCOME_LOCAL) &&
934 + lastmod >= WelcomeLastMod(name)); /* lastmod may not decrease */
937 + Debug((DEBUG_DEBUG, "welcome_make(%d, \"%s\", \"%s\", %Tu, %Tu, "
938 + "FLAGS(0x%04x): local=%s announce=%s insert=%s delete=%s inclastmod=%s)",
939 + name, text, who, create, lastmod, flags,
940 + (flags & WELCOME_LOCAL) ? "yes" : "no",
941 + (flags & WELCOME_ANNOUNCE) ? "yes" : "no",
942 + (flags & WELCOME_INSERT) ? "yes" : "no",
943 + (flags & WELCOME_DELETE) ? "yes" : "no",
944 + (flags & WELCOME_INCLASTMOD) ? "yes" : "no"));
947 + ircd_strncpy(WelcomeArray[name].text, text, WELCOMELEN);
948 + ircd_strncpy(WelcomeArray[name].who, who, ACCOUNTLEN);
949 + /* take current lastmod +1 */
950 + if (flags & WELCOME_INCLASTMOD && WelcomeLastMod(name) >= lastmod)
951 + WelcomeArray[name].lastmod = WelcomeLastMod(name) +1;
952 + /* take new lastmod */
954 + WelcomeArray[name].lastmod = lastmod;
955 + WelcomeArray[name].create = create;
961 +/** Propagate a welcome message.
962 + * @param[in] cptr Local client that sent us the welcome.
963 + * @param[in] sptr Originator of the welcome.
964 + * @param[in] nameint Name of the message.
965 + * @param[in] create When it was set.
966 + * @param[in] lastmod Last modification timestamp.
967 + * @param[in] who Who set this message.
968 + * @param[in] text The welcome message.
969 + * @param[in] flags Flags to set on welcome.
973 +welcome_propagate(struct Client *cptr, struct Client *sptr, int nameint,
974 + time_t create, time_t lastmod, char *who, char *text, unsigned int flags)
977 + assert(NULL != sptr);
978 + assert(NULL != cptr);
979 + assert(WelcomeNameIsValid(nameint));
980 + assert(lastmod > 0);
981 + assert(!(flags & WELCOME_LOCAL));
983 + sendcmdto_serv_butone(sptr, CMD_WELCOME, cptr, "* %s%s%s%d %Tu %Tu %s :%s",
984 + (flags & WELCOME_ANNOUNCE) ? "$" : "",
985 + (flags & WELCOME_INSERT) ? "+" : "",
986 + (flags & WELCOME_DELETE) ? "-" : "",
987 + nameint, create, lastmod, who, text);
993 +/** Resend a welcome message.
994 + * @param[in] cptr Local client that sent us the welcome.
995 + * @param[in] nameint Name of the message.
996 + * @param[in] namearray Name of the array item.
1000 +welcome_resend(struct Client *cptr, int nameint, int namearray)
1003 + assert(NULL != cptr);
1004 + assert(IsServer(cptr));
1005 + assert(WelcomeNameIsValid(nameint));
1006 + assert(WelcomeArrayIsValid(namearray));
1007 + assert(nameint - 1 == namearray);
1009 + sendcmdto_one(&me, CMD_WELCOME, cptr, "* %d %Tu %Tu %s :%s",
1011 + WelcomeCreate(namearray), WelcomeLastMod(namearray),
1012 + WelcomeWho(namearray), WelcomeText(namearray));
1018 +/** Log a welcome message.
1019 + * @param[in] sptr Originator of the welcome.
1020 + * @param[in] msg The message to show.
1021 + * @param[in] flags Flags to set on welcome.
1025 +welcome_log(struct Client *sptr, char *msg, unsigned int flags)
1028 + assert(NULL != sptr);
1029 + assert(NULL != msg);
1032 + sendto_opmask_butone(0, SNO_OLDSNO, "%s %s",
1033 + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
1034 + get_client_name_and_opername(sptr) : cli_name((cli_user(sptr))->server), msg);
1037 + log_write(LS_NETWORK, L_INFO, LOG_NOSNOTICE, "%s %s", get_client_name_and_opername(sptr), msg);
1039 + /* welcome by remote oper, inform of success */
1040 + if ((flags & WELCOME_LOCAL) && IsUser(sptr) && !MyConnect(sptr)) {
1041 + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s %s",
1042 + sptr, get_client_name_and_opername(sptr), msg);
1044 + /* TODO: wallops all local changes, by both local and remote opers? */
1045 + /* tell all opers about the local message being set remotely */
1046 + sendwallto_group_butone(&me, WALL_WALLOPS, 0, "%s %s", get_client_name_and_opername(sptr), msg);
1053 +/** Announce a welcome message to local clients.
1054 + * @param[in] name Welcome message to announce.
1055 + * @param[in] flags Flags to set on welcome.
1058 +welcome_announce(int name, unsigned int flags)
1060 + struct Client *acptr; /* local user */
1061 + struct MsgBuf *msgbuf; /* message to send */
1062 + int i; /* loop variable */
1065 + assert(flags & WELCOME_ANNOUNCE);
1066 + assert(WelcomeArrayIsValid(name));
1067 + assert(WelcomeIsSet(name));
1068 + assert(!WelcomeIsEmpty(name));
1070 + /* build msgbuf */
1071 + msgbuf = msgq_make(0, ":%C %s $%s :[%s] %s", &me, MSG_NOTICE,
1072 + (flags & WELCOME_LOCAL) ? cli_name(&me) : "*",
1073 + (flags & WELCOME_LOCAL) ? cli_name(&me) : feature_str(FEAT_NETWORK),
1074 + WelcomeText(name));
1076 + /* go over local clients */
1077 + for (i = HighestFd; i > 0; --i) {
1079 + /* skip unregistered clients, skip servers */
1080 + if (!(acptr = LocalClientArray[i]) || !IsRegistered(acptr) || IsServer(acptr))
1083 + /* send it away */
1084 + send_buffer(acptr, msgbuf, 0);
1089 +/** Set a welcome message.
1090 + * @param[in] cptr Local client that sent us the welcome.
1091 + * @param[in] sptr Originator of the welcome.
1092 + * @param[in] nameint Name of the message.
1093 + * @param[in] namearray Array entry.
1094 + * @param[in] create When it was set.
1095 + * @param[in] lastmod Last modification timestamp.
1096 + * @param[in] who Who set this message.
1097 + * @param[in] text The message.
1098 + * @param[in] flags Flags to set on welcome.
1102 +welcome_set(struct Client *cptr, struct Client *sptr, int nameint,
1103 + int namearray, time_t create, time_t lastmod, char *who, char *text, unsigned int flags)
1105 + char msg[BUFSIZE]; /* msg for logging */
1106 + int new = 0; /* welcome is new - not set yet */
1109 + assert(NULL != cptr);
1110 + assert(NULL != sptr);
1111 + assert(WelcomeNameIsValid(nameint));
1112 + assert(WelcomeArrayIsValid(namearray));
1113 + assert(lastmod > 0);
1114 + assert(NULL != who);
1115 + assert(NULL != text);
1118 + Debug((DEBUG_DEBUG, "welcome_set(\"%s\", \"%s\", %d, %d, %Tu, %Tu, \"%s\", \"%s\","
1119 + "FLAGS(0x%04x): local=%s announce=%s insert=%s delete=%s)",
1120 + cli_name(cptr), cli_name(sptr), nameint, namearray, create, lastmod, who, text, flags,
1121 + (flags & WELCOME_LOCAL) ? "yes" : "no",
1122 + (flags & WELCOME_ANNOUNCE) ? "yes" : "no",
1123 + (flags & WELCOME_INSERT) ? "yes" : "no",
1124 + (flags & WELCOME_DELETE) ? "yes" : "no"));
1127 + if (WelcomeIsEmpty(namearray))
1131 + welcome_make(namearray, text, who, create, lastmod, flags);
1133 + /* create msg for log */
1134 + ircd_snprintf(0, msg, 0, "%s%s%s WELCOME %d \"%s\" %s [%Tu]",
1135 + new ? "setting" : "changing",
1136 + (flags & WELCOME_ANNOUNCE) ? " and announcing " : " ",
1137 + (flags & WELCOME_LOCAL) ? "local" : "global",
1138 + nameint, WelcomeText(namearray), WelcomeWho(namearray), create);
1141 + welcome_log(sptr, msg, flags);
1143 + /* propagate it */
1144 + if (!(flags & WELCOME_LOCAL))
1145 + welcome_propagate(cptr, sptr, nameint, create, lastmod, who, text, flags);
1148 + if (flags & WELCOME_ANNOUNCE)
1149 + welcome_announce(namearray, flags);
1155 +/** Unset a welcome message.
1156 + * @param[in] cptr Local client that sent us the welcome.
1157 + * @param[in] sptr Originator of the welcome.
1158 + * @param[in] nameint Name of the message.
1159 + * @param[in] namearray Array entry.
1160 + * @param[in] create When it was set.
1161 + * @param[in] lastmod Last modification timestamp.
1162 + * @param[in] who Who set this message.
1163 + * @param[in] flags Flags to set on welcome.
1167 +welcome_unset(struct Client *cptr, struct Client *sptr, int nameint,
1168 + int namearray, time_t create, time_t lastmod, char *who, unsigned int flags)
1170 + char msg[BUFSIZE]; /* msg for logging */
1173 + assert(NULL != cptr);
1174 + assert(NULL != sptr);
1175 + assert(WelcomeNameIsValid(nameint));
1176 + assert(WelcomeArrayIsValid(namearray));
1177 + assert(lastmod > 0);
1178 + assert(NULL != who);
1181 + Debug((DEBUG_DEBUG, "welcome_unset(\"%s\", \"%s\", %d, %d, %Tu, %Tu, \"%s\","
1182 + "FLAGS(0x%04x): local=%s announce=%s insert=%s delete=%s)",
1183 + cli_name(cptr), cli_name(sptr), nameint, namearray, create, lastmod, who, flags,
1184 + (flags & WELCOME_LOCAL) ? "yes" : "no",
1185 + (flags & WELCOME_ANNOUNCE) ? "yes" : "no",
1186 + (flags & WELCOME_INSERT) ? "yes" : "no",
1187 + (flags & WELCOME_DELETE) ? "yes" : "no"));
1189 + /* create msg for log */
1190 + ircd_snprintf(0, msg, 0, "unsetting %s WELCOME %d \"%s\" %s [%Tu]",
1191 + (flags & WELCOME_LOCAL) ? "local" : "global",
1192 + nameint, WelcomeText(namearray), WelcomeWho(namearray), create);
1195 + welcome_log(sptr, msg, flags);
1198 + * not when inserting, welcome_insert() handles that
1199 + * not when deleting, welcome_delete() handles that
1201 + if (!(flags & (WELCOME_INSERT|WELCOME_DELETE)))
1202 + welcome_make(namearray, "", who, create, lastmod, flags);
1204 + /* propagate it, but not when inserting */
1205 + if (!(flags & (WELCOME_LOCAL|WELCOME_INSERT)))
1206 + welcome_propagate(cptr, sptr, nameint, create, lastmod, who, "", flags);
1212 +/** Insert a welcome message.
1213 + * @param[in] cptr Local client that sent us the welcome.
1214 + * @param[in] sptr Originator of the welcome.
1215 + * @param[in] nameint Name of the message.
1216 + * @param[in] namearray Array entry.
1217 + * @param[in] create When it was set.
1218 + * @param[in] lastmod Last modification timestamp.
1219 + * @param[in] who Who set this message.
1220 + * @param[in] text The welcome message.
1221 + * @param[in] flags Flags to set on welcome.
1225 +welcome_insert(struct Client *cptr, struct Client *sptr, int nameint,
1226 + int namearray, time_t create, time_t lastmod, char *who, char *text, unsigned int flags)
1228 + char msg[BUFSIZE]; /* msg for logging */
1229 + int i; /* loop variable */
1230 + int empty = -1; /* first empty spot in array after namearray */
1231 + int end = WELCOME_MAX_ENTRIES -1; /* last element to check in array */
1232 + int last = end; /* last welcome message to feed to welcome_unset */
1235 + assert(NULL != cptr);
1236 + assert(NULL != sptr);
1237 + assert(WelcomeNameIsValid(nameint));
1238 + assert(WelcomeArrayIsValid(namearray));
1239 + assert(lastmod > 0);
1240 + assert(NULL != who);
1241 + assert(NULL != text);
1244 + Debug((DEBUG_DEBUG, "welcome_insert(\"%s\", \"%s\", %d, %d, %Tu, %Tu, \"%s\", \"%s\","
1245 + "FLAGS(0x%04x): local=%s announce=%s insert=%s delete=%s)",
1246 + cli_name(cptr), cli_name(sptr), nameint, namearray, create, lastmod, who, text, flags,
1247 + (flags & WELCOME_LOCAL) ? "yes" : "no",
1248 + (flags & WELCOME_ANNOUNCE) ? "yes" : "no",
1249 + (flags & WELCOME_INSERT) ? "yes" : "no",
1250 + (flags & WELCOME_DELETE) ? "yes" : "no"));
1252 + /* correct end for local offset */
1253 + if (flags & WELCOME_LOCAL)
1254 + end += WELCOME_MAX_ENTRIES;
1256 + /* find first empty spot */
1257 + for (i = namearray; i <= end; i++) {
1258 + if (WelcomeIsEmpty(i)) {
1264 + /* no empty spot, need to unset last */
1265 + if (empty == -1) {
1266 + welcome_unset(cptr, sptr, end +1, end, create, lastmod, who, flags);
1270 + /* move entries down, update lastmod - lastmod for end is already updated above */
1271 + for (i = empty; i > namearray; i--)
1272 + welcome_make(i, WelcomeText(i-1), WelcomeWho(i-1), WelcomeCreate(i-1),
1273 + lastmod, flags | WELCOME_INCLASTMOD);
1275 + /* correct empty for local offset */
1276 + if (flags & WELCOME_LOCAL)
1277 + empty -= WELCOME_MAX_ENTRIES;
1279 + /* create msg for log */
1280 + if (nameint == empty)
1281 + ircd_snprintf(0, msg, 0, "moving %s WELCOME message %d one place down",
1282 + (flags & WELCOME_LOCAL) ? "local" : "global", nameint);
1284 + ircd_snprintf(0, msg, 0, "moving %s WELCOME message %d %s %d one place down",
1285 + (flags & WELCOME_LOCAL) ? "local" : "global", nameint, (empty - nameint > 1) ? "to" : "and" , empty);
1288 + welcome_log(sptr, msg, flags);
1291 + welcome_set(cptr, sptr, nameint, namearray, create, lastmod, who, text, flags);
1297 +/** Delete a welcome message.
1298 + * @param[in] cptr Local client that sent us the welcome.
1299 + * @param[in] sptr Originator of the welcome.
1300 + * @param[in] nameint Name of the message.
1301 + * @param[in] namearray Array entry.
1302 + * @param[in] create When it was set.
1303 + * @param[in] lastmod Last modification timestamp.
1304 + * @param[in] who Who set this message.
1305 + * @param[in] flags Flags to set on welcome.
1309 +welcome_delete(struct Client *cptr, struct Client *sptr, int nameint,
1310 + int namearray, time_t create, time_t lastmod, char *who, unsigned int flags)
1312 + int i; /* loop variable */
1313 + int empty = namearray; /* first empty spot in array after namearray */
1314 + int end = WELCOME_MAX_ENTRIES -1; /* last element to check in array */
1317 + assert(NULL != cptr);
1318 + assert(NULL != sptr);
1319 + assert(WelcomeNameIsValid(nameint));
1320 + assert(WelcomeArrayIsValid(namearray));
1321 + assert(lastmod > 0);
1322 + assert(NULL != who);
1323 + assert(flags & WELCOME_DELETE);
1326 + Debug((DEBUG_DEBUG, "welcome_delete(\"%s\", \"%s\", %d, %d, %Tu, %Tu, \"%s\","
1327 + "FLAGS(0x%04x): local=%s announce=%s insert=%s delete=%s)",
1328 + cli_name(cptr), cli_name(sptr), nameint, namearray, create, lastmod, who, flags,
1329 + (flags & WELCOME_LOCAL) ? "yes" : "no",
1330 + (flags & WELCOME_ANNOUNCE) ? "yes" : "no",
1331 + (flags & WELCOME_INSERT) ? "yes" : "no",
1332 + (flags & WELCOME_DELETE) ? "yes" : "no"));
1335 + welcome_unset(cptr, sptr, nameint, namearray, create, lastmod, who, flags);
1337 + /* correct end for local offset */
1338 + if (flags & WELCOME_LOCAL)
1339 + end += WELCOME_MAX_ENTRIES;
1341 + /* move entries up, update lastmod */
1342 + for (i = namearray; i < end; i++) {
1343 + if (!WelcomeIsSet(i+1))
1345 + welcome_make(i, WelcomeText(i+1), WelcomeWho(i+1), WelcomeCreate(i+1),
1346 + lastmod, flags | WELCOME_INCLASTMOD);
1349 + /* clear last entry */
1351 + welcome_make(i, "", who, create, lastmod, flags | WELCOME_INCLASTMOD);
1353 + /* nothing was moved, clear entry */
1354 + if (i == namearray)
1355 + welcome_make(i, "", who, create, lastmod, flags);
1361 +/** Change a welcome message.
1362 + * @param[in] cptr Local client that sent us the welcome.
1363 + * @param[in] sptr Originator of the welcome.
1364 + * @param[in] name Name of the message.
1365 + * @param[in] create When it was set.
1366 + * @param[in] lastmod Last modification timestamp.
1367 + * @param[in] who Who set this message.
1368 + * @param[in] text The welcome message.
1369 + * @param[in] flags Flags to set on welcome.
1373 +welcome_do(struct Client *cptr, struct Client *sptr, char *name,
1374 + time_t create, time_t lastmod, char *who, char *text, unsigned int flags)
1376 + int nameint = atoi(name); /* transform to int */
1377 + int namearray = nameint - 1; /* used to test the array element */
1380 + assert(NULL != cptr);
1381 + assert(NULL != sptr);
1382 + assert(NULL != name);
1383 + assert(NULL != text);
1384 + assert(NULL != who);
1387 + Debug((DEBUG_DEBUG, "welcome_do(\"%s\", \"%s\", \"%s\", %Tu, %Tu, \"%s\", \"%s\","
1388 + "FLAGS(0x%04x): local=%s announce=%s insert=%s delete=%s)",
1389 + cli_name(cptr), cli_name(sptr), name, create, lastmod, who, text, flags,
1390 + (flags & WELCOME_LOCAL) ? "yes" : "no",
1391 + (flags & WELCOME_ANNOUNCE) ? "yes" : "no",
1392 + (flags & WELCOME_INSERT) ? "yes" : "no",
1393 + (flags & WELCOME_DELETE) ? "yes" : "no"));
1395 + /* name empty after taking off the prefixes? */
1398 + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Welcome: No message number given", sptr);
1400 + protocol_violation(cptr, "Received WELCOME with no message number from %C", sptr);
1405 + if (!WelcomeArrayIsValid(namearray)) {
1407 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1408 + "%C :Welcome: Invalid message number %s - should between 1 and %d",
1409 + sptr, name, WELCOME_MAX_ENTRIES);
1411 + protocol_violation(cptr,
1412 + "Received WELCOME with invalid message number %s from %C - should be between 1 and %d",
1413 + name, sptr, WELCOME_MAX_ENTRIES);
1417 + /* invalid lastmod */
1418 + if (lastmod <= 0) {
1419 + /* from my user - must be a glitch,
1420 + * someone set (my) network time to 0 ?
1424 + /* else it's a protocol violation */
1426 + return protocol_violation(cptr, "Received WELCOME with invalid lastmod timestamp %Tu from %C", lastmod, sptr);
1429 + /* source is user, and is myuser or welcome is local, check length of the message */
1430 + if (IsUser(sptr) && (MyConnect(sptr) || (flags & WELCOME_LOCAL)) && (strlen(text) > WELCOMELEN)) {
1431 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1432 + "%C :Welcome: The message is too long with %d chars - max is %d chars",
1433 + sptr, strlen(text), WELCOMELEN);
1434 + ircd_strncpy(text, text, WELCOMELEN);
1435 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1436 + "%C :Welcome: Change or truncate the message to: \"%s\"", sptr, text);
1440 + /* correct namearray for local offset */
1441 + if (flags & WELCOME_LOCAL)
1442 + namearray += WELCOME_MAX_ENTRIES;
1444 + /* must be true by now */
1445 + assert(WelcomeArrayIsValid(namearray));
1446 + assert(WelcomeNameIsValid(nameint));
1448 + /* cannot unset welcome that is not set */
1449 + if (!WelcomeIsSet(namearray) && *text == 0) {
1451 + /* from user, throw error */
1453 + return send_reply(sptr, ERR_NOSUCHWELCOME, name);
1455 + /* new local welcome from server, but empty - ignore
1456 + * we do accept a new global welcome message that is empty
1458 + if (flags & WELCOME_LOCAL)
1462 + /* check if there is something to change */
1463 + /* we got a record for it */
1464 + if (WelcomeIsSet(namearray)) {
1467 + if (!(flags & WELCOME_LOCAL)) {
1469 + /* myuser changes it,
1470 + * WelcomeLastMod greater than or equal to lastmod, take WelcomeLastMod+1 as lastmod
1471 + * else the change is not accepted upstream because of the older TS
1473 + if (MyUser(sptr)) {
1474 + if (WelcomeLastMod(namearray) >= lastmod)
1475 + lastmod = WelcomeLastMod(namearray) +1;
1478 + /* compare lastmod, ignore welcome when:
1479 + * we got a newer one
1480 + * or when lastmod is the same and our text is 'smaller'
1482 + else if ((lastmod < WelcomeLastMod(namearray)) || /* we got a newer one */
1483 + ((lastmod == WelcomeLastMod(namearray)) && /* same lastmod */
1484 + (strcmp(WelcomeText(namearray), text) < 0))) { /* our text is 'smaller' */
1485 + /* burst or burst ack, cptr gets our version from the burst */
1486 + if (IsBurstOrBurstAck(cptr))
1489 + return welcome_resend(cptr, nameint, namearray);
1492 + /* local welcome - we use our idea of the time */
1494 + create = TStime();
1495 + lastmod = TStime();
1498 + /* new global welcome from my user or local welcome
1499 + * compare new message with old message
1501 + if (IsUser(sptr) && (MyConnect(sptr) || (flags & WELCOME_LOCAL))) {
1502 + if (strcmp(text, WelcomeText(namearray)) == 0) { /* use strcmp instead of ircd_strcmp - oper may wish to change case */
1503 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1504 + "%C :Welcome: Cannot change %s message for %s - nothing to change",
1505 + sptr, (flags & WELCOME_LOCAL) ? "local" : "global", name);
1511 + /* do not insert for last global/local entry and when not set yet */
1512 + if ((flags & WELCOME_INSERT) &&
1513 + ((!WelcomeIsSet(namearray)) || (nameint == WELCOME_MAX_ENTRIES)))
1514 + flags &= ~WELCOME_INSERT;
1519 + /* clear insert flag,
1520 + * when this flag is set, welcome_unset() assumes it is being called from welcome_insert()
1521 + * and wont propagate the change
1522 + * welcome_delete() calls welcome_unset()
1524 + flags &= ~WELCOME_INSERT;
1527 + if (flags & WELCOME_DELETE)
1528 + return welcome_delete(cptr, sptr, nameint, namearray, create, lastmod, who, flags);
1531 + return welcome_unset(cptr, sptr, nameint, namearray, create, lastmod, who, flags);
1535 + if (flags & WELCOME_INSERT)
1536 + return welcome_insert(cptr, sptr, nameint, namearray, create, lastmod, who, text, flags);
1538 + /* new or change */
1539 + return welcome_set(cptr, sptr, nameint, namearray, create, lastmod, who, text, flags);
1543 +/** Send the full list of welcome message to \a cptr.
1544 + * @param[in] cptr Local server to send welcomes to.
1547 +welcome_burst(struct Client *cptr)
1549 + int name; /* loop variable */
1552 + assert(NULL != cptr);
1554 + /* loop over global entries - 0 to max - 1 */
1555 + for (name = 0; name <= WELCOME_MAX_ENTRIES - 1; name++) {
1556 + if (WelcomeIsSet(name))
1557 + sendcmdto_one(&me, CMD_WELCOME, cptr, "* %d %Tu %Tu %s :%s",
1559 + WelcomeCreate(name), WelcomeLastMod(name),
1560 + WelcomeWho(name), WelcomeText(name));
1565 +/** List welcome messages.
1566 + * @param[in] sptr Client requesting the listing.
1567 + * @param[in] connect When non zero do not report no welcome is set
1571 +welcome_list(struct Client *sptr, int connect)
1573 + int name; /* loop variable */
1574 + int found = 0; /* number of welcome messages set */
1575 + int local = 0; /* welcome is local or global */
1578 + assert(NULL != sptr);
1580 + /* loop over all entries - range 0 to 2 * max - 1 */
1581 + for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) {
1583 + /* local entries now */
1584 + if (name == WELCOME_MAX_ENTRIES)
1587 + /* not set or empty - skip */
1588 + if (!WelcomeIsSet(name) || WelcomeIsEmpty(name))
1593 + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :[%s] %s",
1594 + sptr, local ? cli_name(&me) : feature_str(FEAT_NETWORK), WelcomeText(name));
1598 + if (!found && !connect)
1599 + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :No welcome message set.", sptr);
1605 +/** Statistics callback to list Welcome messages.
1606 + * @param[in] sptr Client requesting statistics.
1607 + * @param[in] sd Stats descriptor for request (ignored).
1608 + * @param[in] param Extra parameter from user (ignored).
1611 +welcome_stats(struct Client *sptr, const struct StatDesc *sd, char *param)
1613 + int name; /* loop variable */
1614 + int local = 0; /* welcome is local or global */
1617 + assert(NULL != sptr);
1619 + /* stats header */
1620 + send_reply(sptr, SND_EXPLICIT | RPL_STATSWELCOME,
1621 + "W # Target Who Created LastMod Text");
1623 + /* loop over all entries - range 0 to 2 * max - 1 */
1624 + for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) {
1626 + /* local entries now */
1627 + if (name == WELCOME_MAX_ENTRIES)
1631 + if (!WelcomeIsSet(name))
1635 + send_reply(sptr, RPL_STATSWELCOME,
1636 + local ? name + 1 - WELCOME_MAX_ENTRIES : name + 1,
1637 + local ? cli_name(&me) : "*",
1639 + WelcomeCreate(name), WelcomeLastMod(name),
1640 + WelcomeIsEmpty(name) ? "<Empty>" : WelcomeText(name));
1645 +/** Count welcome messages and memory used by them.
1646 + * @param[out] we_size Receives total number of bytes allocated for welcomes.
1647 + * @return Number of welcome messages currently allocated.
1650 +welcome_memory_count(size_t *we_size)
1652 + int name; /* loop variable */
1653 + unsigned int we = 0; /* number of welcome messages set */
1655 + /* loop over all entries - range 0 to 2 * max - 1 */
1656 + for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) {
1659 + if (!WelcomeIsSet(name))
1664 + *we_size += WelcomeText(name) ? (strlen(WelcomeText(name)) + 1) : 0;
1665 + *we_size += WelcomeWho(name) ? (strlen(WelcomeWho(name)) + 1) : 0;