]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Add WriteNumeric() to User and OnNumeric module event. Note that modules do not chang...
[user/henk/code/inspircd.git] / src / users.cpp
index e81a3e2537cabf3727e0e0692b505cbd2d67f96d..286f08fe655573b39de8332cb339b034a86f6833 100644 (file)
@@ -73,6 +73,9 @@ std::string User::ProcessNoticeMasks(const char *sm)
                                                output += *c;
                                        }
                                }
+                               else
+                                       this->WriteServ("501 %s %c :is unknown snomask char to me", this->nick, *c);
+
                                oldadding = adding;
                        break;
                }
@@ -177,11 +180,11 @@ User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance
        *password = *nick = *ident = *host = *dhost = *fullname = *awaymsg = *oper = *uuid = 0;
        server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName);
        reset_due = ServerInstance->Time();
-       age = ServerInstance->Time(true);
+       age = ServerInstance->Time();
        Penalty = 0;
        lines_in = lastping = signon = idle_lastmsg = nping = registered = 0;
        ChannelCount = timeout = bytes_in = bytes_out = cmds_in = cmds_out = 0;
-       OverPenalty = ExemptFromPenalty = quitting = exempt = haspassed = dns_done = false;
+       quietquit = OverPenalty = ExemptFromPenalty = quitting = exempt = haspassed = dns_done = false;
        fd = -1;
        recvq.clear();
        sendq.clear();
@@ -692,7 +695,7 @@ void User::Oper(const std::string &opertype, const std::string &opername)
 
        catch (...)
        {
-               ServerInstance->Log(DEBUG,"Exception in User::Oper()");
+               ServerInstance->Logs->Log("OPER", DEBUG,"Exception in User::Oper()");
        }
 }
 
@@ -700,11 +703,27 @@ void User::UnOper()
 {
        if (IS_OPER(this))
        {
-               // unset their oper type (what IS_OPER checks), and remove +o
+               /* Remove all oper only modes from the user when the deoper - Bug #466*/
+               std::string moderemove("-");
+
+               for (unsigned char letter = 'A'; letter <= 'z'; letter++)
+               {
+                       if (letter != 'o')
+                       {
+                               ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_USER);
+                               if (mh && mh->NeedsOper())
+                                       moderemove += letter;
+                       }
+               }
+
+               const char* parameters[] = { this->nick, moderemove.c_str() };
+               ServerInstance->Parser->CallHandler("MODE", parameters, 2, this);
+
+               /* unset their oper type (what IS_OPER checks), and remove +o */
                *this->oper = 0;
                this->modes[UM_OPERATOR] = 0;
                        
-               // remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404
+               /* remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404 */
                ServerInstance->Users->all_opers.remove(this);
 
                if (AllowedOperCommands)
@@ -958,7 +977,7 @@ void User::SetSockAddr(int protocol_family, const char* sip, int port)
                }
                break;
                default:
-                       ServerInstance->Log(DEBUG,"Uh oh, I dont know protocol %d to be set on '%s'!", protocol_family, this->nick);
+                       ServerInstance->Logs->Log("USERS",DEBUG,"Uh oh, I dont know protocol %d to be set on '%s'!", protocol_family, this->nick);
                break;
        }
 }
@@ -1065,12 +1084,12 @@ void User::Write(std::string text)
 
        try
        {
-               ServerInstance->Logs->Log("USERIO", DEBUG,"C[%d] O %s", this->GetFd(), text.c_str());
+               ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"C[%d] O %s", this->GetFd(), text.c_str());
                text.append("\r\n");
        }
        catch (...)
        {
-               ServerInstance->Log(DEBUG,"Exception in User::Write() std::string::append");
+               ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"Exception in User::Write() std::string::append");
                return;
        }
 
@@ -1085,7 +1104,7 @@ void User::Write(std::string text)
                }
                catch (CoreException& modexcept)
                {
-                       ServerInstance->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
+                       ServerInstance->Logs->Log("USEROUTPUT", DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
                }
        }
        else
@@ -1134,6 +1153,32 @@ void User::WriteServ(const char* text, ...)
 }
 
 
+void User::WriteNumeric(unsigned int numeric, const char* text, ...)
+{
+       va_list argsPtr;
+       char textbuffer[MAXBUF];
+
+       va_start(argsPtr, text);
+       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
+       va_end(argsPtr);
+
+       this->WriteNumeric(numeric, std::string(textbuffer));
+}
+
+void User::WriteNumeric(unsigned int numeric, const std::string &text)
+{
+       char textbuffer[MAXBUF];
+       int MOD_RESULT = 0;
+
+       FOREACH_RESULT(I_OnNumeric, OnNumeric(this, numeric, text));
+
+       if (MOD_RESULT)
+               return;
+
+       snprintf(textbuffer,MAXBUF,":%s %u %s %s",ServerInstance->Config->ServerName, numeric, this->nick, text.c_str());
+       this->Write(std::string(textbuffer));
+}
+
 void User::WriteFrom(User *user, const std::string &text)
 {
        char tb[MAXBUF];
@@ -1450,7 +1495,7 @@ bool User::ChangeIdent(const char* newident)
        return true;
 }
 
-void User::SendAll(const char* command, char* text, ...)
+void User::SendAll(const char* command, const char* text, ...)
 {
        char textbuffer[MAXBUF];
        char formatbuffer[MAXBUF];
@@ -1590,7 +1635,7 @@ ConnectClass* User::SetClass(const std::string &explicit_name)
                /* deny change if change will take class over the limit */
                if (found->limit && (found->RefCount + 1 >= found->limit))
                {
-                       ServerInstance->Log(DEBUG, "OOPS: Connect class limit (%u) hit, denying", found->limit);
+                       ServerInstance->Logs->Log("USERS", DEBUG, "OOPS: Connect class limit (%u) hit, denying", found->limit);
                        return this->MyClass;
                }
 
@@ -1600,12 +1645,12 @@ ConnectClass* User::SetClass(const std::string &explicit_name)
                        if (found == this->MyClass) // no point changing this shit :P
                                return this->MyClass;
                        this->MyClass->RefCount--;
-                       ServerInstance->Log(DEBUG, "Untying user from connect class -- refcount: %u", this->MyClass->RefCount);
+                       ServerInstance->Logs->Log("USERS", DEBUG, "Untying user from connect class -- refcount: %u", this->MyClass->RefCount);
                }
 
                this->MyClass = found;
                this->MyClass->RefCount++;
-               ServerInstance->Log(DEBUG, "User tied to new class -- connect refcount now: %u", this->MyClass->RefCount);
+               ServerInstance->Logs->Log("USERS", DEBUG, "User tied to new class -- connect refcount now: %u", this->MyClass->RefCount);
        }
 
        return this->MyClass;
@@ -1638,7 +1683,7 @@ void User::PurgeEmptyChannels()
                        }
                        catch (...)
                        {
-                               ServerInstance->Log(DEBUG,"Exception in User::PurgeEmptyChannels to_delete.push_back()");
+                               ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::PurgeEmptyChannels to_delete.push_back()");
                        }
                }
        }
@@ -1716,7 +1761,7 @@ void User::HandleEvent(EventType et, int errornum)
        }
        catch (...)
        {
-               ServerInstance->Log(DEBUG,"Exception in User::HandleEvent intercepted");
+               ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::HandleEvent intercepted");
        }
 
        /* If the user has raised an error whilst being processed, quit them now we're safe to */