+ if (!text)
+ return;
+
+ int offset = snprintf(textbuffer,MAXBUF,":%s ", user->GetFullHost().c_str());
+
+ va_start(argsPtr, text);
+ vsnprintf(textbuffer + offset, MAXBUF - offset, text, argsPtr);
+ va_end(argsPtr);
+
+ this->RawWriteAllExcept(user, serversource, status, except_list, std::string(textbuffer));
+}
+
+void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
+{
+ char tb[MAXBUF];
+
+ snprintf(tb,MAXBUF,":%s %s", serversource ? ServerInstance->Config->ServerName.c_str() : user->GetFullHost().c_str(), text.c_str());
+ std::string out = tb;
+
+ this->RawWriteAllExcept(user, serversource, status, except_list, std::string(tb));
+}
+
+void Channel::RawWriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &out)
+{
+ unsigned int minrank = 0;
+ if (status)
+ {
+ ModeHandler* mh = ServerInstance->Modes->FindPrefix(status);
+ if (mh)
+ minrank = mh->GetPrefixRank();
+ }
+ for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
+ {
+ if (IS_LOCAL(i->first) && (except_list.find(i->first) == except_list.end()))
+ {
+ /* User doesn't have the status we're after */
+ if (minrank && i->second->getRank() < minrank)
+ continue;
+
+ i->first->Write(out);
+ }
+ }
+}
+
+void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text)
+{
+ CUList except_list;
+ except_list.insert(user);
+ this->WriteAllExcept(user, serversource, status, except_list, std::string(text));
+}
+
+/*
+ * return a count of the users on a specific channel accounting for
+ * invisible users who won't increase the count. e.g. for /LIST
+ */
+int Channel::CountInvisible()
+{
+ int count = 0;
+ for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
+ {
+ if (!(i->first->IsModeSet('i')))
+ count++;
+ }
+
+ return count;
+}
+
+char* Channel::ChanModes(bool showkey)
+{
+ static char scratch[MAXBUF];
+ static char sparam[MAXBUF];
+ char* offset = scratch;
+ std::string extparam;
+
+ *scratch = '\0';
+ *sparam = '\0';
+
+ /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
+ for(int n = 0; n < 64; n++)
+ {
+ if(this->modes[n])
+ {
+ *offset++ = n + 65;
+ extparam.clear();
+ if (n == 'k' - 65 && !showkey)
+ {
+ extparam = "<key>";
+ }
+ else
+ {
+ extparam = this->GetModeParameter(n + 65);
+ }
+ if (!extparam.empty())
+ {
+ charlcat(sparam,' ',MAXBUF);
+ strlcat(sparam,extparam.c_str(),MAXBUF);
+ }
+ }
+ }
+
+ /* Null terminate scratch */
+ *offset = '\0';
+ strlcat(scratch,sparam,MAXBUF);
+ return scratch;
+}
+
+/* compile a userlist of a channel into a string, each nick seperated by
+ * spaces and op, voice etc status shown as @ and +, and send it to 'user'
+ */
+void Channel::UserList(User *user)
+{
+ char list[MAXBUF];
+ size_t dlen, curlen;
+
+ if (!IS_LOCAL(user))