summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2016-12-30 18:44:39 +0100
committerAttila Molnar <attilamolnar@hush.com>2016-12-30 18:44:39 +0100
commit0c3b041d1b36d1515913da5230399b379a802b81 (patch)
tree0f7b33dab50fda247d8f51edb418bc3c6b5ecb55 /src
parent688275707a331a94892408408eb74d7ec20c7c1f (diff)
Deduplicate nickname overruling code
Create LocalUser::OverruleNick(), call it from User::ChangeNick() and the UID handler in spanningtree
Diffstat (limited to 'src')
-rw-r--r--src/modules/m_spanningtree/uid.cpp8
-rw-r--r--src/users.cpp17
2 files changed, 14 insertions, 11 deletions
diff --git a/src/modules/m_spanningtree/uid.cpp b/src/modules/m_spanningtree/uid.cpp
index a41fe408d..6f59fcd50 100644
--- a/src/modules/m_spanningtree/uid.cpp
+++ b/src/modules/m_spanningtree/uid.cpp
@@ -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
- 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)
{
diff --git a/src/users.cpp b/src/users.cpp
index 498a27d58..06a1c1149 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -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. */
- 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
{
@@ -659,6 +656,16 @@ bool User::ChangeNick(const std::string& newnick, time_t newts)
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)