]> jfr.im git - irc/quakenet/snircd-patchqueue.git/blame - welcome.patch
add staffpriv.patch - see file for more info
[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
db0ccf80 74include/client.h
75ircd/client.c
76ircd/ircd_lexer.l
77ircd/ircd_parser.y
78add PRIV_LOCAL_WELCOME PRIV_WELCOME
79
4e89d808 80diff -r ed93c5ec7a2b include/client.h
81--- a/include/client.h Tue Feb 03 18:41:29 2009 +0100
82+++ b/include/client.h Tue Feb 03 19:05:37 2009 +0100
83@@ -144,6 +144,8 @@
84 PRIV_USER_PRIVACY, /* oper can bypass user privacy +x etc gives i.e. see real ip's */
85 PRIV_CHANNEL_PRIVACY, /* oper can bypass channel privacy i.e. can see modes on channels they are not on and channel keys */
86 PRIV_SERVERINFO, /* oper can use /get, /stats, /hash, retrieve remote information */
87+ PRIV_WELCOME, /* oper can WELCOME */
88+ PRIV_LOCAL_WELCOME, /* oper can local WELCOME */
89 PRIV_LAST_PRIV /**< number of privileges */
90 };
91
92diff -r ed93c5ec7a2b include/handlers.h
93--- a/include/handlers.h Tue Feb 03 18:41:29 2009 +0100
94+++ b/include/handlers.h Tue Feb 03 19:05:37 2009 +0100
cddf800b 95@@ -151,6 +151,7 @@
96 extern int m_version(struct Client*, struct Client*, int, char*[]);
97 extern int m_wallchops(struct Client*, struct Client*, int, char*[]);
98 extern int m_wallvoices(struct Client*, struct Client*, int, char*[]);
99+extern int m_welcome(struct Client*, struct Client*, int, char*[]);
100 extern int m_who(struct Client*, struct Client*, int, char*[]);
101 extern int m_whois(struct Client*, struct Client*, int, char*[]);
102 extern int m_whowas(struct Client*, struct Client*, int, char*[]);
103@@ -185,6 +186,7 @@
104 extern int mo_version(struct Client*, struct Client*, int, char*[]);
105 extern int mo_wallops(struct Client*, struct Client*, int, char*[]);
106 extern int mo_wallusers(struct Client*, struct Client*, int, char*[]);
107+extern int mo_welcome(struct Client*, struct Client*, int, char*[]);
108 extern int mr_error(struct Client*, struct Client*, int, char*[]);
109 extern int mr_error(struct Client*, struct Client*, int, char*[]);
110 extern int mr_pong(struct Client*, struct Client*, int, char*[]);
111@@ -242,6 +244,7 @@
112 extern int ms_wallops(struct Client*, struct Client*, int, char*[]);
113 extern int ms_wallusers(struct Client*, struct Client*, int, char*[]);
114 extern int ms_wallvoices(struct Client*, struct Client*, int, char*[]);
115+extern int ms_welcome(struct Client*, struct Client*, int, char*[]);
116 extern int ms_whois(struct Client*, struct Client*, int, char*[]);
117
a87bc2c2 118 extern int mh_nohelp(struct Client*, struct Client*, int, char*[]);
119@@ -308,6 +311,7 @@
120 extern int mh_wallops(struct Client*, struct Client*, int, char*[]);
121 extern int mh_wallusers(struct Client*, struct Client*, int, char*[]);
122 extern int mh_wallvoices(struct Client*, struct Client*, int, char*[]);
123+extern int mh_welcome(struct Client*, struct Client*, int, char*[]);
124 extern int mh_who(struct Client*, struct Client*, int, char*[]);
125 extern int mh_whois(struct Client*, struct Client*, int, char*[]);
126 extern int mh_whowas(struct Client*, struct Client*, int, char*[]);
4e89d808 127diff -r ed93c5ec7a2b include/ircd_features.h
128--- a/include/ircd_features.h Tue Feb 03 18:41:29 2009 +0100
129+++ b/include/ircd_features.h Tue Feb 03 19:05:37 2009 +0100
a87bc2c2 130@@ -101,6 +101,7 @@
131 FEAT_IRCD_RES_TIMEOUT,
132 FEAT_AUTH_TIMEOUT,
133 FEAT_ANNOUNCE_INVITES,
134+ FEAT_WELCOME,
135
136 /* features that affect all operators */
137 FEAT_EXTENDED_CHECKCMD,
138@@ -143,6 +144,7 @@
139 FEAT_HIS_STATS_u,
140 FEAT_HIS_STATS_U,
141 FEAT_HIS_STATS_v,
142+ FEAT_HIS_STATS_W,
143 FEAT_HIS_STATS_w,
144 FEAT_HIS_STATS_x,
145 FEAT_HIS_STATS_y,
4e89d808 146diff -r ed93c5ec7a2b include/msg.h
147--- a/include/msg.h Tue Feb 03 18:41:29 2009 +0100
148+++ b/include/msg.h Tue Feb 03 19:05:37 2009 +0100
100a7f47 149@@ -196,6 +196,10 @@
cddf800b 150 #define TOK_NOTICE "O"
151 #define CMD_NOTICE MSG_NOTICE, TOK_NOTICE
100a7f47 152
cddf800b 153+#define MSG_WELCOME "WELCOME" /* WELC */
154+#define TOK_WELCOME "WE"
155+#define CMD_WELCOME MSG_WELCOME, TOK_WELCOME
100a7f47 156+
cddf800b 157 #define MSG_WALLCHOPS "WALLCHOPS" /* WC */
158 #define TOK_WALLCHOPS "WC"
100a7f47 159 #define CMD_WALLCHOPS MSG_WALLCHOPS, TOK_WALLCHOPS
4e89d808 160diff -r ed93c5ec7a2b include/numeric.h
161--- a/include/numeric.h Tue Feb 03 18:41:29 2009 +0100
162+++ b/include/numeric.h Tue Feb 03 19:05:37 2009 +0100
a87bc2c2 163@@ -116,6 +116,7 @@
164 RPL_STATSGLINE 227 Dalnet
165 RPL_STATSVLINE 227 unreal */
166 #define RPL_STATSALINE 226 /* Hybrid, Undernet */
167+#define RPL_STATSWELCOME 227 /* QuakeNet extension */
168 #define RPL_STATSQLINE 228 /* Undernet extension */
169 #define RPL_STATSHEADER 230 /* QuakeNet extension */
170
cb0b5df1 171@@ -445,6 +446,8 @@
a87bc2c2 172 /* ERR_GHOSTEDCLIENT 503 efnet */
173 /* ERR_VWORLDWARN 503 austnet */
174
175+#define ERR_NOSUCHWELCOME 509 /* QuakeNet extension */
176+
177 #define ERR_SILELISTFULL 511 /* Undernet extension */
178 /* ERR_NOTIFYFULL 512 aircd */
179 /* ERR_TOOMANYWATCH 512 Numeric List: Dalnet */
4e89d808 180diff -r ed93c5ec7a2b include/welcome.h
cddf800b 181--- /dev/null Thu Jan 01 00:00:00 1970 +0000
4e89d808 182+++ b/include/welcome.h Tue Feb 03 19:05:37 2009 +0100
6dd3e24f 183@@ -0,0 +1,60 @@
cddf800b 184+#ifndef INCLUDED_welcome_h
185+#define INCLUDED_welcome_h
186+/*
187+ * IRC - Internet Relay Chat, include/welcome.h
188+ * Copyright (C) 1990 Jarkko Oikarinen and
189+ * University of Oulu, Computing Center
190+ * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
191+ *
192+ * This program is free software; you can redistribute it and/or modify
193+ * it under the terms of the GNU General Public License as published by
194+ * the Free Software Foundation; either version 2, or (at your option)
195+ * any later version.
196+ *
197+ * This program is distributed in the hope that it will be useful,
198+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
199+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
200+ * GNU General Public License for more details.
201+ *
202+ * You should have received a copy of the GNU General Public License
203+ * along with this program; if not, write to the Free Software
204+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
205+ */
206+/** @file
a87bc2c2 207+ * @brief Interface and declarations for welcome message handling.
cddf800b 208+ */
209+#ifndef INCLUDED_sys_types_h
210+#include <sys/types.h>
211+#define INCLUDED_sys_types_h
212+#endif
213+
a87bc2c2 214+struct Client;
215+struct StatDesc;
216+
cb0b5df1 217+/* Maximum number of welcome entries (per type; X global, X local) */
6dd3e24f 218+#define WELCOME_MAX_ENTRIES 10
219+/* Maximum timestamp drift in seconds allowed ahead of our idea of nettime
220+ * before we throw a warning to ops
221+ */
222+#define WELCOME_MAX_DRIFT 600
a87bc2c2 223+
224+/* Describes a Welcome message entry. */
225+struct Welcome {
6dd3e24f 226+ time_t timestamp; /**< Timestamp of the welcome */
227+ char text[TOPICLEN + 1]; /**< Message */
228+ char who[ACCOUNTLEN + 1]; /**< Who set it */
a87bc2c2 229+};
230+
cb0b5df1 231+/** Welcome type flags */
a87bc2c2 232+#define WELCOME_LOCAL 0x01 /**< welcome is local */
233+/** Welcome action flags */
234+#define WELCOME_ANNOUNCE 0x02 /**< announce change to users */
235+
a87bc2c2 236+extern int welcome_do(struct Client *cptr, struct Client *sptr, char *name, char *text,
237+ char *who, time_t timestamp, unsigned int flags);
cb0b5df1 238+extern void welcome_announce(int name);
cddf800b 239+extern void welcome_burst(struct Client *cptr);
a87bc2c2 240+extern int welcome_list(struct Client *sptr, int connect);
241+extern void welcome_stats(struct Client *sptr, const struct StatDesc *sd, char *param);
cddf800b 242+
243+#endif /* INCLUDED_welcome_h */
4e89d808 244diff -r ed93c5ec7a2b ircd/Makefile.in
245--- a/ircd/Makefile.in Tue Feb 03 18:41:29 2009 +0100
246+++ b/ircd/Makefile.in Tue Feb 03 19:05:37 2009 +0100
a87bc2c2 247@@ -187,6 +187,7 @@
248 m_wallops.c \
249 m_wallusers.c \
250 m_wallvoices.c \
251+ m_welcome.c \
252 m_who.c \
253 m_whois.c \
254 m_whowas.c \
255@@ -214,6 +215,7 @@
256 send.c \
257 uping.c \
258 userload.c \
259+ welcome.c \
260 whocmds.c \
261 whowas.c \
262 y.tab.c
263@@ -1168,6 +1170,11 @@
264 ../include/ircd_reply.h ../include/ircd_string.h \
265 ../include/ircd_chattr.h ../include/msg.h ../include/numeric.h \
266 ../include/numnicks.h ../include/s_user.h ../include/send.h
267+m_welcome.o: m_welcome.c ../config.h ../include/channel.h \
268+ ../include/client.h ../include/hash.h ../include/ircd.h ../include/ircd_log.h \
269+ ../include/ircd_reply.h ../include/ircd_string.h ../include/msg.h \
270+ ../include/numeric.h ../include/numnicks.h ../include/s_user.h \
271+ ../include/send.h ../include/welcome.h
272 m_who.o: m_who.c ../config.h ../include/channel.h ../include/ircd_defs.h \
273 ../include/res.h ../config.h ../include/client.h ../include/dbuf.h \
274 ../include/msgq.h ../include/ircd_events.h ../include/ircd_handler.h \
275@@ -1429,6 +1436,13 @@
276 ../include/numnicks.h ../include/querycmds.h ../include/ircd_features.h \
277 ../include/s_misc.h ../include/s_stats.h ../include/send.h \
278 ../include/struct.h ../include/sys.h
279+welcome.o: welcome.c ../config.h ../include/client.h \
280+ ../include/hash.h ../include/ircd.h ../include/ircd_alloc.h \
281+ ../include/ircd_features.h ../include/ircd_log.h ../include/ircd_reply.h \
282+ ../include/match.h ../include/msg.h ../include/numeric.h \
283+ ../include/numnicks.h ../include/s_debug.h ../include/s_bsd.h \
284+ ../include/s_misc.h ../include/send.h ../include/struct.h \
285+ ../include/sys.h ../include/welcome.h
286 whocmds.o: whocmds.c ../config.h ../include/whocmds.h \
287 ../include/channel.h ../include/ircd_defs.h ../include/res.h \
288 ../config.h ../include/client.h ../include/dbuf.h ../include/msgq.h \
4e89d808 289diff -r ed93c5ec7a2b ircd/client.c
290--- a/ircd/client.c Tue Feb 03 18:41:29 2009 +0100
291+++ b/ircd/client.c Tue Feb 03 19:05:37 2009 +0100
292@@ -178,6 +178,7 @@
293 FlagSet(&privs_local, PRIV_WHOX);
294 FlagSet(&privs_local, PRIV_DISPLAY);
295 FlagSet(&privs_local, PRIV_FORCE_LOCAL_OPMODE);
296+ FlagSet(&privs_local, PRIV_LOCAL_WELCOME);
297
298 privs_defaults_set = 1;
299 }
300@@ -225,6 +226,7 @@
301 ClrPriv(client, PRIV_OPMODE);
302 ClrPriv(client, PRIV_OPKICK);
303 ClrPriv(client, PRIV_BADCHAN);
304+ ClrPriv(client, PRIV_WELCOME);
305 }
306 }
307
308@@ -248,6 +250,7 @@
309 P(PARANOID), P(CHECK), P(WALL), P(CLOSE),
310 P(ROUTE), P(ROUTEINFO), P(SERVERINFO), P(CHANNEL_PRIVACY),
311 P(USER_PRIVACY),
312+ P(WELCOME), P(LOCAL_WELCOME),
313 #undef P
314 { 0, 0 }
315 };
316diff -r ed93c5ec7a2b ircd/ircd_features.c
317--- a/ircd/ircd_features.c Tue Feb 03 18:41:29 2009 +0100
318+++ b/ircd/ircd_features.c Tue Feb 03 19:05:37 2009 +0100
a87bc2c2 319@@ -355,6 +355,7 @@
320 F_I(IRCD_RES_TIMEOUT, 0, 4, 0),
321 F_I(AUTH_TIMEOUT, 0, 9, 0),
322 F_B(ANNOUNCE_INVITES, 0, 0, 0),
323+ F_B(WELCOME, 0, 1, 0),
324
325 /* features that affect all operators */
326 F_B(EXTENDED_CHECKCMD, 0, 0, 0),
327@@ -397,6 +398,7 @@
328 F_B(HIS_STATS_u, 0, 1, 0),
329 F_B(HIS_STATS_U, 0, 1, 0),
330 F_B(HIS_STATS_v, 0, 1, 0),
331+ F_B(HIS_STATS_W, 0, 1, 0),
332 F_B(HIS_STATS_w, 0, 1, 0),
333 F_B(HIS_STATS_x, 0, 1, 0),
334 F_B(HIS_STATS_y, 0, 1, 0),
4e89d808 335diff -r ed93c5ec7a2b ircd/ircd_lexer.l
336--- a/ircd/ircd_lexer.l Tue Feb 03 18:41:29 2009 +0100
337+++ b/ircd/ircd_lexer.l Tue Feb 03 19:05:37 2009 +0100
338@@ -168,6 +168,8 @@
339 { "serverinfo", TPRIV_SERVERINFO },
340 { "user_privacy", TPRIV_USER_PRIVACY },
341 { "channel_privacy", TPRIV_CHANNEL_PRIVACY },
342+ { "local_welcome", TPRIV_LOCAL_WELCOME },
343+ { "welcome", TPRIV_WELCOME },
344 { NULL, 0 }
345 };
346 static int ntokens;
347diff -r ed93c5ec7a2b ircd/ircd_parser.y
348--- a/ircd/ircd_parser.y Tue Feb 03 18:41:29 2009 +0100
349+++ b/ircd/ircd_parser.y Tue Feb 03 19:05:37 2009 +0100
350@@ -189,7 +189,8 @@
351 %token TPRIV_FORCE_OPMODE TPRIV_FORCE_LOCAL_OPMODE TPRIV_APASS_OPMODE
352 %token TPRIV_CHANSERV TPRIV_XTRA_OPER TPRIV_NOIDLE TPRIV_FREEFORM TPRIV_PARANOID
353 %token TPRIV_CHECK TPRIV_WALL TPRIV_CLOSE TPRIV_ROUTE TPRIV_ROUTEINFO TPRIV_SERVERINFO
354-%token TPRIV_CHANNEL_PRIVACY TPRIV_USER_PRIVACY TPRIV_LIST_CHAN
355+%token TPRIV_CHANNEL_PRIVACY TPRIV_USER_PRIVACY TPRIV_LIST_CHAN
356+%token TPRIV_LOCAL_WELCOME TPRIV_WELCOME
357 /* and some types... */
358 %type <num> sizespec
359 %type <num> timespec timefactor factoredtimes factoredtime
360@@ -704,6 +705,8 @@
361 TPRIV_SERVERINFO { $$ = PRIV_SERVERINFO ; } |
362 TPRIV_CHANNEL_PRIVACY { $$ = PRIV_CHANNEL_PRIVACY ; } |
363 TPRIV_USER_PRIVACY { $$ = PRIV_USER_PRIVACY ; } |
364+ TPRIV_LOCAL_WELCOME { $$ = PRIV_LOCAL_WELCOME; } |
365+ TPRIV_WELCOME { $$ = PRIV_WELCOME; } |
366 TPRIV_PARANOID { $$ = PRIV_PARANOID; } ;
367 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
368
369diff -r ed93c5ec7a2b ircd/m_welcome.c
cddf800b 370--- /dev/null Thu Jan 01 00:00:00 1970 +0000
4e89d808 371+++ b/ircd/m_welcome.c Tue Feb 03 19:05:37 2009 +0100
372@@ -0,0 +1,308 @@
cddf800b 373+/*
374+ * IRC - Internet Relay Chat, ircd/m_welcome.c
375+ * Copyright (C) 1990 Jarkko Oikarinen and
376+ * University of Oulu, Computing Center
377+ *
378+ * See file AUTHORS in IRC package for additional names of
379+ * the programmers.
380+ *
381+ * This program is free software; you can redistribute it and/or modify
382+ * it under the terms of the GNU General Public License as published by
383+ * the Free Software Foundation; either version 1, or (at your option)
384+ * any later version.
385+ *
386+ * This program is distributed in the hope that it will be useful,
387+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
388+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
389+ * GNU General Public License for more details.
390+ *
391+ * You should have received a copy of the GNU General Public License
392+ * along with this program; if not, write to the Free Software
393+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
394+ *
cddf800b 395+ */
396+
397+/*
398+ * m_functions execute protocol messages on this server:
399+ *
400+ * cptr is always NON-NULL, pointing to a *LOCAL* client
401+ * structure (with an open socket connected!). This
402+ * identifies the physical socket where the message
403+ * originated (or which caused the m_function to be
404+ * executed--some m_functions may call others...).
405+ *
406+ * sptr is the source of the message, defined by the
407+ * prefix part of the message if present. If not
408+ * or prefix not found, then sptr==cptr.
409+ *
410+ * (!IsServer(cptr)) => (cptr == sptr), because
411+ * prefixes are taken *only* from servers...
412+ *
413+ * (IsServer(cptr))
414+ * (sptr == cptr) => the message didn't
415+ * have the prefix.
416+ *
417+ * (sptr != cptr && IsServer(sptr) means
418+ * the prefix specified servername. (?)
419+ *
420+ * (sptr != cptr && !IsServer(sptr) means
421+ * that message originated from a remote
422+ * user (not local).
423+ *
424+ * combining
425+ *
426+ * (!IsServer(sptr)) means that, sptr can safely
427+ * taken as defining the target structure of the
428+ * message in this server.
429+ *
430+ * *Always* true (if 'parse' and others are working correct):
431+ *
432+ * 1) sptr->from == cptr (note: cptr->from == cptr)
433+ *
434+ * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
435+ * *cannot* be a local connection, unless it's
436+ * actually cptr!). [MyConnect(x) should probably
437+ * be defined as (x == x->from) --msa ]
438+ *
439+ * parc number of variable parameter strings (if zero,
440+ * parv is allowed to be NULL)
441+ *
442+ * parv a NULL terminated list of parameter pointers,
443+ *
444+ * parv[0], sender (prefix string), if not present
445+ * this points to an empty string.
446+ * parv[1]...parv[parc-1]
447+ * pointers to additional parameters
448+ * parv[parc] == NULL, *always*
449+ *
450+ * note: it is guaranteed that parv[0]..parv[parc-1] are all
451+ * non-NULL pointers.
452+ */
453+#include "config.h"
454+
455+#include "channel.h"
456+#include "client.h"
457+#include "hash.h"
458+#include "ircd.h"
a87bc2c2 459+#include "ircd_features.h"
cddf800b 460+#include "ircd_log.h"
461+#include "ircd_reply.h"
5bb41778 462+#include "ircd_snprintf.h"
cddf800b 463+#include "ircd_string.h"
464+#include "msg.h"
465+#include "numeric.h"
466+#include "numnicks.h"
467+#include "s_user.h"
468+#include "send.h"
a87bc2c2 469+#include "welcome.h"
cddf800b 470+
471+/* #include <assert.h> -- Now using assert in ircd_log.h */
472+
473+/*
474+ * m_welcome - local generic message handler
475+ *
476+ * parv[0] = Send prefix
6dd3e24f 477+ * parv[1] = [remote server to query]
cddf800b 478+ */
479+int m_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
480+{
a87bc2c2 481+ /* feature disabled */
482+ if (!feature_bool(FEAT_WELCOME))
483+ return send_reply(sptr, ERR_DISABLED, "WELCOME");
6dd3e24f 484+
485+ /* only opers can set the welcome messages */
486+ if (parc > 2)
487+ return send_reply(sptr, ERR_NOPRIVILEGES);
488+
489+ /* remote listing request, see if it is for me or a remote server
490+ * check FEAT_HIS_REMOTE to decide if an ordinary user can do this
491+ */
492+ if (parc == 2) {
493+ if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, feature_int(FEAT_HIS_REMOTE),
494+ "%C", 1, parc, parv) != HUNTED_ISME)
495+ return 0;
496+ return welcome_list(sptr, 0);
497+ }
498+
499+ /* just local listing */
a87bc2c2 500+ return welcome_list(sptr, 0);
cddf800b 501+}
502+
503+
504+/*
505+ * mo_welcome - oper message handler
506+ *
507+ * listing:
508+ * parv[0] = Send prefix
509+ *
510+ * remote listing:
511+ * parv[0] = Send prefix
512+ * parv[1] = Target
513+ *
514+ * set global or on remote server:
515+ * parv[0] = Send prefix
6dd3e24f 516+ * parv[1] = Target: server or * for global (or left out for this server)
a87bc2c2 517+ * parv[2] = Name
518+ * parv[3] = Text
cddf800b 519+ */
520+int mo_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
521+{
cb0b5df1 522+ char *target, *name, *who, *text, pattern[BUFSIZE];
a87bc2c2 523+ time_t timestamp;
524+ unsigned int flags = 0;
6dd3e24f 525+ int local = 0;
a87bc2c2 526+
527+ /* feature disabled */
528+ if (!feature_bool(FEAT_WELCOME))
529+ return send_reply(sptr, ERR_DISABLED, "WELCOME");
530+
531+ /* listing */
532+ if (parc < 2)
533+ return welcome_list(sptr, 0);
534+
4e89d808 535+ /* TODO: move feature check here? */
a87bc2c2 536+ /* remote listing request, see if it is for me or a remote server */
537+ if (parc == 2) {
538+ if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C", 1, parc, parv) != HUNTED_ISME)
539+ return 0;
540+ return welcome_list(sptr, 0);
541+ }
4e89d808 542+
543+ /* check PRIVS */
544+ /* local - need PRIV LOCAL_WELCOME or WELCOME */
545+ if (parc == 3 && !HasPriv(sptr,PRIV_LOCAL_WELCOME) && !HasPriv(sptr,PRIV_WELCOME))
546+ return send_reply(sptr, ERR_NOPRIVILEGES);
547+
548+ /* global or remote - need PRIV WELCOME */
549+ if (parc >= 4 && !HasPriv(sptr,PRIV_WELCOME))
550+ return send_reply(sptr, ERR_NOPRIVILEGES);
551+
a87bc2c2 552+ /* set the parameters */
6dd3e24f 553+
554+ /* target not given, only name - setting local welcome */
a87bc2c2 555+ if (parc < 4) {
556+ local++;
557+ target = cli_name(&me);
558+ name = parv[1];
559+ flags |= WELCOME_LOCAL;
6dd3e24f 560+
561+ /* target and name given */
562+ } else {
a87bc2c2 563+ target = parv[1];
564+ name = parv[2];
565+ }
566+ timestamp = TStime();
567+ who = cli_user(sptr)->opername;
568+ text = parv[parc - 1];
569+
570+ /* target is not global */
571+ if (!(target[0] == '*' && target[1] == '\0') && !local) {
6dd3e24f 572+
a87bc2c2 573+ /* build a pattern for hunt_server_cmd since we do not have all we need in parv */
574+ ircd_snprintf(0, pattern, sizeof(pattern), "%s %s %Tu %s :%s", "%C", name, timestamp, who, text);
575+ if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, pattern, 1, 2, parv) != HUNTED_ISME)
576+ return 0;
6dd3e24f 577+
578+ /* else it is a local welcome, for me */
579+ flags |= WELCOME_LOCAL;
a87bc2c2 580+ }
581+
cb0b5df1 582+ /* TODO: disallow global announcement from oper?
583+ * as PRIVMSG/NOTICE to $* is not allowed either by the ircd
584+ * when PRIV for that is added, use that here? PRIV_BROADCAST or something
4e89d808 585+ *
586+ * change prefix to $ ?
cb0b5df1 587+ */
a87bc2c2 588+ /* check for anounce prefix */
589+ if (*name == '!') {
590+ name++;
591+ flags |= WELCOME_ANNOUNCE;
592+ }
593+
594+ /* and do it */
595+ return welcome_do(cptr, sptr, name, text, who, timestamp, flags);
cddf800b 596+}
597+
598+
599+/*
600+ * ms_welcome - server message handler
601+ *
602+ * parv[0] = Send prefix
603+ * parv[1] = Target: server numeric or * for global
a87bc2c2 604+ * parv[2] = Name
605+ * parv[3] = Timestamp
606+ * parv[4] = Who
607+ * parv[5] = Text
cddf800b 608+ */
609+int ms_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
610+{
cb0b5df1 611+ char *target, *name, *who, *text;
a87bc2c2 612+ time_t timestamp;
613+ unsigned int flags = 0;
614+
6dd3e24f 615+ /* not enough - complain */
616+ if (parc < 2) {
617+ protocol_violation(sptr, "Too few parameters for WELCOME (got %d - need 2)", parc);
a87bc2c2 618+ return need_more_params(sptr, "WELCOME");
6dd3e24f 619+ }
a87bc2c2 620+
621+ /* remote listing request, see if it is for me or a remote server */
622+ if (parc == 2) {
6dd3e24f 623+ if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C", 1, parc, parv) != HUNTED_ISME)
624+ return 0;
625+ return welcome_list(sptr, 0);
a87bc2c2 626+ }
627+
6dd3e24f 628+ /* we need at least 6 parameters to continue - complain */
629+ if (parc < 6) {
630+ protocol_violation(sptr, "Too few parameters for WELCOME (got %d - need 6)", parc);
a87bc2c2 631+ return need_more_params(sptr, "WELCOME");
6dd3e24f 632+ }
a87bc2c2 633+
634+ /* set the parameters */
635+ target = parv[1];
636+ name = parv[2];
637+ timestamp = atoi(parv[3]);
638+ who = parv[4];
6dd3e24f 639+ text = parv[parc - 1]; /* parse reason as last parameter */
a87bc2c2 640+
641+ /* target is not global */
642+ if (!(target[0] == '*' && target[1] == '\0')) {
6dd3e24f 643+
a87bc2c2 644+ /* not for me, and forward it */
645+ if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C %s %s %s :%s", 1, parc, parv) != HUNTED_ISME)
646+ return 0;
6dd3e24f 647+
648+ /* local welcome for me */
649+ flags |= WELCOME_LOCAL;
a87bc2c2 650+ }
651+
652+ /* check for anounce prefix */
653+ if (*name == '!') {
654+ name++;
655+ flags |= WELCOME_ANNOUNCE;
656+ }
657+
658+ /* and do it */
659+ return welcome_do(cptr, sptr, name, text, who, timestamp, flags);
660+}
661+
662+
663+/*
664+ * mh_welcome - help message handler
665+ */
666+int mh_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
667+{
668+ if (!IsAnOper(sptr)) {
669+ send_reply(sptr, SND_EXPLICIT | RPL_HELP,
670+ "WELCOME :WELCOME");
671+ send_reply(sptr, SND_EXPLICIT | RPL_HELP,
672+ "WELCOME :Shows welcome messages set on the server.");
673+ } else {
674+ send_reply(sptr, SND_EXPLICIT | RPL_HELP,
675+ "WELCOME :WELCOME [<target>] [[!]<name> :<message>]");
676+ send_reply(sptr, SND_EXPLICIT | RPL_HELP,
677+ "WELCOME :Shows or sets welcome messages on a server.");
678+ }
cddf800b 679+ return 0;
680+}
4e89d808 681diff -r ed93c5ec7a2b ircd/parse.c
682--- a/ircd/parse.c Tue Feb 03 18:41:29 2009 +0100
683+++ b/ircd/parse.c Tue Feb 03 19:05:37 2009 +0100
a87bc2c2 684@@ -667,6 +667,15 @@
685 /* UNREG, CLIENT, SERVER, OPER, SERVICE, HELP */
686 { m_unregistered, m_not_oper, ms_opkick, mo_opkick, m_ignore, mh_nohelp }
cddf800b 687 },
688+
689+ /* add command for WELCOME */
690+ {
691+ MSG_WELCOME,
692+ TOK_WELCOME,
693+ 0, MAXPARA, MFLG_SLOW, 0, NULL,
a87bc2c2 694+ /* UNREG, CLIENT, SERVER, OPER, SERVICE, HELP */
695+ { m_unregistered, m_welcome, ms_welcome, mo_welcome, m_ignore, mh_welcome }
cddf800b 696+ },
697
698 /* This command is an alias for QUIT during the unregistered part of
699 * of the server. This is because someone jumping via a broken web
4e89d808 700diff -r ed93c5ec7a2b ircd/s_err.c
701--- a/ircd/s_err.c Tue Feb 03 18:41:29 2009 +0100
702+++ b/ircd/s_err.c Tue Feb 03 19:05:37 2009 +0100
a87bc2c2 703@@ -486,7 +486,7 @@
704 /* 226 */
705 { RPL_STATSALINE, "%s", "226" },
706 /* 227 */
707- { 0 },
708+ { RPL_STATSWELCOME, "W %d %s %s %Tu :%s", "227" },
709 /* 228 */
710 { RPL_STATSQLINE, "Q %s :%s", "228" },
711 /* 229 */
712@@ -1050,7 +1050,7 @@
713 /* 508 */
714 { 0 },
715 /* 509 */
716- { 0 },
717+ { ERR_NOSUCHWELCOME, "%s :No such welcome", "509" },
718 /* 510 */
719 { 0 },
720 /* 511 */
4e89d808 721diff -r ed93c5ec7a2b ircd/s_serv.c
722--- a/ircd/s_serv.c Tue Feb 03 18:41:29 2009 +0100
723+++ b/ircd/s_serv.c Tue Feb 03 19:05:37 2009 +0100
a87bc2c2 724@@ -57,6 +57,7 @@
725 #include "struct.h"
726 #include "sys.h"
727 #include "userload.h"
728+#include "welcome.h"
729
730 /* #include <assert.h> -- Now using assert in ircd_log.h */
731 #include <stdlib.h>
732@@ -196,6 +197,7 @@
733 */
734 gline_burst(cptr);
735 jupe_burst(cptr);
736+ welcome_burst(cptr);
737
738 /*
739 * Pass on my client information to the new server
4e89d808 740diff -r ed93c5ec7a2b ircd/s_stats.c
741--- a/ircd/s_stats.c Tue Feb 03 18:41:29 2009 +0100
742+++ b/ircd/s_stats.c Tue Feb 03 19:05:37 2009 +0100
a87bc2c2 743@@ -54,6 +54,7 @@
744 #include "send.h"
745 #include "struct.h"
746 #include "userload.h"
747+#include "welcome.h"
748
749 #include <stdio.h>
750 #include <stdlib.h>
751@@ -689,9 +690,12 @@
752 { 'V', "vserversmach", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS), FEAT_HIS_STATS_v,
753 stats_servers_verbose, 0,
754 "Verbose server information." },
755- { 'w', "userload", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_w,
756+ { 'w', "userload", STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS, FEAT_HIS_STATS_w,
757 calc_load, 0,
758 "Userload statistics." },
759+ { 'W', "welcome", STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS, FEAT_HIS_STATS_W,
760+ welcome_stats, 0,
761+ "Welcome messages." },
762 { 'x', "memusage", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_x,
763 stats_meminfo, 0,
764 "List usage information." },
4e89d808 765diff -r ed93c5ec7a2b ircd/s_user.c
766--- a/ircd/s_user.c Tue Feb 03 18:41:29 2009 +0100
767+++ b/ircd/s_user.c Tue Feb 03 19:05:37 2009 +0100
a87bc2c2 768@@ -63,6 +63,7 @@
769 #include "userload.h"
770 #include "version.h"
771 #include "whowas.h"
772+#include "welcome.h"
773
774 #include "handlers.h" /* m_motd and m_lusers */
775
776@@ -411,6 +412,9 @@
777 cli_info(sptr), NumNick(cptr) /* two %s's */);
778
779 IPcheck_connect_succeeded(sptr);
780+
781+ if (feature_bool(FEAT_WELCOME))
782+ welcome_list(sptr, 1);
783 }
784 else {
785 struct Client *acptr = user->server;
4e89d808 786diff -r ed93c5ec7a2b ircd/welcome.c
cddf800b 787--- /dev/null Thu Jan 01 00:00:00 1970 +0000
4e89d808 788+++ b/ircd/welcome.c Tue Feb 03 19:05:37 2009 +0100
6dd3e24f 789@@ -0,0 +1,373 @@
cddf800b 790+/*
a87bc2c2 791+ * IRC - Internet Relay Chat, ircd/welcome.c
cddf800b 792+ * Copyright (C) 1990 Jarkko Oikarinen and
793+ * University of Oulu, Finland
794+ * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
795+ *
796+ * This program is free software; you can redistribute it and/or modify
797+ * it under the terms of the GNU General Public License as published by
798+ * the Free Software Foundation; either version 1, or (at your option)
799+ * any later version.
800+ *
801+ * This program is distributed in the hope that it will be useful,
802+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
803+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
804+ * GNU General Public License for more details.
805+ *
806+ * You should have received a copy of the GNU General Public License
807+ * along with this program; if not, write to the Free Software
808+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
809+ */
810+/** @file
a87bc2c2 811+ * @brief Implementation of welcome message handling functions.
cddf800b 812+ */
813+#include "config.h"
814+
815+#include "client.h"
816+#include "hash.h"
817+#include "ircd.h"
818+#include "ircd_alloc.h"
819+#include "ircd_features.h"
820+#include "ircd_log.h"
821+#include "ircd_reply.h"
822+#include "ircd_string.h"
823+#include "match.h"
824+#include "msg.h"
825+#include "numeric.h"
826+#include "numnicks.h"
827+#include "s_bsd.h"
a87bc2c2 828+#include "s_debug.h"
cddf800b 829+#include "s_misc.h"
830+#include "send.h"
831+#include "struct.h"
832+#include "sys.h" /* FALSE bleah */
833+#include "welcome.h"
834+
835+/* #include <assert.h> -- Now using assert in ircd_log.h */
836+#include <string.h>
837+
cddf800b 838+
cb0b5df1 839+/** List of welcome messages - first MAX for global, second MAX for local */
6dd3e24f 840+static struct Welcome WelcomeArray[WELCOME_MAX_ENTRIES * 2] = { { 0 } };
cddf800b 841+
cddf800b 842+
a87bc2c2 843+/** Allocate a new welcome with the given parameters.
844+ * @param[in] name Name of the welcome message.
845+ * @param[in] text The welcome message.
846+ * @param[in] who Who set it.
847+ * @param[in] timestamp When it was set.
cb0b5df1 848+ * @return name Array number of the welcome set.
cddf800b 849+ */
cb0b5df1 850+static int
851+welcome_make(int name, char *text, char *who, time_t timestamp)
cddf800b 852+{
cb0b5df1 853+ /* range 0 to 2 * max - 1 */
854+ assert(name >= 0 && name <= 2 * WELCOME_MAX_ENTRIES - 1);
855+
856+ /* store it */
857+ ircd_strncpy(WelcomeArray[name].text, text, TOPICLEN);
858+ ircd_strncpy(WelcomeArray[name].who, who, ACCOUNTLEN);
859+ WelcomeArray[name].timestamp = timestamp;
860+
861+ return name;
cddf800b 862+}
863+
cddf800b 864+
a87bc2c2 865+/** Change a welcome message.
866+ * @param[in] cptr Local client that sent us the welcome.
867+ * @param[in] sptr Originator of the welcome.
868+ * @param[in] name Name of the message.
869+ * @param[in] text The welcome message.
870+ * @param[in] timestamp Timestamp of when the message was set.
871+ * @param[in] flags Flags to set on welcome.
872+ * @return Zero
cddf800b 873+ */
874+int
a87bc2c2 875+welcome_do(struct Client *cptr, struct Client *sptr, char *name, char *text,
876+ char *who, time_t timestamp, unsigned int flags)
cddf800b 877+{
cb0b5df1 878+ int nameint = atoi(name); /* transform to int */
879+ int namearray = nameint - 1; /* used to test the array element */
6dd3e24f 880+ char oldtext[TOPICLEN + 1]; /* save old text when unsetting */
881+ static time_t rate;
882+
883+ assert(NULL != cptr);
884+ assert(NULL != sptr);
885+ assert(NULL != name);
886+ assert(NULL != text);
887+ assert(NULL != who);
a87bc2c2 888+
cb0b5df1 889+ /* debug */
a87bc2c2 890+ Debug((DEBUG_DEBUG, "welcome_do(\"%s\", \"%s\", \"%s\", \"%s\" \"%s\", %Tu, 0x%04x)",
891+ cli_name(cptr), cli_name(sptr), name, text, who, timestamp, flags));
892+
893+ /* check name */
cb0b5df1 894+ if (nameint < 1 || nameint > WELCOME_MAX_ENTRIES) {
a87bc2c2 895+ if (IsUser(sptr))
896+ sendcmdto_one(&me, CMD_NOTICE, sptr,
897+ "%C :WELCOME: Invalid message number %s - should between 1 and %d",
898+ sptr, name, WELCOME_MAX_ENTRIES);
cddf800b 899+ return 0;
900+ }
901+
cb0b5df1 902+ /* correct namearray for local offset */
903+ if (flags & WELCOME_LOCAL)
904+ namearray += WELCOME_MAX_ENTRIES;
a87bc2c2 905+
906+ /* cannot unset welcome that is not set */
6dd3e24f 907+ if (WelcomeArray[namearray].timestamp == 0 && EmptyString(text)) {
908+
a87bc2c2 909+ /* from user, throw error */
910+ if (IsUser(sptr))
911+ return send_reply(sptr, ERR_NOSUCHWELCOME, name);
6dd3e24f 912+
913+ /* new local welcome from server, but empty - ignore
914+ * we do accept a new global welcome message that is empty
915+ */
a87bc2c2 916+ if (flags & WELCOME_LOCAL)
917+ return 0;
a87bc2c2 918+ }
cddf800b 919+
a87bc2c2 920+ /* check if there is something to change */
6dd3e24f 921+ /* we got a record for it */
922+ if (WelcomeArray[namearray].timestamp != 0) {
923+
924+ /* global */
925+ if (namearray < WELCOME_MAX_ENTRIES) {
926+
927+ /* netburst and we got the same or a newer one
928+ *
929+ * we only use the timestamp for resolving conflicts in net burst
930+ * outside of netburst, we simply parse whatever we get
931+ * this way we will not get stuck with a welcome message set by a server
932+ * running ahead with the time
933+ */
934+ if (IsBurstOrBurstAck(cptr) && timestamp <= WelcomeArray[namearray].timestamp)
a87bc2c2 935+ return 0;
6dd3e24f 936+
937+ /* local welcome - we use our idea of the time */
cb0b5df1 938+ } else
a87bc2c2 939+ timestamp = TStime();
cb0b5df1 940+
a87bc2c2 941+ /* compare new message with old message */
cb0b5df1 942+ if (ircd_strcmp(text, WelcomeArray[namearray].text) == 0) {
a87bc2c2 943+ if (IsUser(sptr))
944+ sendcmdto_one(&me, CMD_NOTICE, sptr,
cb0b5df1 945+ "%C :WELCOME: Cannot change %smessage for %s - nothing to change.",
946+ sptr, (flags & WELCOME_LOCAL) ? "local " : "", name);
a87bc2c2 947+ return 0;
948+ }
949+ }
cddf800b 950+
6dd3e24f 951+ /* TODO: rate limited for what? max 10 welcome messages..? */
952+ /* possible timestamp drift - warn ops */
953+ if (timestamp - TStime() > WELCOME_MAX_DRIFT) {
954+ sendto_opmask_butone_ratelimited(0, SNO_NETWORK, &rate,
955+ "Possible timestamp drift from %C; timestamp in WELCOME message is %is ahead of time",
956+ IsServer(sptr) ? sptr : cli_user(sptr)->server, timestamp - TStime());
957+
958+ /* warn remote oper too */
959+ if (IsUser(sptr))
960+ sendcmdto_one(&me, CMD_NOTICE, sptr,
961+ "%C :Possible timestamp drift from %C; timestamp in WELCOME message is %is ahead of time",
962+ sptr, cli_user(sptr)->server, timestamp - TStime());
963+ }
964+
965+ /* unsetting - do not announce, save text */
966+ if (EmptyString(text)) {
967+ flags &= ~WELCOME_ANNOUNCE;
968+ ircd_strncpy(oldtext, WelcomeArray[namearray].text, TOPICLEN);
969+ }
970+
cb0b5df1 971+ /* update */
972+ welcome_make(namearray, text, who, timestamp);
973+
cb0b5df1 974+ /* inform ops */
6dd3e24f 975+ sendto_opmask_butone(0, SNO_OLDSNO, "%s %s%s%sWELCOME %d \"%s\" [%Tu]",
a87bc2c2 976+ (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
977+ get_client_name_and_opername(sptr) : cli_name((cli_user(sptr))->server),
6dd3e24f 978+ EmptyString(text) ? "unsetting" : "changing",
979+ (flags & WELCOME_ANNOUNCE) ? " and announcing " : " ",
980+ (flags & WELCOME_LOCAL) ? "local " : "",
981+ nameint,
982+ EmptyString(text) ? oldtext : WelcomeArray[namearray].text,
983+ WelcomeArray[namearray].timestamp);
a87bc2c2 984+
985+ /* log it */
6dd3e24f 986+ log_write(LS_NETWORK, L_INFO, LOG_NOSNOTICE, "%#C (%s) %s%s%sWELCOME %d \"%s\" [%Tu]",
987+ sptr, WelcomeArray[namearray].who,
988+ EmptyString(text) ? "unsetting" : "changing",
989+ (flags & WELCOME_ANNOUNCE) ? " and announcing " : " ",
990+ (flags & WELCOME_LOCAL) ? "local " : "",
991+ nameint,
992+ EmptyString(text) ? oldtext : WelcomeArray[namearray].text,
cb0b5df1 993+ WelcomeArray[namearray].timestamp);
a87bc2c2 994+
995+ /* welcome set by remote user, inform oper of success */
6dd3e24f 996+ if ((flags & WELCOME_LOCAL) && IsUser(sptr) && !MyUser(sptr)) {
997+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s %s%s local WELCOME %d \"%s\" [%Tu]",
998+ sptr, get_client_name_and_opername(sptr),
999+ EmptyString(text) ? "unsetting" : "changing",
1000+ (flags & WELCOME_ANNOUNCE) ? " and announcing" : "",
1001+ nameint,
1002+ EmptyString(text) ? oldtext : WelcomeArray[namearray].text,
1003+ WelcomeArray[namearray].timestamp);
1004+
1005+ /* TODO: wallops all local changes, by both local and remote opers? */
1006+ /* tell all opers about the local message being set remotely */
1007+ sendwallto_group_butone(&me, WALL_WALLOPS, 0,
1008+ "%s %s%s local WELCOME %d \"%s\" [%Tu]",
1009+ get_client_name_and_opername(sptr),
1010+ EmptyString(text) ? "unsetting" : "changing",
1011+ (flags & WELCOME_ANNOUNCE) ? " and announcing" : "",
1012+ nameint,
1013+ EmptyString(text) ? oldtext : WelcomeArray[namearray].text,
1014+ WelcomeArray[namearray].timestamp);
1015+ }
cddf800b 1016+
cb0b5df1 1017+ /* propagate it */
a87bc2c2 1018+ if (!(flags & WELCOME_LOCAL))
1019+ sendcmdto_serv_butone(sptr, CMD_WELCOME, cptr, "* %s%d %Tu %s :%s",
cb0b5df1 1020+ (flags & WELCOME_ANNOUNCE) ? "!" : "", nameint,
1021+ WelcomeArray[namearray].timestamp, WelcomeArray[namearray].who,
1022+ WelcomeArray[namearray].text);
cddf800b 1023+
a87bc2c2 1024+ /* announce it */
6dd3e24f 1025+ if (flags & WELCOME_ANNOUNCE)
cb0b5df1 1026+ welcome_announce(namearray);
a87bc2c2 1027+
1028+ return 0;
cddf800b 1029+}
1030+
a87bc2c2 1031+
1032+/** Announce a welcome message to local clients.
cb0b5df1 1033+ * @param[in] name Welcome message to announce.
cddf800b 1034+ */
a87bc2c2 1035+void
cb0b5df1 1036+welcome_announce(int name)
cddf800b 1037+{
a87bc2c2 1038+ struct Client *acptr;
1039+ struct MsgBuf *msgbuf;
6dd3e24f 1040+ int i;
a87bc2c2 1041+
cb0b5df1 1042+ /* range 0 to 2 * max - 1 */
1043+ assert(name >= 0 && name <= 2 * WELCOME_MAX_ENTRIES - 1);
a87bc2c2 1044+
cb0b5df1 1045+ /* TODO: target is $* as if it were a global broadcast
1046+ * could make it $servername for local message announcement
1047+ * but the type is shown between [ ] already
1048+ * either [Network] or [servername] - using $* is just shorter.
1049+ */
a87bc2c2 1050+ /* build msgbuf */
1051+ msgbuf = msgq_make(0, ":%C %s $* :[%s] %s", &me, MSG_NOTICE,
cb0b5df1 1052+ name >= WELCOME_MAX_ENTRIES ? cli_name(&me) : feature_str(FEAT_NETWORK),
1053+ WelcomeArray[name].text);
a87bc2c2 1054+
6dd3e24f 1055+ /* go over local clients */
1056+ for (i = HighestFd; i > 0; --i) {
cb0b5df1 1057+
6dd3e24f 1058+ /* skip unregistered clients - they see the message during login
1059+ * skip servers
a87bc2c2 1060+ */
6dd3e24f 1061+ if (!(acptr = LocalClientArray[i]) || !IsRegistered(acptr) || IsServer(acptr))
a87bc2c2 1062+ continue;
cb0b5df1 1063+
6dd3e24f 1064+ /* send it away */
a87bc2c2 1065+ send_buffer(acptr, msgbuf, 0);
cddf800b 1066+ }
cddf800b 1067+}
1068+
a87bc2c2 1069+
a87bc2c2 1070+/** Send the full list of welcome message to \a cptr.
1071+ * @param[in] cptr Local server to send welcomes to.
cddf800b 1072+ */
1073+void
a87bc2c2 1074+welcome_burst(struct Client *cptr)
cddf800b 1075+{
cb0b5df1 1076+ int name;
a87bc2c2 1077+
6dd3e24f 1078+ assert(NULL != cptr);
1079+
cb0b5df1 1080+ /* loop over global entries - 0 to max - 1*/
1081+ for (name = 0; name <= WELCOME_MAX_ENTRIES - 1; name++) {
1082+ if (WelcomeArray[name].timestamp != 0)
a87bc2c2 1083+ sendcmdto_one(&me, CMD_WELCOME, cptr, "* %d %Tu %s :%s",
cb0b5df1 1084+ name + 1, WelcomeArray[name].timestamp, WelcomeArray[name].who,
1085+ WelcomeArray[name].text);
cddf800b 1086+ }
1087+}
1088+
a87bc2c2 1089+
a87bc2c2 1090+/** List welcome messages.
1091+ * @param[in] sptr Client requesting the listing.
1092+ * @param[in] connect When non zero do not report no welcome is set
cddf800b 1093+ * @return Zero.
1094+ */
1095+int
a87bc2c2 1096+welcome_list(struct Client *sptr, int connect)
cddf800b 1097+{
cb0b5df1 1098+ int found = 0, local = 0, name;
a87bc2c2 1099+
6dd3e24f 1100+ assert(NULL != sptr);
1101+
cb0b5df1 1102+ /* loop over all entries - range 0 to 2 * max - 1 */
1103+ for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) {
a87bc2c2 1104+
cb0b5df1 1105+ /* local entries now */
1106+ if (name == WELCOME_MAX_ENTRIES)
1107+ local = 1;
a87bc2c2 1108+
cb0b5df1 1109+ /* not set or empty - skip */
6dd3e24f 1110+ /* TODO: EmptyString? */
cb0b5df1 1111+ if (WelcomeArray[name].timestamp == 0 || *WelcomeArray[name].text == 0)
a87bc2c2 1112+ continue;
cb0b5df1 1113+
1114+ /* got one */
a87bc2c2 1115+ found++;
cb0b5df1 1116+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :[%s] %s",
1117+ sptr, local ? cli_name(&me) : feature_str(FEAT_NETWORK), WelcomeArray[name].text);
a87bc2c2 1118+ }
cb0b5df1 1119+
1120+ /* nothing set */
a87bc2c2 1121+ if (!found && !connect)
cb0b5df1 1122+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :No welcome message set.", sptr);
1123+
a87bc2c2 1124+ return 0;
1125+}
cddf800b 1126+
cddf800b 1127+
a87bc2c2 1128+/** Statistics callback to list Welcome messages.
1129+ * @param[in] sptr Client requesting statistics.
1130+ * @param[in] sd Stats descriptor for request (ignored).
1131+ * @param[in] param Extra parameter from user (ignored).
1132+ */
1133+void
1134+welcome_stats(struct Client *sptr, const struct StatDesc *sd, char *param)
1135+{
cb0b5df1 1136+ int name, local = 0;
a87bc2c2 1137+
6dd3e24f 1138+ assert(NULL != sptr);
1139+
a87bc2c2 1140+ /* send header so the client knows what we are showing */
1141+ send_reply(sptr, SND_EXPLICIT | RPL_STATSHEADER,
6dd3e24f 1142+ "W Name Target Opername Timestamp :Message");
a87bc2c2 1143+
cb0b5df1 1144+ /* loop over all entries - range 0 to 2 * max - 1*/
1145+ for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) {
cddf800b 1146+
cb0b5df1 1147+ /* local entries now */
1148+ if (name == WELCOME_MAX_ENTRIES)
1149+ local = 1;
a87bc2c2 1150+
cb0b5df1 1151+ /* not set */
1152+ if (WelcomeArray[name].timestamp == 0)
1153+ continue;
cddf800b 1154+
cb0b5df1 1155+ /* send it */
1156+ send_reply(sptr, RPL_STATSWELCOME,
6dd3e24f 1157+ local ? name + 1 - WELCOME_MAX_ENTRIES : name + 1,
1158+ local ? cli_name(&me) : "*",
cb0b5df1 1159+ WelcomeArray[name].who, WelcomeArray[name].timestamp,
6dd3e24f 1160+ EmptyString(WelcomeArray[name].text) ? "<Empty>" : WelcomeArray[name].text);
cddf800b 1161+ }
cddf800b 1162+}