+/* chanrec::PartUser
+ * remove a channel from a users record, and remove the record from the hash
+ * if the channel has become empty
+ */
+long chanrec::PartUser(userrec *user, const char* reason)
+{
+ if (!user)
+ return this->GetUserCounter();
+
+ for (unsigned int i =0; i < user->chans.size(); i++)
+ {
+ /* zap it from the channel list of the user */
+ if (user->chans[i]->channel == this)
+ {
+ if (reason)
+ {
+ FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason));
+ this->WriteChannel(user, "PART %s :%s", this->name, reason);
+ }
+ else
+ {
+ FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, ""));
+ this->WriteChannel(user, "PART :%s", this->name);
+ }
+ user->chans[i]->uc_modes = 0;
+ user->chans[i]->channel = NULL;
+ this->RemoveAllPrefixes(user);
+ break;
+ }
+ }
+
+ if (!this->DelUser(user)) /* if there are no users left on the channel... */
+ {
+ chan_hash::iterator iter = ServerInstance->chanlist.find(this->name);
+ /* kill the record */
+ if (iter != ServerInstance->chanlist.end())
+ {
+ ServerInstance->Log(DEBUG,"del_channel: destroyed: %s", this->name);
+ FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(this));
+ ServerInstance->chanlist.erase(iter);
+ }
+ return 0;
+ }
+
+ return this->GetUserCounter();
+}
+
+long chanrec::ServerKickUser(userrec* user, const char* reason, bool triggerevents)
+{
+ if (!user || !reason)
+ return this->GetUserCounter();
+
+ if (IS_LOCAL(user))
+ {
+ if (!this->HasUser(user))
+ {
+ /* Not on channel */
+ return this->GetUserCounter();
+ }
+ }
+
+ if (triggerevents)
+ {
+ FOREACH_MOD(I_OnUserKick,OnUserKick(NULL,user,this,reason));
+ }
+
+ for (unsigned int i =0; i < user->chans.size(); i++)
+ {
+ if (user->chans[i]->channel == this)
+ {
+ this->WriteChannelWithServ(ServerInstance->Config->ServerName, "KICK %s %s :%s", this->name, user->nick, reason);
+ user->chans[i]->uc_modes = 0;
+ user->chans[i]->channel = NULL;
+ this->RemoveAllPrefixes(user);
+ break;
+ }
+ }
+
+ if (!this->DelUser(user))
+ {
+ chan_hash::iterator iter = ServerInstance->chanlist.find(this->name);
+ /* kill the record */
+ if (iter != ServerInstance->chanlist.end())
+ {
+ FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(this));
+ ServerInstance->chanlist.erase(iter);
+ }
+ return 0;
+ }
+
+ return this->GetUserCounter();
+}
+
+long chanrec::KickUser(userrec *src, userrec *user, const char* reason)