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