]> jfr.im git - irc/quakenet/snircd-patchqueue.git/blame - welcome.patch
welcome: do not recheck timestamps and text when the source is a local user
[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
f319303e 80diff -r 8c7c9ff0f0ca include/client.h
5632b943 81--- a/include/client.h
82+++ b/include/client.h
308d3fca 83@@ -142,6 +142,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 */
4e89d808 87+ PRIV_WELCOME, /* oper can WELCOME */
88+ PRIV_LOCAL_WELCOME, /* oper can local WELCOME */
89 PRIV_LAST_PRIV /**< number of privileges */
90 };
91
f319303e 92diff -r 8c7c9ff0f0ca include/handlers.h
5632b943 93--- a/include/handlers.h
94+++ b/include/handlers.h
f0f686d6 95@@ -138,6 +138,7 @@
cddf800b 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*[]);
f0f686d6 103@@ -172,6 +173,7 @@
cddf800b 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*[]);
308d3fca 108 extern int mo_xquery(struct Client*, struct Client*, int, char*[]);
cddf800b 109 extern int mr_error(struct Client*, struct Client*, int, char*[]);
110 extern int mr_error(struct Client*, struct Client*, int, char*[]);
f0f686d6 111@@ -230,6 +232,7 @@
cddf800b 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*[]);
308d3fca 117 extern int ms_xquery(struct Client*, struct Client*, int, char*[]);
118 extern int ms_xreply(struct Client*, struct Client*, int, char*[]);
f319303e 119diff -r 8c7c9ff0f0ca include/ircd_features.h
5632b943 120--- a/include/ircd_features.h
121+++ b/include/ircd_features.h
a87bc2c2 122@@ -101,6 +101,7 @@
123 FEAT_IRCD_RES_TIMEOUT,
124 FEAT_AUTH_TIMEOUT,
125 FEAT_ANNOUNCE_INVITES,
126+ FEAT_WELCOME,
127
128 /* features that affect all operators */
129 FEAT_EXTENDED_CHECKCMD,
308d3fca 130@@ -142,6 +143,7 @@
a87bc2c2 131 FEAT_HIS_STATS_u,
132 FEAT_HIS_STATS_U,
133 FEAT_HIS_STATS_v,
134+ FEAT_HIS_STATS_W,
135 FEAT_HIS_STATS_w,
136 FEAT_HIS_STATS_x,
137 FEAT_HIS_STATS_y,
f319303e 138diff -r 8c7c9ff0f0ca include/msg.h
5632b943 139--- a/include/msg.h
140+++ b/include/msg.h
308d3fca 141@@ -196,6 +196,10 @@
cddf800b 142 #define TOK_NOTICE "O"
143 #define CMD_NOTICE MSG_NOTICE, TOK_NOTICE
100a7f47 144
cddf800b 145+#define MSG_WELCOME "WELCOME" /* WELC */
146+#define TOK_WELCOME "WE"
147+#define CMD_WELCOME MSG_WELCOME, TOK_WELCOME
100a7f47 148+
cddf800b 149 #define MSG_WALLCHOPS "WALLCHOPS" /* WC */
150 #define TOK_WALLCHOPS "WC"
100a7f47 151 #define CMD_WALLCHOPS MSG_WALLCHOPS, TOK_WALLCHOPS
f319303e 152diff -r 8c7c9ff0f0ca include/numeric.h
5632b943 153--- a/include/numeric.h
154+++ b/include/numeric.h
a87bc2c2 155@@ -116,6 +116,7 @@
156 RPL_STATSGLINE 227 Dalnet
157 RPL_STATSVLINE 227 unreal */
158 #define RPL_STATSALINE 226 /* Hybrid, Undernet */
159+#define RPL_STATSWELCOME 227 /* QuakeNet extension */
160 #define RPL_STATSQLINE 228 /* Undernet extension */
a87bc2c2 161
308d3fca 162 /* RPL_SERVICEINFO 231 unused */
163@@ -440,6 +441,8 @@
a87bc2c2 164 /* ERR_GHOSTEDCLIENT 503 efnet */
165 /* ERR_VWORLDWARN 503 austnet */
166
167+#define ERR_NOSUCHWELCOME 509 /* QuakeNet extension */
168+
169 #define ERR_SILELISTFULL 511 /* Undernet extension */
170 /* ERR_NOTIFYFULL 512 aircd */
171 /* ERR_TOOMANYWATCH 512 Numeric List: Dalnet */
f319303e 172diff -r 8c7c9ff0f0ca include/welcome.h
5632b943 173--- /dev/null
174+++ b/include/welcome.h
b27ac6fc 175@@ -0,0 +1,75 @@
cddf800b 176+#ifndef INCLUDED_welcome_h
177+#define INCLUDED_welcome_h
178+/*
179+ * IRC - Internet Relay Chat, include/welcome.h
180+ * Copyright (C) 1990 Jarkko Oikarinen and
181+ * University of Oulu, Computing Center
182+ * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
183+ *
184+ * This program is free software; you can redistribute it and/or modify
185+ * it under the terms of the GNU General Public License as published by
186+ * the Free Software Foundation; either version 2, or (at your option)
187+ * any later version.
188+ *
189+ * This program is distributed in the hope that it will be useful,
190+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
191+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
192+ * GNU General Public License for more details.
193+ *
194+ * You should have received a copy of the GNU General Public License
195+ * along with this program; if not, write to the Free Software
196+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
197+ */
198+/** @file
a87bc2c2 199+ * @brief Interface and declarations for welcome message handling.
cddf800b 200+ */
201+#ifndef INCLUDED_sys_types_h
202+#include <sys/types.h>
203+#define INCLUDED_sys_types_h
204+#endif
205+
a87bc2c2 206+struct Client;
207+struct StatDesc;
208+
cb0b5df1 209+/* Maximum number of welcome entries (per type; X global, X local) */
6dd3e24f 210+#define WELCOME_MAX_ENTRIES 10
a7f8ae30 211+/* Maximum length of a welcome message */
212+#define WELCOMELEN TOPICLEN
b27ac6fc 213+
a87bc2c2 214+
6eab3e57 215+/* Test if a welcome entry is in a valid range */
f319303e 216+#define WelcomeIsValid(x) ((unsigned) (x) <= 2 * WELCOME_MAX_ENTRIES -1)
6eab3e57 217+/* Test if a welcome entry is set */
eabbc644 218+#define WelcomeIsSet(x) (WelcomeArray[(x)].timestamp > 0)
6eab3e57 219+/* Test if a welcome entry is empty */
eabbc644 220+#define WelcomeIsEmpty(x) (*WelcomeArray[(x)].text == 0)
d6da6cd7 221+
6eab3e57 222+/* Get welcome timestamp */
223+#define WelcomeTS(x) (WelcomeArray[(x)].timestamp)
224+/* Get welcome text */
225+#define WelcomeText(x) (WelcomeArray[(x)].text)
226+/* Get welcome who info */
227+#define WelcomeWho(x) (WelcomeArray[(x)].who)
228+
229+
a87bc2c2 230+/* Describes a Welcome message entry. */
231+struct Welcome {
6dd3e24f 232+ time_t timestamp; /**< Timestamp of the welcome */
a7f8ae30 233+ char text[WELCOMELEN + 1]; /**< Message */
6dd3e24f 234+ char who[ACCOUNTLEN + 1]; /**< Who set it */
a87bc2c2 235+};
236+
cb0b5df1 237+/** Welcome type flags */
a87bc2c2 238+#define WELCOME_LOCAL 0x01 /**< welcome is local */
239+/** Welcome action flags */
240+#define WELCOME_ANNOUNCE 0x02 /**< announce change to users */
95de96cd 241+#define WELCOME_INSERT 0x04 /**< insert welcome message, move down all others one place */
a87bc2c2 242+
c13e4602 243+extern int welcome_do(struct Client *cptr, struct Client *sptr, char *name,
244+ time_t timestamp, char *who, char *text, unsigned int flags);
cb0b5df1 245+extern void welcome_announce(int name);
cddf800b 246+extern void welcome_burst(struct Client *cptr);
a87bc2c2 247+extern int welcome_list(struct Client *sptr, int connect);
248+extern void welcome_stats(struct Client *sptr, const struct StatDesc *sd, char *param);
cddf800b 249+
250+#endif /* INCLUDED_welcome_h */
f319303e 251diff -r 8c7c9ff0f0ca ircd/Makefile.in
5632b943 252--- a/ircd/Makefile.in
253+++ b/ircd/Makefile.in
308d3fca 254@@ -186,6 +186,7 @@
a87bc2c2 255 m_wallops.c \
256 m_wallusers.c \
257 m_wallvoices.c \
258+ m_welcome.c \
259 m_who.c \
260 m_whois.c \
261 m_whowas.c \
dcd0ea31 262@@ -215,6 +216,7 @@
a87bc2c2 263 send.c \
264 uping.c \
265 userload.c \
266+ welcome.c \
267 whocmds.c \
268 whowas.c \
269 y.tab.c
308d3fca 270@@ -1161,6 +1163,11 @@
a87bc2c2 271 ../include/ircd_reply.h ../include/ircd_string.h \
272 ../include/ircd_chattr.h ../include/msg.h ../include/numeric.h \
273 ../include/numnicks.h ../include/s_user.h ../include/send.h
274+m_welcome.o: m_welcome.c ../config.h ../include/channel.h \
275+ ../include/client.h ../include/hash.h ../include/ircd.h ../include/ircd_log.h \
276+ ../include/ircd_reply.h ../include/ircd_string.h ../include/msg.h \
277+ ../include/numeric.h ../include/numnicks.h ../include/s_user.h \
278+ ../include/send.h ../include/welcome.h
279 m_who.o: m_who.c ../config.h ../include/channel.h ../include/ircd_defs.h \
280 ../include/res.h ../config.h ../include/client.h ../include/dbuf.h \
281 ../include/msgq.h ../include/ircd_events.h ../include/ircd_handler.h \
308d3fca 282@@ -1422,6 +1429,13 @@
a87bc2c2 283 ../include/numnicks.h ../include/querycmds.h ../include/ircd_features.h \
284 ../include/s_misc.h ../include/s_stats.h ../include/send.h \
285 ../include/struct.h ../include/sys.h
286+welcome.o: welcome.c ../config.h ../include/client.h \
287+ ../include/hash.h ../include/ircd.h ../include/ircd_alloc.h \
288+ ../include/ircd_features.h ../include/ircd_log.h ../include/ircd_reply.h \
289+ ../include/match.h ../include/msg.h ../include/numeric.h \
290+ ../include/numnicks.h ../include/s_debug.h ../include/s_bsd.h \
291+ ../include/s_misc.h ../include/send.h ../include/struct.h \
292+ ../include/sys.h ../include/welcome.h
293 whocmds.o: whocmds.c ../config.h ../include/whocmds.h \
294 ../include/channel.h ../include/ircd_defs.h ../include/res.h \
295 ../config.h ../include/client.h ../include/dbuf.h ../include/msgq.h \
f319303e 296diff -r 8c7c9ff0f0ca ircd/client.c
5632b943 297--- a/ircd/client.c
298+++ b/ircd/client.c
308d3fca 299@@ -177,6 +177,7 @@
4e89d808 300 FlagSet(&privs_local, PRIV_WHOX);
301 FlagSet(&privs_local, PRIV_DISPLAY);
302 FlagSet(&privs_local, PRIV_FORCE_LOCAL_OPMODE);
303+ FlagSet(&privs_local, PRIV_LOCAL_WELCOME);
308d3fca 304
305 privs_defaults_set = 1;
306 }
307@@ -223,6 +224,7 @@
308 ClrPriv(client, PRIV_JUPE);
4e89d808 309 ClrPriv(client, PRIV_OPMODE);
4e89d808 310 ClrPriv(client, PRIV_BADCHAN);
311+ ClrPriv(client, PRIV_WELCOME);
312 }
308d3fca 313 }
314
315@@ -244,7 +246,7 @@
316 P(CHANSERV), P(XTRA_OPER), P(NOIDLE), P(FREEFORM),
317 P(PARANOID), P(CHECK), P(WALL), P(CLOSE),
318 P(ROUTE), P(ROUTEINFO), P(SERVERINFO), P(CHANNEL_PRIVACY),
319- P(USER_PRIVACY),
320+ P(USER_PRIVACY), P(WELCOME), P(LOCAL_WELCOME),
4e89d808 321 #undef P
322 { 0, 0 }
323 };
f319303e 324diff -r 8c7c9ff0f0ca ircd/ircd_features.c
5632b943 325--- a/ircd/ircd_features.c
326+++ b/ircd/ircd_features.c
e721b9bb 327@@ -366,6 +366,7 @@
a87bc2c2 328 F_I(IRCD_RES_TIMEOUT, 0, 4, 0),
329 F_I(AUTH_TIMEOUT, 0, 9, 0),
330 F_B(ANNOUNCE_INVITES, 0, 0, 0),
331+ F_B(WELCOME, 0, 1, 0),
332
333 /* features that affect all operators */
334 F_B(EXTENDED_CHECKCMD, 0, 0, 0),
308d3fca 335@@ -407,6 +408,7 @@
a87bc2c2 336 F_B(HIS_STATS_u, 0, 1, 0),
337 F_B(HIS_STATS_U, 0, 1, 0),
338 F_B(HIS_STATS_v, 0, 1, 0),
339+ F_B(HIS_STATS_W, 0, 1, 0),
340 F_B(HIS_STATS_w, 0, 1, 0),
341 F_B(HIS_STATS_x, 0, 1, 0),
342 F_B(HIS_STATS_y, 0, 1, 0),
f319303e 343diff -r 8c7c9ff0f0ca ircd/ircd_lexer.l
5632b943 344--- a/ircd/ircd_lexer.l
345+++ b/ircd/ircd_lexer.l
308d3fca 346@@ -166,6 +166,8 @@
347 { "serverinfo", TPRIV_SERVERINFO },
348 { "user_privacy", TPRIV_USER_PRIVACY },
349 { "channel_privacy", TPRIV_CHANNEL_PRIVACY },
4e89d808 350+ { "local_welcome", TPRIV_LOCAL_WELCOME },
351+ { "welcome", TPRIV_WELCOME },
352 { NULL, 0 }
353 };
354 static int ntokens;
f319303e 355diff -r 8c7c9ff0f0ca ircd/ircd_parser.y
5632b943 356--- a/ircd/ircd_parser.y
357+++ b/ircd/ircd_parser.y
308d3fca 358@@ -189,6 +189,7 @@
359 %token TPRIV_CHANSERV TPRIV_XTRA_OPER TPRIV_NOIDLE TPRIV_FREEFORM TPRIV_PARANOID
360 %token TPRIV_CHECK TPRIV_WALL TPRIV_CLOSE TPRIV_ROUTE TPRIV_ROUTEINFO TPRIV_SERVERINFO
361 %token TPRIV_CHANNEL_PRIVACY TPRIV_USER_PRIVACY TPRIV_LIST_CHAN
dcd0ea31 362+%token TPRIV_LOCAL_WELCOME TPRIV_WELCOME
4e89d808 363 /* and some types... */
364 %type <num> sizespec
365 %type <num> timespec timefactor factoredtimes factoredtime
308d3fca 366@@ -703,6 +704,8 @@
367 TPRIV_SERVERINFO { $$ = PRIV_SERVERINFO ; } |
368 TPRIV_CHANNEL_PRIVACY { $$ = PRIV_CHANNEL_PRIVACY ; } |
369 TPRIV_USER_PRIVACY { $$ = PRIV_USER_PRIVACY ; } |
4e89d808 370+ TPRIV_LOCAL_WELCOME { $$ = PRIV_LOCAL_WELCOME; } |
371+ TPRIV_WELCOME { $$ = PRIV_WELCOME; } |
372 TPRIV_PARANOID { $$ = PRIV_PARANOID; } ;
373 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
374
f319303e 375diff -r 8c7c9ff0f0ca ircd/m_welcome.c
5632b943 376--- /dev/null
377+++ b/ircd/m_welcome.c
084779ef 378@@ -0,0 +1,292 @@
cddf800b 379+/*
380+ * IRC - Internet Relay Chat, ircd/m_welcome.c
381+ * Copyright (C) 1990 Jarkko Oikarinen and
382+ * University of Oulu, Computing Center
383+ *
384+ * See file AUTHORS in IRC package for additional names of
385+ * the programmers.
386+ *
387+ * This program is free software; you can redistribute it and/or modify
388+ * it under the terms of the GNU General Public License as published by
389+ * the Free Software Foundation; either version 1, or (at your option)
390+ * any later version.
391+ *
392+ * This program is distributed in the hope that it will be useful,
393+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
394+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
395+ * GNU General Public License for more details.
396+ *
397+ * You should have received a copy of the GNU General Public License
398+ * along with this program; if not, write to the Free Software
399+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
400+ *
cddf800b 401+ */
402+
403+/*
404+ * m_functions execute protocol messages on this server:
405+ *
406+ * cptr is always NON-NULL, pointing to a *LOCAL* client
407+ * structure (with an open socket connected!). This
408+ * identifies the physical socket where the message
409+ * originated (or which caused the m_function to be
410+ * executed--some m_functions may call others...).
411+ *
412+ * sptr is the source of the message, defined by the
413+ * prefix part of the message if present. If not
414+ * or prefix not found, then sptr==cptr.
415+ *
416+ * (!IsServer(cptr)) => (cptr == sptr), because
417+ * prefixes are taken *only* from servers...
418+ *
419+ * (IsServer(cptr))
420+ * (sptr == cptr) => the message didn't
421+ * have the prefix.
422+ *
423+ * (sptr != cptr && IsServer(sptr) means
424+ * the prefix specified servername. (?)
425+ *
426+ * (sptr != cptr && !IsServer(sptr) means
427+ * that message originated from a remote
428+ * user (not local).
429+ *
430+ * combining
431+ *
432+ * (!IsServer(sptr)) means that, sptr can safely
433+ * taken as defining the target structure of the
434+ * message in this server.
435+ *
436+ * *Always* true (if 'parse' and others are working correct):
437+ *
438+ * 1) sptr->from == cptr (note: cptr->from == cptr)
439+ *
440+ * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
441+ * *cannot* be a local connection, unless it's
442+ * actually cptr!). [MyConnect(x) should probably
443+ * be defined as (x == x->from) --msa ]
444+ *
445+ * parc number of variable parameter strings (if zero,
446+ * parv is allowed to be NULL)
447+ *
448+ * parv a NULL terminated list of parameter pointers,
449+ *
450+ * parv[0], sender (prefix string), if not present
451+ * this points to an empty string.
452+ * parv[1]...parv[parc-1]
453+ * pointers to additional parameters
454+ * parv[parc] == NULL, *always*
455+ *
456+ * note: it is guaranteed that parv[0]..parv[parc-1] are all
457+ * non-NULL pointers.
458+ */
459+#include "config.h"
460+
461+#include "channel.h"
462+#include "client.h"
463+#include "hash.h"
464+#include "ircd.h"
a87bc2c2 465+#include "ircd_features.h"
cddf800b 466+#include "ircd_log.h"
467+#include "ircd_reply.h"
5bb41778 468+#include "ircd_snprintf.h"
cddf800b 469+#include "ircd_string.h"
470+#include "msg.h"
471+#include "numeric.h"
472+#include "numnicks.h"
473+#include "s_user.h"
474+#include "send.h"
a87bc2c2 475+#include "welcome.h"
cddf800b 476+
477+/* #include <assert.h> -- Now using assert in ircd_log.h */
478+
479+/*
480+ * m_welcome - local generic message handler
481+ *
482+ * parv[0] = Send prefix
6dd3e24f 483+ * parv[1] = [remote server to query]
cddf800b 484+ */
485+int m_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
486+{
a87bc2c2 487+ /* feature disabled */
488+ if (!feature_bool(FEAT_WELCOME))
489+ return send_reply(sptr, ERR_DISABLED, "WELCOME");
6dd3e24f 490+
491+ /* only opers can set the welcome messages */
492+ if (parc > 2)
493+ return send_reply(sptr, ERR_NOPRIVILEGES);
494+
495+ /* remote listing request, see if it is for me or a remote server
496+ * check FEAT_HIS_REMOTE to decide if an ordinary user can do this
497+ */
5632b943 498+ if ((parc > 1) && (hunt_server_cmd(sptr, CMD_WELCOME, cptr, feature_int(FEAT_HIS_REMOTE),
499+ "%C", 1, parc, parv) != HUNTED_ISME))
500+ return 0;
6dd3e24f 501+
5632b943 502+ /* local listing */
a87bc2c2 503+ return welcome_list(sptr, 0);
cddf800b 504+}
505+
506+
507+/*
508+ * mo_welcome - oper message handler
509+ *
510+ * listing:
511+ * parv[0] = Send prefix
512+ *
513+ * remote listing:
514+ * parv[0] = Send prefix
515+ * parv[1] = Target
516+ *
517+ * set global or on remote server:
518+ * parv[0] = Send prefix
6dd3e24f 519+ * parv[1] = Target: server or * for global (or left out for this server)
a87bc2c2 520+ * parv[2] = Name
521+ * parv[3] = Text
cddf800b 522+ */
523+int mo_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
524+{
cb0b5df1 525+ char *target, *name, *who, *text, pattern[BUFSIZE];
a87bc2c2 526+ time_t timestamp;
527+ unsigned int flags = 0;
6dd3e24f 528+ int local = 0;
a87bc2c2 529+
530+ /* feature disabled */
531+ if (!feature_bool(FEAT_WELCOME))
532+ return send_reply(sptr, ERR_DISABLED, "WELCOME");
533+
4e89d808 534+ /* TODO: move feature check here? */
a87bc2c2 535+ /* remote listing request, see if it is for me or a remote server */
5632b943 536+ if ((parc == 2) && (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C", 1, parc, parv) != HUNTED_ISME))
537+ return 0;
538+
539+ /* local listing */
540+ if (parc <= 2)
a87bc2c2 541+ return welcome_list(sptr, 0);
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+
582+ /* check for anounce prefix */
542f45ba 583+ if (*name == '$') {
a87bc2c2 584+ name++;
084779ef 585+ /* only allow announce by oper for local welcome */
586+ if (flags & WELCOME_LOCAL)
587+ flags |= WELCOME_ANNOUNCE;
a87bc2c2 588+ }
95de96cd 589+
590+ /* check for insert prefix */
591+ if (*name == '+') {
592+ name++;
593+ flags |= WELCOME_INSERT;
594+ }
595+
a87bc2c2 596+ /* and do it */
c13e4602 597+ return welcome_do(cptr, sptr, name, timestamp, who, text, flags);
cddf800b 598+}
599+
600+
601+/*
602+ * ms_welcome - server message handler
603+ *
604+ * parv[0] = Send prefix
605+ * parv[1] = Target: server numeric or * for global
a87bc2c2 606+ * parv[2] = Name
607+ * parv[3] = Timestamp
608+ * parv[4] = Who
609+ * parv[5] = Text
cddf800b 610+ */
611+int ms_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
612+{
cb0b5df1 613+ char *target, *name, *who, *text;
a87bc2c2 614+ time_t timestamp;
615+ unsigned int flags = 0;
616+
6dd3e24f 617+ /* not enough - complain */
618+ if (parc < 2) {
619+ protocol_violation(sptr, "Too few parameters for WELCOME (got %d - need 2)", parc);
a87bc2c2 620+ return need_more_params(sptr, "WELCOME");
6dd3e24f 621+ }
a87bc2c2 622+
623+ /* remote listing request, see if it is for me or a remote server */
624+ if (parc == 2) {
d2e4469e 625+ if (IsServer(sptr))
626+ return protocol_violation(cptr, "WELCOME listing request from server %C", sptr);
6dd3e24f 627+ if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C", 1, parc, parv) != HUNTED_ISME)
628+ return 0;
629+ return welcome_list(sptr, 0);
a87bc2c2 630+ }
631+
6dd3e24f 632+ /* we need at least 6 parameters to continue - complain */
633+ if (parc < 6) {
634+ protocol_violation(sptr, "Too few parameters for WELCOME (got %d - need 6)", parc);
a87bc2c2 635+ return need_more_params(sptr, "WELCOME");
6dd3e24f 636+ }
a87bc2c2 637+
638+ /* set the parameters */
639+ target = parv[1];
640+ name = parv[2];
641+ timestamp = atoi(parv[3]);
642+ who = parv[4];
6dd3e24f 643+ text = parv[parc - 1]; /* parse reason as last parameter */
a87bc2c2 644+
645+ /* target is not global */
646+ if (!(target[0] == '*' && target[1] == '\0')) {
6dd3e24f 647+
a87bc2c2 648+ /* not for me, and forward it */
649+ if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C %s %s %s :%s", 1, parc, parv) != HUNTED_ISME)
650+ return 0;
6dd3e24f 651+
652+ /* local welcome for me */
653+ flags |= WELCOME_LOCAL;
a87bc2c2 654+ }
655+
656+ /* check for anounce prefix */
542f45ba 657+ if (*name == '$') {
a87bc2c2 658+ name++;
659+ flags |= WELCOME_ANNOUNCE;
660+ }
661+
95de96cd 662+ /* check for insert prefix */
663+ if (*name == '+') {
664+ name++;
665+ flags |= WELCOME_INSERT;
666+ }
667+
a87bc2c2 668+ /* and do it */
c13e4602 669+ return welcome_do(cptr, sptr, name, timestamp, who, text, flags);
a87bc2c2 670+}
f319303e 671diff -r 8c7c9ff0f0ca ircd/parse.c
5632b943 672--- a/ircd/parse.c
673+++ b/ircd/parse.c
f0f686d6 674@@ -661,6 +661,15 @@
675 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
676 { m_unregistered, m_not_oper, ms_check, mo_check, m_ignore }
cddf800b 677 },
678+
679+ /* add command for WELCOME */
680+ {
681+ MSG_WELCOME,
682+ TOK_WELCOME,
683+ 0, MAXPARA, MFLG_SLOW, 0, NULL,
a87bc2c2 684+ /* UNREG, CLIENT, SERVER, OPER, SERVICE, HELP */
308d3fca 685+ { m_unregistered, m_welcome, ms_welcome, mo_welcome, m_ignore }
cddf800b 686+ },
687
688 /* This command is an alias for QUIT during the unregistered part of
689 * of the server. This is because someone jumping via a broken web
f319303e 690diff -r 8c7c9ff0f0ca ircd/s_err.c
5632b943 691--- a/ircd/s_err.c
692+++ b/ircd/s_err.c
a87bc2c2 693@@ -486,7 +486,7 @@
694 /* 226 */
695 { RPL_STATSALINE, "%s", "226" },
696 /* 227 */
697- { 0 },
698+ { RPL_STATSWELCOME, "W %d %s %s %Tu :%s", "227" },
699 /* 228 */
700 { RPL_STATSQLINE, "Q %s :%s", "228" },
701 /* 229 */
702@@ -1050,7 +1050,7 @@
703 /* 508 */
704 { 0 },
705 /* 509 */
706- { 0 },
707+ { ERR_NOSUCHWELCOME, "%s :No such welcome", "509" },
708 /* 510 */
709 { 0 },
710 /* 511 */
f319303e 711diff -r 8c7c9ff0f0ca ircd/s_serv.c
5632b943 712--- a/ircd/s_serv.c
713+++ b/ircd/s_serv.c
a87bc2c2 714@@ -57,6 +57,7 @@
715 #include "struct.h"
716 #include "sys.h"
717 #include "userload.h"
718+#include "welcome.h"
719
720 /* #include <assert.h> -- Now using assert in ircd_log.h */
721 #include <stdlib.h>
722@@ -196,6 +197,7 @@
723 */
724 gline_burst(cptr);
725 jupe_burst(cptr);
726+ welcome_burst(cptr);
727
728 /*
729 * Pass on my client information to the new server
f319303e 730diff -r 8c7c9ff0f0ca ircd/s_stats.c
5632b943 731--- a/ircd/s_stats.c
732+++ b/ircd/s_stats.c
a87bc2c2 733@@ -54,6 +54,7 @@
734 #include "send.h"
735 #include "struct.h"
736 #include "userload.h"
737+#include "welcome.h"
738
739 #include <stdio.h>
740 #include <stdlib.h>
308d3fca 741@@ -654,9 +655,12 @@
a87bc2c2 742 { 'V', "vserversmach", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS), FEAT_HIS_STATS_v,
743 stats_servers_verbose, 0,
744 "Verbose server information." },
745- { 'w', "userload", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_w,
746+ { 'w', "userload", STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS, FEAT_HIS_STATS_w,
747 calc_load, 0,
748 "Userload statistics." },
749+ { 'W', "welcome", STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS, FEAT_HIS_STATS_W,
750+ welcome_stats, 0,
751+ "Welcome messages." },
752 { 'x', "memusage", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_x,
753 stats_meminfo, 0,
754 "List usage information." },
f319303e 755diff -r 8c7c9ff0f0ca ircd/s_user.c
5632b943 756--- a/ircd/s_user.c
757+++ b/ircd/s_user.c
a87bc2c2 758@@ -63,6 +63,7 @@
759 #include "userload.h"
760 #include "version.h"
761 #include "whowas.h"
762+#include "welcome.h"
763
764 #include "handlers.h" /* m_motd and m_lusers */
765
f0f686d6 766@@ -410,6 +411,9 @@
a87bc2c2 767 cli_info(sptr), NumNick(cptr) /* two %s's */);
768
769 IPcheck_connect_succeeded(sptr);
770+
771+ if (feature_bool(FEAT_WELCOME))
772+ welcome_list(sptr, 1);
773 }
774 else {
775 struct Client *acptr = user->server;
f319303e 776diff -r 8c7c9ff0f0ca ircd/welcome.c
5632b943 777--- /dev/null
778+++ b/ircd/welcome.c
edf9cf79 779@@ -0,0 +1,611 @@
cddf800b 780+/*
a87bc2c2 781+ * IRC - Internet Relay Chat, ircd/welcome.c
cddf800b 782+ * Copyright (C) 1990 Jarkko Oikarinen and
783+ * University of Oulu, Finland
784+ * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
785+ *
786+ * This program is free software; you can redistribute it and/or modify
787+ * it under the terms of the GNU General Public License as published by
788+ * the Free Software Foundation; either version 1, or (at your option)
789+ * any later version.
790+ *
791+ * This program is distributed in the hope that it will be useful,
792+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
793+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
794+ * GNU General Public License for more details.
795+ *
796+ * You should have received a copy of the GNU General Public License
797+ * along with this program; if not, write to the Free Software
798+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
799+ */
800+/** @file
a87bc2c2 801+ * @brief Implementation of welcome message handling functions.
cddf800b 802+ */
803+#include "config.h"
804+
805+#include "client.h"
806+#include "hash.h"
807+#include "ircd.h"
808+#include "ircd_alloc.h"
809+#include "ircd_features.h"
810+#include "ircd_log.h"
811+#include "ircd_reply.h"
812+#include "ircd_string.h"
813+#include "match.h"
814+#include "msg.h"
815+#include "numeric.h"
816+#include "numnicks.h"
817+#include "s_bsd.h"
a87bc2c2 818+#include "s_debug.h"
cddf800b 819+#include "s_misc.h"
820+#include "send.h"
821+#include "struct.h"
822+#include "sys.h" /* FALSE bleah */
823+#include "welcome.h"
824+
825+/* #include <assert.h> -- Now using assert in ircd_log.h */
826+#include <string.h>
827+
cddf800b 828+
cb0b5df1 829+/** List of welcome messages - first MAX for global, second MAX for local */
6dd3e24f 830+static struct Welcome WelcomeArray[WELCOME_MAX_ENTRIES * 2] = { { 0 } };
cddf800b 831+
cddf800b 832+
a87bc2c2 833+/** Allocate a new welcome with the given parameters.
834+ * @param[in] name Name of the welcome message.
835+ * @param[in] text The welcome message.
836+ * @param[in] who Who set it.
837+ * @param[in] timestamp When it was set.
cb0b5df1 838+ * @return name Array number of the welcome set.
cddf800b 839+ */
cb0b5df1 840+static int
841+welcome_make(int name, char *text, char *who, time_t timestamp)
cddf800b 842+{
d6da6cd7 843+ /* valid range */
844+ assert(WelcomeIsValid(name));
cb0b5df1 845+
846+ /* store it */
38c95254 847+ ircd_strncpy(WelcomeArray[name].text, text, WELCOMELEN);
cb0b5df1 848+ ircd_strncpy(WelcomeArray[name].who, who, ACCOUNTLEN);
849+ WelcomeArray[name].timestamp = timestamp;
850+
851+ return name;
cddf800b 852+}
853+
cddf800b 854+
c13e4602 855+/** Propagate a welcome message.
a87bc2c2 856+ * @param[in] cptr Local client that sent us the welcome.
857+ * @param[in] sptr Originator of the welcome.
c13e4602 858+ * @param[in] nameint Name of the message.
a87bc2c2 859+ * @param[in] timestamp Timestamp of when the message was set.
c13e4602 860+ * @param[in] who Who set this message.
861+ * @param[in] text The welcome message.
a87bc2c2 862+ * @param[in] flags Flags to set on welcome.
863+ * @return Zero
cddf800b 864+ */
865+int
c13e4602 866+welcome_propagate(struct Client *cptr, struct Client *sptr, int nameint,
867+ time_t timestamp, char *who, char *text, unsigned int flags)
cddf800b 868+{
536d09ac 869+ /* must be global */
c13e4602 870+ assert(!(flags & WELCOME_LOCAL));
b27ac6fc 871+ assert(NULL != sptr);
872+ assert(NULL != cptr);
6dd3e24f 873+
c13e4602 874+ sendcmdto_serv_butone(sptr, CMD_WELCOME, cptr, "* %s%s%d %Tu %s :%s",
542f45ba 875+ (flags & WELCOME_ANNOUNCE) ? "$" : "", (flags & WELCOME_INSERT) ? "+" : "",
c13e4602 876+ nameint, timestamp, who, text);
a87bc2c2 877+
c13e4602 878+ return 0;
879+}
371f9aee 880+
cddf800b 881+
b27ac6fc 882+/** Resend a welcome message.
883+ * @param[in] cptr Local client that sent us the welcome.
884+ * @param[in] nameint Name of the message.
885+ * @param[in] namearray Name of the array item.
886+ * @return Zero
887+ */
888+int
889+welcome_resend(struct Client *cptr, int nameint, int namearray)
890+{
891+ /* must be valid */
892+ assert(WelcomeIsValid(namearray));
893+ assert(NULL != cptr);
894+ assert(IsServer(cptr));
895+
896+ sendcmdto_one(&me, CMD_WELCOME, cptr, "* %d %Tu %s :%s",
897+ nameint, WelcomeTS(namearray), WelcomeWho(namearray), WelcomeText(namearray));
898+
899+ return 0;
900+}
901+
902+
469e14e1 903+/** Log a welcome message.
904+ * @param[in] sptr Originator of the welcome.
905+ * @param[in] msg The message to show.
469e14e1 906+ * @param[in] flags Flags to set on welcome.
907+ * @return Zero
908+ */
909+int
a717ac9f 910+welcome_log(struct Client *sptr, char *msg, unsigned int flags)
469e14e1 911+{
2f08b785 912+ assert(NULL != sptr);
913+ assert(NULL != msg);
469e14e1 914+
915+ /* inform ops */
916+ sendto_opmask_butone(0, SNO_OLDSNO, "%s %s",
917+ (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
918+ get_client_name_and_opername(sptr) : cli_name((cli_user(sptr))->server), msg);
919+
920+ /* log it */
a717ac9f 921+ log_write(LS_NETWORK, L_INFO, LOG_NOSNOTICE, "%s %s", get_client_name_and_opername(sptr), msg);
469e14e1 922+
923+ /* welcome by remote user, inform oper of success */
924+ if ((flags & WELCOME_LOCAL) && IsUser(sptr) && !MyUser(sptr)) {
925+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s %s",
926+ sptr, get_client_name_and_opername(sptr), msg);
927+
928+ /* TODO: wallops all local changes, by both local and remote opers? */
929+ /* tell all opers about the local message being set remotely */
930+ sendwallto_group_butone(&me, WALL_WALLOPS, 0, "%s %s", get_client_name_and_opername(sptr), msg);
931+ }
932+
933+ return 0;
934+}
935+
936+
c13e4602 937+/** Set a welcome message.
938+ * @param[in] cptr Local client that sent us the welcome.
939+ * @param[in] sptr Originator of the welcome.
940+ * @param[in] nameint Name of the message.
941+ * @param[in] namearray Array entry.
942+ * @param[in] timestamp Timestamp of when the message was set.
943+ * @param[in] who Who set this message.
944+ * @param[in] text The message.
945+ * @param[in] flags Flags to set on welcome.
946+ * @return Zero
947+ */
948+int
949+welcome_set(struct Client *cptr, struct Client *sptr, int nameint,
950+ int namearray, time_t timestamp, char *who, char *text, unsigned int flags)
951+{
536d09ac 952+ char msg[BUFSIZE]; /* msg for logging */
c13e4602 953+ int new = 0;
a87bc2c2 954+
c13e4602 955+ /* debug */
956+ Debug((DEBUG_DEBUG, "welcome_set(\"%s\", \"%s\", %d, %d, %Tu, \"%s\", \"%s\", 0x%04x)",
957+ cli_name(cptr), cli_name(sptr), nameint, namearray, timestamp, who, text, flags));
6dd3e24f 958+
c13e4602 959+ /* not set */
eabbc644 960+ if (WelcomeIsEmpty(namearray))
c13e4602 961+ new = 1;
6dd3e24f 962+
c13e4602 963+ /* update */
964+ welcome_make(namearray, text, who, timestamp);
cddf800b 965+
536d09ac 966+ /* create msg for log */
a717ac9f 967+ ircd_snprintf(0, msg, 0, "%s%s%s WELCOME %d \"%s\" %s [%Tu]",
c13e4602 968+ new ? "setting" : "changing",
969+ (flags & WELCOME_ANNOUNCE) ? " and announcing " : " ",
970+ (flags & WELCOME_LOCAL) ? "local" : "global",
6270d9ef 971+ nameint, WelcomeText(namearray), WelcomeWho(namearray), timestamp);
6dd3e24f 972+
c13e4602 973+ /* log it */
a717ac9f 974+ welcome_log(sptr, msg, flags);
cddf800b 975+
c13e4602 976+ /* propagate it */
977+ if (!(flags & WELCOME_LOCAL))
978+ welcome_propagate(cptr, sptr, nameint, timestamp, who, text, flags);
6dd3e24f 979+
c13e4602 980+ /* announce it */
981+ if (flags & WELCOME_ANNOUNCE)
982+ welcome_announce(namearray);
6dd3e24f 983+
c13e4602 984+ return 0;
985+}
6dd3e24f 986+
c13e4602 987+
988+/** Unset a welcome message.
989+ * @param[in] cptr Local client that sent us the welcome.
990+ * @param[in] sptr Originator of the welcome.
991+ * @param[in] nameint Name of the message.
992+ * @param[in] namearray Array entry.
993+ * @param[in] timestamp Timestamp of when the message was set.
994+ * @param[in] who Who set this message.
995+ * @param[in] flags Flags to set on welcome.
996+ * @return Zero
997+ */
998+int
999+welcome_unset(struct Client *cptr, struct Client *sptr, int nameint,
1000+ int namearray, time_t timestamp, char *who, unsigned int flags)
1001+{
536d09ac 1002+ char msg[BUFSIZE]; /* msg for logging */
3da53d64 1003+ int i; /* loop variable */
eabbc644 1004+ int empty = namearray; /* first empty spot in array after namearray */
3da53d64 1005+ int end = WELCOME_MAX_ENTRIES -1; /* last element to check in array */
c13e4602 1006+
1007+ /* debug */
1008+ Debug((DEBUG_DEBUG, "welcome_unset(\"%s\", \"%s\", %d, %d, %Tu, \"%s\", 0x%04x)",
1009+ cli_name(cptr), cli_name(sptr), nameint, namearray, timestamp, who, flags));
1010+
536d09ac 1011+ /* create msg for log */
a717ac9f 1012+ ircd_snprintf(0, msg, 0, "unsetting %s WELCOME %d \"%s\" %s [%Tu]",
6270d9ef 1013+ (flags & WELCOME_LOCAL) ? "local" : "global",
1014+ nameint, WelcomeText(namearray), WelcomeWho(namearray), timestamp);
a87bc2c2 1015+
1016+ /* log it */
a717ac9f 1017+ welcome_log(sptr, msg, flags);
cddf800b 1018+
6270d9ef 1019+ /* update */
1020+ welcome_make(namearray, "", who, timestamp);
1021+
c13e4602 1022+ /* propagate it, but not when inserting */
1023+ if (!(flags & (WELCOME_LOCAL|WELCOME_INSERT)))
1024+ welcome_propagate(cptr, sptr, nameint, timestamp, who, "", flags);
a87bc2c2 1025+
3da53d64 1026+ /* correct end for local offset */
1027+ if (flags & WELCOME_LOCAL)
1028+ end += WELCOME_MAX_ENTRIES;
1029+
536d09ac 1030+ /* move entries up, update timestamp */
3da53d64 1031+ for (i = namearray; i < end; i++)
6eab3e57 1032+ welcome_make(i, WelcomeText(i+1), WelcomeWho(i+1), timestamp);
3da53d64 1033+
536d09ac 1034+ /* clear last entry, update timestamp */
3da53d64 1035+ welcome_make(end, "", who, timestamp);
1036+
a87bc2c2 1037+ return 0;
cddf800b 1038+}
1039+
a87bc2c2 1040+
c13e4602 1041+/** Insert a welcome message.
95de96cd 1042+ * @param[in] cptr Local client that sent us the welcome.
1043+ * @param[in] sptr Originator of the welcome.
95de96cd 1044+ * @param[in] nameint Name of the message.
1045+ * @param[in] namearray Array entry.
95de96cd 1046+ * @param[in] timestamp Timestamp of when the message was set.
c13e4602 1047+ * @param[in] who Who set this message.
1048+ * @param[in] text The welcome message.
95de96cd 1049+ * @param[in] flags Flags to set on welcome.
1050+ * @return Zero
1051+ */
1052+int
c13e4602 1053+welcome_insert(struct Client *cptr, struct Client *sptr, int nameint,
1054+ int namearray, time_t timestamp, char *who, char *text, unsigned int flags)
95de96cd 1055+{
536d09ac 1056+ char msg[BUFSIZE]; /* msg for logging */
95de96cd 1057+ int i; /* loop variable */
eabbc644 1058+ int empty = -1; /* first empty spot in array after namearray */
95de96cd 1059+ int end = WELCOME_MAX_ENTRIES -1; /* last element to check in array */
c13e4602 1060+ int last = end; /* last welcome message to feed to welcome_unset */
95de96cd 1061+
1062+ /* debug */
c13e4602 1063+ Debug((DEBUG_DEBUG, "welcome_insert(\"%s\", \"%s\", %d, %d, %Tu, \"%s\", \"%s\", 0x%04x)",
1064+ cli_name(cptr), cli_name(sptr), nameint, namearray, timestamp, who, text, flags));
95de96cd 1065+
95de96cd 1066+ /* correct end for local offset */
1067+ if (flags & WELCOME_LOCAL)
1068+ end += WELCOME_MAX_ENTRIES;
1069+
536d09ac 1070+ /* find first empty spot */
95de96cd 1071+ for (i = namearray; i <= end; i++) {
eabbc644 1072+ if (WelcomeIsEmpty(i)) {
95de96cd 1073+ empty = i;
1074+ break;
1075+ }
1076+ }
1077+
c13e4602 1078+ /* no empty spot, need to unset last */
95de96cd 1079+ if (empty == -1) {
c13e4602 1080+ welcome_unset(cptr, sptr, end, namearray, timestamp, who, flags);
95de96cd 1081+ empty = end;
1082+ }
1083+
c13e4602 1084+ /* move entries down, update timestamp */
95de96cd 1085+ for (i = empty; i > namearray; i--)
6eab3e57 1086+ welcome_make(i, WelcomeText(i-1), WelcomeWho(i-1), timestamp);
95de96cd 1087+
1088+ /* correct empty for local offset */
1089+ if (flags & WELCOME_LOCAL)
1090+ empty -= WELCOME_MAX_ENTRIES;
1091+
536d09ac 1092+ /* create msg for log */
95de96cd 1093+ if (nameint == empty)
1094+ ircd_snprintf(0, msg, 0, "moving %s WELCOME message %d one place down",
1095+ (flags & WELCOME_LOCAL) ? "local" : "global", nameint);
1096+ else
1097+ ircd_snprintf(0, msg, 0, "moving %s WELCOME message %d %s %d one place down",
1098+ (flags & WELCOME_LOCAL) ? "local" : "global", nameint, (empty - nameint > 1) ? "to" : "and" , empty);
1099+
95de96cd 1100+ /* log it */
a717ac9f 1101+ welcome_log(sptr, msg, flags);
c13e4602 1102+
1103+ /* set it */
1104+ welcome_set(cptr, sptr, nameint, namearray, timestamp, who, text, flags);
1105+
95de96cd 1106+ return 0;
1107+}
1108+
1109+
c13e4602 1110+/** Change a welcome message.
1111+ * @param[in] cptr Local client that sent us the welcome.
1112+ * @param[in] sptr Originator of the welcome.
1113+ * @param[in] name Name of the message.
1114+ * @param[in] timestamp Timestamp of when the message was set.
1115+ * @param[in] who Who set this message.
1116+ * @param[in] text The welcome message.
1117+ * @param[in] flags Flags to set on welcome.
1118+ * @return Zero
1119+ */
1120+int
1121+welcome_do(struct Client *cptr, struct Client *sptr, char *name,
1122+ time_t timestamp, char *who, char *text, unsigned int flags)
1123+{
1124+ int nameint = atoi(name); /* transform to int */
1125+ int namearray = nameint - 1; /* used to test the array element */
d9e2917e 1126+ int max = WELCOME_MAX_ENTRIES; /* max number of entries */
c13e4602 1127+
1128+ assert(NULL != cptr);
1129+ assert(NULL != sptr);
1130+ assert(NULL != name);
1131+ assert(NULL != text);
1132+ assert(NULL != who);
1133+
1134+ /* debug */
1135+ Debug((DEBUG_DEBUG, "welcome_do(\"%s\", \"%s\", \"%s\", %Tu, \"%s\", \"%s\", 0x%04x)",
1136+ cli_name(cptr), cli_name(sptr), name, timestamp, who, text, flags));
1137+
9223cb06 1138+ /* if for some reason timestamp is 0, increase it */
1139+ if (timestamp == 0)
1140+ timestamp++;
1141+
c13e4602 1142+ /* name empty after taking off the prefixes? */
1143+ if (EmptyString(name)) {
1144+ if (IsUser(sptr))
1145+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :WELCOME: No message number given", sptr);
1146+ else
1147+ protocol_violation(cptr, "WELCOME: No message number given by %C", sptr);
1148+ return 0;
1149+ }
1150+
1151+ /* check name */
d9e2917e 1152+ if (!WelcomeIsValid(namearray)) {
c13e4602 1153+ if (IsUser(sptr))
1154+ sendcmdto_one(&me, CMD_NOTICE, sptr,
1155+ "%C :WELCOME: Invalid message number %s - should between 1 and %d",
d9e2917e 1156+ sptr, name, max);
b27ac6fc 1157+ else
1158+ protocol_violation(cptr,
1159+ "WELCOME: Invalid message number %s from %C - should be between 1 and %d",
d9e2917e 1160+ name, sptr, max);
c13e4602 1161+ return 0;
1162+ }
1163+
7f642bb5 1164+ /* source is user, and is myuser or welcome is local, check length of the message */
1165+ if ((IsUser(sptr)) && ((MyUser(sptr)) || (flags & WELCOME_LOCAL)) && (strlen(text) > WELCOMELEN)) {
1166+ sendcmdto_one(&me, CMD_NOTICE, sptr,
1167+ "%C :WELCOME: The message is too long with %d chars - max is %d chars",
1168+ sptr, strlen(text), WELCOMELEN);
1169+ ircd_strncpy(text, text, WELCOMELEN);
1170+ sendcmdto_one(&me, CMD_NOTICE, sptr,
d06a9d1f 1171+ "%C :WELCOME: Change or truncate the message to: \"%s\"", sptr, text);
7f642bb5 1172+ return 0;
1173+ }
1174+
c13e4602 1175+ /* correct namearray for local offset */
1176+ if (flags & WELCOME_LOCAL)
1177+ namearray += WELCOME_MAX_ENTRIES;
1178+
1179+ /* must be true by now */
d6da6cd7 1180+ assert(WelcomeIsValid(namearray));
c13e4602 1181+
1182+ /* cannot unset welcome that is not set */
eabbc644 1183+ if (!WelcomeIsSet(namearray) && EmptyString(text)) {
c13e4602 1184+
1185+ /* from user, throw error */
1186+ if (IsUser(sptr))
1187+ return send_reply(sptr, ERR_NOSUCHWELCOME, name);
1188+
1189+ /* new local welcome from server, but empty - ignore
1190+ * we do accept a new global welcome message that is empty
1191+ */
1192+ if (flags & WELCOME_LOCAL)
1193+ return 0;
1194+ }
1195+
1196+ /* check if there is something to change */
1197+ /* we got a record for it */
eabbc644 1198+ if (WelcomeIsSet(namearray)) {
c13e4602 1199+
1200+ /* global */
1201+ if (!(flags & WELCOME_LOCAL)) {
1202+
b27ac6fc 1203+ /* myuser changes it,
1204+ * welcomeTS greater than or equal to timestamp, take welcomeTS+1 as timestamp
1205+ * else the change is not accepted upstream because of the older TS
c13e4602 1206+ */
edf9cf79 1207+ if (MyUser(sptr)) {
1208+ if (WelcomeTS(namearray) >= timestamp)
1209+ timestamp = WelcomeTS(namearray) +1;
1210+ }
b27ac6fc 1211+
1212+ /* compare timestamps, ignore welcome when:
1213+ * we got a newer one
5fbab47d 1214+ * or when timestamps are the same and our text is 'smaller'
b27ac6fc 1215+ */
edf9cf79 1216+ else if ((timestamp < WelcomeTS(namearray)) || /* we got a newer one */
1217+ ((timestamp == WelcomeTS(namearray)) && /* same timestamp */
1218+ (ircd_strcmp(WelcomeText(namearray), text) < 0))) { /* our text is 'smaller' */
b27ac6fc 1219+ /* burst or burst ack, cptr gets our version from the burst */
1220+ if (IsBurstOrBurstAck(cptr))
1221+ return 0;
1222+ /* sync server */
1223+ return welcome_resend(cptr, nameint, namearray);
1224+ }
c13e4602 1225+
1226+ /* local welcome - we use our idea of the time */
1227+ } else
1228+ timestamp = TStime();
1229+
b27ac6fc 1230+ /* new global welcome from my user or local welcome
1231+ * compare new message with old message
1232+ */
1233+ if (IsUser(sptr) && (MyUser(sptr) || (flags & WELCOME_LOCAL))) {
1234+ if (ircd_strcmp(text, WelcomeText(namearray)) == 0) {
c13e4602 1235+ sendcmdto_one(&me, CMD_NOTICE, sptr,
b27ac6fc 1236+ "%C :WELCOME: Cannot change %s message for %s - nothing to change",
c13e4602 1237+ sptr, (flags & WELCOME_LOCAL) ? "local" : "global", name);
b27ac6fc 1238+ return 0;
1239+ }
c13e4602 1240+ }
1241+ }
1242+
4fef2533 1243+ /* do not insert for last global/local entry and when not set yet */
eabbc644 1244+ if ((flags & WELCOME_INSERT) && ((!WelcomeIsSet(namearray)) || (nameint == max)))
d9e2917e 1245+ flags &= ~WELCOME_INSERT;
4fef2533 1246+
c13e4602 1247+ /* unset */
1248+ if (EmptyString(text)) {
4fef2533 1249+ /* clear insert flag,
b34e1931 1250+ * when this flag is set, welcome_unset() assumes it is being called from welcome_insert()
4fef2533 1251+ * and wont propagate the change
1252+ */
c13e4602 1253+ flags &= ~WELCOME_INSERT;
1254+ return welcome_unset(cptr, sptr, nameint, namearray, timestamp, who, flags);
1255+ }
1256+
1257+ /* insert */
1258+ if (flags & WELCOME_INSERT)
1259+ return welcome_insert(cptr, sptr, nameint, namearray, timestamp, who, text, flags);
1260+
1261+ /* new or change */
1262+ return welcome_set(cptr, sptr, nameint, namearray, timestamp, who, text, flags);
1263+}
1264+
1265+
a87bc2c2 1266+/** Announce a welcome message to local clients.
cb0b5df1 1267+ * @param[in] name Welcome message to announce.
cddf800b 1268+ */
a87bc2c2 1269+void
cb0b5df1 1270+welcome_announce(int name)
cddf800b 1271+{
a87bc2c2 1272+ struct Client *acptr;
1273+ struct MsgBuf *msgbuf;
6dd3e24f 1274+ int i;
a87bc2c2 1275+
7205d4e6 1276+ /* valid range, set and not empty */
1277+ assert(WelcomeIsValid(name));
1278+ assert(WelcomeIsSet(name));
1279+ assert(!WelcomeIsEmpty(name));
a87bc2c2 1280+
cb0b5df1 1281+ /* TODO: target is $* as if it were a global broadcast
1282+ * could make it $servername for local message announcement
1283+ * but the type is shown between [ ] already
1284+ * either [Network] or [servername] - using $* is just shorter.
1285+ */
a87bc2c2 1286+ /* build msgbuf */
1287+ msgbuf = msgq_make(0, ":%C %s $* :[%s] %s", &me, MSG_NOTICE,
cb0b5df1 1288+ name >= WELCOME_MAX_ENTRIES ? cli_name(&me) : feature_str(FEAT_NETWORK),
6eab3e57 1289+ WelcomeText(name));
a87bc2c2 1290+
6dd3e24f 1291+ /* go over local clients */
1292+ for (i = HighestFd; i > 0; --i) {
cb0b5df1 1293+
7205d4e6 1294+ /* skip unregistered clients, skip servers */
6dd3e24f 1295+ if (!(acptr = LocalClientArray[i]) || !IsRegistered(acptr) || IsServer(acptr))
a87bc2c2 1296+ continue;
cb0b5df1 1297+
6dd3e24f 1298+ /* send it away */
a87bc2c2 1299+ send_buffer(acptr, msgbuf, 0);
cddf800b 1300+ }
cddf800b 1301+}
1302+
a87bc2c2 1303+
a87bc2c2 1304+/** Send the full list of welcome message to \a cptr.
1305+ * @param[in] cptr Local server to send welcomes to.
cddf800b 1306+ */
1307+void
a87bc2c2 1308+welcome_burst(struct Client *cptr)
cddf800b 1309+{
cb0b5df1 1310+ int name;
a87bc2c2 1311+
6dd3e24f 1312+ assert(NULL != cptr);
1313+
cb0b5df1 1314+ /* loop over global entries - 0 to max - 1*/
1315+ for (name = 0; name <= WELCOME_MAX_ENTRIES - 1; name++) {
eabbc644 1316+ if (WelcomeIsSet(name))
a87bc2c2 1317+ sendcmdto_one(&me, CMD_WELCOME, cptr, "* %d %Tu %s :%s",
6eab3e57 1318+ name + 1, WelcomeTS(name), WelcomeWho(name), WelcomeText(name));
cddf800b 1319+ }
1320+}
1321+
a87bc2c2 1322+
a87bc2c2 1323+/** List welcome messages.
1324+ * @param[in] sptr Client requesting the listing.
1325+ * @param[in] connect When non zero do not report no welcome is set
cddf800b 1326+ * @return Zero.
1327+ */
1328+int
a87bc2c2 1329+welcome_list(struct Client *sptr, int connect)
cddf800b 1330+{
cb0b5df1 1331+ int found = 0, local = 0, name;
a87bc2c2 1332+
6dd3e24f 1333+ assert(NULL != sptr);
1334+
cb0b5df1 1335+ /* loop over all entries - range 0 to 2 * max - 1 */
1336+ for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) {
a87bc2c2 1337+
cb0b5df1 1338+ /* local entries now */
1339+ if (name == WELCOME_MAX_ENTRIES)
1340+ local = 1;
a87bc2c2 1341+
cb0b5df1 1342+ /* not set or empty - skip */
eabbc644 1343+ if (!WelcomeIsSet(name) || WelcomeIsEmpty(name))
a87bc2c2 1344+ continue;
cb0b5df1 1345+
1346+ /* got one */
a87bc2c2 1347+ found++;
cb0b5df1 1348+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :[%s] %s",
6eab3e57 1349+ sptr, local ? cli_name(&me) : feature_str(FEAT_NETWORK), WelcomeText(name));
a87bc2c2 1350+ }
cb0b5df1 1351+
1352+ /* nothing set */
a87bc2c2 1353+ if (!found && !connect)
cb0b5df1 1354+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :No welcome message set.", sptr);
1355+
a87bc2c2 1356+ return 0;
1357+}
cddf800b 1358+
cddf800b 1359+
a87bc2c2 1360+/** Statistics callback to list Welcome messages.
1361+ * @param[in] sptr Client requesting statistics.
1362+ * @param[in] sd Stats descriptor for request (ignored).
1363+ * @param[in] param Extra parameter from user (ignored).
1364+ */
1365+void
1366+welcome_stats(struct Client *sptr, const struct StatDesc *sd, char *param)
1367+{
cb0b5df1 1368+ int name, local = 0;
a87bc2c2 1369+
6dd3e24f 1370+ assert(NULL != sptr);
1371+
cb0b5df1 1372+ /* loop over all entries - range 0 to 2 * max - 1*/
1373+ for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) {
cddf800b 1374+
cb0b5df1 1375+ /* local entries now */
1376+ if (name == WELCOME_MAX_ENTRIES)
1377+ local = 1;
a87bc2c2 1378+
cb0b5df1 1379+ /* not set */
eabbc644 1380+ if (!WelcomeIsSet(name))
cb0b5df1 1381+ continue;
cddf800b 1382+
cb0b5df1 1383+ /* send it */
1384+ send_reply(sptr, RPL_STATSWELCOME,
6dd3e24f 1385+ local ? name + 1 - WELCOME_MAX_ENTRIES : name + 1,
1386+ local ? cli_name(&me) : "*",
6eab3e57 1387+ WelcomeWho(name), WelcomeTS(name),
1388+ WelcomeIsEmpty(name) ? "<Empty>" : WelcomeText(name));
cddf800b 1389+ }
cddf800b 1390+}