]> jfr.im git - irc/quakenet/snircd-patchqueue.git/blame - welcome.patch
badchanzombie.patch - remove redundant IsZombie() check.
[irc/quakenet/snircd-patchqueue.git] / welcome.patch
CommitLineData
a87bc2c2 1Add welcome message functionality.
2
3client commands:
4user:
5/WELCOME
6shows welcome messages set, same is shown on connect
7
8oper:
9/WELCOME [<target>] [[!]<name> :<message>]
10to view welcome messages from a remote server
11to set a local welcome message on this server or a remote server
12set a global welcome message (target *)
13the ! prefix makes the server annouce the welcome message to its clients when setting
14
15server:
cb0b5df1 16:<source> WE <target> [[!]<name> <timestamp> <who> :<text>]
a87bc2c2 17who is who set the message, the server puts in the opername when a client sets it.
cb0b5df1 18:<name> is a number 1 to WELCOME_MAX_ENTRIES - currently set at 10 (should be more than we ever need)
a87bc2c2 19that means there is room for 10 local and 10 global entries
a87bc2c2 20
cb0b5df1 21STATS W/welcome (/STATS w/userload made case sensitive)
a87bc2c2 22:server 230 nick W Name Target Who Timestamp :Message
23:server 227 nick W 1 * opername 1233072583 :Latest news: testing this welcome patch :)
24:server 227 nick W 2 * opername 1233072583 :
25:server 227 nick W 1 servername opername 1233072590 :This is a test server, expect restarts.
26:server 219 nick W :End of /STATS report
27
28listing welcomes or on connect:
29:server NOTICE nick :[QuakeNet] Latest news: testing this welcome patch :)
30:server NOTICE nick :[server] This is a test server, expect restarts.
31
32announcement is done by a notice by the local server to $* with the same message
33format as for listing welcome messages.
34:server NOTICE $* :[QuakeNet] Latest news: testing this welcome patch :)
35:server NOTICE $* :[server] This is a test server, expect restarts.
36
37
38Files:
39
40include/handlers.h
41add m_welcome mo_welcome ms_welcome mh_welcome functions
42
43include/features.h
44ircd/features.c
45add features FEAT_WELCOME and FEAT_HIS_STATS_W
46
47include/msg.h
48add MSG_WELCOME TOK_WELCOME CMD_WELCOME
49
50ircd/parse.c
51add welcome message functions
52
53include/numeric.h
54ircd/s_err.c
55add RPL_STATSWELCOME ERR_NOSUCHWELCOME
56
57include/welcome.h
58ircd/welcome.c
59ircd/m_welcome.c
60new
61
62ircd/Makefile.in
63add welcome.c and m_welcome.c files
64
a87bc2c2 65ircd/s_serv.c
66add burst welcome message
67
68ircd/s_stats.c
69add /STATS W/welcome
70
71ircd/s_user.c
72add showing of welcome messages on connect
73
6dd3e24f 74diff -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
cddf800b 77@@ -151,6 +151,7 @@
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*[]);
85@@ -185,6 +186,7 @@
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*[]);
93@@ -242,6 +244,7 @@
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*[]);
99
a87bc2c2 100 extern int mh_nohelp(struct Client*, struct Client*, int, char*[]);
101@@ -308,6 +311,7 @@
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*[]);
6dd3e24f 109diff -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
a87bc2c2 112@@ -101,6 +101,7 @@
113 FEAT_IRCD_RES_TIMEOUT,
114 FEAT_AUTH_TIMEOUT,
115 FEAT_ANNOUNCE_INVITES,
116+ FEAT_WELCOME,
117
118 /* features that affect all operators */
119 FEAT_EXTENDED_CHECKCMD,
120@@ -143,6 +144,7 @@
121 FEAT_HIS_STATS_u,
122 FEAT_HIS_STATS_U,
123 FEAT_HIS_STATS_v,
124+ FEAT_HIS_STATS_W,
125 FEAT_HIS_STATS_w,
126 FEAT_HIS_STATS_x,
127 FEAT_HIS_STATS_y,
6dd3e24f 128diff -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
100a7f47 131@@ -196,6 +196,10 @@
cddf800b 132 #define TOK_NOTICE "O"
133 #define CMD_NOTICE MSG_NOTICE, TOK_NOTICE
100a7f47 134
cddf800b 135+#define MSG_WELCOME "WELCOME" /* WELC */
136+#define TOK_WELCOME "WE"
137+#define CMD_WELCOME MSG_WELCOME, TOK_WELCOME
100a7f47 138+
cddf800b 139 #define MSG_WALLCHOPS "WALLCHOPS" /* WC */
140 #define TOK_WALLCHOPS "WC"
100a7f47 141 #define CMD_WALLCHOPS MSG_WALLCHOPS, TOK_WALLCHOPS
6dd3e24f 142diff -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
a87bc2c2 145@@ -116,6 +116,7 @@
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 */
152
cb0b5df1 153@@ -445,6 +446,8 @@
a87bc2c2 154 /* ERR_GHOSTEDCLIENT 503 efnet */
155 /* ERR_VWORLDWARN 503 austnet */
156
157+#define ERR_NOSUCHWELCOME 509 /* QuakeNet extension */
158+
159 #define ERR_SILELISTFULL 511 /* Undernet extension */
160 /* ERR_NOTIFYFULL 512 aircd */
161 /* ERR_TOOMANYWATCH 512 Numeric List: Dalnet */
6dd3e24f 162diff -r 42bf40ebc839 include/welcome.h
cddf800b 163--- /dev/null Thu Jan 01 00:00:00 1970 +0000
6dd3e24f 164+++ b/include/welcome.h Fri Jan 30 13:14:46 2009 +0100
165@@ -0,0 +1,60 @@
cddf800b 166+#ifndef INCLUDED_welcome_h
167+#define INCLUDED_welcome_h
168+/*
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>
173+ *
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.
178+ *
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.
183+ *
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.
187+ */
188+/** @file
a87bc2c2 189+ * @brief Interface and declarations for welcome message handling.
cddf800b 190+ */
191+#ifndef INCLUDED_sys_types_h
192+#include <sys/types.h>
193+#define INCLUDED_sys_types_h
194+#endif
195+
a87bc2c2 196+struct Client;
197+struct StatDesc;
198+
cb0b5df1 199+/* Maximum number of welcome entries (per type; X global, X local) */
6dd3e24f 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
203+ */
204+#define WELCOME_MAX_DRIFT 600
a87bc2c2 205+
206+/* Describes a Welcome message entry. */
207+struct Welcome {
6dd3e24f 208+ time_t timestamp; /**< Timestamp of the welcome */
209+ char text[TOPICLEN + 1]; /**< Message */
210+ char who[ACCOUNTLEN + 1]; /**< Who set it */
a87bc2c2 211+};
212+
cb0b5df1 213+/** Welcome type flags */
a87bc2c2 214+#define WELCOME_LOCAL 0x01 /**< welcome is local */
215+/** Welcome action flags */
216+#define WELCOME_ANNOUNCE 0x02 /**< announce change to users */
217+
a87bc2c2 218+extern int welcome_do(struct Client *cptr, struct Client *sptr, char *name, char *text,
219+ char *who, time_t timestamp, unsigned int flags);
cb0b5df1 220+extern void welcome_announce(int name);
cddf800b 221+extern void welcome_burst(struct Client *cptr);
a87bc2c2 222+extern int welcome_list(struct Client *sptr, int connect);
223+extern void welcome_stats(struct Client *sptr, const struct StatDesc *sd, char *param);
cddf800b 224+
225+#endif /* INCLUDED_welcome_h */
6dd3e24f 226diff -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
a87bc2c2 229@@ -187,6 +187,7 @@
230 m_wallops.c \
231 m_wallusers.c \
232 m_wallvoices.c \
233+ m_welcome.c \
234 m_who.c \
235 m_whois.c \
236 m_whowas.c \
237@@ -214,6 +215,7 @@
238 send.c \
239 uping.c \
240 userload.c \
241+ welcome.c \
242 whocmds.c \
243 whowas.c \
244 y.tab.c
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 \
6dd3e24f 271diff -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
a87bc2c2 274@@ -355,6 +355,7 @@
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),
279
280 /* features that affect all operators */
281 F_B(EXTENDED_CHECKCMD, 0, 0, 0),
282@@ -397,6 +398,7 @@
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),
6dd3e24f 290diff -r 42bf40ebc839 ircd/m_welcome.c
cddf800b 291--- /dev/null Thu Jan 01 00:00:00 1970 +0000
6dd3e24f 292+++ b/ircd/m_welcome.c Fri Jan 30 13:14:46 2009 +0100
293@@ -0,0 +1,300 @@
cddf800b 294+/*
295+ * IRC - Internet Relay Chat, ircd/m_welcome.c
296+ * Copyright (C) 1990 Jarkko Oikarinen and
297+ * University of Oulu, Computing Center
298+ *
299+ * See file AUTHORS in IRC package for additional names of
300+ * the programmers.
301+ *
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.
306+ *
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.
311+ *
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.
315+ *
cddf800b 316+ */
317+
318+/*
319+ * m_functions execute protocol messages on this server:
320+ *
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...).
326+ *
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.
330+ *
331+ * (!IsServer(cptr)) => (cptr == sptr), because
332+ * prefixes are taken *only* from servers...
333+ *
334+ * (IsServer(cptr))
335+ * (sptr == cptr) => the message didn't
336+ * have the prefix.
337+ *
338+ * (sptr != cptr && IsServer(sptr) means
339+ * the prefix specified servername. (?)
340+ *
341+ * (sptr != cptr && !IsServer(sptr) means
342+ * that message originated from a remote
343+ * user (not local).
344+ *
345+ * combining
346+ *
347+ * (!IsServer(sptr)) means that, sptr can safely
348+ * taken as defining the target structure of the
349+ * message in this server.
350+ *
351+ * *Always* true (if 'parse' and others are working correct):
352+ *
353+ * 1) sptr->from == cptr (note: cptr->from == cptr)
354+ *
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 ]
359+ *
360+ * parc number of variable parameter strings (if zero,
361+ * parv is allowed to be NULL)
362+ *
363+ * parv a NULL terminated list of parameter pointers,
364+ *
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*
370+ *
371+ * note: it is guaranteed that parv[0]..parv[parc-1] are all
372+ * non-NULL pointers.
373+ */
374+#include "config.h"
375+
376+#include "channel.h"
377+#include "client.h"
378+#include "hash.h"
379+#include "ircd.h"
a87bc2c2 380+#include "ircd_features.h"
cddf800b 381+#include "ircd_log.h"
382+#include "ircd_reply.h"
383+#include "ircd_string.h"
384+#include "msg.h"
385+#include "numeric.h"
386+#include "numnicks.h"
387+#include "s_user.h"
388+#include "send.h"
a87bc2c2 389+#include "welcome.h"
cddf800b 390+
391+/* #include <assert.h> -- Now using assert in ircd_log.h */
392+
393+/*
394+ * m_welcome - local generic message handler
395+ *
396+ * parv[0] = Send prefix
6dd3e24f 397+ * parv[1] = [remote server to query]
cddf800b 398+ */
399+int m_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
400+{
a87bc2c2 401+ /* feature disabled */
402+ if (!feature_bool(FEAT_WELCOME))
403+ return send_reply(sptr, ERR_DISABLED, "WELCOME");
6dd3e24f 404+
405+ /* only opers can set the welcome messages */
406+ if (parc > 2)
407+ return send_reply(sptr, ERR_NOPRIVILEGES);
408+
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
411+ */
412+ if (parc == 2) {
413+ if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, feature_int(FEAT_HIS_REMOTE),
414+ "%C", 1, parc, parv) != HUNTED_ISME)
415+ return 0;
416+ return welcome_list(sptr, 0);
417+ }
418+
419+ /* just local listing */
a87bc2c2 420+ return welcome_list(sptr, 0);
cddf800b 421+}
422+
423+
424+/*
425+ * mo_welcome - oper message handler
426+ *
427+ * listing:
428+ * parv[0] = Send prefix
429+ *
430+ * remote listing:
431+ * parv[0] = Send prefix
432+ * parv[1] = Target
433+ *
434+ * set global or on remote server:
435+ * parv[0] = Send prefix
6dd3e24f 436+ * parv[1] = Target: server or * for global (or left out for this server)
a87bc2c2 437+ * parv[2] = Name
438+ * parv[3] = Text
cddf800b 439+ */
440+int mo_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
441+{
cb0b5df1 442+ char *target, *name, *who, *text, pattern[BUFSIZE];
a87bc2c2 443+ time_t timestamp;
444+ unsigned int flags = 0;
6dd3e24f 445+ int local = 0;
a87bc2c2 446+
447+ /* feature disabled */
448+ if (!feature_bool(FEAT_WELCOME))
449+ return send_reply(sptr, ERR_DISABLED, "WELCOME");
450+
451+ /* listing */
452+ if (parc < 2)
453+ return welcome_list(sptr, 0);
454+
cb0b5df1 455+ /* TODO: add PRIV_WELCOME? */
a87bc2c2 456+ /* check PRIVS */
457+ if (!HasPriv(sptr,PRIV_SERVERINFO))
458+ return send_reply(sptr, ERR_NOPRIVILEGES);
459+
460+ /* remote listing request, see if it is for me or a remote server */
461+ if (parc == 2) {
462+ if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C", 1, parc, parv) != HUNTED_ISME)
463+ return 0;
464+ return welcome_list(sptr, 0);
465+ }
466+
467+ /* set the parameters */
6dd3e24f 468+
469+ /* target not given, only name - setting local welcome */
a87bc2c2 470+ if (parc < 4) {
471+ local++;
472+ target = cli_name(&me);
473+ name = parv[1];
474+ flags |= WELCOME_LOCAL;
6dd3e24f 475+
476+ /* target and name given */
477+ } else {
a87bc2c2 478+ target = parv[1];
479+ name = parv[2];
480+ }
481+ timestamp = TStime();
482+ who = cli_user(sptr)->opername;
483+ text = parv[parc - 1];
484+
485+ /* target is not global */
486+ if (!(target[0] == '*' && target[1] == '\0') && !local) {
6dd3e24f 487+
a87bc2c2 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)
491+ return 0;
6dd3e24f 492+
493+ /* else it is a local welcome, for me */
494+ flags |= WELCOME_LOCAL;
a87bc2c2 495+ }
496+
cb0b5df1 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
500+ */
a87bc2c2 501+ /* check for anounce prefix */
502+ if (*name == '!') {
503+ name++;
504+ flags |= WELCOME_ANNOUNCE;
505+ }
506+
507+ /* and do it */
508+ return welcome_do(cptr, sptr, name, text, who, timestamp, flags);
cddf800b 509+}
510+
511+
512+/*
513+ * ms_welcome - server message handler
514+ *
515+ * parv[0] = Send prefix
516+ * parv[1] = Target: server numeric or * for global
a87bc2c2 517+ * parv[2] = Name
518+ * parv[3] = Timestamp
519+ * parv[4] = Who
520+ * parv[5] = Text
cddf800b 521+ */
522+int ms_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
523+{
cb0b5df1 524+ char *target, *name, *who, *text;
a87bc2c2 525+ time_t timestamp;
526+ unsigned int flags = 0;
527+
6dd3e24f 528+ /* not enough - complain */
529+ if (parc < 2) {
530+ protocol_violation(sptr, "Too few parameters for WELCOME (got %d - need 2)", parc);
a87bc2c2 531+ return need_more_params(sptr, "WELCOME");
6dd3e24f 532+ }
a87bc2c2 533+
534+ /* remote listing request, see if it is for me or a remote server */
535+ if (parc == 2) {
6dd3e24f 536+ if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C", 1, parc, parv) != HUNTED_ISME)
537+ return 0;
538+ return welcome_list(sptr, 0);
a87bc2c2 539+ }
540+
6dd3e24f 541+ /* we need at least 6 parameters to continue - complain */
542+ if (parc < 6) {
543+ protocol_violation(sptr, "Too few parameters for WELCOME (got %d - need 6)", parc);
a87bc2c2 544+ return need_more_params(sptr, "WELCOME");
6dd3e24f 545+ }
a87bc2c2 546+
547+ /* set the parameters */
548+ target = parv[1];
549+ name = parv[2];
550+ timestamp = atoi(parv[3]);
551+ who = parv[4];
6dd3e24f 552+ text = parv[parc - 1]; /* parse reason as last parameter */
a87bc2c2 553+
554+ /* target is not global */
555+ if (!(target[0] == '*' && target[1] == '\0')) {
6dd3e24f 556+
a87bc2c2 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)
559+ return 0;
6dd3e24f 560+
561+ /* local welcome for me */
562+ flags |= WELCOME_LOCAL;
a87bc2c2 563+ }
564+
565+ /* check for anounce prefix */
566+ if (*name == '!') {
567+ name++;
568+ flags |= WELCOME_ANNOUNCE;
569+ }
570+
571+ /* and do it */
572+ return welcome_do(cptr, sptr, name, text, who, timestamp, flags);
573+}
574+
575+
576+/*
577+ * mh_welcome - help message handler
578+ */
579+int mh_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
580+{
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.");
586+ } else {
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.");
591+ }
cddf800b 592+ return 0;
593+}
6dd3e24f 594diff -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
a87bc2c2 597@@ -667,6 +667,15 @@
598 /* UNREG, CLIENT, SERVER, OPER, SERVICE, HELP */
599 { m_unregistered, m_not_oper, ms_opkick, mo_opkick, m_ignore, mh_nohelp }
cddf800b 600 },
601+
602+ /* add command for WELCOME */
603+ {
604+ MSG_WELCOME,
605+ TOK_WELCOME,
606+ 0, MAXPARA, MFLG_SLOW, 0, NULL,
a87bc2c2 607+ /* UNREG, CLIENT, SERVER, OPER, SERVICE, HELP */
608+ { m_unregistered, m_welcome, ms_welcome, mo_welcome, m_ignore, mh_welcome }
cddf800b 609+ },
610
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
6dd3e24f 613diff -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
a87bc2c2 616@@ -486,7 +486,7 @@
617 /* 226 */
618 { RPL_STATSALINE, "%s", "226" },
619 /* 227 */
620- { 0 },
621+ { RPL_STATSWELCOME, "W %d %s %s %Tu :%s", "227" },
622 /* 228 */
623 { RPL_STATSQLINE, "Q %s :%s", "228" },
624 /* 229 */
625@@ -1050,7 +1050,7 @@
626 /* 508 */
627 { 0 },
628 /* 509 */
629- { 0 },
630+ { ERR_NOSUCHWELCOME, "%s :No such welcome", "509" },
631 /* 510 */
632 { 0 },
633 /* 511 */
6dd3e24f 634diff -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
a87bc2c2 637@@ -57,6 +57,7 @@
638 #include "struct.h"
639 #include "sys.h"
640 #include "userload.h"
641+#include "welcome.h"
642
643 /* #include <assert.h> -- Now using assert in ircd_log.h */
644 #include <stdlib.h>
645@@ -196,6 +197,7 @@
646 */
647 gline_burst(cptr);
648 jupe_burst(cptr);
649+ welcome_burst(cptr);
650
651 /*
652 * Pass on my client information to the new server
6dd3e24f 653diff -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
a87bc2c2 656@@ -54,6 +54,7 @@
657 #include "send.h"
658 #include "struct.h"
659 #include "userload.h"
660+#include "welcome.h"
661
662 #include <stdio.h>
663 #include <stdlib.h>
664@@ -689,9 +690,12 @@
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,
670 calc_load, 0,
671 "Userload statistics." },
672+ { 'W', "welcome", STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS, FEAT_HIS_STATS_W,
673+ welcome_stats, 0,
674+ "Welcome messages." },
675 { 'x', "memusage", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_x,
676 stats_meminfo, 0,
677 "List usage information." },
6dd3e24f 678diff -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
a87bc2c2 681@@ -63,6 +63,7 @@
682 #include "userload.h"
683 #include "version.h"
684 #include "whowas.h"
685+#include "welcome.h"
686
687 #include "handlers.h" /* m_motd and m_lusers */
688
689@@ -411,6 +412,9 @@
690 cli_info(sptr), NumNick(cptr) /* two %s's */);
691
692 IPcheck_connect_succeeded(sptr);
693+
694+ if (feature_bool(FEAT_WELCOME))
695+ welcome_list(sptr, 1);
696 }
697 else {
698 struct Client *acptr = user->server;
6dd3e24f 699diff -r 42bf40ebc839 ircd/welcome.c
cddf800b 700--- /dev/null Thu Jan 01 00:00:00 1970 +0000
6dd3e24f 701+++ b/ircd/welcome.c Fri Jan 30 13:14:46 2009 +0100
702@@ -0,0 +1,373 @@
cddf800b 703+/*
a87bc2c2 704+ * IRC - Internet Relay Chat, ircd/welcome.c
cddf800b 705+ * Copyright (C) 1990 Jarkko Oikarinen and
706+ * University of Oulu, Finland
707+ * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
708+ *
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.
713+ *
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.
718+ *
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.
722+ */
723+/** @file
a87bc2c2 724+ * @brief Implementation of welcome message handling functions.
cddf800b 725+ */
726+#include "config.h"
727+
728+#include "client.h"
729+#include "hash.h"
730+#include "ircd.h"
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"
736+#include "match.h"
737+#include "msg.h"
738+#include "numeric.h"
739+#include "numnicks.h"
740+#include "s_bsd.h"
a87bc2c2 741+#include "s_debug.h"
cddf800b 742+#include "s_misc.h"
743+#include "send.h"
744+#include "struct.h"
745+#include "sys.h" /* FALSE bleah */
746+#include "welcome.h"
747+
748+/* #include <assert.h> -- Now using assert in ircd_log.h */
749+#include <string.h>
750+
cddf800b 751+
cb0b5df1 752+/** List of welcome messages - first MAX for global, second MAX for local */
6dd3e24f 753+static struct Welcome WelcomeArray[WELCOME_MAX_ENTRIES * 2] = { { 0 } };
cddf800b 754+
cddf800b 755+
a87bc2c2 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.
cb0b5df1 761+ * @return name Array number of the welcome set.
cddf800b 762+ */
cb0b5df1 763+static int
764+welcome_make(int name, char *text, char *who, time_t timestamp)
cddf800b 765+{
cb0b5df1 766+ /* range 0 to 2 * max - 1 */
767+ assert(name >= 0 && name <= 2 * WELCOME_MAX_ENTRIES - 1);
768+
769+ /* store it */
770+ ircd_strncpy(WelcomeArray[name].text, text, TOPICLEN);
771+ ircd_strncpy(WelcomeArray[name].who, who, ACCOUNTLEN);
772+ WelcomeArray[name].timestamp = timestamp;
773+
774+ return name;
cddf800b 775+}
776+
cddf800b 777+
a87bc2c2 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.
785+ * @return Zero
cddf800b 786+ */
787+int
a87bc2c2 788+welcome_do(struct Client *cptr, struct Client *sptr, char *name, char *text,
789+ char *who, time_t timestamp, unsigned int flags)
cddf800b 790+{
cb0b5df1 791+ int nameint = atoi(name); /* transform to int */
792+ int namearray = nameint - 1; /* used to test the array element */
6dd3e24f 793+ char oldtext[TOPICLEN + 1]; /* save old text when unsetting */
794+ static time_t rate;
795+
796+ assert(NULL != cptr);
797+ assert(NULL != sptr);
798+ assert(NULL != name);
799+ assert(NULL != text);
800+ assert(NULL != who);
a87bc2c2 801+
cb0b5df1 802+ /* debug */
a87bc2c2 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));
805+
806+ /* check name */
cb0b5df1 807+ if (nameint < 1 || nameint > WELCOME_MAX_ENTRIES) {
a87bc2c2 808+ if (IsUser(sptr))
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);
cddf800b 812+ return 0;
813+ }
814+
cb0b5df1 815+ /* correct namearray for local offset */
816+ if (flags & WELCOME_LOCAL)
817+ namearray += WELCOME_MAX_ENTRIES;
a87bc2c2 818+
819+ /* cannot unset welcome that is not set */
6dd3e24f 820+ if (WelcomeArray[namearray].timestamp == 0 && EmptyString(text)) {
821+
a87bc2c2 822+ /* from user, throw error */
823+ if (IsUser(sptr))
824+ return send_reply(sptr, ERR_NOSUCHWELCOME, name);
6dd3e24f 825+
826+ /* new local welcome from server, but empty - ignore
827+ * we do accept a new global welcome message that is empty
828+ */
a87bc2c2 829+ if (flags & WELCOME_LOCAL)
830+ return 0;
a87bc2c2 831+ }
cddf800b 832+
a87bc2c2 833+ /* check if there is something to change */
6dd3e24f 834+ /* we got a record for it */
835+ if (WelcomeArray[namearray].timestamp != 0) {
836+
837+ /* global */
838+ if (namearray < WELCOME_MAX_ENTRIES) {
839+
840+ /* netburst and we got the same or a newer one
841+ *
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
846+ */
847+ if (IsBurstOrBurstAck(cptr) && timestamp <= WelcomeArray[namearray].timestamp)
a87bc2c2 848+ return 0;
6dd3e24f 849+
850+ /* local welcome - we use our idea of the time */
cb0b5df1 851+ } else
a87bc2c2 852+ timestamp = TStime();
cb0b5df1 853+
a87bc2c2 854+ /* compare new message with old message */
cb0b5df1 855+ if (ircd_strcmp(text, WelcomeArray[namearray].text) == 0) {
a87bc2c2 856+ if (IsUser(sptr))
857+ sendcmdto_one(&me, CMD_NOTICE, sptr,
cb0b5df1 858+ "%C :WELCOME: Cannot change %smessage for %s - nothing to change.",
859+ sptr, (flags & WELCOME_LOCAL) ? "local " : "", name);
a87bc2c2 860+ return 0;
861+ }
862+ }
cddf800b 863+
6dd3e24f 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());
870+
871+ /* warn remote oper too */
872+ if (IsUser(sptr))
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());
876+ }
877+
878+ /* unsetting - do not announce, save text */
879+ if (EmptyString(text)) {
880+ flags &= ~WELCOME_ANNOUNCE;
881+ ircd_strncpy(oldtext, WelcomeArray[namearray].text, TOPICLEN);
882+ }
883+
cb0b5df1 884+ /* update */
885+ welcome_make(namearray, text, who, timestamp);
886+
cb0b5df1 887+ /* inform ops */
6dd3e24f 888+ sendto_opmask_butone(0, SNO_OLDSNO, "%s %s%s%sWELCOME %d \"%s\" [%Tu]",
a87bc2c2 889+ (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
890+ get_client_name_and_opername(sptr) : cli_name((cli_user(sptr))->server),
6dd3e24f 891+ EmptyString(text) ? "unsetting" : "changing",
892+ (flags & WELCOME_ANNOUNCE) ? " and announcing " : " ",
893+ (flags & WELCOME_LOCAL) ? "local " : "",
894+ nameint,
895+ EmptyString(text) ? oldtext : WelcomeArray[namearray].text,
896+ WelcomeArray[namearray].timestamp);
a87bc2c2 897+
898+ /* log it */
6dd3e24f 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 " : "",
904+ nameint,
905+ EmptyString(text) ? oldtext : WelcomeArray[namearray].text,
cb0b5df1 906+ WelcomeArray[namearray].timestamp);
a87bc2c2 907+
908+ /* welcome set by remote user, inform oper of success */
6dd3e24f 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" : "",
914+ nameint,
915+ EmptyString(text) ? oldtext : WelcomeArray[namearray].text,
916+ WelcomeArray[namearray].timestamp);
917+
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" : "",
925+ nameint,
926+ EmptyString(text) ? oldtext : WelcomeArray[namearray].text,
927+ WelcomeArray[namearray].timestamp);
928+ }
cddf800b 929+
cb0b5df1 930+ /* propagate it */
a87bc2c2 931+ if (!(flags & WELCOME_LOCAL))
932+ sendcmdto_serv_butone(sptr, CMD_WELCOME, cptr, "* %s%d %Tu %s :%s",
cb0b5df1 933+ (flags & WELCOME_ANNOUNCE) ? "!" : "", nameint,
934+ WelcomeArray[namearray].timestamp, WelcomeArray[namearray].who,
935+ WelcomeArray[namearray].text);
cddf800b 936+
a87bc2c2 937+ /* announce it */
6dd3e24f 938+ if (flags & WELCOME_ANNOUNCE)
cb0b5df1 939+ welcome_announce(namearray);
a87bc2c2 940+
941+ return 0;
cddf800b 942+}
943+
a87bc2c2 944+
945+/** Announce a welcome message to local clients.
cb0b5df1 946+ * @param[in] name Welcome message to announce.
cddf800b 947+ */
a87bc2c2 948+void
cb0b5df1 949+welcome_announce(int name)
cddf800b 950+{
a87bc2c2 951+ struct Client *acptr;
952+ struct MsgBuf *msgbuf;
6dd3e24f 953+ int i;
a87bc2c2 954+
cb0b5df1 955+ /* range 0 to 2 * max - 1 */
956+ assert(name >= 0 && name <= 2 * WELCOME_MAX_ENTRIES - 1);
a87bc2c2 957+
cb0b5df1 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.
962+ */
a87bc2c2 963+ /* build msgbuf */
964+ msgbuf = msgq_make(0, ":%C %s $* :[%s] %s", &me, MSG_NOTICE,
cb0b5df1 965+ name >= WELCOME_MAX_ENTRIES ? cli_name(&me) : feature_str(FEAT_NETWORK),
966+ WelcomeArray[name].text);
a87bc2c2 967+
6dd3e24f 968+ /* go over local clients */
969+ for (i = HighestFd; i > 0; --i) {
cb0b5df1 970+
6dd3e24f 971+ /* skip unregistered clients - they see the message during login
972+ * skip servers
a87bc2c2 973+ */
6dd3e24f 974+ if (!(acptr = LocalClientArray[i]) || !IsRegistered(acptr) || IsServer(acptr))
a87bc2c2 975+ continue;
cb0b5df1 976+
6dd3e24f 977+ /* send it away */
a87bc2c2 978+ send_buffer(acptr, msgbuf, 0);
cddf800b 979+ }
cddf800b 980+}
981+
a87bc2c2 982+
a87bc2c2 983+/** Send the full list of welcome message to \a cptr.
984+ * @param[in] cptr Local server to send welcomes to.
cddf800b 985+ */
986+void
a87bc2c2 987+welcome_burst(struct Client *cptr)
cddf800b 988+{
cb0b5df1 989+ int name;
a87bc2c2 990+
6dd3e24f 991+ assert(NULL != cptr);
992+
cb0b5df1 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)
a87bc2c2 996+ sendcmdto_one(&me, CMD_WELCOME, cptr, "* %d %Tu %s :%s",
cb0b5df1 997+ name + 1, WelcomeArray[name].timestamp, WelcomeArray[name].who,
998+ WelcomeArray[name].text);
cddf800b 999+ }
1000+}
1001+
a87bc2c2 1002+
a87bc2c2 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
cddf800b 1006+ * @return Zero.
1007+ */
1008+int
a87bc2c2 1009+welcome_list(struct Client *sptr, int connect)
cddf800b 1010+{
cb0b5df1 1011+ int found = 0, local = 0, name;
a87bc2c2 1012+
6dd3e24f 1013+ assert(NULL != sptr);
1014+
cb0b5df1 1015+ /* loop over all entries - range 0 to 2 * max - 1 */
1016+ for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) {
a87bc2c2 1017+
cb0b5df1 1018+ /* local entries now */
1019+ if (name == WELCOME_MAX_ENTRIES)
1020+ local = 1;
a87bc2c2 1021+
cb0b5df1 1022+ /* not set or empty - skip */
6dd3e24f 1023+ /* TODO: EmptyString? */
cb0b5df1 1024+ if (WelcomeArray[name].timestamp == 0 || *WelcomeArray[name].text == 0)
a87bc2c2 1025+ continue;
cb0b5df1 1026+
1027+ /* got one */
a87bc2c2 1028+ found++;
cb0b5df1 1029+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :[%s] %s",
1030+ sptr, local ? cli_name(&me) : feature_str(FEAT_NETWORK), WelcomeArray[name].text);
a87bc2c2 1031+ }
cb0b5df1 1032+
1033+ /* nothing set */
a87bc2c2 1034+ if (!found && !connect)
cb0b5df1 1035+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :No welcome message set.", sptr);
1036+
a87bc2c2 1037+ return 0;
1038+}
cddf800b 1039+
cddf800b 1040+
a87bc2c2 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).
1045+ */
1046+void
1047+welcome_stats(struct Client *sptr, const struct StatDesc *sd, char *param)
1048+{
cb0b5df1 1049+ int name, local = 0;
a87bc2c2 1050+
6dd3e24f 1051+ assert(NULL != sptr);
1052+
a87bc2c2 1053+ /* send header so the client knows what we are showing */
1054+ send_reply(sptr, SND_EXPLICIT | RPL_STATSHEADER,
6dd3e24f 1055+ "W Name Target Opername Timestamp :Message");
a87bc2c2 1056+
cb0b5df1 1057+ /* loop over all entries - range 0 to 2 * max - 1*/
1058+ for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) {
cddf800b 1059+
cb0b5df1 1060+ /* local entries now */
1061+ if (name == WELCOME_MAX_ENTRIES)
1062+ local = 1;
a87bc2c2 1063+
cb0b5df1 1064+ /* not set */
1065+ if (WelcomeArray[name].timestamp == 0)
1066+ continue;
cddf800b 1067+
cb0b5df1 1068+ /* send it */
1069+ send_reply(sptr, RPL_STATSWELCOME,
6dd3e24f 1070+ local ? name + 1 - WELCOME_MAX_ENTRIES : name + 1,
1071+ local ? cli_name(&me) : "*",
cb0b5df1 1072+ WelcomeArray[name].who, WelcomeArray[name].timestamp,
6dd3e24f 1073+ EmptyString(WelcomeArray[name].text) ? "<Empty>" : WelcomeArray[name].text);
cddf800b 1074+ }
cddf800b 1075+}