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