]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Pass the ModeHandler to User::HasModePermission()
[user/henk/code/inspircd.git] / src / users.cpp
index f6cdcc769926d132a980051f8fb0ff8ad5cdf479..5d1c12b136c1979863d90af3dc4e0b46ce64bee9 100644 (file)
@@ -51,7 +51,7 @@ const char* User::FormatModes(bool showparameters)
                if (mh && IsModeSet(mh))
                {
                        data.push_back(n + 65);
-                       if (showparameters && mh->GetNumParams(true))
+                       if (showparameters && mh->NeedsParam(true))
                        {
                                std::string p = mh->GetUserParameter(this);
                                if (p.length())
@@ -64,12 +64,14 @@ const char* User::FormatModes(bool showparameters)
 }
 
 User::User(const std::string& uid, Server* srv, int type)
-       : uuid(uid), server(srv), usertype(type)
+       : age(ServerInstance->Time())
+       , signon(0)
+       , uuid(uid)
+       , server(srv)
+       , registered(REG_NONE)
+       , quitting(false)
+       , usertype(type)
 {
-       age = ServerInstance->Time();
-       signon = 0;
-       registered = 0;
-       quitting = false;
        client_sa.sa.sa_family = AF_UNSPEC;
 
        ServerInstance->Logs->Log("USERS", LOG_DEBUG, "New UUID for user: %s", uuid.c_str());
@@ -83,14 +85,24 @@ User::User(const std::string& uid, Server* srv, int type)
 }
 
 LocalUser::LocalUser(int myfd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* servaddr)
-       : User(ServerInstance->UIDGen.GetUID(), ServerInstance->FakeClient->server, USERTYPE_LOCAL), eh(this),
-       bytes_in(0), bytes_out(0), cmds_in(0), cmds_out(0), nping(0), CommandFloodPenalty(0),
-       already_sent(0)
-{
-       exempt = quitting_sendq = false;
-       idle_lastmsg = 0;
+       : User(ServerInstance->UIDGen.GetUID(), ServerInstance->FakeClient->server, USERTYPE_LOCAL)
+       , eh(this)
+       , bytes_in(0)
+       , bytes_out(0)
+       , cmds_in(0)
+       , cmds_out(0)
+       , quitting_sendq(false)
+       , lastping(true)
+       , exempt(false)
+       , nping(0)
+       , idle_lastmsg(0)
+       , CommandFloodPenalty(0)
+       , already_sent(0)
+{
+       signon = ServerInstance->Time();
+       // The user's default nick is their UUID
+       nick = uuid;
        ident = "unknown";
-       lastping = 0;
        eh.SetFd(myfd);
        memcpy(&client_sa, client, sizeof(irc::sockets::sockaddrs));
        memcpy(&server_sa, servaddr, sizeof(irc::sockets::sockaddrs));
@@ -141,19 +153,20 @@ const std::string& User::GetFullRealHost()
        return this->cached_fullrealhost;
 }
 
-bool User::HasModePermission(unsigned char, ModeType)
+bool User::HasModePermission(const ModeHandler* mh) const
 {
        return true;
 }
 
-bool LocalUser::HasModePermission(unsigned char mode, ModeType type)
+bool LocalUser::HasModePermission(const ModeHandler* mh) const
 {
        if (!this->IsOper())
                return false;
 
+       const unsigned char mode = mh->GetModeChar();
        if (mode < 'A' || mode > ('A' + 64)) return false;
 
-       return ((type == MODETYPE_USER ? oper->AllowedUserModes : oper->AllowedChanModes))[(mode - 'A')];
+       return ((mh->GetModeType() == MODETYPE_USER ? oper->AllowedUserModes : oper->AllowedChanModes))[(mode - 'A')];
 
 }
 /*
@@ -340,7 +353,7 @@ void User::Oper(OperInfo* info)
                LocalUser* l = IS_LOCAL(this);
                std::string vhost = oper->getConfig("vhost");
                if (!vhost.empty())
-                       l->ChangeDisplayedHost(vhost.c_str());
+                       l->ChangeDisplayedHost(vhost);
                std::string opClass = oper->getConfig("class");
                if (!opClass.empty())
                        l->SetClass(opClass);
@@ -811,7 +824,8 @@ void User::WriteNumeric(const Numeric::Numeric& numeric)
        if (MOD_RESULT == MOD_RES_DENY)
                return;
 
-       this->Write(BuildNumeric(ServerInstance->Config->ServerName, this, numeric.GetNumeric(), numeric.GetParams()));
+       const std::string& servername = (numeric.GetServer() ? numeric.GetServer()->GetName() : ServerInstance->Config->ServerName);
+       this->Write(BuildNumeric(servername, this, numeric.GetNumeric(), numeric.GetParams()));
 }
 
 void User::WriteFrom(User *user, const std::string &text)
@@ -830,6 +844,16 @@ void User::WriteFrom(User *user, const char* text, ...)
        this->WriteFrom(user, textbuffer);
 }
 
+void User::WriteRemoteNotice(const std::string& text)
+{
+       ServerInstance->PI->SendUserNotice(this, text);
+}
+
+void LocalUser::WriteRemoteNotice(const std::string& text)
+{
+       WriteNotice(text);
+}
+
 namespace
 {
        class WriteCommonRawHandler : public User::ForEachNeighborHandler
@@ -916,48 +940,9 @@ void User::ForEachNeighbor(ForEachNeighborHandler& handler, bool include_self)
        }
 }
 
-void LocalUser::SendText(const std::string& line)
-{
-       Write(line);
-}
-
-void RemoteUser::SendText(const std::string& line)
-{
-       ServerInstance->PI->PushToClient(this, line);
-}
-
-void FakeUser::SendText(const std::string& line)
-{
-}
-
-void User::SendText(const char *text, ...)
-{
-       std::string line;
-       VAFORMAT(line, text, text);
-       SendText(line);
-}
-
-void User::SendText(const std::string& linePrefix, std::stringstream& textStream)
-{
-       std::string line;
-       std::string word;
-       while (textStream >> word)
-       {
-               size_t lineLength = linePrefix.length() + line.length() + word.length() + 3; // "\s\n\r"
-               if (lineLength > ServerInstance->Config->Limits.MaxLine)
-               {
-                       SendText(linePrefix + line);
-                       line.clear();
-               }
-               line += " " + word;
-       }
-       SendText(linePrefix + line);
-}
-
 void User::WriteRemoteNumeric(const Numeric::Numeric& numeric)
 {
-       const std::string& servername = (numeric.GetServer() ? numeric.GetServer()->GetName() : ServerInstance->Config->ServerName);
-       SendText(BuildNumeric(servername, this, numeric.GetNumeric(), numeric.GetParams()));
+       WriteNumeric(numeric);
 }
 
 /* return 0 or 1 depending if users u and u2 share one or more common channels