]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Added idea from ircu: /invite with too few params shows the channels youve been invit...
[user/henk/code/inspircd.git] / src / users.cpp
index 0d305a3b71e116048a01750c0b07f7c22047b7cc..6fca08abc4424832fcf501a245843d1f1dd80e0d 100644 (file)
@@ -36,7 +36,6 @@ userrec::userrec()
        strcpy(dhost,"");
        strcpy(fullname,"");
        strcpy(modes,"");
-       strcpy(inbuf,"");
        strcpy(server,"");
        strcpy(awaymsg,"");
        strcpy(oper,"");
@@ -47,6 +46,7 @@ userrec::userrec()
        haspassed = false;
        dns_done = false;
        recvq = "";
+       sendq = "";
        strcpy(result,"");
        for (int i = 0; i < MAXCHANS; i++)
        {
@@ -85,6 +85,11 @@ bool userrec::IsInvited(char* channel)
        return false;
 }
 
+InvitedList* userrec::GetInviteList()
+{
+       return &invites;
+}
+
 void userrec::InviteTo(char* channel)
 {
        Invited i;
@@ -182,6 +187,11 @@ bool userrec::AddBuffer(std::string a)
                if (recvq[i++] == '\n')
                        break;
        }
+       if (recvq.length() > this->recvqmax)
+       {
+               this->SetWriteError("RecvQ exceeded");
+               WriteOpers("*** User %s RecvQ of %d exceeds connect class maximum of %d",this->nick,recvq.length(),this->recvqmax);
+       }
        // return false if we've had more than 600 characters WITHOUT
        // a carriage return (this is BAD, drop the socket)
        return (i < 600);
@@ -202,7 +212,8 @@ void userrec::ClearBuffer()
 
 std::string userrec::GetBuffer()
 {
-       log(DEBUG,"GetBuffer\n%s\n",recvq.c_str());
+       if (recvq == "")
+               return "";
         char* line = (char*)recvq.c_str();
         std::string ret = "";
         while ((*line != '\n') && (strlen(line)))
@@ -216,3 +227,53 @@ std::string userrec::GetBuffer()
         return ret;
 }
 
+void userrec::AddWriteBuf(std::string data)
+{
+       if (this->GetWriteError() != "")
+               return;
+       if (sendq.length() + data.length() > this->sendqmax)
+       {
+               WriteOpers("*** User %s SendQ of %d exceeds connect class maximum of %d",this->nick,sendq.length() + data.length(),this->sendqmax);
+               this->SetWriteError("SendQ exceeded");
+               return;
+       }
+        std::stringstream stream;
+        stream << sendq << data;
+        sendq = stream.str();
+}
+
+// send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
+void userrec::FlushWriteBuf()
+{
+       if (sendq.length())
+       {
+               char* tb = (char*)this->sendq.c_str();
+               int n_sent = write(this->fd,tb,this->sendq.length());
+               if (n_sent == -1)
+               {
+                       this->SetWriteError(strerror(errno));
+               }
+               else
+               {
+                       // advance the queue
+                       tb += n_sent;
+                       this->sendq = tb;
+                       // update the user's stats counters
+                       this->bytes_out += n_sent;
+                       this->cmds_out++;
+               }
+       }
+}
+
+void userrec::SetWriteError(std::string error)
+{
+       log(DEBUG,"Setting error string for %s to '%s'",this->nick,error.c_str());
+       // don't try to set the error twice, its already set take the first string.
+       if (this->WriteError == "")
+               this->WriteError = error;
+}
+
+std::string userrec::GetWriteError()
+{
+       return this->WriteError;
+}