]> jfr.im git - irc/quakenet/snircd-patchqueue.git/blob - welcome.patch
welcome: add WELCOME_UNSET flag
[irc/quakenet/snircd-patchqueue.git] / welcome.patch
1 Add welcome message functionality.
2
3 client commands:
4 user:
5 /WELCOME [<server>]
6 shows welcome messages set, same is shown on connect
7 feature HIS_REMOTE controls whether ordinary users can request a listing from a remote server
8
9 oper:
10 /WELCOME [<server>] [[$][+]<N> :<message>]
11 to view welcome messages from a remote server
12 to set a local welcome message on this server or a remote server
13 set a global welcome message (server *)
14 the $ prefix makes the server annouce the welcome message to its clients when setting
15 the + prefix moves message in N and all after that one spot down, and inserts the new message
16 in spot N, if there is no room, the last entry is deleted
17 when an entry is cleared (no text), then all entries after it are moved on place up, so all empty
18 spots are at the end
19
20 server:
21 :<source> WE <target> [[$][+]<N> <timestamp> <who> :<text>]
22 who is who set the message, the server puts in the opername when a client sets it.
23 :<N> is a number 1 to WELCOME_MAX_ENTRIES - currently set at 10 (should be more than we ever need)
24 that means there is room for 10 local and 10 global entries
25
26 STATS W/welcome (/STATS w/userload made case sensitive)
27 :server 230 nick W Name Target Who Timestamp :Message
28 :server 227 nick W 1 * opername 1233072583 :Latest news: testing this welcome patch :)
29 :server 227 nick W 2 * opername 1233072583 :
30 :server 227 nick W 1 servername opername 1233072590 :This is a test server, expect restarts.
31 :server 219 nick W :End of /STATS report
32
33 listing welcomes or on connect:
34 :server NOTICE nick :[QuakeNet] Latest news: testing this welcome patch :)
35 :server NOTICE nick :[server] This is a test server, expect restarts.
36
37 announcement is done by a notice by the local server to $* ($servername for local) with the same message
38 format as for listing welcome messages.
39 :server NOTICE $* :[QuakeNet] Latest news: testing this welcome patch :)
40 :server NOTICE $server :[server] This is a test server, expect restarts.
41
42
43 Files:
44
45 include/handlers.h
46 add m_welcome mo_welcome ms_welcome functions
47
48 include/features.h
49 ircd/features.c
50 add features FEAT_WELCOME and FEAT_HIS_STATS_W
51
52 include/msg.h
53 add MSG_WELCOME TOK_WELCOME CMD_WELCOME
54
55 ircd/parse.c
56 add welcome message functions
57
58 include/numeric.h
59 ircd/s_err.c
60 add RPL_STATSWELCOME ERR_NOSUCHWELCOME
61
62 include/welcome.h
63 ircd/welcome.c
64 ircd/m_welcome.c
65 new
66
67 ircd/Makefile.in
68 add welcome.c and m_welcome.c files
69
70 ircd/s_serv.c
71 add burst welcome message
72
73 ircd/s_stats.c
74 add /STATS W/welcome
75
76 ircd/s_user.c
77 add showing of welcome messages on connect
78
79 ircd/s_debug.c
80 add count and memusage of welcome messages
81
82 include/client.h
83 ircd/client.c
84 ircd/ircd_lexer.l
85 ircd/ircd_parser.y
86 add PRIV_LOCAL_WELCOME PRIV_WELCOME
87
88 diff -r 8bf1b05cdfe7 include/client.h
89 --- a/include/client.h
90 +++ b/include/client.h
91 @@ -142,6 +142,8 @@
92 PRIV_USER_PRIVACY, /* oper can bypass user privacy +x etc gives i.e. see real ip's */
93 PRIV_CHANNEL_PRIVACY, /* oper can bypass channel privacy i.e. can see modes on channels they are not on and channel keys */
94 PRIV_SERVERINFO, /* oper can use /get, /stats, /hash, retrieve remote information */
95 + PRIV_WELCOME, /* oper can WELCOME */
96 + PRIV_LOCAL_WELCOME, /* oper can local WELCOME */
97 PRIV_LAST_PRIV /**< number of privileges */
98 };
99
100 diff -r 8bf1b05cdfe7 include/handlers.h
101 --- a/include/handlers.h
102 +++ b/include/handlers.h
103 @@ -138,6 +138,7 @@
104 extern int m_version(struct Client*, struct Client*, int, char*[]);
105 extern int m_wallchops(struct Client*, struct Client*, int, char*[]);
106 extern int m_wallvoices(struct Client*, struct Client*, int, char*[]);
107 +extern int m_welcome(struct Client*, struct Client*, int, char*[]);
108 extern int m_who(struct Client*, struct Client*, int, char*[]);
109 extern int m_whois(struct Client*, struct Client*, int, char*[]);
110 extern int m_whowas(struct Client*, struct Client*, int, char*[]);
111 @@ -172,6 +173,7 @@
112 extern int mo_version(struct Client*, struct Client*, int, char*[]);
113 extern int mo_wallops(struct Client*, struct Client*, int, char*[]);
114 extern int mo_wallusers(struct Client*, struct Client*, int, char*[]);
115 +extern int mo_welcome(struct Client*, struct Client*, int, char*[]);
116 extern int mo_xquery(struct Client*, struct Client*, int, char*[]);
117 extern int mr_error(struct Client*, struct Client*, int, char*[]);
118 extern int mr_error(struct Client*, struct Client*, int, char*[]);
119 @@ -230,6 +232,7 @@
120 extern int ms_wallops(struct Client*, struct Client*, int, char*[]);
121 extern int ms_wallusers(struct Client*, struct Client*, int, char*[]);
122 extern int ms_wallvoices(struct Client*, struct Client*, int, char*[]);
123 +extern int ms_welcome(struct Client*, struct Client*, int, char*[]);
124 extern int ms_whois(struct Client*, struct Client*, int, char*[]);
125 extern int ms_xquery(struct Client*, struct Client*, int, char*[]);
126 extern int ms_xreply(struct Client*, struct Client*, int, char*[]);
127 diff -r 8bf1b05cdfe7 include/ircd_features.h
128 --- a/include/ircd_features.h
129 +++ b/include/ircd_features.h
130 @@ -101,6 +101,7 @@
131 FEAT_IRCD_RES_TIMEOUT,
132 FEAT_AUTH_TIMEOUT,
133 FEAT_ANNOUNCE_INVITES,
134 + FEAT_WELCOME,
135
136 /* features that affect all operators */
137 FEAT_EXTENDED_CHECKCMD,
138 @@ -142,6 +143,7 @@
139 FEAT_HIS_STATS_u,
140 FEAT_HIS_STATS_U,
141 FEAT_HIS_STATS_v,
142 + FEAT_HIS_STATS_W,
143 FEAT_HIS_STATS_w,
144 FEAT_HIS_STATS_x,
145 FEAT_HIS_STATS_y,
146 diff -r 8bf1b05cdfe7 include/msg.h
147 --- a/include/msg.h
148 +++ b/include/msg.h
149 @@ -196,6 +196,10 @@
150 #define TOK_NOTICE "O"
151 #define CMD_NOTICE MSG_NOTICE, TOK_NOTICE
152
153 +#define MSG_WELCOME "WELCOME" /* WELC */
154 +#define TOK_WELCOME "WE"
155 +#define CMD_WELCOME MSG_WELCOME, TOK_WELCOME
156 +
157 #define MSG_WALLCHOPS "WALLCHOPS" /* WC */
158 #define TOK_WALLCHOPS "WC"
159 #define CMD_WALLCHOPS MSG_WALLCHOPS, TOK_WALLCHOPS
160 diff -r 8bf1b05cdfe7 include/numeric.h
161 --- a/include/numeric.h
162 +++ b/include/numeric.h
163 @@ -116,6 +116,7 @@
164 RPL_STATSGLINE 227 Dalnet
165 RPL_STATSVLINE 227 unreal */
166 #define RPL_STATSALINE 226 /* Hybrid, Undernet */
167 +#define RPL_STATSWELCOME 227 /* QuakeNet extension */
168 #define RPL_STATSQLINE 228 /* Undernet extension */
169
170 /* RPL_SERVICEINFO 231 unused */
171 @@ -440,6 +441,8 @@
172 /* ERR_GHOSTEDCLIENT 503 efnet */
173 /* ERR_VWORLDWARN 503 austnet */
174
175 +#define ERR_NOSUCHWELCOME 509 /* QuakeNet extension */
176 +
177 #define ERR_SILELISTFULL 511 /* Undernet extension */
178 /* ERR_NOTIFYFULL 512 aircd */
179 /* ERR_TOOMANYWATCH 512 Numeric List: Dalnet */
180 diff -r 8bf1b05cdfe7 include/welcome.h
181 --- /dev/null
182 +++ b/include/welcome.h
183 @@ -0,0 +1,80 @@
184 +#ifndef INCLUDED_welcome_h
185 +#define INCLUDED_welcome_h
186 +/*
187 + * IRC - Internet Relay Chat, include/welcome.h
188 + * Copyright (C) 1990 Jarkko Oikarinen and
189 + * University of Oulu, Computing Center
190 + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
191 + *
192 + * This program is free software; you can redistribute it and/or modify
193 + * it under the terms of the GNU General Public License as published by
194 + * the Free Software Foundation; either version 2, or (at your option)
195 + * any later version.
196 + *
197 + * This program is distributed in the hope that it will be useful,
198 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
199 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
200 + * GNU General Public License for more details.
201 + *
202 + * You should have received a copy of the GNU General Public License
203 + * along with this program; if not, write to the Free Software
204 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
205 + */
206 +/** @file
207 + * @brief Interface and declarations for welcome message handling.
208 + */
209 +
210 +struct Client;
211 +struct StatDesc;
212 +
213 +/* Maximum number of welcome entries (per type; X global, X local) */
214 +#define WELCOME_MAX_ENTRIES 10
215 +/* Maximum length of a welcome message */
216 +#define WELCOMELEN TOPICLEN
217 +
218 +
219 +/* Test if a welcome entry is in a valid range */
220 +#define WelcomeArrayIsValid(x) ((unsigned) (x) <= 2 * WELCOME_MAX_ENTRIES -1)
221 +/* Test if a welcome name is in a valid range */
222 +#define WelcomeNameIsValid(x) ((unsigned) (x) <= WELCOME_MAX_ENTRIES)
223 +/* Test if a welcome entry is set */
224 +#define WelcomeIsSet(x) (WelcomeArray[(x)].lastmod > 0)
225 +/* Test if a welcome entry is empty */
226 +#define WelcomeIsEmpty(x) (*WelcomeArray[(x)].text == 0)
227 +
228 +/* Get welcome create timestamp */
229 +#define WelcomeCreate(x) (WelcomeArray[(x)].create)
230 +/* Get welcome lastmod timestamp */
231 +#define WelcomeLastMod(x) (WelcomeArray[(x)].lastmod)
232 +/* Get welcome who info */
233 +#define WelcomeWho(x) (WelcomeArray[(x)].who)
234 +/* Get welcome text */
235 +#define WelcomeText(x) (WelcomeArray[(x)].text)
236 +
237 +
238 +/* Describes a Welcome message entry. */
239 +struct Welcome {
240 + time_t create; /**< When it was set */
241 + time_t lastmod; /**< Last modification timestamp (used for resolving conflicts in burst) */
242 + char text[WELCOMELEN + 1]; /**< Message */
243 + char who[ACCOUNTLEN + 1]; /**< Who set it */
244 +};
245 +
246 +/** Welcome type flags */
247 +#define WELCOME_LOCAL 0x01 /**< welcome is local */
248 +/** Welcome action flags */
249 +#define WELCOME_ANNOUNCE 0x02 /**< announce new welcome to users */
250 +#define WELCOME_UNSET 0x04 /**< unset welcome */
251 +#define WELCOME_INSERT 0x08 /**< insert welcome message, move down all others one place */
252 +#define WELCOME_DELETE 0x10 /**< delete welcome message, move up all others one place */
253 +#define WELCOME_INCLASTMOD 0x20 /**< increase lastmod if needed */
254 +#define WELCOME_FORCE 0x40 /**< force change, bypass lastmod check */
255 +
256 +extern int welcome_do(struct Client *cptr, struct Client *sptr, char *name,
257 + time_t create, time_t lastmod, char *who, char *text, unsigned int flags);
258 +extern void welcome_burst(struct Client *cptr);
259 +extern int welcome_list(struct Client *sptr, int connect);
260 +extern void welcome_stats(struct Client *sptr, const struct StatDesc *sd, char *param);
261 +extern int welcome_memory_count(size_t *we_size);
262 +
263 +#endif /* INCLUDED_welcome_h */
264 diff -r 8bf1b05cdfe7 ircd/Makefile.in
265 --- a/ircd/Makefile.in
266 +++ b/ircd/Makefile.in
267 @@ -186,6 +186,7 @@
268 m_wallops.c \
269 m_wallusers.c \
270 m_wallvoices.c \
271 + m_welcome.c \
272 m_who.c \
273 m_whois.c \
274 m_whowas.c \
275 @@ -215,6 +216,7 @@
276 send.c \
277 uping.c \
278 userload.c \
279 + welcome.c \
280 whocmds.c \
281 whowas.c \
282 y.tab.c
283 @@ -1161,6 +1163,11 @@
284 ../include/ircd_reply.h ../include/ircd_string.h \
285 ../include/ircd_chattr.h ../include/msg.h ../include/numeric.h \
286 ../include/numnicks.h ../include/s_user.h ../include/send.h
287 +m_welcome.o: m_welcome.c ../config.h ../include/channel.h \
288 + ../include/client.h ../include/hash.h ../include/ircd.h ../include/ircd_log.h \
289 + ../include/ircd_reply.h ../include/ircd_string.h ../include/msg.h \
290 + ../include/numeric.h ../include/numnicks.h ../include/s_user.h \
291 + ../include/send.h ../include/welcome.h
292 m_who.o: m_who.c ../config.h ../include/channel.h ../include/ircd_defs.h \
293 ../include/res.h ../config.h ../include/client.h ../include/dbuf.h \
294 ../include/msgq.h ../include/ircd_events.h ../include/ircd_handler.h \
295 @@ -1422,6 +1429,13 @@
296 ../include/numnicks.h ../include/querycmds.h ../include/ircd_features.h \
297 ../include/s_misc.h ../include/s_stats.h ../include/send.h \
298 ../include/struct.h ../include/sys.h
299 +welcome.o: welcome.c ../config.h ../include/client.h \
300 + ../include/hash.h ../include/ircd.h ../include/ircd_alloc.h \
301 + ../include/ircd_features.h ../include/ircd_log.h ../include/ircd_reply.h \
302 + ../include/match.h ../include/msg.h ../include/numeric.h \
303 + ../include/numnicks.h ../include/s_debug.h ../include/s_bsd.h \
304 + ../include/s_misc.h ../include/send.h ../include/struct.h \
305 + ../include/sys.h ../include/welcome.h
306 whocmds.o: whocmds.c ../config.h ../include/whocmds.h \
307 ../include/channel.h ../include/ircd_defs.h ../include/res.h \
308 ../config.h ../include/client.h ../include/dbuf.h ../include/msgq.h \
309 diff -r 8bf1b05cdfe7 ircd/client.c
310 --- a/ircd/client.c
311 +++ b/ircd/client.c
312 @@ -177,6 +177,7 @@
313 FlagSet(&privs_local, PRIV_WHOX);
314 FlagSet(&privs_local, PRIV_DISPLAY);
315 FlagSet(&privs_local, PRIV_FORCE_LOCAL_OPMODE);
316 + FlagSet(&privs_local, PRIV_LOCAL_WELCOME);
317
318 privs_defaults_set = 1;
319 }
320 @@ -223,6 +224,7 @@
321 ClrPriv(client, PRIV_JUPE);
322 ClrPriv(client, PRIV_OPMODE);
323 ClrPriv(client, PRIV_BADCHAN);
324 + ClrPriv(client, PRIV_WELCOME);
325 }
326 }
327
328 @@ -244,7 +246,7 @@
329 P(CHANSERV), P(XTRA_OPER), P(NOIDLE), P(FREEFORM),
330 P(PARANOID), P(CHECK), P(WALL), P(CLOSE),
331 P(ROUTE), P(ROUTEINFO), P(SERVERINFO), P(CHANNEL_PRIVACY),
332 - P(USER_PRIVACY),
333 + P(USER_PRIVACY), P(WELCOME), P(LOCAL_WELCOME),
334 #undef P
335 { 0, 0 }
336 };
337 diff -r 8bf1b05cdfe7 ircd/ircd_features.c
338 --- a/ircd/ircd_features.c
339 +++ b/ircd/ircd_features.c
340 @@ -366,6 +366,7 @@
341 F_I(IRCD_RES_TIMEOUT, 0, 4, 0),
342 F_I(AUTH_TIMEOUT, 0, 9, 0),
343 F_B(ANNOUNCE_INVITES, 0, 0, 0),
344 + F_B(WELCOME, 0, 1, 0),
345
346 /* features that affect all operators */
347 F_B(EXTENDED_CHECKCMD, 0, 0, 0),
348 @@ -407,6 +408,7 @@
349 F_B(HIS_STATS_u, 0, 1, 0),
350 F_B(HIS_STATS_U, 0, 1, 0),
351 F_B(HIS_STATS_v, 0, 1, 0),
352 + F_B(HIS_STATS_W, 0, 1, 0),
353 F_B(HIS_STATS_w, 0, 1, 0),
354 F_B(HIS_STATS_x, 0, 1, 0),
355 F_B(HIS_STATS_y, 0, 1, 0),
356 diff -r 8bf1b05cdfe7 ircd/ircd_lexer.l
357 --- a/ircd/ircd_lexer.l
358 +++ b/ircd/ircd_lexer.l
359 @@ -166,6 +166,8 @@
360 { "serverinfo", TPRIV_SERVERINFO },
361 { "user_privacy", TPRIV_USER_PRIVACY },
362 { "channel_privacy", TPRIV_CHANNEL_PRIVACY },
363 + { "local_welcome", TPRIV_LOCAL_WELCOME },
364 + { "welcome", TPRIV_WELCOME },
365 { NULL, 0 }
366 };
367 static int ntokens;
368 diff -r 8bf1b05cdfe7 ircd/ircd_parser.y
369 --- a/ircd/ircd_parser.y
370 +++ b/ircd/ircd_parser.y
371 @@ -189,6 +189,7 @@
372 %token TPRIV_CHANSERV TPRIV_XTRA_OPER TPRIV_NOIDLE TPRIV_FREEFORM TPRIV_PARANOID
373 %token TPRIV_CHECK TPRIV_WALL TPRIV_CLOSE TPRIV_ROUTE TPRIV_ROUTEINFO TPRIV_SERVERINFO
374 %token TPRIV_CHANNEL_PRIVACY TPRIV_USER_PRIVACY TPRIV_LIST_CHAN
375 +%token TPRIV_LOCAL_WELCOME TPRIV_WELCOME
376 /* and some types... */
377 %type <num> sizespec
378 %type <num> timespec timefactor factoredtimes factoredtime
379 @@ -703,6 +704,8 @@
380 TPRIV_SERVERINFO { $$ = PRIV_SERVERINFO ; } |
381 TPRIV_CHANNEL_PRIVACY { $$ = PRIV_CHANNEL_PRIVACY ; } |
382 TPRIV_USER_PRIVACY { $$ = PRIV_USER_PRIVACY ; } |
383 + TPRIV_LOCAL_WELCOME { $$ = PRIV_LOCAL_WELCOME; } |
384 + TPRIV_WELCOME { $$ = PRIV_WELCOME; } |
385 TPRIV_PARANOID { $$ = PRIV_PARANOID; } ;
386 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
387
388 diff -r 8bf1b05cdfe7 ircd/m_welcome.c
389 --- /dev/null
390 +++ b/ircd/m_welcome.c
391 @@ -0,0 +1,352 @@
392 +/*
393 + * IRC - Internet Relay Chat, ircd/m_welcome.c
394 + * Copyright (C) 1990 Jarkko Oikarinen and
395 + * University of Oulu, Computing Center
396 + *
397 + * See file AUTHORS in IRC package for additional names of
398 + * the programmers.
399 + *
400 + * This program is free software; you can redistribute it and/or modify
401 + * it under the terms of the GNU General Public License as published by
402 + * the Free Software Foundation; either version 1, or (at your option)
403 + * any later version.
404 + *
405 + * This program is distributed in the hope that it will be useful,
406 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
407 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
408 + * GNU General Public License for more details.
409 + *
410 + * You should have received a copy of the GNU General Public License
411 + * along with this program; if not, write to the Free Software
412 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
413 + *
414 + */
415 +
416 +/*
417 + * m_functions execute protocol messages on this server:
418 + *
419 + * cptr is always NON-NULL, pointing to a *LOCAL* client
420 + * structure (with an open socket connected!). This
421 + * identifies the physical socket where the message
422 + * originated (or which caused the m_function to be
423 + * executed--some m_functions may call others...).
424 + *
425 + * sptr is the source of the message, defined by the
426 + * prefix part of the message if present. If not
427 + * or prefix not found, then sptr==cptr.
428 + *
429 + * (!IsServer(cptr)) => (cptr == sptr), because
430 + * prefixes are taken *only* from servers...
431 + *
432 + * (IsServer(cptr))
433 + * (sptr == cptr) => the message didn't
434 + * have the prefix.
435 + *
436 + * (sptr != cptr && IsServer(sptr) means
437 + * the prefix specified servername. (?)
438 + *
439 + * (sptr != cptr && !IsServer(sptr) means
440 + * that message originated from a remote
441 + * user (not local).
442 + *
443 + * combining
444 + *
445 + * (!IsServer(sptr)) means that, sptr can safely
446 + * taken as defining the target structure of the
447 + * message in this server.
448 + *
449 + * *Always* true (if 'parse' and others are working correct):
450 + *
451 + * 1) sptr->from == cptr (note: cptr->from == cptr)
452 + *
453 + * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
454 + * *cannot* be a local connection, unless it's
455 + * actually cptr!). [MyConnect(x) should probably
456 + * be defined as (x == x->from) --msa ]
457 + *
458 + * parc number of variable parameter strings (if zero,
459 + * parv is allowed to be NULL)
460 + *
461 + * parv a NULL terminated list of parameter pointers,
462 + *
463 + * parv[0], sender (prefix string), if not present
464 + * this points to an empty string.
465 + * parv[1]...parv[parc-1]
466 + * pointers to additional parameters
467 + * parv[parc] == NULL, *always*
468 + *
469 + * note: it is guaranteed that parv[0]..parv[parc-1] are all
470 + * non-NULL pointers.
471 + */
472 +
473 +#include "client.h"
474 +#include "ircd.h"
475 +#include "ircd_features.h"
476 +#include "msg.h"
477 +#include "numeric.h"
478 +#include "s_user.h"
479 +#include "welcome.h"
480 +
481 +
482 +/*
483 + * m_welcome - local generic message handler
484 + *
485 + *
486 + * WELCOME
487 + *
488 + * listing:
489 + * parv[0] = Send prefix
490 + *
491 + *
492 + * WELCOME [<server>]
493 + *
494 + * remote listing:
495 + * parv[0] = Send prefix
496 + * parv[1] = Target
497 + *
498 + */
499 +int m_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
500 +{
501 + /* feature disabled */
502 + if (!feature_bool(FEAT_WELCOME))
503 + return send_reply(sptr, ERR_DISABLED, "WELCOME");
504 +
505 + /* only opers can set the welcome messages */
506 + if (parc > 2)
507 + return send_reply(sptr, ERR_NOPRIVILEGES);
508 +
509 + /* remote listing request, see if it is for me or a remote server
510 + * check FEAT_HIS_REMOTE to decide if an ordinary user can do this
511 + */
512 + if ((parc > 1) && (hunt_server_cmd(sptr, CMD_WELCOME, cptr, feature_int(FEAT_HIS_REMOTE),
513 + "%C", 1, parc, parv) != HUNTED_ISME))
514 + return 0;
515 +
516 + /* local listing */
517 + return welcome_list(sptr, 0);
518 +}
519 +
520 +
521 +/*
522 + * mo_welcome - oper message handler
523 + *
524 + *
525 + * WELCOME
526 + *
527 + * listing:
528 + * parv[0] = Send prefix
529 + *
530 + *
531 + * WELCOME <server>
532 + *
533 + * remote listing:
534 + * parv[0] = Send prefix
535 + * parv[1] = Target
536 + *
537 + *
538 + * WELCOME <server> <name> :<text>
539 + *
540 + * set global or on remote server:
541 + * parv[0] = Send prefix
542 + * parv[1] = Target: server or * for global (or left out for this server)
543 + * parv[2] = Name
544 + * parv[3] = Text
545 + *
546 + */
547 +int mo_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
548 +{
549 + char *target, *name, *who, *text, pattern[BUFSIZE];
550 + time_t create, lastmod;
551 + unsigned int flags = 0;
552 + int local = 0;
553 +
554 + /* feature disabled */
555 + if (!feature_bool(FEAT_WELCOME))
556 + return send_reply(sptr, ERR_DISABLED, "WELCOME");
557 +
558 + /* TODO: move feature check here? */
559 + /* remote listing request, see if it is for me or a remote server */
560 + if ((parc == 2) && (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C", 1, parc, parv) != HUNTED_ISME))
561 + return 0;
562 +
563 + /* local listing */
564 + if (parc <= 2)
565 + return welcome_list(sptr, 0);
566 +
567 + /* check PRIVS */
568 + /* local - need PRIV LOCAL_WELCOME or WELCOME */
569 + if (parc == 3 && !HasPriv(sptr,PRIV_LOCAL_WELCOME) && !HasPriv(sptr,PRIV_WELCOME))
570 + return send_reply(sptr, ERR_NOPRIVILEGES);
571 +
572 + /* global or remote - need PRIV WELCOME */
573 + if (parc >= 4 && !HasPriv(sptr,PRIV_WELCOME))
574 + return send_reply(sptr, ERR_NOPRIVILEGES);
575 +
576 + /* set the parameters */
577 +
578 + /* target not given, only name - setting local welcome */
579 + if (parc < 4) {
580 + local++;
581 + target = cli_name(&me);
582 + name = parv[1];
583 + flags |= WELCOME_LOCAL;
584 +
585 + /* target and name given */
586 + } else {
587 + target = parv[1];
588 + name = parv[2];
589 + }
590 + create = TStime();
591 + lastmod = TStime();
592 + who = cli_user(sptr)->opername;
593 + text = parv[parc - 1];
594 +
595 + /* target is not global */
596 + if (!(target[0] == '*' && target[1] == '\0') && !local) {
597 +
598 + /* build a pattern for hunt_server_cmd since we do not have all we need in parv */
599 + ircd_snprintf(0, pattern, sizeof(pattern), "%s %s %Tu %Tu %s :%s", "%C", name, create, lastmod, who, text);
600 + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, pattern, 1, 2, parv) != HUNTED_ISME)
601 + return 0;
602 +
603 + /* else it is a local welcome, for me */
604 + flags |= WELCOME_LOCAL;
605 + }
606 +
607 + /* check for anounce prefix */
608 + if (*name == '$') {
609 + name++;
610 + /* only allow announce by oper for local welcome */
611 + if (flags & WELCOME_LOCAL)
612 + flags |= WELCOME_ANNOUNCE;
613 + }
614 +
615 + /* check for force prefix */
616 + if (*name == '!') {
617 + name++;
618 + flags |= WELCOME_FORCE;
619 + }
620 +
621 + /* check for insert prefix */
622 + if (*name == '+') {
623 + name++;
624 + flags |= WELCOME_INSERT;
625 + }
626 +
627 + /* check for delete prefix */
628 + else if (*name == '-') {
629 + name++;
630 + flags |= WELCOME_DELETE;
631 + }
632 +
633 + /* empty text, set unset and delete flag */
634 + if (*text == 0) {
635 + flags |= WELCOME_UNSET;
636 + flags |= WELCOME_DELETE;
637 + }
638 +
639 + /* and do it */
640 + return welcome_do(cptr, sptr, name, create, lastmod, who, text, flags);
641 +}
642 +
643 +
644 +/*
645 + * ms_welcome - server message handler
646 + *
647 + *
648 + * <source> WE <target>
649 + *
650 + * remote listing:
651 + * parv[0] = Send prefix
652 + * parv[1] = Target: server numeric or * for global
653 + *
654 + *
655 + * <source> WE <target> <name> <create> <lastmod> <who> :<text>
656 + *
657 + * set global or on remote server:
658 + * parv[0] = Send prefix
659 + * parv[1] = Target: server numeric or * for global
660 + * parv[2] = Name
661 + * parv[3] = Create
662 + * parv[4] = LastMod
663 + * parv[5] = Who
664 + * parv[6] = Text
665 + *
666 + */
667 +int ms_welcome(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
668 +{
669 + char *target, *name, *who, *text;
670 + time_t create, lastmod;
671 + unsigned int flags = 0;
672 +
673 + /* not enough - complain */
674 + if (parc < 2) {
675 + protocol_violation(cptr, "Received too few parameters for WELCOME from %C (got %d - need 2)", sptr, parc);
676 + return need_more_params(sptr, "WELCOME");
677 + }
678 +
679 + /* remote listing request, see if it is for me or a remote server */
680 + if (parc == 2) {
681 + if (IsServer(sptr))
682 + return protocol_violation(cptr, "Received WELCOME listing request from server %C", sptr);
683 + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C", 1, parc, parv) != HUNTED_ISME)
684 + return 0;
685 + return welcome_list(sptr, 0);
686 + }
687 +
688 + /* we need at least 7 parameters to continue - complain */
689 + if (parc < 7) {
690 + protocol_violation(cptr, "Received too few parameters for WELCOME from %C (got %d - need 7)", sptr, parc);
691 + return need_more_params(sptr, "WELCOME");
692 + }
693 +
694 + /* set the parameters */
695 + target = parv[1];
696 + name = parv[2];
697 + create = atoi(parv[3]);
698 + lastmod = atoi(parv[4]);
699 + who = parv[5];
700 + text = parv[parc - 1]; /* parse reason as last parameter */
701 +
702 + /* target is not global */
703 + if (!(target[0] == '*' && target[1] == '\0')) {
704 +
705 + /* not for me, and forward it */
706 + if (hunt_server_cmd(sptr, CMD_WELCOME, cptr, 0, "%C %s %s %s %s :%s", 1, parc, parv) != HUNTED_ISME)
707 + return 0;
708 +
709 + /* local welcome for me */
710 + flags |= WELCOME_LOCAL;
711 + }
712 +
713 + /* check for anounce prefix */
714 + if (*name == '$') {
715 + name++;
716 + flags |= WELCOME_ANNOUNCE;
717 + }
718 +
719 + /* check for force prefix */
720 + if (*name == '!') {
721 + name++;
722 + flags |= WELCOME_FORCE;
723 + }
724 +
725 + /* check for insert prefix */
726 + if (*name == '+') {
727 + name++;
728 + flags |= WELCOME_INSERT;
729 + }
730 +
731 + /* check for delete prefix */
732 + else if (*name == '-') {
733 + name++;
734 + flags |= WELCOME_DELETE;
735 + }
736 +
737 + /* empty text, set unset flag */
738 + if (*text == 0)
739 + flags |= WELCOME_UNSET;
740 +
741 + /* and do it */
742 + return welcome_do(cptr, sptr, name, create, lastmod, who, text, flags);
743 +}
744 diff -r 8bf1b05cdfe7 ircd/parse.c
745 --- a/ircd/parse.c
746 +++ b/ircd/parse.c
747 @@ -661,6 +661,15 @@
748 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
749 { m_unregistered, m_not_oper, ms_check, mo_check, m_ignore }
750 },
751 +
752 + /* add command for WELCOME */
753 + {
754 + MSG_WELCOME,
755 + TOK_WELCOME,
756 + 0, MAXPARA, MFLG_SLOW, 0, NULL,
757 + /* UNREG, CLIENT, SERVER, OPER, SERVICE, HELP */
758 + { m_unregistered, m_welcome, ms_welcome, mo_welcome, m_ignore }
759 + },
760
761 /* This command is an alias for QUIT during the unregistered part of
762 * of the server. This is because someone jumping via a broken web
763 diff -r 8bf1b05cdfe7 ircd/s_debug.c
764 --- a/ircd/s_debug.c
765 +++ b/ircd/s_debug.c
766 @@ -50,6 +50,7 @@
767 #include "send.h"
768 #include "struct.h"
769 #include "sys.h"
770 +#include "welcome.h"
771 #include "whowas.h"
772
773 /* #include <assert.h> -- Now using assert in ircd_log.h */
774 @@ -231,7 +232,8 @@
775 aw = 0, /* aways set */
776 wwa = 0, /* whowas aways */
777 gl = 0, /* glines */
778 - ju = 0; /* jupes */
779 + ju = 0, /* jupes */
780 + we = 0; /* welcomes */
781
782 size_t chm = 0, /* memory used by channels */
783 chbm = 0, /* memory used by channel bans */
784 @@ -244,6 +246,7 @@
785 wwm = 0, /* whowas array memory used */
786 glm = 0, /* memory used by glines */
787 jum = 0, /* memory used by jupes */
788 + wem = 0, /* memory used by welcomes */
789 com = 0, /* memory used by conf lines */
790 dbufs_allocated = 0, /* memory used by dbufs */
791 dbufs_used = 0, /* memory used by dbufs */
792 @@ -351,6 +354,10 @@
793 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
794 ":Glines %d(%zu) Jupes %d(%zu)", gl, glm, ju, jum);
795
796 + we = welcome_memory_count(&wem);
797 + send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
798 + ":Welcomes %d(%zu)", we, wem);
799 +
800 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
801 ":Hash: client %d(%zu), chan is the same", HASHSIZE,
802 sizeof(void *) * HASHSIZE);
803 diff -r 8bf1b05cdfe7 ircd/s_err.c
804 --- a/ircd/s_err.c
805 +++ b/ircd/s_err.c
806 @@ -486,7 +486,7 @@
807 /* 226 */
808 { RPL_STATSALINE, "%s", "226" },
809 /* 227 */
810 - { 0 },
811 + { RPL_STATSWELCOME, "W %d %s %s %Tu %Tu :%s", "227" },
812 /* 228 */
813 { RPL_STATSQLINE, "Q %s :%s", "228" },
814 /* 229 */
815 @@ -1050,7 +1050,7 @@
816 /* 508 */
817 { 0 },
818 /* 509 */
819 - { 0 },
820 + { ERR_NOSUCHWELCOME, "%s :No such welcome", "509" },
821 /* 510 */
822 { 0 },
823 /* 511 */
824 diff -r 8bf1b05cdfe7 ircd/s_serv.c
825 --- a/ircd/s_serv.c
826 +++ b/ircd/s_serv.c
827 @@ -57,6 +57,7 @@
828 #include "struct.h"
829 #include "sys.h"
830 #include "userload.h"
831 +#include "welcome.h"
832
833 /* #include <assert.h> -- Now using assert in ircd_log.h */
834 #include <stdlib.h>
835 @@ -196,6 +197,7 @@
836 */
837 gline_burst(cptr);
838 jupe_burst(cptr);
839 + welcome_burst(cptr);
840
841 /*
842 * Pass on my client information to the new server
843 diff -r 8bf1b05cdfe7 ircd/s_stats.c
844 --- a/ircd/s_stats.c
845 +++ b/ircd/s_stats.c
846 @@ -54,6 +54,7 @@
847 #include "send.h"
848 #include "struct.h"
849 #include "userload.h"
850 +#include "welcome.h"
851
852 #include <stdio.h>
853 #include <stdlib.h>
854 @@ -650,9 +651,12 @@
855 { 'V', "vserversmach", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS), FEAT_HIS_STATS_v,
856 stats_servers_verbose, 0,
857 "Verbose server information." },
858 - { 'w', "userload", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_w,
859 + { 'w', "userload", STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS, FEAT_HIS_STATS_w,
860 calc_load, 0,
861 "Userload statistics." },
862 + { 'W', "welcome", STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS, FEAT_HIS_STATS_W,
863 + welcome_stats, 0,
864 + "Welcome messages." },
865 { 'x', "memusage", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_x,
866 stats_meminfo, 0,
867 "List usage information." },
868 diff -r 8bf1b05cdfe7 ircd/s_user.c
869 --- a/ircd/s_user.c
870 +++ b/ircd/s_user.c
871 @@ -63,6 +63,7 @@
872 #include "userload.h"
873 #include "version.h"
874 #include "whowas.h"
875 +#include "welcome.h"
876
877 #include "handlers.h" /* m_motd and m_lusers */
878
879 @@ -402,6 +403,10 @@
880
881 IPcheck_connect_succeeded(sptr);
882
883 + /* send welcome */
884 + if (feature_bool(FEAT_WELCOME))
885 + welcome_list(sptr, 1);
886 +
887 /* TODO: */
888 /* apply auto sethost if needed */
889 apply_spoofblock(sptr);
890 diff -r 8bf1b05cdfe7 ircd/welcome.c
891 --- /dev/null
892 +++ b/ircd/welcome.c
893 @@ -0,0 +1,862 @@
894 +/*
895 + * IRC - Internet Relay Chat, ircd/welcome.c
896 + * Copyright (C) 1990 Jarkko Oikarinen and
897 + * University of Oulu, Finland
898 + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
899 + *
900 + * This program is free software; you can redistribute it and/or modify
901 + * it under the terms of the GNU General Public License as published by
902 + * the Free Software Foundation; either version 1, or (at your option)
903 + * any later version.
904 + *
905 + * This program is distributed in the hope that it will be useful,
906 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
907 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
908 + * GNU General Public License for more details.
909 + *
910 + * You should have received a copy of the GNU General Public License
911 + * along with this program; if not, write to the Free Software
912 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
913 + */
914 +/** @file
915 + * @brief Implementation of welcome message handling functions.
916 + */
917 +
918 +#include "client.h"
919 +#include "ircd.h"
920 +#include "ircd_features.h"
921 +#include "ircd_log.h"
922 +#include "ircd_reply.h"
923 +#include "ircd_string.h"
924 +#include "msg.h"
925 +#include "numeric.h"
926 +#include "s_bsd.h"
927 +#include "s_debug.h"
928 +#include "send.h"
929 +#include "welcome.h"
930 +
931 +
932 +/** List of welcome messages - first MAX for global, second MAX for local */
933 +static struct Welcome WelcomeArray[WELCOME_MAX_ENTRIES * 2] = { { 0 } };
934 +
935 +
936 +/** Allocate a new welcome with the given parameters.
937 + * @param[in] name Name of the welcome message.
938 + * @param[in] text The welcome message.
939 + * @param[in] who Who set it.
940 + * @param[in] create When it was set.
941 + * @param[in] lastmod Last modification timestamp.
942 + * @return name Array number of the welcome set.
943 + */
944 +static int
945 +welcome_make(int name, char *text, char *who, time_t create, time_t lastmod, unsigned int flags)
946 +{
947 +
948 + /* assert */
949 + assert(WelcomeArrayIsValid(name));
950 + assert(NULL != text);
951 + assert(NULL != who);
952 + assert((flags & WELCOME_FORCE) || lastmod > 0); /* lastmod must not be 0 unless forced */
953 + assert(!(flags & WELCOME_LOCAL) &&
954 + ((flags & WELCOME_FORCE) ||
955 + lastmod >= WelcomeLastMod(name))); /* lastmod may not decrease for global welcome unless forced */
956 +
957 + /* debug */
958 + Debug((DEBUG_DEBUG, "welcome_make(name=%d, text=\"%s\", who=%s, create=%Tu, lastmod=%Tu, "
959 + "FLAGS(0x%04x): local=%s announce=%s force=%s unset=%s insert=%s delete=%s inclastmod=%s)",
960 + name, text, who, create, lastmod, flags,
961 + (flags & WELCOME_LOCAL) ? "yes" : "no",
962 + (flags & WELCOME_ANNOUNCE) ? "yes" : "no",
963 + (flags & WELCOME_FORCE) ? "yes" : "no",
964 + (flags & WELCOME_UNSET) ? "yes" : "no",
965 + (flags & WELCOME_INSERT) ? "yes" : "no",
966 + (flags & WELCOME_DELETE) ? "yes" : "no",
967 + (flags & WELCOME_INCLASTMOD) ? "yes" : "no"));
968 +
969 + /* forced and lastmod is zero, clear text and who */
970 + if (flags & WELCOME_FORCE && lastmod == 0) {
971 + text = "";
972 + who = "";
973 + }
974 +
975 + /* store it */
976 + ircd_strncpy(WelcomeArray[name].text, text, WELCOMELEN);
977 + ircd_strncpy(WelcomeArray[name].who, who, ACCOUNTLEN);
978 +
979 + if (flags & WELCOME_INCLASTMOD && /* take current lastmod+1 if needed*/
980 + !(flags & WELCOME_FORCE) && /* not forced */
981 + WelcomeLastMod(name) >= lastmod) /* current lastmod greater or equal than lastmod*/
982 + WelcomeArray[name].lastmod = WelcomeLastMod(name) +1;
983 + else
984 + WelcomeArray[name].lastmod = lastmod;
985 +
986 + WelcomeArray[name].create = create;
987 +
988 + return name;
989 +}
990 +
991 +
992 +/** Propagate a welcome message.
993 + * @param[in] cptr Local client that sent us the welcome.
994 + * @param[in] sptr Originator of the welcome.
995 + * @param[in] nameint Name of the message.
996 + * @param[in] create When it was set.
997 + * @param[in] lastmod Last modification timestamp.
998 + * @param[in] who Who set this message.
999 + * @param[in] text The welcome message.
1000 + * @param[in] flags Flags to set on welcome.
1001 + * @return Zero
1002 + */
1003 +int
1004 +welcome_propagate(struct Client *cptr, struct Client *sptr, int nameint,
1005 + time_t create, time_t lastmod, char *who, char *text, unsigned int flags)
1006 +{
1007 + /* assert */
1008 + assert(NULL != sptr);
1009 + assert(NULL != cptr);
1010 + assert(WelcomeNameIsValid(nameint));
1011 + assert(lastmod >= 0);
1012 + assert(lastmod > 0 || flags & WELCOME_FORCE); /* lastmod must not be 0 unless forced */
1013 + assert(!(flags & WELCOME_LOCAL)); /* must not be local */
1014 +
1015 + sendcmdto_serv_butone(sptr, CMD_WELCOME, cptr, "* %s%s%s%s%d %Tu %Tu %s :%s",
1016 + (flags & WELCOME_ANNOUNCE) ? "$" : "",
1017 + (flags & WELCOME_FORCE) ? "!" : "",
1018 + (flags & WELCOME_INSERT) ? "+" : "",
1019 + (flags & WELCOME_DELETE) ? "-" : "",
1020 + nameint, create, lastmod, who, text);
1021 +
1022 + return 0;
1023 +}
1024 +
1025 +
1026 +/** Resend a welcome message.
1027 + * @param[in] cptr Local client that sent us the welcome.
1028 + * @param[in] nameint Name of the message.
1029 + * @param[in] namearray Name of the array item.
1030 + * @param[in] flags Flags to set on welcome.
1031 + * @return Zero
1032 + */
1033 +int
1034 +welcome_resend(struct Client *cptr, int nameint, int namearray, unsigned int flags)
1035 +{
1036 +
1037 + int name; /* loop variable */
1038 +
1039 + /* assert */
1040 + assert(NULL != cptr);
1041 + assert(IsServer(cptr));
1042 + assert(WelcomeNameIsValid(nameint));
1043 + assert(WelcomeArrayIsValid(namearray));
1044 + assert(nameint - 1 == namearray);
1045 + assert(!(flags & WELCOME_LOCAL)); /* must not be local */
1046 + assert(!(flags & WELCOME_FORCE)); /* must not be forced */
1047 +
1048 + /* send our version */
1049 + sendcmdto_one(&me, CMD_WELCOME, cptr, "* %d %Tu %Tu %s :%s",
1050 + nameint,
1051 + WelcomeCreate(namearray), WelcomeLastMod(namearray),
1052 + WelcomeWho(namearray), WelcomeText(namearray));
1053 +
1054 + /* bad welcome did not have insert or delete prefix */
1055 + if (!(flags & (WELCOME_INSERT|WELCOME_DELETE)))
1056 + return 0;
1057 +
1058 + /* loop over global entries - nameint+1 to max - 1 */
1059 + for (name = namearray +1; name <= WELCOME_MAX_ENTRIES - 1; name++) {
1060 + if (!WelcomeIsSet(name)) /* not set, force */
1061 + sendcmdto_one(&me, CMD_WELCOME, cptr, "* !%d 0 0 0 :", name +1);
1062 + else /* send our version */
1063 + sendcmdto_one(&me, CMD_WELCOME, cptr, "* %d %Tu %Tu %s :%s",
1064 + name +1,
1065 + WelcomeCreate(name), WelcomeLastMod(name),
1066 + WelcomeWho(name), WelcomeText(name));
1067 + }
1068 +
1069 + return 0;
1070 +}
1071 +
1072 +
1073 +/** Log a welcome message.
1074 + * @param[in] sptr Originator of the welcome.
1075 + * @param[in] msg The message to show.
1076 + * @param[in] flags Flags to set on welcome.
1077 + * @return Zero
1078 + */
1079 +int
1080 +welcome_log(struct Client *sptr, char *msg, unsigned int flags)
1081 +{
1082 + /* assert */
1083 + assert(NULL != sptr);
1084 + assert(NULL != msg);
1085 +
1086 + /* inform ops */
1087 + sendto_opmask_butone(0, SNO_OLDSNO, "%s %s",
1088 + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
1089 + get_client_name_and_opername(sptr) : cli_name((cli_user(sptr))->server), msg);
1090 +
1091 + /* log it */
1092 + log_write(LS_NETWORK, L_INFO, LOG_NOSNOTICE, "%s %s", get_client_name_and_opername(sptr), msg);
1093 +
1094 + /* welcome by remote oper, inform of success */
1095 + if ((flags & WELCOME_LOCAL) && IsUser(sptr) && !MyConnect(sptr)) {
1096 + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s %s",
1097 + sptr, get_client_name_and_opername(sptr), msg);
1098 +
1099 + /* TODO: wallops all local changes, by both local and remote opers? */
1100 + /* tell all opers about the local message being set remotely */
1101 + sendwallto_group_butone(&me, WALL_WALLOPS, 0, "%s %s", get_client_name_and_opername(sptr), msg);
1102 + }
1103 +
1104 + return 0;
1105 +}
1106 +
1107 +
1108 +/** Announce a welcome message to local clients.
1109 + * @param[in] name Welcome message to announce.
1110 + * @param[in] flags Flags to set on welcome.
1111 + */
1112 +void
1113 +welcome_announce(int name, unsigned int flags)
1114 +{
1115 + struct Client *acptr; /* local user */
1116 + struct MsgBuf *msgbuf; /* message to send */
1117 + int i; /* loop variable */
1118 +
1119 + /* assert */
1120 + assert(flags & WELCOME_ANNOUNCE);
1121 + assert(WelcomeArrayIsValid(name));
1122 + assert(WelcomeIsSet(name));
1123 + assert(!WelcomeIsEmpty(name));
1124 +
1125 + /* build msgbuf */
1126 + msgbuf = msgq_make(0, ":%C %s $%s :[%s] %s", &me, MSG_NOTICE,
1127 + (flags & WELCOME_LOCAL) ? cli_name(&me) : "*",
1128 + (flags & WELCOME_LOCAL) ? cli_name(&me) : feature_str(FEAT_NETWORK),
1129 + WelcomeText(name));
1130 +
1131 + /* go over local clients */
1132 + for (i = HighestFd; i > 0; --i) {
1133 +
1134 + /* skip unregistered clients, skip servers */
1135 + if (!(acptr = LocalClientArray[i]) || !IsRegistered(acptr) || IsServer(acptr))
1136 + continue;
1137 +
1138 + /* send it away */
1139 + send_buffer(acptr, msgbuf, 0);
1140 + }
1141 +}
1142 +
1143 +
1144 +/** Set a welcome message.
1145 + * @param[in] cptr Local client that sent us the welcome.
1146 + * @param[in] sptr Originator of the welcome.
1147 + * @param[in] nameint Name of the message.
1148 + * @param[in] namearray Array entry.
1149 + * @param[in] create When it was set.
1150 + * @param[in] lastmod Last modification timestamp.
1151 + * @param[in] who Who set this message.
1152 + * @param[in] text The message.
1153 + * @param[in] flags Flags to set on welcome.
1154 + * @return Zero
1155 + */
1156 +int
1157 +welcome_set(struct Client *cptr, struct Client *sptr, int nameint,
1158 + int namearray, time_t create, time_t lastmod, char *who, char *text, unsigned int flags)
1159 +{
1160 + char msg[BUFSIZE]; /* msg for logging */
1161 + int new = 0; /* welcome is new - not set yet */
1162 +
1163 + /* assert */
1164 + assert(NULL != cptr);
1165 + assert(NULL != sptr);
1166 + assert(WelcomeNameIsValid(nameint));
1167 + assert(WelcomeArrayIsValid(namearray));
1168 + assert(lastmod >= 0);
1169 + assert(lastmod > 0 || flags & WELCOME_FORCE); /* lastmod must not be 0 unless forced */
1170 + assert(NULL != who);
1171 + assert(NULL != text);
1172 + assert(!(flags & WELCOME_UNSET)); /* must not be unset */
1173 +
1174 + /* debug */
1175 + Debug((DEBUG_DEBUG, "welcome_set(cptr=%s, sptr=%s, nameint=%d, namearray=%d, "
1176 + "create=%Tu, lastmod=%Tu, who=%s, text=\"%s\", "
1177 + "FLAGS(0x%04x): local=%s announce=%s force=%s unset=%s insert=%s delete=%s)",
1178 + cli_name(cptr), cli_name(sptr), nameint, namearray, create, lastmod, who, text, flags,
1179 + (flags & WELCOME_LOCAL) ? "yes" : "no",
1180 + (flags & WELCOME_ANNOUNCE) ? "yes" : "no",
1181 + (flags & WELCOME_FORCE) ? "yes" : "no",
1182 + (flags & WELCOME_UNSET) ? "yes" : "no",
1183 + (flags & WELCOME_INSERT) ? "yes" : "no",
1184 + (flags & WELCOME_DELETE) ? "yes" : "no"));
1185 +
1186 + /* not set */
1187 + if (WelcomeIsEmpty(namearray))
1188 + new = 1;
1189 +
1190 + /* update */
1191 + welcome_make(namearray, text, who, create, lastmod, flags);
1192 +
1193 + /* create msg for log */
1194 + ircd_snprintf(0, msg, 0, "%s%s%s WELCOME %d \"%s\" %s [%Tu]",
1195 + new ? "setting" : "changing",
1196 + (flags & WELCOME_ANNOUNCE) ? " and announcing " : " ",
1197 + (flags & WELCOME_LOCAL) ? "local" : "global",
1198 + nameint, WelcomeText(namearray), WelcomeWho(namearray), create);
1199 +
1200 + /* log it */
1201 + welcome_log(sptr, msg, flags);
1202 +
1203 + /* propagate it */
1204 + if (!(flags & WELCOME_LOCAL))
1205 + welcome_propagate(cptr, sptr, nameint, create, lastmod, who, text, flags);
1206 +
1207 + /* announce it */
1208 + if (flags & WELCOME_ANNOUNCE)
1209 + welcome_announce(namearray, flags);
1210 +
1211 + return 0;
1212 +}
1213 +
1214 +
1215 +/** Unset a welcome message.
1216 + * @param[in] cptr Local client that sent us the welcome.
1217 + * @param[in] sptr Originator of the welcome.
1218 + * @param[in] nameint Name of the message.
1219 + * @param[in] namearray Array entry.
1220 + * @param[in] create When it was set.
1221 + * @param[in] lastmod Last modification timestamp.
1222 + * @param[in] who Who set this message.
1223 + * @param[in] flags Flags to set on welcome.
1224 + * @return Zero
1225 + */
1226 +int
1227 +welcome_unset(struct Client *cptr, struct Client *sptr, int nameint,
1228 + int namearray, time_t create, time_t lastmod, char *who, unsigned int flags)
1229 +{
1230 + char msg[BUFSIZE]; /* msg for logging */
1231 +
1232 + /* assert */
1233 + assert(NULL != cptr);
1234 + assert(NULL != sptr);
1235 + assert(WelcomeNameIsValid(nameint));
1236 + assert(WelcomeArrayIsValid(namearray));
1237 + assert(lastmod >= 0);
1238 + assert(lastmod > 0 || flags & WELCOME_FORCE); /* lastmod must not be 0 unless forced */
1239 + assert(NULL != who);
1240 + assert(flags & (WELCOME_UNSET|WELCOME_INSERT|WELCOME_DELETE)); /* must be unset, insert or delete */
1241 +
1242 + /* debug */
1243 + Debug((DEBUG_DEBUG, "welcome_unset(cptr=%s, sptr=%s, nameint=%d, namearray=%d, "
1244 + "create=%Tu, lastmod=%Tu, who=%s, "
1245 + "FLAGS(0x%04x): local=%s announce=%s force=%s unset=%s insert=%s delete=%s)",
1246 + cli_name(cptr), cli_name(sptr), nameint, namearray, create, lastmod, who, flags,
1247 + (flags & WELCOME_LOCAL) ? "yes" : "no",
1248 + (flags & WELCOME_ANNOUNCE) ? "yes" : "no",
1249 + (flags & WELCOME_FORCE) ? "yes" : "no",
1250 + (flags & WELCOME_UNSET) ? "yes" : "no",
1251 + (flags & WELCOME_INSERT) ? "yes" : "no",
1252 + (flags & WELCOME_DELETE) ? "yes" : "no"));
1253 +
1254 + /* create msg for log */
1255 + ircd_snprintf(0, msg, 0, "unsetting %s WELCOME %d \"%s\" %s [%Tu]",
1256 + (flags & WELCOME_LOCAL) ? "local" : "global",
1257 + nameint, WelcomeText(namearray), WelcomeWho(namearray), create);
1258 +
1259 + /* log it but only if it was set
1260 + * welcome unset could have crossed with another welcome unset,
1261 + * still need to update lastmod
1262 + * can be a forced unset on a welcome that is not set
1263 + */
1264 + if (!WelcomeIsEmpty(namearray))
1265 + welcome_log(sptr, msg, flags);
1266 +
1267 + /* update,
1268 + * not when inserting, welcome_insert() handles that
1269 + * not when deleting, welcome_delete() handles that
1270 + */
1271 + if (!(flags & (WELCOME_INSERT|WELCOME_DELETE)))
1272 + welcome_make(namearray, "", who, create, lastmod, flags);
1273 +
1274 + /* propagate it, but not when inserting */
1275 + if (!(flags & (WELCOME_LOCAL|WELCOME_INSERT)))
1276 + welcome_propagate(cptr, sptr, nameint, create, lastmod, who, "", flags);
1277 +
1278 + return 0;
1279 +}
1280 +
1281 +
1282 +/** Insert a welcome message.
1283 + * @param[in] cptr Local client that sent us the welcome.
1284 + * @param[in] sptr Originator of the welcome.
1285 + * @param[in] nameint Name of the message.
1286 + * @param[in] namearray Array entry.
1287 + * @param[in] create When it was set.
1288 + * @param[in] lastmod Last modification timestamp.
1289 + * @param[in] who Who set this message.
1290 + * @param[in] text The welcome message.
1291 + * @param[in] flags Flags to set on welcome.
1292 + * @return Zero
1293 + */
1294 +int
1295 +welcome_insert(struct Client *cptr, struct Client *sptr, int nameint,
1296 + int namearray, time_t create, time_t lastmod, char *who, char *text, unsigned int flags)
1297 +{
1298 + char msg[BUFSIZE]; /* msg for logging */
1299 + int i; /* loop variable */
1300 + int empty = -1; /* first empty spot in array after namearray */
1301 + int end = WELCOME_MAX_ENTRIES -1; /* last element to check in array */
1302 + int last = end; /* last welcome message to feed to welcome_unset */
1303 +
1304 + /* assert */
1305 + assert(NULL != cptr);
1306 + assert(NULL != sptr);
1307 + assert(WelcomeNameIsValid(nameint));
1308 + assert(WelcomeArrayIsValid(namearray));
1309 + assert(lastmod >= 0);
1310 + assert(lastmod > 0 || flags & WELCOME_FORCE); /* lastmod must not be 0 unless forced */
1311 + assert(NULL != who);
1312 + assert(NULL != text);
1313 + assert(flags & WELCOME_INSERT); /* must be insert */
1314 +
1315 + /* debug */
1316 + Debug((DEBUG_DEBUG, "welcome_insert(cptr=%s, sptr=%s, nameint=%d, namearray=%d, "
1317 + "create=%Tu, lastmod=%Tu, who=%s, text=\"%s\", "
1318 + "FLAGS(0x%04x): local=%s announce=%s force=%s unset=%s insert=%s delete=%s)",
1319 + cli_name(cptr), cli_name(sptr), nameint, namearray, create, lastmod, who, text, flags,
1320 + (flags & WELCOME_LOCAL) ? "yes" : "no",
1321 + (flags & WELCOME_ANNOUNCE) ? "yes" : "no",
1322 + (flags & WELCOME_FORCE) ? "yes" : "no",
1323 + (flags & WELCOME_UNSET) ? "yes" : "no",
1324 + (flags & WELCOME_INSERT) ? "yes" : "no",
1325 + (flags & WELCOME_DELETE) ? "yes" : "no"));
1326 +
1327 + /* correct end for local offset */
1328 + if (flags & WELCOME_LOCAL)
1329 + end += WELCOME_MAX_ENTRIES;
1330 +
1331 + /* find first empty spot */
1332 + for (i = namearray; i <= end; i++) {
1333 + if (WelcomeIsEmpty(i)) {
1334 + empty = i;
1335 + break;
1336 + }
1337 + }
1338 +
1339 + /* no empty spot, need to unset last */
1340 + if (empty == -1) {
1341 + welcome_unset(cptr, sptr, end +1, end, create, lastmod, who, flags);
1342 + empty = end;
1343 + }
1344 +
1345 + /* move entries down, update lastmod */
1346 + for (i = empty; i > namearray; i--)
1347 + welcome_make(i, WelcomeText(i-1), WelcomeWho(i-1), WelcomeCreate(i-1),
1348 + lastmod, flags | WELCOME_INCLASTMOD);
1349 +
1350 + /* correct empty for local offset */
1351 + if (flags & WELCOME_LOCAL)
1352 + empty -= WELCOME_MAX_ENTRIES;
1353 +
1354 + /* create msg for log */
1355 + if (nameint == empty)
1356 + ircd_snprintf(0, msg, 0, "moving %s WELCOME message %d one place down",
1357 + (flags & WELCOME_LOCAL) ? "local" : "global", nameint);
1358 + else
1359 + ircd_snprintf(0, msg, 0, "moving %s WELCOME message %d %s %d one place down",
1360 + (flags & WELCOME_LOCAL) ? "local" : "global", nameint, (empty - nameint > 1) ? "to" : "and" , empty);
1361 +
1362 + /* log it */
1363 + welcome_log(sptr, msg, flags);
1364 +
1365 + /* set it */
1366 + welcome_set(cptr, sptr, nameint, namearray, create, lastmod, who, text, flags);
1367 +
1368 + return 0;
1369 +}
1370 +
1371 +
1372 +/** Delete a welcome message.
1373 + * @param[in] cptr Local client that sent us the welcome.
1374 + * @param[in] sptr Originator of the welcome.
1375 + * @param[in] nameint Name of the message.
1376 + * @param[in] namearray Array entry.
1377 + * @param[in] create When it was set.
1378 + * @param[in] lastmod Last modification timestamp.
1379 + * @param[in] who Who set this message.
1380 + * @param[in] flags Flags to set on welcome.
1381 + * @return Zero
1382 + */
1383 +int
1384 +welcome_delete(struct Client *cptr, struct Client *sptr, int nameint,
1385 + int namearray, time_t create, time_t lastmod, char *who, unsigned int flags)
1386 +{
1387 + int i; /* loop variable */
1388 + int empty = namearray; /* first empty spot in array after namearray */
1389 + int end = WELCOME_MAX_ENTRIES -1; /* last element to check in array */
1390 +
1391 + /* assert */
1392 + assert(NULL != cptr);
1393 + assert(NULL != sptr);
1394 + assert(WelcomeNameIsValid(nameint));
1395 + assert(WelcomeArrayIsValid(namearray));
1396 + assert(lastmod >= 0);
1397 + assert(lastmod > 0 || flags & WELCOME_FORCE); /* lastmod must not be 0 unless forced */
1398 + assert(NULL != who);
1399 + assert(flags & WELCOME_UNSET); /* must be unset */
1400 + assert(flags & WELCOME_DELETE); /* must be delete */
1401 +
1402 + /* debug */
1403 + Debug((DEBUG_DEBUG, "welcome_delete(cptr=%s, sptr=%s, nameint=%d, namearray=%d, "
1404 + "create=%Tu, lastmod=%Tu, who=%s, "
1405 + "FLAGS(0x%04x): local=%s announce=%s force=%s unset=%s insert=%s delete=%s)",
1406 + cli_name(cptr), cli_name(sptr), nameint, namearray, create, lastmod, who, flags,
1407 + (flags & WELCOME_LOCAL) ? "yes" : "no",
1408 + (flags & WELCOME_ANNOUNCE) ? "yes" : "no",
1409 + (flags & WELCOME_FORCE) ? "yes" : "no",
1410 + (flags & WELCOME_UNSET) ? "yes" : "no",
1411 + (flags & WELCOME_INSERT) ? "yes" : "no",
1412 + (flags & WELCOME_DELETE) ? "yes" : "no"));
1413 +
1414 + /* unset it */
1415 + welcome_unset(cptr, sptr, nameint, namearray, create, lastmod, who, flags);
1416 +
1417 + /* correct end for local offset */
1418 + if (flags & WELCOME_LOCAL)
1419 + end += WELCOME_MAX_ENTRIES;
1420 +
1421 + /* move entries up, update lastmod */
1422 + for (i = namearray; i < end; i++) {
1423 + if (!WelcomeIsSet(i+1))
1424 + break;
1425 + welcome_make(i, WelcomeText(i+1), WelcomeWho(i+1), WelcomeCreate(i+1),
1426 + lastmod, flags | WELCOME_INCLASTMOD);
1427 + }
1428 +
1429 + /* clear last entry */
1430 + if (i == end)
1431 + welcome_make(i, "", who, create, lastmod, flags | WELCOME_INCLASTMOD);
1432 +
1433 + /* nothing was moved, clear entry */
1434 + if (i == namearray)
1435 + welcome_make(i, "", who, create, lastmod, flags);
1436 +
1437 + return 0;
1438 +}
1439 +
1440 +
1441 +/** Change a welcome message.
1442 + * @param[in] cptr Local client that sent us the welcome.
1443 + * @param[in] sptr Originator of the welcome.
1444 + * @param[in] name Name of the message.
1445 + * @param[in] create When it was set.
1446 + * @param[in] lastmod Last modification timestamp.
1447 + * @param[in] who Who set this message.
1448 + * @param[in] text The welcome message.
1449 + * @param[in] flags Flags to set on welcome.
1450 + * @return Zero
1451 + */
1452 +int
1453 +welcome_do(struct Client *cptr, struct Client *sptr, char *name,
1454 + time_t create, time_t lastmod, char *who, char *text, unsigned int flags)
1455 +{
1456 + int nameint = atoi(name); /* transform to int */
1457 + int namearray = nameint - 1; /* used to test the array element */
1458 +
1459 + /* assert */
1460 + assert(NULL != cptr);
1461 + assert(NULL != sptr);
1462 + assert(NULL != name);
1463 + assert(NULL != text);
1464 + assert(NULL != who);
1465 +
1466 + /* debug */
1467 + Debug((DEBUG_DEBUG, "welcome_do(cptr=%s, sptr=%s, name=%s, "
1468 + "create=%Tu, lastmod=%Tu, who=%s, text=\"%s\", "
1469 + "FLAGS(0x%04x): local=%s announce=%s force=%s unset=%s insert=%s delete=%s)",
1470 + cli_name(cptr), cli_name(sptr), name, create, lastmod, who, text, flags,
1471 + (flags & WELCOME_LOCAL) ? "yes" : "no",
1472 + (flags & WELCOME_ANNOUNCE) ? "yes" : "no",
1473 + (flags & WELCOME_FORCE) ? "yes" : "no",
1474 + (flags & WELCOME_UNSET) ? "yes" : "no",
1475 + (flags & WELCOME_INSERT) ? "yes" : "no",
1476 + (flags & WELCOME_DELETE) ? "yes" : "no"));
1477 +
1478 + /* name empty after taking off the prefixes? */
1479 + if (*name == 0) {
1480 + if (MyUser(sptr) && (MyConnect(sptr) || flags & WELCOME_LOCAL))
1481 + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Welcome: No message number given", sptr);
1482 + else
1483 + protocol_violation(cptr, "Received WELCOME with no message number from %C", sptr);
1484 + return 0;
1485 + }
1486 +
1487 + /* check name */
1488 + if (!WelcomeArrayIsValid(namearray)) {
1489 + if (IsUser(sptr) && (MyConnect(sptr) || flags & WELCOME_LOCAL))
1490 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1491 + "%C :Welcome: Invalid message number %s - should between 1 and %d",
1492 + sptr, name, WELCOME_MAX_ENTRIES);
1493 + else
1494 + protocol_violation(cptr,
1495 + "Received WELCOME with invalid message number %s from %C - should be between 1 and %d",
1496 + name, sptr, WELCOME_MAX_ENTRIES);
1497 + return 0;
1498 + }
1499 +
1500 + /* invalid lastmod */
1501 + if (lastmod <= 0) {
1502 + /* from my user - must be a glitch,
1503 + * someone set (my) network time to 0 ?
1504 + */
1505 + if (MyUser(sptr))
1506 + lastmod = 1;
1507 + /* not forced or negative, it is a protocol violation */
1508 + else if (!(flags & WELCOME_FORCE) || lastmod < 0)
1509 + return protocol_violation(cptr, "Received WELCOME with invalid lastmod timestamp %Tu from %C", lastmod, sptr);
1510 + }
1511 +
1512 + /* source is user, and is myuser or welcome is local, check length of the message */
1513 + if (IsUser(sptr) && (MyConnect(sptr) || (flags & WELCOME_LOCAL)) && (strlen(text) > WELCOMELEN)) {
1514 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1515 + "%C :Welcome: The message is too long with %d chars - max is %d chars",
1516 + sptr, strlen(text), WELCOMELEN);
1517 + ircd_strncpy(text, text, WELCOMELEN);
1518 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1519 + "%C :Welcome: Change or truncate the message to: \"%s\"", sptr, text);
1520 + return 0;
1521 + }
1522 +
1523 + /* correct namearray for local offset */
1524 + if (flags & WELCOME_LOCAL)
1525 + namearray += WELCOME_MAX_ENTRIES;
1526 +
1527 + /* must be true by now */
1528 + assert(WelcomeArrayIsValid(namearray));
1529 + assert(WelcomeNameIsValid(nameint));
1530 +
1531 + /* cannot unset welcome that is not set */
1532 + if (!WelcomeIsSet(namearray) && flags & WELCOME_UNSET) {
1533 +
1534 + /* from user, throw error */
1535 + if (IsUser(sptr) && (MyConnect(sptr) || flags & WELCOME_LOCAL))
1536 + return send_reply(sptr, ERR_NOSUCHWELCOME, name);
1537 +
1538 + /* new local welcome from server, but empty - ignore
1539 + * we do accept a new global welcome message that is empty
1540 + */
1541 + if (flags & WELCOME_LOCAL)
1542 + return 0;
1543 + }
1544 +
1545 + /* check if there is something to change */
1546 + /* we got a record for it */
1547 + if (WelcomeIsSet(namearray)) {
1548 +
1549 + /* global and not forced */
1550 + if (!(flags & (WELCOME_LOCAL|WELCOME_FORCE))) {
1551 +
1552 + /* myuser changes it,
1553 + * WelcomeLastMod greater than or equal to lastmod, take WelcomeLastMod+1 as lastmod
1554 + * else the change is not accepted upstream because of the older TS
1555 + */
1556 + if (MyUser(sptr)) {
1557 + if (WelcomeLastMod(namearray) >= lastmod)
1558 + lastmod = WelcomeLastMod(namearray) +1;
1559 + }
1560 +
1561 + /* compare lastmod, ignore welcome when:
1562 + * we got a newer one
1563 + * or when lastmod is the same and our text is 'smaller'
1564 + */
1565 + else if ((lastmod < WelcomeLastMod(namearray)) || /* we got a newer one */
1566 + ((lastmod == WelcomeLastMod(namearray)) && /* same lastmod */
1567 + (strcmp(WelcomeText(namearray), text) < 0))) { /* our text is 'smaller' */
1568 + /* burst or burst ack, cptr gets our version from the burst */
1569 + if (IsBurstOrBurstAck(cptr))
1570 + return 0;
1571 + /* sync server */
1572 + return welcome_resend(cptr, nameint, namearray, flags);
1573 + }
1574 +
1575 + /* local welcome - we use our idea of the time */
1576 + } else if (flags & WELCOME_LOCAL) {
1577 + create = TStime();
1578 + lastmod = TStime();
1579 + }
1580 +
1581 + /* new global welcome from my user or local welcome
1582 + * compare new message with old message
1583 + */
1584 + if (IsUser(sptr) && (MyConnect(sptr) || (flags & WELCOME_LOCAL))) {
1585 + if (strcmp(text, WelcomeText(namearray)) == 0) { /* use strcmp instead of ircd_strcmp - oper may wish to change case */
1586 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1587 + "%C :Welcome: Cannot change %s message for %s - nothing to change",
1588 + sptr, (flags & WELCOME_LOCAL) ? "local" : "global", name);
1589 + return 0;
1590 + }
1591 + }
1592 + }
1593 +
1594 + /* do not insert for last global/local entry and when not set yet */
1595 + if ((flags & WELCOME_INSERT) &&
1596 + ((!WelcomeIsSet(namearray)) || (nameint == WELCOME_MAX_ENTRIES)))
1597 + flags &= ~WELCOME_INSERT;
1598 +
1599 + /* clear delete flag if text is not empty */
1600 + if (flags & WELCOME_DELETE && *text != 0)
1601 + flags &= ~WELCOME_DELETE;
1602 +
1603 + /* unset */
1604 + if (flags & WELCOME_UNSET) {
1605 +
1606 + /* clear insert flag,
1607 + * when this flag is set, welcome_unset() assumes it is being called from welcome_insert()
1608 + * and wont propagate the change
1609 + * welcome_delete() calls welcome_unset()
1610 + */
1611 + flags &= ~WELCOME_INSERT;
1612 +
1613 + /* delete */
1614 + if (flags & WELCOME_DELETE)
1615 + return welcome_delete(cptr, sptr, nameint, namearray, create, lastmod, who, flags);
1616 +
1617 + /* unset */
1618 + return welcome_unset(cptr, sptr, nameint, namearray, create, lastmod, who, flags);
1619 + }
1620 +
1621 + /* insert */
1622 + if (flags & WELCOME_INSERT)
1623 + return welcome_insert(cptr, sptr, nameint, namearray, create, lastmod, who, text, flags);
1624 +
1625 + /* new or change */
1626 + return welcome_set(cptr, sptr, nameint, namearray, create, lastmod, who, text, flags);
1627 +}
1628 +
1629 +
1630 +/** Send the full list of welcome message to \a cptr.
1631 + * @param[in] cptr Local server to send welcomes to.
1632 + */
1633 +void
1634 +welcome_burst(struct Client *cptr)
1635 +{
1636 + int name; /* loop variable */
1637 +
1638 + /* assert */
1639 + assert(NULL != cptr);
1640 +
1641 + /* loop over global entries - 0 to max - 1 */
1642 + for (name = 0; name <= WELCOME_MAX_ENTRIES - 1; name++) {
1643 + if (WelcomeIsSet(name))
1644 + sendcmdto_one(&me, CMD_WELCOME, cptr, "* %d %Tu %Tu %s :%s",
1645 + name + 1,
1646 + WelcomeCreate(name), WelcomeLastMod(name),
1647 + WelcomeWho(name), WelcomeText(name));
1648 + }
1649 +}
1650 +
1651 +
1652 +/** List welcome messages.
1653 + * @param[in] sptr Client requesting the listing.
1654 + * @param[in] connect When non zero do not report no welcome is set
1655 + * @return Zero.
1656 + */
1657 +int
1658 +welcome_list(struct Client *sptr, int connect)
1659 +{
1660 + int name; /* loop variable */
1661 + int found = 0; /* number of welcome messages set */
1662 + int local = 0; /* welcome is local or global */
1663 +
1664 + /* assert */
1665 + assert(NULL != sptr);
1666 +
1667 + /* loop over all entries - range 0 to 2 * max - 1 */
1668 + for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) {
1669 +
1670 + /* local entries now */
1671 + if (name == WELCOME_MAX_ENTRIES)
1672 + local = 1;
1673 +
1674 + /* not set or empty - skip */
1675 + if (!WelcomeIsSet(name) || WelcomeIsEmpty(name))
1676 + continue;
1677 +
1678 + /* got one */
1679 + found++;
1680 + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :[%s] %s",
1681 + sptr, local ? cli_name(&me) : feature_str(FEAT_NETWORK), WelcomeText(name));
1682 + }
1683 +
1684 + /* nothing set */
1685 + if (!found && !connect)
1686 + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :No welcome message set.", sptr);
1687 +
1688 + return 0;
1689 +}
1690 +
1691 +
1692 +/** Statistics callback to list Welcome messages.
1693 + * @param[in] sptr Client requesting statistics.
1694 + * @param[in] sd Stats descriptor for request (ignored).
1695 + * @param[in] param Extra parameter from user (ignored).
1696 + */
1697 +void
1698 +welcome_stats(struct Client *sptr, const struct StatDesc *sd, char *param)
1699 +{
1700 + int name; /* loop variable */
1701 + int local = 0; /* welcome is local or global */
1702 +
1703 + /* assert */
1704 + assert(NULL != sptr);
1705 +
1706 + /* stats header */
1707 + send_reply(sptr, SND_EXPLICIT | RPL_STATSWELCOME,
1708 + "W # Target Who Created LastMod Text");
1709 +
1710 + /* loop over all entries - range 0 to 2 * max - 1 */
1711 + for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) {
1712 +
1713 + /* local entries now */
1714 + if (name == WELCOME_MAX_ENTRIES)
1715 + local = 1;
1716 +
1717 + /* not set */
1718 + if (!WelcomeIsSet(name))
1719 + continue;
1720 +
1721 + /* send it */
1722 + send_reply(sptr, RPL_STATSWELCOME,
1723 + local ? name + 1 - WELCOME_MAX_ENTRIES : name + 1,
1724 + local ? cli_name(&me) : "*",
1725 + WelcomeWho(name),
1726 + WelcomeCreate(name), WelcomeLastMod(name),
1727 + WelcomeIsEmpty(name) ? "<Empty>" : WelcomeText(name));
1728 + }
1729 +}
1730 +
1731 +
1732 +/** Count welcome messages and memory used by them.
1733 + * @param[out] we_size Receives total number of bytes allocated for welcomes.
1734 + * @return Number of welcome messages currently allocated.
1735 + */
1736 +int
1737 +welcome_memory_count(size_t *we_size)
1738 +{
1739 + int name; /* loop variable */
1740 + unsigned int we = 0; /* number of welcome messages set */
1741 +
1742 + /* loop over all entries - range 0 to 2 * max - 1 */
1743 + for (name = 0; name <= 2 * WELCOME_MAX_ENTRIES - 1; name++) {
1744 +
1745 + /* not set */
1746 + if (!WelcomeIsSet(name))
1747 + continue;
1748 +
1749 + /* count */
1750 + we++;
1751 + *we_size += WelcomeText(name) ? (strlen(WelcomeText(name)) + 1) : 0;
1752 + *we_size += WelcomeWho(name) ? (strlen(WelcomeWho(name)) + 1) : 0;
1753 + }
1754 + return we;
1755 +}