]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Release v3.0.0 release candidate 1.
[user/henk/code/inspircd.git] / src / users.cpp
index 1ddd3ca0ef99864d0c1da9a87b8ede2654be3c96..f11a7a38079e43d3fba28c9fc914f1ce0fcc3deb 100644 (file)
@@ -357,10 +357,12 @@ CullResult FakeUser::cull()
 void User::Oper(OperInfo* info)
 {
        ModeHandler* opermh = ServerInstance->Modes->FindMode('o', MODETYPE_USER);
-       if (this->IsModeSet(opermh))
-               this->UnOper();
-
-       this->SetMode(opermh, true);
+       if (opermh)
+       {
+               if (this->IsModeSet(opermh))
+                       this->UnOper();
+               this->SetMode(opermh, true);
+       }
        this->oper = info;
 
        LocalUser* localuser = IS_LOCAL(this);
@@ -474,7 +476,8 @@ void User::UnOper()
        stdalgo::vector::swaperase(ServerInstance->Users->all_opers, this);
 
        ModeHandler* opermh = ServerInstance->Modes->FindMode('o', MODETYPE_USER);
-       this->SetMode(opermh, false);
+       if (opermh)
+               this->SetMode(opermh, false);
        FOREACH_MOD(OnPostDeoper, (this));
 }
 
@@ -722,21 +725,31 @@ irc::sockets::cidr_mask User::GetCIDRMask()
 
 bool User::SetClientIP(const std::string& address, bool recheck_eline)
 {
-       this->InvalidateCache();
-       return irc::sockets::aptosa(address, 0, client_sa);
+       irc::sockets::sockaddrs sa;
+       if (!irc::sockets::aptosa(address, client_sa.port(), sa))
+               return false;
+
+       User::SetClientIP(sa, recheck_eline);
+       return true;
 }
 
 void User::SetClientIP(const irc::sockets::sockaddrs& sa, bool recheck_eline)
 {
-       this->InvalidateCache();
+       const std::string oldip(GetIPString());
        memcpy(&client_sa, &sa, sizeof(irc::sockets::sockaddrs));
+       this->InvalidateCache();
+
+       // If the users hostname was their IP then update it.
+       if (GetRealHost() == oldip)
+               ChangeRealHost(GetIPString(), false);
+       if (GetDisplayedHost() == oldip)
+               ChangeDisplayedHost(GetIPString());
 }
 
 bool LocalUser::SetClientIP(const std::string& address, bool recheck_eline)
 {
        irc::sockets::sockaddrs sa;
-       if (!irc::sockets::aptosa(address, 0, sa))
-               // Invalid
+       if (!irc::sockets::aptosa(address, client_sa.port(), sa))
                return false;
 
        LocalUser::SetClientIP(sa, recheck_eline);
@@ -1151,8 +1164,6 @@ void User::PurgeEmptyChannels()
                ++i;
                c->DelUser(this);
        }
-
-       this->UnOper();
 }
 
 void User::WriteNotice(const std::string& text)