+ int MOD_RESULT = 0;
+ FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
+ if (MOD_RESULT == 1)
+ return 1; // delete halted by module
+ FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
+ ServerInstance->chanlist->erase(iter);
+ }
+ return 0;
+ }
+
+ return this->GetUserCounter();
+}
+
+void Channel::WriteChannel(User* user, const char* text, ...)
+{
+ char textbuffer[MAXBUF];
+ va_list argsPtr;
+
+ if (!user || !text)
+ return;
+
+ va_start(argsPtr, text);
+ vsnprintf(textbuffer, MAXBUF, text, argsPtr);
+ va_end(argsPtr);
+
+ this->WriteChannel(user, std::string(textbuffer));
+}
+
+void Channel::WriteChannel(User* user, const std::string &text)
+{
+ CUList *ulist = this->GetUsers();
+ char tb[MAXBUF];
+
+ if (!user)
+ return;
+
+ snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
+ std::string out = tb;
+
+ for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
+ {
+ if (IS_LOCAL(i->first))
+ i->first->Write(out);
+ }
+}
+
+void Channel::WriteChannelWithServ(const char* ServName, const char* text, ...)
+{
+ char textbuffer[MAXBUF];
+ va_list argsPtr;
+
+ if (!text)
+ return;
+
+ va_start(argsPtr, text);
+ vsnprintf(textbuffer, MAXBUF, text, argsPtr);
+ va_end(argsPtr);
+
+ this->WriteChannelWithServ(ServName, std::string(textbuffer));
+}
+
+void Channel::WriteChannelWithServ(const char* ServName, const std::string &text)
+{
+ CUList *ulist = this->GetUsers();
+ char tb[MAXBUF];
+
+ snprintf(tb,MAXBUF,":%s %s", ServName ? ServName : ServerInstance->Config->ServerName, text.c_str());
+ std::string out = tb;
+
+ for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
+ {
+ if (IS_LOCAL(i->first))
+ i->first->Write(out);
+ }
+}
+
+/* write formatted text from a source user to all users on a channel except
+ * for the sender (for privmsg etc) */
+void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...)
+{
+ char textbuffer[MAXBUF];
+ va_list argsPtr;
+
+ if (!text)
+ return;
+
+ va_start(argsPtr, text);
+ vsnprintf(textbuffer, MAXBUF, text, argsPtr);
+ va_end(argsPtr);
+
+ this->WriteAllExceptSender(user, serversource, status, std::string(textbuffer));
+}
+
+void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...)
+{
+ char textbuffer[MAXBUF];
+ va_list argsPtr;
+
+ if (!text)
+ return;
+
+ va_start(argsPtr, text);
+ vsnprintf(textbuffer, MAXBUF, text, argsPtr);
+ va_end(argsPtr);
+
+ this->WriteAllExcept(user, serversource, status, except_list, std::string(textbuffer));
+}
+
+void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
+{
+ CUList *ulist = this->GetUsers();
+ char tb[MAXBUF];
+
+ snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
+ std::string out = tb;
+
+ for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
+ {
+ if ((IS_LOCAL(i->first)) && (except_list.find(i->first) == except_list.end()))
+ {
+ /* User doesnt have the status we're after */
+ if (status && !strchr(this->GetAllPrefixChars(i->first), status))
+ continue;
+
+ if (serversource)
+ i->first->WriteServ(text);
+ else
+ i->first->Write(out);
+ }
+ }
+}
+
+void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text)
+{
+ CUList except_list;
+ except_list[user] = user->nick;
+ 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;
+ CUList *ulist= this->GetUsers();
+ for (CUList::iterator i = ulist->begin(); i != ulist->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();
+ switch (n)