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