]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Deduplicate nickname overruling code
authorAttila Molnar <attilamolnar@hush.com>
Fri, 30 Dec 2016 17:44:39 +0000 (18:44 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Fri, 30 Dec 2016 17:44:39 +0000 (18:44 +0100)
Create LocalUser::OverruleNick(), call it from User::ChangeNick() and the UID handler in spanningtree

include/users.h
src/modules/m_spanningtree/uid.cpp
src/users.cpp

index fc31a8297448a546b6e5aa57e0a0771fac1ad40d..8cf78a585c890807a12318c0924434932d88a8aa 100644 (file)
@@ -872,6 +872,12 @@ class CoreExport LocalUser : public User, public insp::intrusive_list_node<Local
         * @return True if the user can set or unset this mode.
         */
        bool HasModePermission(const ModeHandler* mh) const;
         * @return True if the user can set or unset this mode.
         */
        bool HasModePermission(const ModeHandler* mh) const;
+
+       /** Change nick to uuid, unset REG_NICK and send a nickname overruled numeric.
+        * This is called when another user (either local or remote) needs the nick of this user and this user
+        * isn't registered.
+        */
+       void OverruleNick();
 };
 
 class RemoteUser : public User
 };
 
 class RemoteUser : public User
index a41fe408d990a3525cd6d97863a878f2720a4c64..6f59fcd50cf7853cbe2eb1323d073ecc6531540b 100644 (file)
@@ -50,12 +50,8 @@ CmdResult CommandUID::HandleServer(TreeServer* remoteserver, std::vector<std::st
        {
                // User that the incoming user is colliding with is not fully registered, we force nick change the
                // unregistered user to their uuid and tell them what happened
        {
                // User that the incoming user is colliding with is not fully registered, we force nick change the
                // unregistered user to their uuid and tell them what happened
-               collideswith->WriteFrom(collideswith, "NICK %s", collideswith->uuid.c_str());
-               collideswith->WriteNumeric(ERR_NICKNAMEINUSE, collideswith->nick, "Nickname overruled.");
-
-               // Clear the bit before calling User::ChangeNick() to make it NOT run the OnUserPostNick() hook
-               collideswith->registered &= ~REG_NICK;
-               collideswith->ChangeNick(collideswith->uuid);
+               LocalUser* const localuser = static_cast<LocalUser*>(collideswith);
+               localuser->OverruleNick();
        }
        else if (collideswith)
        {
        }
        else if (collideswith)
        {
index 498a27d582b87bd578e9c56716e807a4772eea9d..06a1c1149d93e67f3a363c300d0eaa8bddd7fa0f 100644 (file)
@@ -627,11 +627,8 @@ bool User::ChangeNick(const std::string& newnick, time_t newts)
                        if (InUse->registered != REG_ALL)
                        {
                                /* force the camper to their UUID, and ask them to re-send a NICK. */
                        if (InUse->registered != REG_ALL)
                        {
                                /* force the camper to their UUID, and ask them to re-send a NICK. */
-                               InUse->WriteFrom(InUse, "NICK %s", InUse->uuid.c_str());
-                               InUse->WriteNumeric(ERR_NICKNAMEINUSE, InUse->nick, "Nickname overruled.");
-
-                               InUse->registered &= ~REG_NICK;
-                               InUse->ChangeNick(InUse->uuid);
+                               LocalUser* const localuser = static_cast<LocalUser*>(InUse);
+                               localuser->OverruleNick();
                        }
                        else
                        {
                        }
                        else
                        {
@@ -659,6 +656,16 @@ bool User::ChangeNick(const std::string& newnick, time_t newts)
        return true;
 }
 
        return true;
 }
 
+void LocalUser::OverruleNick()
+{
+       this->WriteFrom(this, "NICK %s", this->uuid.c_str());
+       this->WriteNumeric(ERR_NICKNAMEINUSE, this->nick, "Nickname overruled.");
+
+       // Clear the bit before calling ChangeNick() to make it NOT run the OnUserPostNick() hook
+       this->registered &= ~REG_NICK;
+       this->ChangeNick(this->uuid);
+}
+
 int LocalUser::GetServerPort()
 {
        switch (this->server_sa.sa.sa_family)
 int LocalUser::GetServerPort()
 {
        switch (this->server_sa.sa.sa_family)