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