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