+ if (ServerInstance->Config->RestrictBannedUsers)
+ {
+ for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
+ {
+ Channel *chan = *i;
+ if (chan->GetPrefixValue(this) < VOICE_VALUE && chan->IsBanned(this))
+ {
+ this->WriteNumeric(404, "%s %s :Cannot send to channel (you're banned)", this->nick.c_str(), chan->name.c_str());
+ return false;
+ }
+ }
+ }
+ }
+
+ /*
+ * Uh oh.. if the nickname is in use, and it's not in use by the person using it (doh) --
+ * then we have a potential collide. Check whether someone else is camping on the nick
+ * (i.e. connect -> send NICK, don't send USER.) If they are camping, force-change the
+ * camper to their UID, and allow the incoming nick change.
+ *
+ * If the guy using the nick is already using it, tell the incoming nick change to gtfo,
+ * because the nick is already (rightfully) in use. -- w00t
+ */
+ User* InUse = ServerInstance->FindNickOnly(newnick);
+ if (InUse && (InUse != this))
+ {
+ if (InUse->registered != REG_ALL)
+ {
+ /* force the camper to their UUID, and ask them to re-send a NICK. */
+ InUse->WriteTo(InUse, "NICK %s", InUse->uuid.c_str());
+ InUse->WriteNumeric(433, "%s %s :Nickname overruled.", InUse->nick.c_str(), InUse->nick.c_str());
+
+ ServerInstance->Users->clientlist->erase(InUse->nick);
+ (*(ServerInstance->Users->clientlist))[InUse->uuid] = InUse;
+
+ InUse->nick = InUse->uuid;
+ InUse->InvalidateCache();
+ InUse->registered &= ~REG_NICK;
+ }
+ else
+ {
+ /* No camping, tell the incoming user to stop trying to change nick ;p */
+ this->WriteNumeric(433, "%s %s :Nickname is already in use.", this->registered >= REG_NICK ? this->nick.c_str() : "*", newnick.c_str());
+ return false;
+ }
+ }
+ }
+
+ if (this->registered == REG_ALL)
+ this->WriteCommon("NICK %s",newnick.c_str());
+ std::string oldnick = nick;
+ nick = newnick;
+
+ InvalidateCache();
+ ServerInstance->Users->clientlist->erase(oldnick);
+ (*(ServerInstance->Users->clientlist))[newnick] = this;
+
+ if (registered == REG_ALL)
+ FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(this,oldnick));
+
+ return true;