+/**
+ * Announce a channel and its users in the network.
+ */
+static bool
+Announce_Channel(CLIENT *Client, CHANNEL *Chan)
+{
+ CL2CHAN *cl2chan;
+ CLIENT *cl;
+ char str[COMMAND_LEN], *ptr;
+ bool njoin, xop;
+
+ /* Check features of remote server */
+ njoin = Conn_Options(Client_Conn(Client)) & CONN_RFC1459 ? false : true;
+ xop = Client_HasFlag(Client, 'X') ? true : false;
+
+ /* Get all the members of this channel */
+ cl2chan = Channel_FirstMember(Chan);
+ snprintf(str, sizeof(str), "NJOIN %s :", Channel_Name(Chan));
+ while (cl2chan) {
+ cl = Channel_GetClient(cl2chan);
+ assert(cl != NULL);
+
+ if (njoin) {
+ /* RFC 2813: send NJOIN with nicknames and modes
+ * (if user is channel operator or has voice) */
+ if (str[strlen(str) - 1] != ':')
+ strlcat(str, ",", sizeof(str));
+
+ /* Prepare user prefix (ChanOp, voiced, ...) */
+ if (xop && Channel_UserHasMode(Chan, cl, 'q'))
+ strlcat(str, "~", sizeof(str));
+ if (xop && Channel_UserHasMode(Chan, cl, 'a'))
+ strlcat(str, "&", sizeof(str));
+ if (Channel_UserHasMode(Chan, cl, 'o'))
+ strlcat(str, "@", sizeof(str));
+ if (xop && Channel_UserHasMode(Chan, cl, 'h'))
+ strlcat(str, "%", sizeof(str));
+ if (Channel_UserHasMode(Chan, cl, 'v'))
+ strlcat(str, "+", sizeof(str));