]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Add builtin modes using AddService()
[user/henk/code/inspircd.git] / src / users.cpp
index e55c7e0997346412daca37b43e35caddb6126f66..5058cfcc24503d18da5265b1aca3d8769af26b4e 100644 (file)
@@ -28,7 +28,6 @@
 #include "socketengine.h"
 #include "xline.h"
 #include "bancache.h"
-#include "commands/cmd_whowas.h"
 
 already_sent_t LocalUser::already_sent_id = 0;
 
@@ -114,11 +113,10 @@ void LocalUser::StartDNSLookup()
        try
        {
                bool cached = false;
-               const char* sip = this->GetIPString();
                UserResolver *res_reverse;
 
                QueryType resolvtype = this->client_sa.sa.sa_family == AF_INET6 ? DNS_QUERY_PTR6 : DNS_QUERY_PTR4;
-               res_reverse = new UserResolver(this, sip, resolvtype, cached);
+               res_reverse = new UserResolver(this, this->GetIPString(), resolvtype, cached);
 
                ServerInstance->AddResolver(res_reverse, cached);
        }
@@ -202,10 +200,9 @@ User::User(const std::string &uid, const std::string& sid, int type)
        : uuid(uid), server(sid), usertype(type)
 {
        age = ServerInstance->Time();
-       signon = idle_lastmsg = 0;
+       signon = 0;
        registered = 0;
-       quietquit = quitting = exempt = dns_done = false;
-       quitting_sendq = false;
+       quietquit = quitting = false;
        client_sa.sa.sa_family = AF_UNSPEC;
 
        ServerInstance->Logs->Log("USERS", DEBUG, "New UUID for user: %s", uuid.c_str());
@@ -223,6 +220,8 @@ LocalUser::LocalUser(int myfd, irc::sockets::sockaddrs* client, irc::sockets::so
        bytes_in(0), bytes_out(0), cmds_in(0), cmds_out(0), nping(0), CommandFloodPenalty(0),
        already_sent(0)
 {
+       exempt = quitting_sendq = dns_done = false;
+       idle_lastmsg = 0;
        ident = "unknown";
        lastping = 0;
        eh.SetFd(myfd);
@@ -268,7 +267,7 @@ const std::string& User::MakeHostIP()
        for(const char* n = ident.c_str(); *n; n++)
                *t++ = *n;
        *t++ = '@';
-       for(const char* n = this->GetIPString(); *n; n++)
+       for(const char* n = this->GetIPString().c_str(); *n; n++)
                *t++ = *n;
        *t = 0;
 
@@ -688,18 +687,6 @@ void User::UnOper()
        this->modes[UM_OPERATOR] = 0;
 }
 
-/* adds or updates an entry in the whowas list */
-void User::AddToWhoWas()
-{
-       Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so");
-       if (whowas)
-       {
-               WhowasRequest req(NULL, whowas, WhowasRequest::WHOWAS_ADD);
-               req.user = this;
-               req.Send();
-       }
-}
-
 /*
  * Check class restrictions
  */
@@ -721,21 +708,21 @@ void LocalUser::CheckClass()
        {
                ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (local)");
                if (a->maxconnwarn)
-                       ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
+                       ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString().c_str());
                return;
        }
        else if ((a->GetMaxGlobal()) && (ServerInstance->Users->GlobalCloneCount(this) > a->GetMaxGlobal()))
        {
                ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (global)");
                if (a->maxconnwarn)
-                       ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
+                       ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString().c_str());
                return;
        }
 
        this->nping = ServerInstance->Time() + a->GetPingTime() + ServerInstance->Config->dns_timeout;
 }
 
-bool User::CheckLines(bool doZline)
+bool LocalUser::CheckLines(bool doZline)
 {
        const char* check[] = { "G" , "K", (doZline) ? "Z" : NULL, NULL };
 
@@ -775,8 +762,6 @@ void LocalUser::FullConnect()
        if (quitting)
                return;
 
-       if (ServerInstance->Config->WelcomeNotice)
-               this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network.c_str());
        this->WriteNumeric(RPL_WELCOME, "%s :Welcome to the %s IRC Network %s",this->nick.c_str(), ServerInstance->Config->Network.c_str(), GetFullRealHost().c_str());
        this->WriteNumeric(RPL_YOURHOSTIS, "%s :Your host is %s, running version %s",this->nick.c_str(),ServerInstance->Config->ServerName.c_str(),BRANCH);
        this->WriteNumeric(RPL_SERVERCREATED, "%s :This server was created %s %s", this->nick.c_str(), __TIME__, __DATE__);
@@ -795,14 +780,14 @@ void LocalUser::FullConnect()
 
        /* Trigger MOTD and LUSERS output, give modules a chance too */
        ModResult MOD_RESULT;
-       std::string command("MOTD");
+       std::string command("LUSERS");
        std::vector<std::string> parameters;
        FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, this, true, command));
        if (!MOD_RESULT)
                ServerInstance->Parser->CallHandler(command, parameters, this);
 
        MOD_RESULT = MOD_RES_PASSTHRU;
-       command = "LUSERS";
+       command = "MOTD";
        FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, this, true, command));
        if (!MOD_RESULT)
                ServerInstance->Parser->CallHandler(command, parameters, this);
@@ -821,8 +806,8 @@ void LocalUser::FullConnect()
        FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
 
        ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d (class %s): %s (%s) [%s]",
-               this->GetServerPort(), this->MyClass->name.c_str(), GetFullRealHost().c_str(), this->GetIPString(), this->fullname.c_str());
-       ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCache: Adding NEGATIVE hit for %s", this->GetIPString());
+               this->GetServerPort(), this->MyClass->name.c_str(), GetFullRealHost().c_str(), this->GetIPString().c_str(), this->fullname.c_str());
+       ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCache: Adding NEGATIVE hit for " + this->GetIPString());
        ServerInstance->BanCache->AddHit(this->GetIPString(), "", "");
        // reset the flood penalty (which could have been raised due to things like auto +x)
        CommandFloodPenalty = 0;
@@ -958,18 +943,18 @@ int LocalUser::GetServerPort()
        return 0;
 }
 
-const char* User::GetIPString()
+const std::string& User::GetIPString()
 {
        int port;
        if (cachedip.empty())
        {
                irc::sockets::satoap(client_sa, cachedip, port);
                /* IP addresses starting with a : on irc are a Bad Thing (tm) */
-               if (cachedip.c_str()[0] == ':')
+               if (cachedip[0] == ':')
                        cachedip.insert(0,1,'0');
        }
 
-       return cachedip.c_str();
+       return cachedip;
 }
 
 irc::sockets::cidr_mask User::GetCIDRMask()
@@ -987,36 +972,39 @@ irc::sockets::cidr_mask User::GetCIDRMask()
        return irc::sockets::cidr_mask(client_sa, range);
 }
 
-bool User::SetClientIP(const char* sip)
+bool User::SetClientIP(const char* sip, bool recheck_eline)
 {
        cachedip.clear();
        cached_hostip.clear();
        return irc::sockets::aptosa(sip, 0, client_sa);
 }
 
-void User::SetClientIP(const irc::sockets::sockaddrs& sa)
+void User::SetClientIP(const irc::sockets::sockaddrs& sa, bool recheck_eline)
 {
        cachedip.clear();
        cached_hostip.clear();
        memcpy(&client_sa, &sa, sizeof(irc::sockets::sockaddrs));
 }
 
-bool LocalUser::SetClientIP(const char* sip)
+bool LocalUser::SetClientIP(const char* sip, bool recheck_eline)
 {
        irc::sockets::sockaddrs sa;
        if (!irc::sockets::aptosa(sip, 0, sa))
                // Invalid
                return false;
 
-       LocalUser::SetClientIP(sa);
+       LocalUser::SetClientIP(sa, recheck_eline);
        return true;
 }
 
-void LocalUser::SetClientIP(const irc::sockets::sockaddrs& sa)
+void LocalUser::SetClientIP(const irc::sockets::sockaddrs& sa, bool recheck_eline)
 {
        if (sa != client_sa)
        {
                User::SetClientIP(sa);
+               if (recheck_eline)
+                       this->exempt = (ServerInstance->XLines->MatchesLine("E", this) != NULL);
+
                FOREACH_MOD(I_OnSetUserIP,OnSetUserIP(this));
        }
 }
@@ -1483,7 +1471,7 @@ bool User::ChangeIdent(const char* newident)
 
        std::string quitstr = ":" + GetFullHost() + " QUIT :Changing ident";
 
-       this->ident.assign(newident, 0, ServerInstance->Config->Limits.IdentMax + 1);
+       this->ident.assign(newident, 0, ServerInstance->Config->Limits.IdentMax);
 
        this->InvalidateCache();