1 Add welcome message functionality.
6 shows welcome messages set, same is shown on connect
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
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
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
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.
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.
41 add m_welcome mo_welcome ms_welcome mh_welcome functions
45 add features FEAT_WELCOME and FEAT_HIS_STATS_W
48 add MSG_WELCOME TOK_WELCOME CMD_WELCOME
51 add welcome message functions
55 add RPL_STATSWELCOME ERR_NOSUCHWELCOME
63 add welcome.c and m_welcome.c files
66 add burst welcome message
72 add showing of welcome messages on connect
78 add PRIV_LOCAL_WELCOME PRIV_WELCOME
80 diff -r 211f48754a7f include/client.h
81 --- a/include/client.h
82 +++ b/include/client.h
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 */
92 diff -r 211f48754a7f include/handlers.h
93 --- a/include/handlers.h
94 +++ b/include/handlers.h
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*[]);
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*[]);
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 211f48754a7f include/ircd_features.h
120 --- a/include/ircd_features.h
121 +++ b/include/ircd_features.h
123 FEAT_IRCD_RES_TIMEOUT,
125 FEAT_ANNOUNCE_INVITES,
128 /* features that affect all operators */
129 FEAT_EXTENDED_CHECKCMD,
138 diff -r 211f48754a7f include/msg.h
142 #define TOK_NOTICE "O"
143 #define CMD_NOTICE MSG_NOTICE, TOK_NOTICE
145 +#define MSG_WELCOME "WELCOME" /* WELC */
146 +#define TOK_WELCOME "WE"
147 +#define CMD_WELCOME MSG_WELCOME, TOK_WELCOME
149 #define MSG_WALLCHOPS "WALLCHOPS" /* WC */
150 #define TOK_WALLCHOPS "WC"
151 #define CMD_WALLCHOPS MSG_WALLCHOPS, TOK_WALLCHOPS
152 diff -r 211f48754a7f include/numeric.h
153 --- a/include/numeric.h
154 +++ b/include/numeric.h
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 */
162 /* RPL_SERVICEINFO 231 unused */
164 /* ERR_GHOSTEDCLIENT 503 efnet */
165 /* ERR_VWORLDWARN 503 austnet */
167 +#define ERR_NOSUCHWELCOME 509 /* QuakeNet extension */
169 #define ERR_SILELISTFULL 511 /* Undernet extension */
170 /* ERR_NOTIFYFULL 512 aircd */
171 /* ERR_TOOMANYWATCH 512 Numeric List: Dalnet */
172 diff -r 211f48754a7f include/welcome.h
174 +++ b/include/welcome.h
176 +#ifndef INCLUDED_welcome_h
177 +#define INCLUDED_welcome_h
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>
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.
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.
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.
199 + * @brief Interface and declarations for welcome message handling.
201 +#ifndef INCLUDED_sys_types_h
202 +#include <sys/types.h>
203 +#define INCLUDED_sys_types_h
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
216 +#define WELCOME_MAX_DRIFT 600
218 +/* Describes a Welcome message entry. */
220 + time_t timestamp; /**< Timestamp of the welcome */
221 + char text[WELCOMELEN + 1]; /**< Message */
222 + char who[ACCOUNTLEN + 1]; /**< Who set it */
225 +/** Welcome type flags */
226 +#define WELCOME_LOCAL 0x01 /**< welcome is local */
227 +/** Welcome action flags */
228 +#define WELCOME_ANNOUNCE 0x02 /**< announce change to users */
230 +extern int welcome_do(struct Client *cptr, struct Client *sptr, char *name, char *text,
231 + char *who, time_t timestamp, unsigned int flags);
232 +extern void welcome_announce(int name);
233 +extern void welcome_burst(struct Client *cptr);
234 +extern int welcome_list(struct Client *sptr, int connect);
235 +extern void welcome_stats(struct Client *sptr, const struct StatDesc *sd, char *param);
237 +#endif /* INCLUDED_welcome_h */
238 diff -r 211f48754a7f ircd/Makefile.in
239 --- a/ircd/Makefile.in
240 +++ b/ircd/Makefile.in
257 @@ -1161,6 +1163,11 @@
258 ../include/ircd_reply.h ../include/ircd_string.h \
259 ../include/ircd_chattr.h ../include/msg.h ../include/numeric.h \
260 ../include/numnicks.h ../include/s_user.h ../include/send.h
261 +m_welcome.o: m_welcome.c ../config.h ../include/channel.h \
262 + ../include/client.h ../include/hash.h ../include/ircd.h ../include/ircd_log.h \
263 + ../include/ircd_reply.h ../include/ircd_string.h ../include/msg.h \
264 + ../include/numeric.h ../include/numnicks.h ../include/s_user.h \
265 + ../include/send.h ../include/welcome.h
266 m_who.o: m_who.c ../config.h ../include/channel.h ../include/ircd_defs.h \
267 ../include/res.h ../config.h ../include/client.h ../include/dbuf.h \
268 ../include/msgq.h ../include/ircd_events.h ../include/ircd_handler.h \
269 @@ -1422,6 +1429,13 @@
270 ../include/numnicks.h ../include/querycmds.h ../include/ircd_features.h \
271 ../include/s_misc.h ../include/s_stats.h ../include/send.h \
272 ../include/struct.h ../include/sys.h
273 +welcome.o: welcome.c ../config.h ../include/client.h \
274 + ../include/hash.h ../include/ircd.h ../include/ircd_alloc.h \
275 + ../include/ircd_features.h ../include/ircd_log.h ../include/ircd_reply.h \
276 + ../include/match.h ../include/msg.h ../include/numeric.h \
277 + ../include/numnicks.h ../include/s_debug.h ../include/s_bsd.h \
278 + ../include/s_misc.h ../include/send.h ../include/struct.h \
279 + ../include/sys.h ../include/welcome.h
280 whocmds.o: whocmds.c ../config.h ../include/whocmds.h \
281 ../include/channel.h ../include/ircd_defs.h ../include/res.h \
282 ../config.h ../include/client.h ../include/dbuf.h ../include/msgq.h \
283 diff -r 211f48754a7f ircd/client.c
287 FlagSet(&privs_local, PRIV_WHOX);
288 FlagSet(&privs_local, PRIV_DISPLAY);
289 FlagSet(&privs_local, PRIV_FORCE_LOCAL_OPMODE);
290 + FlagSet(&privs_local, PRIV_LOCAL_WELCOME);
292 privs_defaults_set = 1;
295 ClrPriv(client, PRIV_JUPE);
296 ClrPriv(client, PRIV_OPMODE);
297 ClrPriv(client, PRIV_BADCHAN);
298 + ClrPriv(client, PRIV_WELCOME);
303 P(CHANSERV), P(XTRA_OPER), P(NOIDLE), P(FREEFORM),
304 P(PARANOID), P(CHECK), P(WALL), P(CLOSE),
305 P(ROUTE), P(ROUTEINFO), P(SERVERINFO), P(CHANNEL_PRIVACY),
307 + P(USER_PRIVACY), P(WELCOME), P(LOCAL_WELCOME),
311 diff -r 211f48754a7f ircd/ircd_features.c
312 --- a/ircd/ircd_features.c
313 +++ b/ircd/ircd_features.c
315 F_I(IRCD_RES_TIMEOUT, 0, 4, 0),
316 F_I(AUTH_TIMEOUT, 0, 9, 0),
317 F_B(ANNOUNCE_INVITES, 0, 0, 0),
318 + F_B(WELCOME, 0, 1, 0),
320 /* features that affect all operators */
321 F_B(EXTENDED_CHECKCMD, 0, 0, 0),
323 F_B(HIS_STATS_u, 0, 1, 0),
324 F_B(HIS_STATS_U, 0, 1, 0),
325 F_B(HIS_STATS_v, 0, 1, 0),
326 + F_B(HIS_STATS_W, 0, 1, 0),
327 F_B(HIS_STATS_w, 0, 1, 0),
328 F_B(HIS_STATS_x, 0, 1, 0),
329 F_B(HIS_STATS_y, 0, 1, 0),
330 diff -r 211f48754a7f ircd/ircd_lexer.l
331 --- a/ircd/ircd_lexer.l
332 +++ b/ircd/ircd_lexer.l
334 { "serverinfo", TPRIV_SERVERINFO },
335 { "user_privacy", TPRIV_USER_PRIVACY },
336 { "channel_privacy", TPRIV_CHANNEL_PRIVACY },
337 + { "local_welcome", TPRIV_LOCAL_WELCOME },
338 + { "welcome", TPRIV_WELCOME },
342 diff -r 211f48754a7f ircd/ircd_parser.y
343 --- a/ircd/ircd_parser.y
344 +++ b/ircd/ircd_parser.y
346 %token TPRIV_CHANSERV TPRIV_XTRA_OPER TPRIV_NOIDLE TPRIV_FREEFORM TPRIV_PARANOID
347 %token TPRIV_CHECK TPRIV_WALL TPRIV_CLOSE TPRIV_ROUTE TPRIV_ROUTEINFO TPRIV_SERVERINFO
348 %token TPRIV_CHANNEL_PRIVACY TPRIV_USER_PRIVACY TPRIV_LIST_CHAN
349 +%token TPRIV_LOCAL_WELCOME TPRIV_WELCOME
350 /* and some types... */
352 %type <num> timespec timefactor factoredtimes factoredtime
354 TPRIV_SERVERINFO { $$ = PRIV_SERVERINFO ; } |
355 TPRIV_CHANNEL_PRIVACY { $$ = PRIV_CHANNEL_PRIVACY ; } |
356 TPRIV_USER_PRIVACY { $$ = PRIV_USER_PRIVACY ; } |
357 + TPRIV_LOCAL_WELCOME { $$ = PRIV_LOCAL_WELCOME; } |
358 + TPRIV_WELCOME { $$ = PRIV_WELCOME; } |
359 TPRIV_PARANOID { $$ = PRIV_PARANOID; } ;
360 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
362 diff -r 211f48754a7f ircd/m_welcome.c
364 +++ b/ircd/m_welcome.c
367 + * IRC - Internet Relay Chat, ircd/m_welcome.c
368 + * Copyright (C) 1990 Jarkko Oikarinen and
369 + * University of Oulu, Computing Center
371 + * See file AUTHORS in IRC package for additional names of
374 + * This program is free software; you can redistribute it and/or modify
375 + * it under the terms of the GNU General Public License as published by
376 + * the Free Software Foundation; either version 1, or (at your option)
377 + * any later version.
379 + * This program is distributed in the hope that it will be useful,
380 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
381 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
382 + * GNU General Public License for more details.
384 + * You should have received a copy of the GNU General Public License
385 + * along with this program; if not, write to the Free Software
386 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
391 + * m_functions execute protocol messages on this server:
393 + * cptr is always NON-NULL, pointing to a *LOCAL* client
394 + * structure (with an open socket connected!). This
395 + * identifies the physical socket where the message
396 + * originated (or which caused the m_function to be
397 + * executed--some m_functions may call others...).
399 + * sptr is the source of the message, defined by the
400 + * prefix part of the message if present. If not
401 + * or prefix not found, then sptr==cptr.
403 + * (!IsServer(cptr)) => (cptr == sptr), because
404 + * prefixes are taken *only* from servers...
407 + * (sptr == cptr) => the message didn't
410 + * (sptr != cptr && IsServer(sptr) means
411 + * the prefix specified servername. (?)
413 + * (sptr != cptr && !IsServer(sptr) means
414 + * that message originated from a remote
415 + * user (not local).
419 + * (!IsServer(sptr)) means that, sptr can safely
420 + * taken as defining the target structure of the
421 + * message in this server.
423 + * *Always* true (if 'parse' and others are working correct):
425 + * 1) sptr->from == cptr (note: cptr->from == cptr)
427 + * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
428 + * *cannot* be a local connection, unless it's
429 + * actually cptr!). [MyConnect(x) should probably
430 + * be defined as (x == x->from) --msa ]
432 + * parc number of variable parameter strings (if zero,
433 + * parv is allowed to be NULL)
435 + * parv a NULL terminated list of parameter pointers,
437 + * parv[0], sender (prefix string), if not present
438 + * this points to an empty string.
439 + * parv[1]...parv[parc-1]
440 + * pointers to additional parameters
441 + * parv[parc] == NULL, *always*
443 + * note: it is guaranteed that parv[0]..parv[parc-1] are all
444 + * non-NULL pointers.
448 +#include "channel.h"
452 +#include "ircd_features.h"
453 +#include "ircd_log.h"
454 +#include "ircd_reply.h"
455 +#include "ircd_snprintf.h"
456 +#include "ircd_string.h"
458 +#include "numeric.h"
459 +#include "numnicks.h"
462 +#include "welcome.h"
464 +/* #include <assert.h> -- Now using assert in ircd_log.h */
467 + * m_welcome - local generic message handler
469 + * parv[0] = Send prefix
470 + * parv[1] = [remote server to query]
472 +int m_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
474 + /* feature disabled */
475 + if (!feature_bool(FEAT_WELCOME))
476 + return send_reply(sptr, ERR_DISABLED, "WELCOME");
478 + /* only opers can set the welcome messages */
480 + return send_reply(sptr, ERR_NOPRIVILEGES);
482 + /* remote listing request, see if it is for me or a remote server
483 + * check FEAT_HIS_REMOTE to decide if an ordinary user can do this
485 + if ((parc > 1) && (hunt_server_cmd(sptr, CMD_WELCOME, cptr, feature_int(FEAT_HIS_REMOTE),
486 + "%C", 1, parc, parv) != HUNTED_ISME))
489 + /* local listing */
490 + return welcome_list(sptr, 0);
495 + * mo_welcome - oper message handler
498 + * parv[0] = Send prefix
501 + * parv[0] = Send prefix
504 + * set global or on remote server:
505 + * parv[0] = Send prefix
506 + * parv[1] = Target: server or * for global (or left out for this server)
510 +int mo_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
512 + char *target, *name, *who, *text, pattern[BUFSIZE];
514 + unsigned int flags = 0;
517 + /* feature disabled */
518 + if (!feature_bool(FEAT_WELCOME))
519 + return send_reply(sptr, ERR_DISABLED, "WELCOME");
521 + /* TODO: move feature check here? */
522 + /* remote listing request, see if it is for me or a remote server */
523 + if ((parc == 2) && (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C", 1, parc, parv) != HUNTED_ISME))
526 + /* local listing */
528 + return welcome_list(sptr, 0);
531 + /* local - need PRIV LOCAL_WELCOME or WELCOME */
532 + if (parc == 3 && !HasPriv(sptr,PRIV_LOCAL_WELCOME) && !HasPriv(sptr,PRIV_WELCOME))
533 + return send_reply(sptr, ERR_NOPRIVILEGES);
535 + /* global or remote - need PRIV WELCOME */
536 + if (parc >= 4 && !HasPriv(sptr,PRIV_WELCOME))
537 + return send_reply(sptr, ERR_NOPRIVILEGES);
539 + /* set the parameters */
541 + /* target not given, only name - setting local welcome */
544 + target = cli_name(&me);
546 + flags |= WELCOME_LOCAL;
548 + /* target and name given */
553 + timestamp = TStime();
554 + who = cli_user(sptr)->opername;
555 + text = parv[parc - 1];
557 + /* target is not global */
558 + if (!(target[0] == '*' && target[1] == '\0') && !local) {
560 + /* build a pattern for hunt_server_cmd since we do not have all we need in parv */
561 + ircd_snprintf(0, pattern, sizeof(pattern), "%s %s %Tu %s :%s", "%C", name, timestamp, who, text);
562 + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, pattern, 1, 2, parv) != HUNTED_ISME)
565 + /* else it is a local welcome, for me */
566 + flags |= WELCOME_LOCAL;
569 + /* TODO: disallow global announcement from oper?
570 + * as PRIVMSG/NOTICE to $* is not allowed either by the ircd
571 + * when PRIV for that is added, use that here? PRIV_BROADCAST or something
573 + * change prefix to $ ?
575 + /* check for anounce prefix */
576 + if (*name == '!') {
578 + flags |= WELCOME_ANNOUNCE;
582 + return welcome_do(cptr, sptr, name, text, who, timestamp, flags);
587 + * ms_welcome - server message handler
589 + * parv[0] = Send prefix
590 + * parv[1] = Target: server numeric or * for global
592 + * parv[3] = Timestamp
596 +int ms_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
598 + char *target, *name, *who, *text;
600 + unsigned int flags = 0;
602 + /* not enough - complain */
604 + protocol_violation(sptr, "Too few parameters for WELCOME (got %d - need 2)", parc);
605 + return need_more_params(sptr, "WELCOME");
608 + /* remote listing request, see if it is for me or a remote server */
610 + if (IsServer(sptr))
611 + return protocol_violation(cptr, "WELCOME listing request from server %C", sptr);
612 + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C", 1, parc, parv) != HUNTED_ISME)
614 + return welcome_list(sptr, 0);
617 + /* we need at least 6 parameters to continue - complain */
619 + protocol_violation(sptr, "Too few parameters for WELCOME (got %d - need 6)", parc);
620 + return need_more_params(sptr, "WELCOME");
623 + /* set the parameters */
626 + timestamp = atoi(parv[3]);
628 + text = parv[parc - 1]; /* parse reason as last parameter */
630 + /* target is not global */
631 + if (!(target[0] == '*' && target[1] == '\0')) {
633 + /* not for me, and forward it */
634 + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C %s %s %s :%s", 1, parc, parv) != HUNTED_ISME)
637 + /* local welcome for me */
638 + flags |= WELCOME_LOCAL;
641 + /* check for anounce prefix */
642 + if (*name == '!') {
644 + flags |= WELCOME_ANNOUNCE;
648 + return welcome_do(cptr, sptr, name, text, who, timestamp, flags);
650 diff -r 211f48754a7f ircd/parse.c
654 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
655 { m_unregistered, m_not_oper, ms_check, mo_check, m_ignore }
658 + /* add command for WELCOME */
662 + 0, MAXPARA, MFLG_SLOW, 0, NULL,
663 + /* UNREG, CLIENT, SERVER, OPER, SERVICE, HELP */
664 + { m_unregistered, m_welcome, ms_welcome, mo_welcome, m_ignore }
667 /* This command is an alias for QUIT during the unregistered part of
668 * of the server. This is because someone jumping via a broken web
669 diff -r 211f48754a7f ircd/s_err.c
674 { RPL_STATSALINE, "%s", "226" },
677 + { RPL_STATSWELCOME, "W %d %s %s %Tu :%s", "227" },
679 { RPL_STATSQLINE, "Q %s :%s", "228" },
681 @@ -1050,7 +1050,7 @@
686 + { ERR_NOSUCHWELCOME, "%s :No such welcome", "509" },
690 diff -r 211f48754a7f ircd/s_serv.c
696 #include "userload.h"
697 +#include "welcome.h"
699 /* #include <assert.h> -- Now using assert in ircd_log.h */
705 + welcome_burst(cptr);
708 * Pass on my client information to the new server
709 diff -r 211f48754a7f ircd/s_stats.c
715 #include "userload.h"
716 +#include "welcome.h"
721 { 'V', "vserversmach", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS), FEAT_HIS_STATS_v,
722 stats_servers_verbose, 0,
723 "Verbose server information." },
724 - { 'w', "userload", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_w,
725 + { 'w', "userload", STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS, FEAT_HIS_STATS_w,
727 "Userload statistics." },
728 + { 'W', "welcome", STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS, FEAT_HIS_STATS_W,
730 + "Welcome messages." },
731 { 'x', "memusage", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_x,
733 "List usage information." },
734 diff -r 211f48754a7f ircd/s_user.c
738 #include "userload.h"
741 +#include "welcome.h"
743 #include "handlers.h" /* m_motd and m_lusers */
746 cli_info(sptr), NumNick(cptr) /* two %s's */);
748 IPcheck_connect_succeeded(sptr);
750 + if (feature_bool(FEAT_WELCOME))
751 + welcome_list(sptr, 1);
754 struct Client *acptr = user->server;
755 diff -r 211f48754a7f ircd/welcome.c
760 + * IRC - Internet Relay Chat, ircd/welcome.c
761 + * Copyright (C) 1990 Jarkko Oikarinen and
762 + * University of Oulu, Finland
763 + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
765 + * This program is free software; you can redistribute it and/or modify
766 + * it under the terms of the GNU General Public License as published by
767 + * the Free Software Foundation; either version 1, or (at your option)
768 + * any later version.
770 + * This program is distributed in the hope that it will be useful,
771 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
772 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
773 + * GNU General Public License for more details.
775 + * You should have received a copy of the GNU General Public License
776 + * along with this program; if not, write to the Free Software
777 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
780 + * @brief Implementation of welcome message handling functions.
787 +#include "ircd_alloc.h"
788 +#include "ircd_features.h"
789 +#include "ircd_log.h"
790 +#include "ircd_reply.h"
791 +#include "ircd_string.h"
794 +#include "numeric.h"
795 +#include "numnicks.h"
797 +#include "s_debug.h"
801 +#include "sys.h" /* FALSE bleah */
802 +#include "welcome.h"
804 +/* #include <assert.h> -- Now using assert in ircd_log.h */
808 +/** List of welcome messages - first MAX for global, second MAX for local */
809 +static struct Welcome WelcomeArray[WELCOME_MAX_ENTRIES * 2] = { { 0 } };
812 +/** Allocate a new welcome with the given parameters.
813 + * @param[in] name Name of the welcome message.
814 + * @param[in] text The welcome message.
815 + * @param[in] who Who set it.
816 + * @param[in] timestamp When it was set.
817 + * @return name Array number of the welcome set.
820 +welcome_make(int name, char *text, char *who, time_t timestamp)
822 + /* range 0 to 2 * max - 1 */
823 + assert(name >= 0 && name <= 2 * WELCOME_MAX_ENTRIES - 1);
826 + ircd_strncpy(WelcomeArray[name].text, text, TOPICLEN);
827 + ircd_strncpy(WelcomeArray[name].who, who, ACCOUNTLEN);
828 + WelcomeArray[name].timestamp = timestamp;
834 +/** Change a welcome message.
835 + * @param[in] cptr Local client that sent us the welcome.
836 + * @param[in] sptr Originator of the welcome.
837 + * @param[in] name Name of the message.
838 + * @param[in] text The welcome message.
839 + * @param[in] timestamp Timestamp of when the message was set.
840 + * @param[in] flags Flags to set on welcome.
844 +welcome_do(struct Client *cptr, struct Client *sptr, char *name, char *text,
845 + char *who, time_t timestamp, unsigned int flags)
847 + int nameint = atoi(name); /* transform to int */
848 + int namearray = nameint - 1; /* used to test the array element */
849 + char oldtext[TOPICLEN + 1]; /* save old text when unsetting */
850 + static time_t rate;
852 + assert(NULL != cptr);
853 + assert(NULL != sptr);
854 + assert(NULL != name);
855 + assert(NULL != text);
856 + assert(NULL != who);
859 + Debug((DEBUG_DEBUG, "welcome_do(\"%s\", \"%s\", \"%s\", \"%s\" \"%s\", %Tu, 0x%04x)",
860 + cli_name(cptr), cli_name(sptr), name, text, who, timestamp, flags));
863 + if (nameint < 1 || nameint > WELCOME_MAX_ENTRIES) {
865 + sendcmdto_one(&me, CMD_NOTICE, sptr,
866 + "%C :WELCOME: Invalid message number %s - should between 1 and %d",
867 + sptr, name, WELCOME_MAX_ENTRIES);
869 + protocol_violation(cptr, "WELCOME: Invalid message number %s from %C", name, sptr);
873 + /* correct namearray for local offset */
874 + if (flags & WELCOME_LOCAL)
875 + namearray += WELCOME_MAX_ENTRIES;
877 + /* cannot unset welcome that is not set */
878 + if (WelcomeArray[namearray].timestamp == 0 && EmptyString(text)) {
880 + /* from user, throw error */
882 + return send_reply(sptr, ERR_NOSUCHWELCOME, name);
884 + /* new local welcome from server, but empty - ignore
885 + * we do accept a new global welcome message that is empty
887 + if (flags & WELCOME_LOCAL)
891 + /* check if there is something to change */
892 + /* we got a record for it */
893 + if (WelcomeArray[namearray].timestamp != 0) {
896 + if (!(flags & WELCOME_LOCAL)) {
898 + /* netburst and we got the same or a newer one
900 + * we only use the timestamp for resolving conflicts in net burst
901 + * outside of netburst, we simply parse whatever we get
902 + * this way we will not get stuck with a welcome message set by a server
903 + * running ahead with the time
905 + if (IsBurstOrBurstAck(cptr) && timestamp <= WelcomeArray[namearray].timestamp)
908 + /* local welcome - we use our idea of the time */
910 + timestamp = TStime();
912 + /* compare new message with old message */
913 + if (ircd_strcmp(text, WelcomeArray[namearray].text) == 0) {
915 + sendcmdto_one(&me, CMD_NOTICE, sptr,
916 + "%C :WELCOME: Cannot change %s message for %s - nothing to change.",
917 + sptr, (flags & WELCOME_LOCAL) ? "local" : "global", name);
922 + /* TODO: rate limited for what? max 10 welcome messages..? */
923 + /* possible timestamp drift - warn ops */
924 + if (timestamp - TStime() > WELCOME_MAX_DRIFT) {
925 + sendto_opmask_butone_ratelimited(0, SNO_NETWORK, &rate,
926 + "Possible timestamp drift from %C; timestamp in WELCOME message is %is ahead of time",
927 + IsServer(sptr) ? sptr : cli_user(sptr)->server, timestamp - TStime());
929 + /* warn remote oper too */
931 + sendcmdto_one(&me, CMD_NOTICE, sptr,
932 + "%C :Possible timestamp drift from %C; timestamp in WELCOME message is %is ahead of time",
933 + sptr, cli_user(sptr)->server, timestamp - TStime());
936 + /* unsetting - do not announce, save text */
937 + if (EmptyString(text)) {
938 + flags &= ~WELCOME_ANNOUNCE;
939 + ircd_strncpy(oldtext, WelcomeArray[namearray].text, TOPICLEN);
943 + welcome_make(namearray, text, who, timestamp);
946 + sendto_opmask_butone(0, SNO_OLDSNO, "%s %s%s%s WELCOME %d \"%s\" [%Tu]",
947 + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
948 + get_client_name_and_opername(sptr) : cli_name((cli_user(sptr))->server),
949 + EmptyString(text) ? "unsetting" : "changing",
950 + (flags & WELCOME_ANNOUNCE) ? " and announcing " : " ",
951 + (flags & WELCOME_LOCAL) ? "local" : "global",
953 + EmptyString(text) ? oldtext : WelcomeArray[namearray].text,
954 + WelcomeArray[namearray].timestamp);
957 + log_write(LS_NETWORK, L_INFO, LOG_NOSNOTICE, "%#C (%s) %s%s%s WELCOME %d \"%s\" [%Tu]",
958 + sptr, WelcomeArray[namearray].who,
959 + EmptyString(text) ? "unsetting" : "changing",
960 + (flags & WELCOME_ANNOUNCE) ? " and announcing " : " ",
961 + (flags & WELCOME_LOCAL) ? "local" : "global",
963 + EmptyString(text) ? oldtext : WelcomeArray[namearray].text,
964 + WelcomeArray[namearray].timestamp);
966 + /* welcome set by remote user, inform oper of success */
967 + if ((flags & WELCOME_LOCAL) && IsUser(sptr) && !MyUser(sptr)) {
968 + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s %s%s local WELCOME %d \"%s\" [%Tu]",
969 + sptr, get_client_name_and_opername(sptr),
970 + EmptyString(text) ? "unsetting" : "changing",
971 + (flags & WELCOME_ANNOUNCE) ? " and announcing" : "",
973 + EmptyString(text) ? oldtext : WelcomeArray[namearray].text,
974 + WelcomeArray[namearray].timestamp);
976 + /* TODO: wallops all local changes, by both local and remote opers? */
977 + /* tell all opers about the local message being set remotely */
978 + sendwallto_group_butone(&me, WALL_WALLOPS, 0,
979 + "%s %s%s local WELCOME %d \"%s\" [%Tu]",
980 + get_client_name_and_opername(sptr),
981 + EmptyString(text) ? "unsetting" : "changing",
982 + (flags & WELCOME_ANNOUNCE) ? " and announcing" : "",
984 + EmptyString(text) ? oldtext : WelcomeArray[namearray].text,
985 + WelcomeArray[namearray].timestamp);
989 + if (!(flags & WELCOME_LOCAL))
990 + sendcmdto_serv_butone(sptr, CMD_WELCOME, cptr, "* %s%d %Tu %s :%s",
991 + (flags & WELCOME_ANNOUNCE) ? "!" : "", nameint,
992 + WelcomeArray[namearray].timestamp, WelcomeArray[namearray].who,
993 + WelcomeArray[namearray].text);
996 + if (flags & WELCOME_ANNOUNCE)
997 + welcome_announce(namearray);
1003 +/** Announce a welcome message to local clients.
1004 + * @param[in] name Welcome message to announce.
1007 +welcome_announce(int name)
1009 + struct Client *acptr;
1010 + struct MsgBuf *msgbuf;
1013 + /* range 0 to 2 * max - 1 */
1014 + assert(name >= 0 && name <= 2 * WELCOME_MAX_ENTRIES - 1);
1016 + /* TODO: target is $* as if it were a global broadcast
1017 + * could make it $servername for local message announcement
1018 + * but the type is shown between [ ] already
1019 + * either [Network] or [servername] - using $* is just shorter.
1021 + /* build msgbuf */
1022 + msgbuf = msgq_make(0, ":%C %s $* :[%s] %s", &me, MSG_NOTICE,
1023 + name >= WELCOME_MAX_ENTRIES ? cli_name(&me) : feature_str(FEAT_NETWORK),
1024 + WelcomeArray[name].text);
1026 + /* go over local clients */
1027 + for (i = HighestFd; i > 0; --i) {
1029 + /* skip unregistered clients - they see the message during login
1032 + if (!(acptr = LocalClientArray[i]) || !IsRegistered(acptr) || IsServer(acptr))
1035 + /* send it away */
1036 + send_buffer(acptr, msgbuf, 0);
1041 +/** Send the full list of welcome message to \a cptr.
1042 + * @param[in] cptr Local server to send welcomes to.
1045 +welcome_burst(struct Client *cptr)
1049 + assert(NULL != cptr);
1051 + /* loop over global entries - 0 to max - 1*/
1052 + for (name = 0; name <= WELCOME_MAX_ENTRIES - 1; name++) {
1053 + if (WelcomeArray[name].timestamp != 0)
1054 + sendcmdto_one(&me, CMD_WELCOME, cptr, "* %d %Tu %s :%s",
1055 + name + 1, WelcomeArray[name].timestamp, WelcomeArray[name].who,
1056 + WelcomeArray[name].text);
1061 +/** List welcome messages.
1062 + * @param[in] sptr Client requesting the listing.
1063 + * @param[in] connect When non zero do not report no welcome is set
1067 +welcome_list(struct Client *sptr, int connect)
1069 + int found = 0, local = 0, name;
1071 + assert(NULL != sptr);
1073 + /* loop over all entries - range 0 to 2 * max - 1 */
1074 + for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) {
1076 + /* local entries now */
1077 + if (name == WELCOME_MAX_ENTRIES)
1080 + /* not set or empty - skip */
1081 + /* TODO: EmptyString? */
1082 + if (WelcomeArray[name].timestamp == 0 || *WelcomeArray[name].text == 0)
1087 + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :[%s] %s",
1088 + sptr, local ? cli_name(&me) : feature_str(FEAT_NETWORK), WelcomeArray[name].text);
1092 + if (!found && !connect)
1093 + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :No welcome message set.", sptr);
1099 +/** Statistics callback to list Welcome messages.
1100 + * @param[in] sptr Client requesting statistics.
1101 + * @param[in] sd Stats descriptor for request (ignored).
1102 + * @param[in] param Extra parameter from user (ignored).
1105 +welcome_stats(struct Client *sptr, const struct StatDesc *sd, char *param)
1107 + int name, local = 0;
1109 + assert(NULL != sptr);
1111 + /* loop over all entries - range 0 to 2 * max - 1*/
1112 + for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) {
1114 + /* local entries now */
1115 + if (name == WELCOME_MAX_ENTRIES)
1119 + if (WelcomeArray[name].timestamp == 0)
1123 + send_reply(sptr, RPL_STATSWELCOME,
1124 + local ? name + 1 - WELCOME_MAX_ENTRIES : name + 1,
1125 + local ? cli_name(&me) : "*",
1126 + WelcomeArray[name].who, WelcomeArray[name].timestamp,
1127 + EmptyString(WelcomeArray[name].text) ? "<Empty>" : WelcomeArray[name].text);