diff -r a9b437e961ec ircd/welcome.c
--- /dev/null
+++ b/ircd/welcome.c
-@@ -0,0 +1,585 @@
+@@ -0,0 +1,592 @@
+/*
+ * IRC - Internet Relay Chat, ircd/welcome.c
+ * Copyright (C) 1990 Jarkko Oikarinen and
+/** Log a welcome message.
+ * @param[in] sptr Originator of the welcome.
+ * @param[in] msg The message to show.
-+ * @param[in] who Who set this message.
+ * @param[in] flags Flags to set on welcome.
+ * @return Zero
+ */
+int
-+welcome_log(struct Client *sptr, char *msg, char *who, unsigned int flags)
++welcome_log(struct Client *sptr, char *msg, unsigned int flags)
+{
+
+ /* inform ops */
+ get_client_name_and_opername(sptr) : cli_name((cli_user(sptr))->server), msg);
+
+ /* log it */
-+ log_write(LS_NETWORK, L_INFO, LOG_NOSNOTICE, "%#C (%s) %s", sptr, who, msg);
++ log_write(LS_NETWORK, L_INFO, LOG_NOSNOTICE, "%s %s", get_client_name_and_opername(sptr), msg);
+
+ /* welcome by remote user, inform oper of success */
+ if ((flags & WELCOME_LOCAL) && IsUser(sptr) && !MyUser(sptr)) {
+ welcome_make(namearray, text, who, timestamp);
+
+ /* create msg for log */
-+ ircd_snprintf(0, msg, 0, "%s%s%s WELCOME %d \"%s\" [%Tu]",
++ ircd_snprintf(0, msg, 0, "%s%s%s WELCOME %d \"%s\" %s [%Tu]",
+ new ? "setting" : "changing",
+ (flags & WELCOME_ANNOUNCE) ? " and announcing " : " ",
+ (flags & WELCOME_LOCAL) ? "local" : "global",
-+ nameint, text, timestamp);
++ nameint, text, who, timestamp);
+
+ /* log it */
-+ welcome_log(sptr, msg, who, flags);
++ welcome_log(sptr, msg, flags);
+
+ /* propagate it */
+ if (!(flags & WELCOME_LOCAL))
+ welcome_make(namearray, "", who, timestamp);
+
+ /* create msg for log */
-+ ircd_snprintf(0, msg, 0, "unsetting %s WELCOME %d \"%s\" [%Tu]",
-+ (flags & WELCOME_LOCAL) ? "local" : "global", nameint, text, timestamp);
++ ircd_snprintf(0, msg, 0, "unsetting %s WELCOME %d \"%s\" %s [%Tu]",
++ (flags & WELCOME_LOCAL) ? "local" : "global", nameint, text, who, timestamp);
+
+ /* log it */
-+ welcome_log(sptr, msg, who, flags);
++ welcome_log(sptr, msg, flags);
+
+ /* propagate it, but not when inserting */
+ if (!(flags & (WELCOME_LOCAL|WELCOME_INSERT)))
+ (flags & WELCOME_LOCAL) ? "local" : "global", nameint, (empty - nameint > 1) ? "to" : "and" , empty);
+
+ /* log it */
-+ welcome_log(sptr, msg, who, flags);
++ welcome_log(sptr, msg, flags);
+
+ /* set it */
+ welcome_set(cptr, sptr, nameint, namearray, timestamp, who, text, flags);
+{
+ int nameint = atoi(name); /* transform to int */
+ int namearray = nameint - 1; /* used to test the array element */
++ int max = WELCOME_MAX_ENTRIES; /* max number of entries */
+ static time_t rate; /* rate limit snomask message */
+
+ assert(NULL != cptr);
+ }
+
+ /* check name */
-+ if (nameint < 1 || nameint > WELCOME_MAX_ENTRIES) {
++ if (!WelcomeIsValid(namearray)) {
+ if (IsUser(sptr))
+ sendcmdto_one(&me, CMD_NOTICE, sptr,
+ "%C :WELCOME: Invalid message number %s - should between 1 and %d",
-+ sptr, name, WELCOME_MAX_ENTRIES);
++ sptr, name, max);
+ else {
+ protocol_violation(cptr, "WELCOME: Invalid message number %s from %C - should be between 1 and %d",
-+ name, sptr, WELCOME_MAX_ENTRIES);
-+ /* nameint greater than MAX, perhaps we are upgrading, but used extra slots too soon?
++ name, sptr, max);
++ /* nameint greater than max, perhaps we are upgrading, but used extra slots too soon?
+ * propagate it manually
+ * TODO: cant do announce here?
+ */
-+ if (nameint > WELCOME_MAX_ENTRIES && !(flags & WELCOME_LOCAL))
++ if (nameint > max && !(flags & WELCOME_LOCAL))
+ welcome_propagate(cptr, sptr, nameint, timestamp, who, text, flags);
+ }
+ return 0;
+ }
+
++ /* source is user, and is myuser or welcome is local, check length of the message */
++ if ((IsUser(sptr)) && ((MyUser(sptr)) || (flags & WELCOME_LOCAL)) && (strlen(text) > WELCOMELEN)) {
++ sendcmdto_one(&me, CMD_NOTICE, sptr,
++ "%C :WELCOME: The message is too long with %d chars - max is %d chars",
++ sptr, strlen(text), WELCOMELEN);
++ ircd_strncpy(text, text, WELCOMELEN);
++ sendcmdto_one(&me, CMD_NOTICE, sptr,
++ "%C :WELCOME: Change or trunacte the message to: \"%s\"", sptr, text);
++ return 0;
++ }
++
+ /* correct namearray for local offset */
+ if (flags & WELCOME_LOCAL)
+ namearray += WELCOME_MAX_ENTRIES;
+ }
+
+ /* do not insert for last global/local entry and when not set yet */
-+ if (flags & WELCOME_INSERT) {
-+ if ((WelcomeArray[namearray].timestamp == 0) ||
-+ (!(flags & WELCOME_LOCAL) && nameint == WELCOME_MAX_ENTRIES) ||
-+ ((flags & WELCOME_LOCAL) && nameint == 2 * WELCOME_MAX_ENTRIES))
-+ flags &= ~WELCOME_INSERT;
-+ }
++ if ((flags & WELCOME_INSERT) && ((WelcomeArray[namearray].timestamp == 0) || (nameint == max)))
++ flags &= ~WELCOME_INSERT;
+
+ /* TODO: rate limited for what? max 10 welcome messages..? */
+ /* possible timestamp drift - warn ops */