]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Reorder local user initialization steps
[user/henk/code/inspircd.git] / src / users.cpp
index 6e282f7c07e483d8560f92abb275ac2ba28b66c7..92276d07c2d555372f8dd9684d810c6c688fe3ce 100644 (file)
@@ -222,10 +222,12 @@ 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)
 {
+       ident = "unknown";
        lastping = 0;
        eh.SetFd(myfd);
        memcpy(&client_sa, client, sizeof(irc::sockets::sockaddrs));
        memcpy(&server_sa, servaddr, sizeof(irc::sockets::sockaddrs));
+       dhost = host = GetIPString();
 }
 
 User::~User()
@@ -586,7 +588,7 @@ void User::Oper(OperInfo* info)
                nick.c_str(), ident.c_str(), host.c_str(), oper->NameStr(), opername.c_str());
        this->WriteNumeric(381, "%s :You are now %s %s", nick.c_str(), strchr("aeiouAEIOU", oper->name[0]) ? "an" : "a", oper->NameStr());
 
-       ServerInstance->Logs->Log("OPER", DEFAULT, "%s!%s@%s opered as type: %s", this->nick.c_str(), this->ident.c_str(), this->host.c_str(), oper->NameStr());
+       ServerInstance->Logs->Log("OPER", DEFAULT, "%s opered as type: %s", GetFullRealHost().c_str(), oper->NameStr());
        ServerInstance->Users->all_opers.push_back(this);
 
        // Expand permissions from config for faster lookup
@@ -621,7 +623,8 @@ void OperInfo::init()
                        AllowedPrivs.insert(mypriv);
                }
 
-               for (unsigned char* c = (unsigned char*)tag->getString("usermodes").c_str(); *c; ++c)
+               std::string modes = tag->getString("usermodes");
+               for (std::string::const_iterator c = modes.begin(); c != modes.end(); ++c)
                {
                        if (*c == '*')
                        {
@@ -633,7 +636,8 @@ void OperInfo::init()
                        }
                }
 
-               for (unsigned char* c = (unsigned char*)tag->getString("chanmodes").c_str(); *c; ++c)
+               modes = tag->getString("chanmodes");
+               for (std::string::const_iterator c = modes.begin(); c != modes.end(); ++c)
                {
                        if (*c == '*')
                        {
@@ -772,10 +776,14 @@ void LocalUser::FullConnect()
 
        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!%s@%s",this->nick.c_str(), ServerInstance->Config->Network.c_str(), this->nick.c_str(), this->ident.c_str(), this->host.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__);
-       this->WriteNumeric(RPL_SERVERVERSION, "%s %s %s %s %s %s", this->nick.c_str(), ServerInstance->Config->ServerName.c_str(), BRANCH, ServerInstance->Modes->UserModeList().c_str(), ServerInstance->Modes->ChannelModeList().c_str(), ServerInstance->Modes->ParaModeList().c_str());
+
+       std::string umlist = ServerInstance->Modes->UserModeList();
+       std::string cmlist = ServerInstance->Modes->ChannelModeList();
+       std::string pmlist = ServerInstance->Modes->ParaModeList();
+       this->WriteNumeric(RPL_SERVERVERSION, "%s %s %s %s %s %s", this->nick.c_str(), ServerInstance->Config->ServerName.c_str(), BRANCH, umlist.c_str(), cmlist.c_str(), pmlist.c_str());
 
        ServerInstance->Config->Send005(this);
        this->WriteNumeric(RPL_YOURUUID, "%s %s :your unique ID", this->nick.c_str(), this->uuid.c_str());
@@ -790,13 +798,13 @@ void LocalUser::FullConnect()
        std::vector<std::string> parameters;
        FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, this, true, command));
        if (!MOD_RESULT)
-               ServerInstance->CallCommandHandler(command, parameters, this);
+               ServerInstance->Parser->CallHandler(command, parameters, this);
 
        MOD_RESULT = MOD_RES_PASSTHRU;
        command = "LUSERS";
        FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, this, true, command));
        if (!MOD_RESULT)
-               ServerInstance->CallCommandHandler(command, parameters, this);
+               ServerInstance->Parser->CallHandler(command, parameters, this);
 
        if (ServerInstance->Config->RawLog)
                WriteServ("PRIVMSG %s :*** Raw I/O logging is enabled on this server. All messages, passwords, and commands are being recorded.", nick.c_str());
@@ -811,8 +819,8 @@ void LocalUser::FullConnect()
 
        FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
 
-       ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d (class %s): %s!%s@%s (%s) [%s]",
-               this->GetServerPort(), this->MyClass->name.c_str(), this->nick.c_str(), this->ident.c_str(), this->host.c_str(), this->GetIPString(), this->fullname.c_str());
+       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());
        ServerInstance->BanCache->AddHit(this->GetIPString(), "", "");
        // reset the flood penalty (which could have been raised due to things like auto +x)
@@ -867,8 +875,8 @@ bool User::ChangeNick(const std::string& newnick, bool force)
                        {
                                if (this->registered == REG_ALL)
                                {
-                                       ServerInstance->SNO->WriteGlobalSno('a', "Q-Lined nickname %s from %s!%s@%s: %s",
-                                               newnick.c_str(), this->nick.c_str(), this->ident.c_str(), this->host.c_str(), mq->reason.c_str());
+                                       ServerInstance->SNO->WriteGlobalSno('a', "Q-Lined nickname %s from %s: %s",
+                                               newnick.c_str(), GetFullRealHost().c_str(), mq->reason.c_str());
                                }
                                this->WriteNumeric(432, "%s %s :Invalid nickname: %s",this->nick.c_str(), newnick.c_str(), mq->reason.c_str());
                                return false;
@@ -980,10 +988,38 @@ irc::sockets::cidr_mask User::GetCIDRMask()
 
 bool User::SetClientIP(const char* sip)
 {
-       this->cachedip = "";
+       cachedip.clear();
+       cached_hostip.clear();
        return irc::sockets::aptosa(sip, 0, client_sa);
 }
 
+void User::SetClientIP(const irc::sockets::sockaddrs& sa)
+{
+       cachedip.clear();
+       cached_hostip.clear();
+       memcpy(&client_sa, &sa, sizeof(irc::sockets::sockaddrs));
+}
+
+bool LocalUser::SetClientIP(const char* sip)
+{
+       irc::sockets::sockaddrs sa;
+       if (!irc::sockets::aptosa(sip, 0, sa))
+               // Invalid
+               return false;
+
+       LocalUser::SetClientIP(sa);
+       return true;
+}
+
+void LocalUser::SetClientIP(const irc::sockets::sockaddrs& sa)
+{
+       if (sa != client_sa)
+       {
+               User::SetClientIP(sa);
+               FOREACH_MOD(I_OnSetUserIP,OnSetUserIP(this));
+       }
+}
+
 static std::string wide_newline("\r\n");
 
 void User::Write(const std::string& text)
@@ -1470,7 +1506,8 @@ void User::SendAll(const char* command, const char* text, ...)
 
        for (std::vector<LocalUser*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
        {
-               (*i)->Write(fmt);
+               if ((*i)->registered == REG_ALL)
+                       (*i)->Write(fmt);
        }
 }