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