]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Fix server prefix on JOIN.
[user/henk/code/inspircd.git] / src / users.cpp
index 4bfb8955a666b5b663dc0d15a3962a8d3e9d30a7..4a77b450f2422304cbebdcb9dd434595129c9831 100644 (file)
@@ -2,14 +2,11 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- *                    E-mail:
- *             <brain@chatspike.net>
- *               <Craig@chatspike.net>
- *     
- * Written by Craig Edwards, Craig McLure, and others.
+ *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
  * This program is free but copyrighted software; see
- *         the file COPYING for details.
+ *            the file COPYING for details.
  *
  * ---------------------------------------------------
  */
@@ -156,7 +153,7 @@ void userrec::StartDNSLookup()
                res_reverse = new UserResolver(this->ServerInstance, this, this->GetIPString(), DNS_QUERY_REVERSE);
                this->ServerInstance->AddResolver(res_reverse);
        }
-       catch (ModuleException& e)
+       catch (CoreException& e)
        {
                ServerInstance->Log(DEBUG,"Error in resolver: %s",e.GetReason());
        }
@@ -189,7 +186,7 @@ void UserResolver::OnLookupComplete(const std::string &result)
                                this->ServerInstance->AddResolver(bound_user->res_forward);
                        }
                }
-               catch (ModuleException& e)
+               catch (CoreException& e)
                {
                        ServerInstance->Log(DEBUG,"Error in resolver: %s",e.GetReason());
                }
@@ -439,13 +436,11 @@ char* userrec::GetFullRealHost()
        return fresult;
 }
 
-bool userrec::IsInvited(irc::string &channel)
+bool userrec::IsInvited(const irc::string &channel)
 {
        for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
        {
-               irc::string compare = i->channel;
-               
-               if (compare == channel)
+               if (channel == *i)
                {
                        return true;
                }
@@ -458,30 +453,22 @@ InvitedList* userrec::GetInviteList()
        return &invites;
 }
 
-void userrec::InviteTo(irc::string &channel)
+void userrec::InviteTo(const irc::string &channel)
 {
-       Invited i;
-       i.channel = channel;
-       invites.push_back(i);
+       invites.push_back(channel);
 }
 
-void userrec::RemoveInvite(irc::string &channel)
+void userrec::RemoveInvite(const irc::string &channel)
 {
        ServerInstance->Log(DEBUG,"Removing invites");
-       
-       if (invites.size())
+       for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
        {
-               for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
+               if (channel == *i)
                {
-                       irc::string compare = i->channel;
-                       
-                       if (compare == channel)
-                       {
-                               invites.erase(i);
-                               return;
-                               }
-                       }
-               }
+                       invites.erase(i);
+                       return;
+               }
+       }
 }
 
 bool userrec::HasPermission(const std::string &command)
@@ -667,21 +654,26 @@ void userrec::FlushWriteBuf()
                        {
                                if (errno == EAGAIN)
                                {
+                                       /* The socket buffer is full. This isnt fatal,
+                                        * try again later.
+                                        */
                                        ServerInstance->Log(DEBUG,"EAGAIN, want write");
                                        this->ServerInstance->SE->WantWrite(this);
                                }
                                else
                                {
-                                       this->QuitUser(ServerInstance, this, strerror(errno));
+                                       /* Fatal error, set write error and bail
+                                        */
+                                       this->SetWriteError(strerror(errno));
                                        return;
                                }
                        }
                        else
                        {
-                               // advance the queue
+                               /* advance the queue */
                                if (n_sent)
                                        this->sendq = this->sendq.substr(n_sent);
-                               // update the user's stats counters
+                               /* update the user's stats counters */
                                this->bytes_out += n_sent;
                                this->cmds_out++;
                                if (n_sent != old_sendq_length)
@@ -703,7 +695,6 @@ void userrec::SetWriteError(const std::string &error)
 {
        try
        {
-               ServerInstance->Log(DEBUG,"SetWriteError: %s",error.c_str());
                // don't try to set the error twice, its already set take the first string.
                if (this->WriteError.empty())
                {
@@ -777,13 +768,17 @@ void userrec::QuitUser(InspIRCd* Instance, userrec *user, const std::string &qui
                reason.resize(MAXQUIT - 1);
        
        if (IS_LOCAL(user))
+       {
                user->Write("ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,reason.c_str());
+               if ((!user->sendq.empty()) && (!(*user->GetWriteError())))
+                       user->FlushWriteBuf();
+       }
 
        if (user->registered == REG_ALL)
        {
                user->PurgeEmptyChannels();
-               FOREACH_MOD_I(Instance,I_OnUserQuit,OnUserQuit(user,reason));
                user->WriteCommonExcept("QUIT :%s",reason.c_str());
+               FOREACH_MOD_I(Instance,I_OnUserQuit,OnUserQuit(user,reason));
        }
 
        FOREACH_MOD_I(Instance,I_OnUserDisconnect,OnUserDisconnect(user));
@@ -796,9 +791,9 @@ void userrec::QuitUser(InspIRCd* Instance, userrec *user, const std::string &qui
                        {
                                Instance->Config->GetIOHook(user->GetPort())->OnRawSocketClose(user->fd);
                        }
-                       catch (ModuleException& modexcept)
+                       catch (CoreException& modexcept)
                        {
-                               Instance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason());
+                               Instance->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
                        }
                }
                
@@ -1327,7 +1322,6 @@ int userrec::GetPort()
                }
                break;
                default:
-                       ServerInstance->Log(DEBUG,"Ut oh, '%s' has an unknown protocol family!",this->nick);
                break;
        }
        return 0;
@@ -1377,7 +1371,6 @@ const char* userrec::GetIPString()
                }
                break;
                default:
-                       ServerInstance->Log(DEBUG,"Ut oh, '%s' has an unknown protocol family!",this->nick);
                break;
        }
        return "";
@@ -1420,7 +1413,6 @@ const char* userrec::GetIPString(char* buf)
                break;
 
                default:
-                       ServerInstance->Log(DEBUG,"Ut oh, '%s' has an unknown protocol family!",this->nick);
                break;
        }
        return "";
@@ -1453,9 +1445,9 @@ void userrec::Write(std::string text)
                {
                        ServerInstance->Config->GetIOHook(this->GetPort())->OnRawSocketWrite(this->fd, text.data(), text.length());
                }
-               catch (ModuleException& modexcept)
+               catch (CoreException& modexcept)
                {
-                       ServerInstance->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason());
+                       ServerInstance->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
                }
        }
        else
@@ -1761,16 +1753,6 @@ bool userrec::SharesChannelWith(userrec *other)
        return false;
 }
 
-int userrec::CountChannels()
-{
-       return ChannelCount;
-}
-
-void userrec::ModChannelCount(int n)
-{
-       ChannelCount += n;
-}
-
 bool userrec::ChangeName(const char* gecos)
 {
        if (!strcmp(gecos, this->fullname))
@@ -2031,13 +2013,14 @@ void userrec::HandleEvent(EventType et, int errornum)
                {
                        case EVENT_READ:
                                ServerInstance->ProcessUser(this);
+
                        break;
                        case EVENT_WRITE:
                                this->FlushWriteBuf();
                        break;
                        case EVENT_ERROR:
                                /** This should be safe, but dont DARE do anything after it -- Brain */
-                               userrec::QuitUser(ServerInstance, this, errornum ? strerror(errornum) : "EOF from client");
+                               this->SetWriteError(errornum ? strerror(errornum) : "EOF from client");
                        break;
                }
        }
@@ -2045,4 +2028,11 @@ void userrec::HandleEvent(EventType et, int errornum)
        {
                ServerInstance->Log(DEBUG,"Exception in userrec::HandleEvent intercepted");
        }
+
+       /* If the user has raised an error whilst being processed, quit them now we're safe to */
+       if (!WriteError.empty())
+       {
+               userrec::QuitUser(ServerInstance, this, GetWriteError());
+       }
 }
+