++/** Propagate a welcome message.
++ * @param[in] cptr Local client that sent us the welcome.
++ * @param[in] sptr Originator of the welcome.
++ * @param[in] nameint Name of the message.
++ * @param[in] timestamp Timestamp of when the message was set.
++ * @param[in] who Who set this message.
++ * @param[in] text The welcome message.
++ * @param[in] flags Flags to set on welcome.
++ * @return Zero
++ */
++int
++welcome_propagate(struct Client *cptr, struct Client *sptr, int nameint,
++ time_t timestamp, char *who, char *text, unsigned int flags)
++{
++ /* must be global */
++ assert(!(flags & WELCOME_LOCAL));
++
++ sendcmdto_serv_butone(sptr, CMD_WELCOME, cptr, "* %s%s%d %Tu %s :%s",
++ (flags & WELCOME_ANNOUNCE) ? "!" : "", (flags & WELCOME_INSERT) ? "+" : "",
++ nameint, timestamp, who, text);
++
++ return 0;
++}
++
++
++/** Log a welcome message.
++ * @param[in] sptr Originator of the welcome.
++ * @param[in] msg The message to show.
++ * @param[in] flags Flags to set on welcome.
++ * @return Zero
++ */
++int
++welcome_log(struct Client *sptr, char *msg, unsigned int flags)
++{
++
++ /* inform ops */
++ sendto_opmask_butone(0, SNO_OLDSNO, "%s %s",
++ (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
++ get_client_name_and_opername(sptr) : cli_name((cli_user(sptr))->server), msg);
++
++ /* log it */
++ 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)) {
++ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s %s",
++ sptr, get_client_name_and_opername(sptr), msg);
++
++ /* TODO: wallops all local changes, by both local and remote opers? */
++ /* tell all opers about the local message being set remotely */
++ sendwallto_group_butone(&me, WALL_WALLOPS, 0, "%s %s", get_client_name_and_opername(sptr), msg);
++ }
++
++ return 0;
++}
++
++
++/** Set a welcome message.
++ * @param[in] cptr Local client that sent us the welcome.
++ * @param[in] sptr Originator of the welcome.
++ * @param[in] nameint Name of the message.
++ * @param[in] namearray Array entry.
++ * @param[in] timestamp Timestamp of when the message was set.
++ * @param[in] who Who set this message.
++ * @param[in] text The message.
++ * @param[in] flags Flags to set on welcome.
++ * @return Zero
++ */
++int
++welcome_set(struct Client *cptr, struct Client *sptr, int nameint,
++ int namearray, time_t timestamp, char *who, char *text, unsigned int flags)
++{
++ char msg[BUFSIZE]; /* msg for logging */
++ int new = 0;
++
++ /* debug */
++ Debug((DEBUG_DEBUG, "welcome_set(\"%s\", \"%s\", %d, %d, %Tu, \"%s\", \"%s\", 0x%04x)",
++ cli_name(cptr), cli_name(sptr), nameint, namearray, timestamp, who, text, flags));
++
++ /* not set */
++ if (WelcomeIsEmpty(namearray))
++ new = 1;
++
++ /* update */
++ welcome_make(namearray, text, who, timestamp);
++
++ /* create msg for log */
++ 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, who, timestamp);
++
++ /* log it */
++ welcome_log(sptr, msg, flags);
++
++ /* propagate it */
++ if (!(flags & WELCOME_LOCAL))
++ welcome_propagate(cptr, sptr, nameint, timestamp, who, text, flags);
++
++ /* announce it */
++ if (flags & WELCOME_ANNOUNCE)
++ welcome_announce(namearray);
++
++ return 0;
++}
++
++
++/** Unset a welcome message.
++ * @param[in] cptr Local client that sent us the welcome.
++ * @param[in] sptr Originator of the welcome.
++ * @param[in] nameint Name of the message.
++ * @param[in] namearray Array entry.
++ * @param[in] timestamp Timestamp of when the message was set.
++ * @param[in] who Who set this message.
++ * @param[in] flags Flags to set on welcome.
++ * @return Zero
++ */
++int
++welcome_unset(struct Client *cptr, struct Client *sptr, int nameint,
++ int namearray, time_t timestamp, char *who, unsigned int flags)
++{
++ char msg[BUFSIZE]; /* msg for logging */
++ char text[WELCOMELEN + 1]; /* save old text */
++ int i; /* loop variable */
++ int empty = namearray; /* first empty spot in array after namearray */
++ int end = WELCOME_MAX_ENTRIES -1; /* last element to check in array */
++
++ /* debug */
++ Debug((DEBUG_DEBUG, "welcome_unset(\"%s\", \"%s\", %d, %d, %Tu, \"%s\", 0x%04x)",
++ cli_name(cptr), cli_name(sptr), nameint, namearray, timestamp, who, flags));
++
++ /* save text */
++ ircd_strncpy(text, WelcomeArray[namearray].text, WELCOMELEN);
++
++ /* update */
++ welcome_make(namearray, "", who, timestamp);
++
++ /* create msg for log */
++ 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, flags);
++
++ /* propagate it, but not when inserting */
++ if (!(flags & (WELCOME_LOCAL|WELCOME_INSERT)))
++ welcome_propagate(cptr, sptr, nameint, timestamp, who, "", flags);
++
++ /* correct end for local offset */
++ if (flags & WELCOME_LOCAL)
++ end += WELCOME_MAX_ENTRIES;
++
++ /* move entries up, update timestamp */
++ for (i = namearray; i < end; i++)
++ welcome_make(i, WelcomeArray[i+1].text, WelcomeArray[i+1].who, timestamp);
++
++ /* clear last entry, update timestamp */
++ welcome_make(end, "", who, timestamp);
++
++ return 0;
++}
++
++
++/** Insert a welcome message.
++ * @param[in] cptr Local client that sent us the welcome.
++ * @param[in] sptr Originator of the welcome.
++ * @param[in] nameint Name of the message.
++ * @param[in] namearray Array entry.
++ * @param[in] timestamp Timestamp of when the message was set.
++ * @param[in] who Who set this message.
++ * @param[in] text The welcome message.
++ * @param[in] flags Flags to set on welcome.
++ * @return Zero
++ */
++int
++welcome_insert(struct Client *cptr, struct Client *sptr, int nameint,
++ int namearray, time_t timestamp, char *who, char *text, unsigned int flags)
++{
++ char msg[BUFSIZE]; /* msg for logging */
++ int i; /* loop variable */
++ int empty = -1; /* first empty spot in array after namearray */
++ int end = WELCOME_MAX_ENTRIES -1; /* last element to check in array */
++ int last = end; /* last welcome message to feed to welcome_unset */
++
++ /* debug */
++ Debug((DEBUG_DEBUG, "welcome_insert(\"%s\", \"%s\", %d, %d, %Tu, \"%s\", \"%s\", 0x%04x)",
++ cli_name(cptr), cli_name(sptr), nameint, namearray, timestamp, who, text, flags));
++
++ /* correct end for local offset */
++ if (flags & WELCOME_LOCAL)
++ end += WELCOME_MAX_ENTRIES;
++
++ /* find first empty spot */
++ for (i = namearray; i <= end; i++) {
++ if (WelcomeIsEmpty(i)) {
++ empty = i;
++ break;
++ }
++ }
++
++ /* no empty spot, need to unset last */
++ if (empty == -1) {
++ welcome_unset(cptr, sptr, end, namearray, timestamp, who, flags);
++ empty = end;
++ }
++
++ /* move entries down, update timestamp */
++ for (i = empty; i > namearray; i--)
++ welcome_make(i, WelcomeArray[i-1].text, WelcomeArray[i-1].who, timestamp);
++
++ /* correct empty for local offset */
++ if (flags & WELCOME_LOCAL)
++ empty -= WELCOME_MAX_ENTRIES;
++
++ /* create msg for log */
++ if (nameint == empty)
++ ircd_snprintf(0, msg, 0, "moving %s WELCOME message %d one place down",
++ (flags & WELCOME_LOCAL) ? "local" : "global", nameint);
++ else
++ ircd_snprintf(0, msg, 0, "moving %s WELCOME message %d %s %d one place down",
++ (flags & WELCOME_LOCAL) ? "local" : "global", nameint, (empty - nameint > 1) ? "to" : "and" , empty);
++
++ /* log it */
++ welcome_log(sptr, msg, flags);
++
++ /* set it */
++ welcome_set(cptr, sptr, nameint, namearray, timestamp, who, text, flags);
++
++ return 0;
++}
++
++