X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fusers.cpp;h=0e676600edb5b6571a67375644b3e844d7419228;hb=70246812d3304b7c0ce81e7708c0fd98438ccd49;hp=0ece63bc9ac7b759ca1dc0571301a50fde3ad6e6;hpb=96bf59631c7a17d9f0e99847a33df85a279aae4d;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/users.cpp b/src/users.cpp index 0ece63bc9..0e676600e 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -47,6 +47,7 @@ userrec::userrec() haspassed = false; dns_done = false; recvq = ""; + sendq = ""; strcpy(result,""); for (int i = 0; i < MAXCHANS; i++) { @@ -166,7 +167,7 @@ bool userrec::HasPermission(char* command) } -void userrec::AddBuffer(std::string a) +bool userrec::AddBuffer(std::string a) { std::string b = ""; for (int i = 0; i < a.length(); i++) @@ -175,6 +176,16 @@ void userrec::AddBuffer(std::string a) std::stringstream stream(recvq); stream << b; recvq = stream.str(); + int i = 0; + // count the size of the first line in the buffer. + while (i < recvq.length()) + { + if (recvq[i++] == '\n') + break; + } + // return false if we've had more than 600 characters WITHOUT + // a carriage return (this is BAD, drop the socket) + return (i < 600); } bool userrec::BufferIsReady() @@ -192,7 +203,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))) @@ -206,3 +218,45 @@ std::string userrec::GetBuffer() return ret; } +void userrec::AddWriteBuf(std::string data) +{ + 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; +}