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
74 diff -r 42bf40ebc839 include/handlers.h
75 --- a/include/handlers.h Fri Jan 30 11:47:37 2009 +0100
76 +++ b/include/handlers.h Fri Jan 30 13:14:46 2009 +0100
78 extern int m_version(struct Client*, struct Client*, int, char*[]);
79 extern int m_wallchops(struct Client*, struct Client*, int, char*[]);
80 extern int m_wallvoices(struct Client*, struct Client*, int, char*[]);
81 +extern int m_welcome(struct Client*, struct Client*, int, char*[]);
82 extern int m_who(struct Client*, struct Client*, int, char*[]);
83 extern int m_whois(struct Client*, struct Client*, int, char*[]);
84 extern int m_whowas(struct Client*, struct Client*, int, char*[]);
86 extern int mo_version(struct Client*, struct Client*, int, char*[]);
87 extern int mo_wallops(struct Client*, struct Client*, int, char*[]);
88 extern int mo_wallusers(struct Client*, struct Client*, int, char*[]);
89 +extern int mo_welcome(struct Client*, struct Client*, int, char*[]);
90 extern int mr_error(struct Client*, struct Client*, int, char*[]);
91 extern int mr_error(struct Client*, struct Client*, int, char*[]);
92 extern int mr_pong(struct Client*, struct Client*, int, char*[]);
94 extern int ms_wallops(struct Client*, struct Client*, int, char*[]);
95 extern int ms_wallusers(struct Client*, struct Client*, int, char*[]);
96 extern int ms_wallvoices(struct Client*, struct Client*, int, char*[]);
97 +extern int ms_welcome(struct Client*, struct Client*, int, char*[]);
98 extern int ms_whois(struct Client*, struct Client*, int, char*[]);
100 extern int mh_nohelp(struct Client*, struct Client*, int, char*[]);
102 extern int mh_wallops(struct Client*, struct Client*, int, char*[]);
103 extern int mh_wallusers(struct Client*, struct Client*, int, char*[]);
104 extern int mh_wallvoices(struct Client*, struct Client*, int, char*[]);
105 +extern int mh_welcome(struct Client*, struct Client*, int, char*[]);
106 extern int mh_who(struct Client*, struct Client*, int, char*[]);
107 extern int mh_whois(struct Client*, struct Client*, int, char*[]);
108 extern int mh_whowas(struct Client*, struct Client*, int, char*[]);
109 diff -r 42bf40ebc839 include/ircd_features.h
110 --- a/include/ircd_features.h Fri Jan 30 11:47:37 2009 +0100
111 +++ b/include/ircd_features.h Fri Jan 30 13:14:46 2009 +0100
113 FEAT_IRCD_RES_TIMEOUT,
115 FEAT_ANNOUNCE_INVITES,
118 /* features that affect all operators */
119 FEAT_EXTENDED_CHECKCMD,
128 diff -r 42bf40ebc839 include/msg.h
129 --- a/include/msg.h Fri Jan 30 11:47:37 2009 +0100
130 +++ b/include/msg.h Fri Jan 30 13:14:46 2009 +0100
132 #define TOK_NOTICE "O"
133 #define CMD_NOTICE MSG_NOTICE, TOK_NOTICE
135 +#define MSG_WELCOME "WELCOME" /* WELC */
136 +#define TOK_WELCOME "WE"
137 +#define CMD_WELCOME MSG_WELCOME, TOK_WELCOME
139 #define MSG_WALLCHOPS "WALLCHOPS" /* WC */
140 #define TOK_WALLCHOPS "WC"
141 #define CMD_WALLCHOPS MSG_WALLCHOPS, TOK_WALLCHOPS
142 diff -r 42bf40ebc839 include/numeric.h
143 --- a/include/numeric.h Fri Jan 30 11:47:37 2009 +0100
144 +++ b/include/numeric.h Fri Jan 30 13:14:46 2009 +0100
146 RPL_STATSGLINE 227 Dalnet
147 RPL_STATSVLINE 227 unreal */
148 #define RPL_STATSALINE 226 /* Hybrid, Undernet */
149 +#define RPL_STATSWELCOME 227 /* QuakeNet extension */
150 #define RPL_STATSQLINE 228 /* Undernet extension */
151 #define RPL_STATSHEADER 230 /* QuakeNet extension */
154 /* ERR_GHOSTEDCLIENT 503 efnet */
155 /* ERR_VWORLDWARN 503 austnet */
157 +#define ERR_NOSUCHWELCOME 509 /* QuakeNet extension */
159 #define ERR_SILELISTFULL 511 /* Undernet extension */
160 /* ERR_NOTIFYFULL 512 aircd */
161 /* ERR_TOOMANYWATCH 512 Numeric List: Dalnet */
162 diff -r 42bf40ebc839 include/welcome.h
163 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
164 +++ b/include/welcome.h Fri Jan 30 13:14:46 2009 +0100
166 +#ifndef INCLUDED_welcome_h
167 +#define INCLUDED_welcome_h
169 + * IRC - Internet Relay Chat, include/welcome.h
170 + * Copyright (C) 1990 Jarkko Oikarinen and
171 + * University of Oulu, Computing Center
172 + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
174 + * This program is free software; you can redistribute it and/or modify
175 + * it under the terms of the GNU General Public License as published by
176 + * the Free Software Foundation; either version 2, or (at your option)
177 + * any later version.
179 + * This program is distributed in the hope that it will be useful,
180 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
181 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
182 + * GNU General Public License for more details.
184 + * You should have received a copy of the GNU General Public License
185 + * along with this program; if not, write to the Free Software
186 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
189 + * @brief Interface and declarations for welcome message handling.
191 +#ifndef INCLUDED_sys_types_h
192 +#include <sys/types.h>
193 +#define INCLUDED_sys_types_h
199 +/* Maximum number of welcome entries (per type; X global, X local) */
200 +#define WELCOME_MAX_ENTRIES 10
201 +/* Maximum timestamp drift in seconds allowed ahead of our idea of nettime
202 + * before we throw a warning to ops
204 +#define WELCOME_MAX_DRIFT 600
206 +/* Describes a Welcome message entry. */
208 + time_t timestamp; /**< Timestamp of the welcome */
209 + char text[TOPICLEN + 1]; /**< Message */
210 + char who[ACCOUNTLEN + 1]; /**< Who set it */
213 +/** Welcome type flags */
214 +#define WELCOME_LOCAL 0x01 /**< welcome is local */
215 +/** Welcome action flags */
216 +#define WELCOME_ANNOUNCE 0x02 /**< announce change to users */
218 +extern int welcome_do(struct Client *cptr, struct Client *sptr, char *name, char *text,
219 + char *who, time_t timestamp, unsigned int flags);
220 +extern void welcome_announce(int name);
221 +extern void welcome_burst(struct Client *cptr);
222 +extern int welcome_list(struct Client *sptr, int connect);
223 +extern void welcome_stats(struct Client *sptr, const struct StatDesc *sd, char *param);
225 +#endif /* INCLUDED_welcome_h */
226 diff -r 42bf40ebc839 ircd/Makefile.in
227 --- a/ircd/Makefile.in Fri Jan 30 11:47:37 2009 +0100
228 +++ b/ircd/Makefile.in Fri Jan 30 13:14:46 2009 +0100
245 @@ -1168,6 +1170,11 @@
246 ../include/ircd_reply.h ../include/ircd_string.h \
247 ../include/ircd_chattr.h ../include/msg.h ../include/numeric.h \
248 ../include/numnicks.h ../include/s_user.h ../include/send.h
249 +m_welcome.o: m_welcome.c ../config.h ../include/channel.h \
250 + ../include/client.h ../include/hash.h ../include/ircd.h ../include/ircd_log.h \
251 + ../include/ircd_reply.h ../include/ircd_string.h ../include/msg.h \
252 + ../include/numeric.h ../include/numnicks.h ../include/s_user.h \
253 + ../include/send.h ../include/welcome.h
254 m_who.o: m_who.c ../config.h ../include/channel.h ../include/ircd_defs.h \
255 ../include/res.h ../config.h ../include/client.h ../include/dbuf.h \
256 ../include/msgq.h ../include/ircd_events.h ../include/ircd_handler.h \
257 @@ -1429,6 +1436,13 @@
258 ../include/numnicks.h ../include/querycmds.h ../include/ircd_features.h \
259 ../include/s_misc.h ../include/s_stats.h ../include/send.h \
260 ../include/struct.h ../include/sys.h
261 +welcome.o: welcome.c ../config.h ../include/client.h \
262 + ../include/hash.h ../include/ircd.h ../include/ircd_alloc.h \
263 + ../include/ircd_features.h ../include/ircd_log.h ../include/ircd_reply.h \
264 + ../include/match.h ../include/msg.h ../include/numeric.h \
265 + ../include/numnicks.h ../include/s_debug.h ../include/s_bsd.h \
266 + ../include/s_misc.h ../include/send.h ../include/struct.h \
267 + ../include/sys.h ../include/welcome.h
268 whocmds.o: whocmds.c ../config.h ../include/whocmds.h \
269 ../include/channel.h ../include/ircd_defs.h ../include/res.h \
270 ../config.h ../include/client.h ../include/dbuf.h ../include/msgq.h \
271 diff -r 42bf40ebc839 ircd/ircd_features.c
272 --- a/ircd/ircd_features.c Fri Jan 30 11:47:37 2009 +0100
273 +++ b/ircd/ircd_features.c Fri Jan 30 13:14:46 2009 +0100
275 F_I(IRCD_RES_TIMEOUT, 0, 4, 0),
276 F_I(AUTH_TIMEOUT, 0, 9, 0),
277 F_B(ANNOUNCE_INVITES, 0, 0, 0),
278 + F_B(WELCOME, 0, 1, 0),
280 /* features that affect all operators */
281 F_B(EXTENDED_CHECKCMD, 0, 0, 0),
283 F_B(HIS_STATS_u, 0, 1, 0),
284 F_B(HIS_STATS_U, 0, 1, 0),
285 F_B(HIS_STATS_v, 0, 1, 0),
286 + F_B(HIS_STATS_W, 0, 1, 0),
287 F_B(HIS_STATS_w, 0, 1, 0),
288 F_B(HIS_STATS_x, 0, 1, 0),
289 F_B(HIS_STATS_y, 0, 1, 0),
290 diff -r 42bf40ebc839 ircd/m_welcome.c
291 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
292 +++ b/ircd/m_welcome.c Fri Jan 30 13:14:46 2009 +0100
295 + * IRC - Internet Relay Chat, ircd/m_welcome.c
296 + * Copyright (C) 1990 Jarkko Oikarinen and
297 + * University of Oulu, Computing Center
299 + * See file AUTHORS in IRC package for additional names of
302 + * This program is free software; you can redistribute it and/or modify
303 + * it under the terms of the GNU General Public License as published by
304 + * the Free Software Foundation; either version 1, or (at your option)
305 + * any later version.
307 + * This program is distributed in the hope that it will be useful,
308 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
309 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
310 + * GNU General Public License for more details.
312 + * You should have received a copy of the GNU General Public License
313 + * along with this program; if not, write to the Free Software
314 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
319 + * m_functions execute protocol messages on this server:
321 + * cptr is always NON-NULL, pointing to a *LOCAL* client
322 + * structure (with an open socket connected!). This
323 + * identifies the physical socket where the message
324 + * originated (or which caused the m_function to be
325 + * executed--some m_functions may call others...).
327 + * sptr is the source of the message, defined by the
328 + * prefix part of the message if present. If not
329 + * or prefix not found, then sptr==cptr.
331 + * (!IsServer(cptr)) => (cptr == sptr), because
332 + * prefixes are taken *only* from servers...
335 + * (sptr == cptr) => the message didn't
338 + * (sptr != cptr && IsServer(sptr) means
339 + * the prefix specified servername. (?)
341 + * (sptr != cptr && !IsServer(sptr) means
342 + * that message originated from a remote
343 + * user (not local).
347 + * (!IsServer(sptr)) means that, sptr can safely
348 + * taken as defining the target structure of the
349 + * message in this server.
351 + * *Always* true (if 'parse' and others are working correct):
353 + * 1) sptr->from == cptr (note: cptr->from == cptr)
355 + * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
356 + * *cannot* be a local connection, unless it's
357 + * actually cptr!). [MyConnect(x) should probably
358 + * be defined as (x == x->from) --msa ]
360 + * parc number of variable parameter strings (if zero,
361 + * parv is allowed to be NULL)
363 + * parv a NULL terminated list of parameter pointers,
365 + * parv[0], sender (prefix string), if not present
366 + * this points to an empty string.
367 + * parv[1]...parv[parc-1]
368 + * pointers to additional parameters
369 + * parv[parc] == NULL, *always*
371 + * note: it is guaranteed that parv[0]..parv[parc-1] are all
372 + * non-NULL pointers.
376 +#include "channel.h"
380 +#include "ircd_features.h"
381 +#include "ircd_log.h"
382 +#include "ircd_reply.h"
383 +#include "ircd_string.h"
385 +#include "numeric.h"
386 +#include "numnicks.h"
389 +#include "welcome.h"
391 +/* #include <assert.h> -- Now using assert in ircd_log.h */
394 + * m_welcome - local generic message handler
396 + * parv[0] = Send prefix
397 + * parv[1] = [remote server to query]
399 +int m_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
401 + /* feature disabled */
402 + if (!feature_bool(FEAT_WELCOME))
403 + return send_reply(sptr, ERR_DISABLED, "WELCOME");
405 + /* only opers can set the welcome messages */
407 + return send_reply(sptr, ERR_NOPRIVILEGES);
409 + /* remote listing request, see if it is for me or a remote server
410 + * check FEAT_HIS_REMOTE to decide if an ordinary user can do this
413 + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, feature_int(FEAT_HIS_REMOTE),
414 + "%C", 1, parc, parv) != HUNTED_ISME)
416 + return welcome_list(sptr, 0);
419 + /* just local listing */
420 + return welcome_list(sptr, 0);
425 + * mo_welcome - oper message handler
428 + * parv[0] = Send prefix
431 + * parv[0] = Send prefix
434 + * set global or on remote server:
435 + * parv[0] = Send prefix
436 + * parv[1] = Target: server or * for global (or left out for this server)
440 +int mo_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
442 + char *target, *name, *who, *text, pattern[BUFSIZE];
444 + unsigned int flags = 0;
447 + /* feature disabled */
448 + if (!feature_bool(FEAT_WELCOME))
449 + return send_reply(sptr, ERR_DISABLED, "WELCOME");
453 + return welcome_list(sptr, 0);
455 + /* TODO: add PRIV_WELCOME? */
457 + if (!HasPriv(sptr,PRIV_SERVERINFO))
458 + return send_reply(sptr, ERR_NOPRIVILEGES);
460 + /* remote listing request, see if it is for me or a remote server */
462 + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C", 1, parc, parv) != HUNTED_ISME)
464 + return welcome_list(sptr, 0);
467 + /* set the parameters */
469 + /* target not given, only name - setting local welcome */
472 + target = cli_name(&me);
474 + flags |= WELCOME_LOCAL;
476 + /* target and name given */
481 + timestamp = TStime();
482 + who = cli_user(sptr)->opername;
483 + text = parv[parc - 1];
485 + /* target is not global */
486 + if (!(target[0] == '*' && target[1] == '\0') && !local) {
488 + /* build a pattern for hunt_server_cmd since we do not have all we need in parv */
489 + ircd_snprintf(0, pattern, sizeof(pattern), "%s %s %Tu %s :%s", "%C", name, timestamp, who, text);
490 + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, pattern, 1, 2, parv) != HUNTED_ISME)
493 + /* else it is a local welcome, for me */
494 + flags |= WELCOME_LOCAL;
497 + /* TODO: disallow global announcement from oper?
498 + * as PRIVMSG/NOTICE to $* is not allowed either by the ircd
499 + * when PRIV for that is added, use that here? PRIV_BROADCAST or something
501 + /* check for anounce prefix */
502 + if (*name == '!') {
504 + flags |= WELCOME_ANNOUNCE;
508 + return welcome_do(cptr, sptr, name, text, who, timestamp, flags);
513 + * ms_welcome - server message handler
515 + * parv[0] = Send prefix
516 + * parv[1] = Target: server numeric or * for global
518 + * parv[3] = Timestamp
522 +int ms_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
524 + char *target, *name, *who, *text;
526 + unsigned int flags = 0;
528 + /* not enough - complain */
530 + protocol_violation(sptr, "Too few parameters for WELCOME (got %d - need 2)", parc);
531 + return need_more_params(sptr, "WELCOME");
534 + /* remote listing request, see if it is for me or a remote server */
536 + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C", 1, parc, parv) != HUNTED_ISME)
538 + return welcome_list(sptr, 0);
541 + /* we need at least 6 parameters to continue - complain */
543 + protocol_violation(sptr, "Too few parameters for WELCOME (got %d - need 6)", parc);
544 + return need_more_params(sptr, "WELCOME");
547 + /* set the parameters */
550 + timestamp = atoi(parv[3]);
552 + text = parv[parc - 1]; /* parse reason as last parameter */
554 + /* target is not global */
555 + if (!(target[0] == '*' && target[1] == '\0')) {
557 + /* not for me, and forward it */
558 + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C %s %s %s :%s", 1, parc, parv) != HUNTED_ISME)
561 + /* local welcome for me */
562 + flags |= WELCOME_LOCAL;
565 + /* check for anounce prefix */
566 + if (*name == '!') {
568 + flags |= WELCOME_ANNOUNCE;
572 + return welcome_do(cptr, sptr, name, text, who, timestamp, flags);
577 + * mh_welcome - help message handler
579 +int mh_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
581 + if (!IsAnOper(sptr)) {
582 + send_reply(sptr, SND_EXPLICIT | RPL_HELP,
583 + "WELCOME :WELCOME");
584 + send_reply(sptr, SND_EXPLICIT | RPL_HELP,
585 + "WELCOME :Shows welcome messages set on the server.");
587 + send_reply(sptr, SND_EXPLICIT | RPL_HELP,
588 + "WELCOME :WELCOME [<target>] [[!]<name> :<message>]");
589 + send_reply(sptr, SND_EXPLICIT | RPL_HELP,
590 + "WELCOME :Shows or sets welcome messages on a server.");
594 diff -r 42bf40ebc839 ircd/parse.c
595 --- a/ircd/parse.c Fri Jan 30 11:47:37 2009 +0100
596 +++ b/ircd/parse.c Fri Jan 30 13:14:46 2009 +0100
598 /* UNREG, CLIENT, SERVER, OPER, SERVICE, HELP */
599 { m_unregistered, m_not_oper, ms_opkick, mo_opkick, m_ignore, mh_nohelp }
602 + /* add command for WELCOME */
606 + 0, MAXPARA, MFLG_SLOW, 0, NULL,
607 + /* UNREG, CLIENT, SERVER, OPER, SERVICE, HELP */
608 + { m_unregistered, m_welcome, ms_welcome, mo_welcome, m_ignore, mh_welcome }
611 /* This command is an alias for QUIT during the unregistered part of
612 * of the server. This is because someone jumping via a broken web
613 diff -r 42bf40ebc839 ircd/s_err.c
614 --- a/ircd/s_err.c Fri Jan 30 11:47:37 2009 +0100
615 +++ b/ircd/s_err.c Fri Jan 30 13:14:46 2009 +0100
618 { RPL_STATSALINE, "%s", "226" },
621 + { RPL_STATSWELCOME, "W %d %s %s %Tu :%s", "227" },
623 { RPL_STATSQLINE, "Q %s :%s", "228" },
625 @@ -1050,7 +1050,7 @@
630 + { ERR_NOSUCHWELCOME, "%s :No such welcome", "509" },
634 diff -r 42bf40ebc839 ircd/s_serv.c
635 --- a/ircd/s_serv.c Fri Jan 30 11:47:37 2009 +0100
636 +++ b/ircd/s_serv.c Fri Jan 30 13:14:46 2009 +0100
640 #include "userload.h"
641 +#include "welcome.h"
643 /* #include <assert.h> -- Now using assert in ircd_log.h */
649 + welcome_burst(cptr);
652 * Pass on my client information to the new server
653 diff -r 42bf40ebc839 ircd/s_stats.c
654 --- a/ircd/s_stats.c Fri Jan 30 11:47:37 2009 +0100
655 +++ b/ircd/s_stats.c Fri Jan 30 13:14:46 2009 +0100
659 #include "userload.h"
660 +#include "welcome.h"
665 { 'V', "vserversmach", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS), FEAT_HIS_STATS_v,
666 stats_servers_verbose, 0,
667 "Verbose server information." },
668 - { 'w', "userload", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_w,
669 + { 'w', "userload", STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS, FEAT_HIS_STATS_w,
671 "Userload statistics." },
672 + { 'W', "welcome", STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS, FEAT_HIS_STATS_W,
674 + "Welcome messages." },
675 { 'x', "memusage", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_x,
677 "List usage information." },
678 diff -r 42bf40ebc839 ircd/s_user.c
679 --- a/ircd/s_user.c Fri Jan 30 11:47:37 2009 +0100
680 +++ b/ircd/s_user.c Fri Jan 30 13:14:46 2009 +0100
682 #include "userload.h"
685 +#include "welcome.h"
687 #include "handlers.h" /* m_motd and m_lusers */
690 cli_info(sptr), NumNick(cptr) /* two %s's */);
692 IPcheck_connect_succeeded(sptr);
694 + if (feature_bool(FEAT_WELCOME))
695 + welcome_list(sptr, 1);
698 struct Client *acptr = user->server;
699 diff -r 42bf40ebc839 ircd/welcome.c
700 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
701 +++ b/ircd/welcome.c Fri Jan 30 13:14:46 2009 +0100
704 + * IRC - Internet Relay Chat, ircd/welcome.c
705 + * Copyright (C) 1990 Jarkko Oikarinen and
706 + * University of Oulu, Finland
707 + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
709 + * This program is free software; you can redistribute it and/or modify
710 + * it under the terms of the GNU General Public License as published by
711 + * the Free Software Foundation; either version 1, or (at your option)
712 + * any later version.
714 + * This program is distributed in the hope that it will be useful,
715 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
716 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
717 + * GNU General Public License for more details.
719 + * You should have received a copy of the GNU General Public License
720 + * along with this program; if not, write to the Free Software
721 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
724 + * @brief Implementation of welcome message handling functions.
731 +#include "ircd_alloc.h"
732 +#include "ircd_features.h"
733 +#include "ircd_log.h"
734 +#include "ircd_reply.h"
735 +#include "ircd_string.h"
738 +#include "numeric.h"
739 +#include "numnicks.h"
741 +#include "s_debug.h"
745 +#include "sys.h" /* FALSE bleah */
746 +#include "welcome.h"
748 +/* #include <assert.h> -- Now using assert in ircd_log.h */
752 +/** List of welcome messages - first MAX for global, second MAX for local */
753 +static struct Welcome WelcomeArray[WELCOME_MAX_ENTRIES * 2] = { { 0 } };
756 +/** Allocate a new welcome with the given parameters.
757 + * @param[in] name Name of the welcome message.
758 + * @param[in] text The welcome message.
759 + * @param[in] who Who set it.
760 + * @param[in] timestamp When it was set.
761 + * @return name Array number of the welcome set.
764 +welcome_make(int name, char *text, char *who, time_t timestamp)
766 + /* range 0 to 2 * max - 1 */
767 + assert(name >= 0 && name <= 2 * WELCOME_MAX_ENTRIES - 1);
770 + ircd_strncpy(WelcomeArray[name].text, text, TOPICLEN);
771 + ircd_strncpy(WelcomeArray[name].who, who, ACCOUNTLEN);
772 + WelcomeArray[name].timestamp = timestamp;
778 +/** Change a welcome message.
779 + * @param[in] cptr Local client that sent us the welcome.
780 + * @param[in] sptr Originator of the welcome.
781 + * @param[in] name Name of the message.
782 + * @param[in] text The welcome message.
783 + * @param[in] timestamp Timestamp of when the message was set.
784 + * @param[in] flags Flags to set on welcome.
788 +welcome_do(struct Client *cptr, struct Client *sptr, char *name, char *text,
789 + char *who, time_t timestamp, unsigned int flags)
791 + int nameint = atoi(name); /* transform to int */
792 + int namearray = nameint - 1; /* used to test the array element */
793 + char oldtext[TOPICLEN + 1]; /* save old text when unsetting */
794 + static time_t rate;
796 + assert(NULL != cptr);
797 + assert(NULL != sptr);
798 + assert(NULL != name);
799 + assert(NULL != text);
800 + assert(NULL != who);
803 + Debug((DEBUG_DEBUG, "welcome_do(\"%s\", \"%s\", \"%s\", \"%s\" \"%s\", %Tu, 0x%04x)",
804 + cli_name(cptr), cli_name(sptr), name, text, who, timestamp, flags));
807 + if (nameint < 1 || nameint > WELCOME_MAX_ENTRIES) {
809 + sendcmdto_one(&me, CMD_NOTICE, sptr,
810 + "%C :WELCOME: Invalid message number %s - should between 1 and %d",
811 + sptr, name, WELCOME_MAX_ENTRIES);
815 + /* correct namearray for local offset */
816 + if (flags & WELCOME_LOCAL)
817 + namearray += WELCOME_MAX_ENTRIES;
819 + /* cannot unset welcome that is not set */
820 + if (WelcomeArray[namearray].timestamp == 0 && EmptyString(text)) {
822 + /* from user, throw error */
824 + return send_reply(sptr, ERR_NOSUCHWELCOME, name);
826 + /* new local welcome from server, but empty - ignore
827 + * we do accept a new global welcome message that is empty
829 + if (flags & WELCOME_LOCAL)
833 + /* check if there is something to change */
834 + /* we got a record for it */
835 + if (WelcomeArray[namearray].timestamp != 0) {
838 + if (namearray < WELCOME_MAX_ENTRIES) {
840 + /* netburst and we got the same or a newer one
842 + * we only use the timestamp for resolving conflicts in net burst
843 + * outside of netburst, we simply parse whatever we get
844 + * this way we will not get stuck with a welcome message set by a server
845 + * running ahead with the time
847 + if (IsBurstOrBurstAck(cptr) && timestamp <= WelcomeArray[namearray].timestamp)
850 + /* local welcome - we use our idea of the time */
852 + timestamp = TStime();
854 + /* compare new message with old message */
855 + if (ircd_strcmp(text, WelcomeArray[namearray].text) == 0) {
857 + sendcmdto_one(&me, CMD_NOTICE, sptr,
858 + "%C :WELCOME: Cannot change %smessage for %s - nothing to change.",
859 + sptr, (flags & WELCOME_LOCAL) ? "local " : "", name);
864 + /* TODO: rate limited for what? max 10 welcome messages..? */
865 + /* possible timestamp drift - warn ops */
866 + if (timestamp - TStime() > WELCOME_MAX_DRIFT) {
867 + sendto_opmask_butone_ratelimited(0, SNO_NETWORK, &rate,
868 + "Possible timestamp drift from %C; timestamp in WELCOME message is %is ahead of time",
869 + IsServer(sptr) ? sptr : cli_user(sptr)->server, timestamp - TStime());
871 + /* warn remote oper too */
873 + sendcmdto_one(&me, CMD_NOTICE, sptr,
874 + "%C :Possible timestamp drift from %C; timestamp in WELCOME message is %is ahead of time",
875 + sptr, cli_user(sptr)->server, timestamp - TStime());
878 + /* unsetting - do not announce, save text */
879 + if (EmptyString(text)) {
880 + flags &= ~WELCOME_ANNOUNCE;
881 + ircd_strncpy(oldtext, WelcomeArray[namearray].text, TOPICLEN);
885 + welcome_make(namearray, text, who, timestamp);
888 + sendto_opmask_butone(0, SNO_OLDSNO, "%s %s%s%sWELCOME %d \"%s\" [%Tu]",
889 + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
890 + get_client_name_and_opername(sptr) : cli_name((cli_user(sptr))->server),
891 + EmptyString(text) ? "unsetting" : "changing",
892 + (flags & WELCOME_ANNOUNCE) ? " and announcing " : " ",
893 + (flags & WELCOME_LOCAL) ? "local " : "",
895 + EmptyString(text) ? oldtext : WelcomeArray[namearray].text,
896 + WelcomeArray[namearray].timestamp);
899 + log_write(LS_NETWORK, L_INFO, LOG_NOSNOTICE, "%#C (%s) %s%s%sWELCOME %d \"%s\" [%Tu]",
900 + sptr, WelcomeArray[namearray].who,
901 + EmptyString(text) ? "unsetting" : "changing",
902 + (flags & WELCOME_ANNOUNCE) ? " and announcing " : " ",
903 + (flags & WELCOME_LOCAL) ? "local " : "",
905 + EmptyString(text) ? oldtext : WelcomeArray[namearray].text,
906 + WelcomeArray[namearray].timestamp);
908 + /* welcome set by remote user, inform oper of success */
909 + if ((flags & WELCOME_LOCAL) && IsUser(sptr) && !MyUser(sptr)) {
910 + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s %s%s local WELCOME %d \"%s\" [%Tu]",
911 + sptr, get_client_name_and_opername(sptr),
912 + EmptyString(text) ? "unsetting" : "changing",
913 + (flags & WELCOME_ANNOUNCE) ? " and announcing" : "",
915 + EmptyString(text) ? oldtext : WelcomeArray[namearray].text,
916 + WelcomeArray[namearray].timestamp);
918 + /* TODO: wallops all local changes, by both local and remote opers? */
919 + /* tell all opers about the local message being set remotely */
920 + sendwallto_group_butone(&me, WALL_WALLOPS, 0,
921 + "%s %s%s local WELCOME %d \"%s\" [%Tu]",
922 + get_client_name_and_opername(sptr),
923 + EmptyString(text) ? "unsetting" : "changing",
924 + (flags & WELCOME_ANNOUNCE) ? " and announcing" : "",
926 + EmptyString(text) ? oldtext : WelcomeArray[namearray].text,
927 + WelcomeArray[namearray].timestamp);
931 + if (!(flags & WELCOME_LOCAL))
932 + sendcmdto_serv_butone(sptr, CMD_WELCOME, cptr, "* %s%d %Tu %s :%s",
933 + (flags & WELCOME_ANNOUNCE) ? "!" : "", nameint,
934 + WelcomeArray[namearray].timestamp, WelcomeArray[namearray].who,
935 + WelcomeArray[namearray].text);
938 + if (flags & WELCOME_ANNOUNCE)
939 + welcome_announce(namearray);
945 +/** Announce a welcome message to local clients.
946 + * @param[in] name Welcome message to announce.
949 +welcome_announce(int name)
951 + struct Client *acptr;
952 + struct MsgBuf *msgbuf;
955 + /* range 0 to 2 * max - 1 */
956 + assert(name >= 0 && name <= 2 * WELCOME_MAX_ENTRIES - 1);
958 + /* TODO: target is $* as if it were a global broadcast
959 + * could make it $servername for local message announcement
960 + * but the type is shown between [ ] already
961 + * either [Network] or [servername] - using $* is just shorter.
964 + msgbuf = msgq_make(0, ":%C %s $* :[%s] %s", &me, MSG_NOTICE,
965 + name >= WELCOME_MAX_ENTRIES ? cli_name(&me) : feature_str(FEAT_NETWORK),
966 + WelcomeArray[name].text);
968 + /* go over local clients */
969 + for (i = HighestFd; i > 0; --i) {
971 + /* skip unregistered clients - they see the message during login
974 + if (!(acptr = LocalClientArray[i]) || !IsRegistered(acptr) || IsServer(acptr))
978 + send_buffer(acptr, msgbuf, 0);
983 +/** Send the full list of welcome message to \a cptr.
984 + * @param[in] cptr Local server to send welcomes to.
987 +welcome_burst(struct Client *cptr)
991 + assert(NULL != cptr);
993 + /* loop over global entries - 0 to max - 1*/
994 + for (name = 0; name <= WELCOME_MAX_ENTRIES - 1; name++) {
995 + if (WelcomeArray[name].timestamp != 0)
996 + sendcmdto_one(&me, CMD_WELCOME, cptr, "* %d %Tu %s :%s",
997 + name + 1, WelcomeArray[name].timestamp, WelcomeArray[name].who,
998 + WelcomeArray[name].text);
1003 +/** List welcome messages.
1004 + * @param[in] sptr Client requesting the listing.
1005 + * @param[in] connect When non zero do not report no welcome is set
1009 +welcome_list(struct Client *sptr, int connect)
1011 + int found = 0, local = 0, name;
1013 + assert(NULL != sptr);
1015 + /* loop over all entries - range 0 to 2 * max - 1 */
1016 + for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) {
1018 + /* local entries now */
1019 + if (name == WELCOME_MAX_ENTRIES)
1022 + /* not set or empty - skip */
1023 + /* TODO: EmptyString? */
1024 + if (WelcomeArray[name].timestamp == 0 || *WelcomeArray[name].text == 0)
1029 + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :[%s] %s",
1030 + sptr, local ? cli_name(&me) : feature_str(FEAT_NETWORK), WelcomeArray[name].text);
1034 + if (!found && !connect)
1035 + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :No welcome message set.", sptr);
1041 +/** Statistics callback to list Welcome messages.
1042 + * @param[in] sptr Client requesting statistics.
1043 + * @param[in] sd Stats descriptor for request (ignored).
1044 + * @param[in] param Extra parameter from user (ignored).
1047 +welcome_stats(struct Client *sptr, const struct StatDesc *sd, char *param)
1049 + int name, local = 0;
1051 + assert(NULL != sptr);
1053 + /* send header so the client knows what we are showing */
1054 + send_reply(sptr, SND_EXPLICIT | RPL_STATSHEADER,
1055 + "W Name Target Opername Timestamp :Message");
1057 + /* loop over all entries - range 0 to 2 * max - 1*/
1058 + for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) {
1060 + /* local entries now */
1061 + if (name == WELCOME_MAX_ENTRIES)
1065 + if (WelcomeArray[name].timestamp == 0)
1069 + send_reply(sptr, RPL_STATSWELCOME,
1070 + local ? name + 1 - WELCOME_MAX_ENTRIES : name + 1,
1071 + local ? cli_name(&me) : "*",
1072 + WelcomeArray[name].who, WelcomeArray[name].timestamp,
1073 + EmptyString(WelcomeArray[name].text) ? "<Empty>" : WelcomeArray[name].text);