summaryrefslogtreecommitdiff
path: root/src/users.cpp
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2019-01-23 21:45:50 +0000
committerPeter Powell <petpow@saberuk.com>2019-01-24 14:28:21 +0000
commitcbef0241a04eafe5250b75ebb3f7ef8c32ecb260 (patch)
treed856c8ac6db6cf2514bc5090e6b11f759d3c0290 /src/users.cpp
parenta7fac86ccda9e75c6f426b07faa85081f5857d33 (diff)
Implement support for the extended tag space for client tags.
Diffstat (limited to 'src/users.cpp')
-rw-r--r--src/users.cpp42
1 files changed, 19 insertions, 23 deletions
diff --git a/src/users.cpp b/src/users.cpp
index eb87824fc..506cdf6d8 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -239,23 +239,30 @@ void UserIOHandler::OnDataReady()
if (!user->HasPrivPermission("users/flood/no-fakelag"))
penaltymax = user->MyClass->GetPenaltyThreshold() * 1000;
- // The maximum size of an IRC message minus the terminating CR+LF.
- const size_t maxmessage = ServerInstance->Config->Limits.MaxLine - 2;
+ // The cleaned message sent by the user or empty if not found yet.
std::string line;
- line.reserve(maxmessage);
- bool eol_found;
+ // The position of the most \n character or npos if not found yet.
+ std::string::size_type eolpos;
+
+ // The position within the recvq of the current character.
std::string::size_type qpos;
while (user->CommandFloodPenalty < penaltymax && getSendQSize() < sendqmax)
{
- qpos = 0;
- eol_found = false;
+ // Check the newly received data for an EOL.
+ eolpos = recvq.find('\n', checked_until);
+ if (eolpos == std::string::npos)
+ {
+ checked_until = recvq.length();
+ return;
+ }
- const size_t qlen = recvq.length();
- while (qpos < qlen)
+ // We've found a line! Clean it up and move it to the line buffer.
+ line.reserve(eolpos);
+ for (qpos = 0; qpos < eolpos; ++qpos)
{
- char c = recvq[qpos++];
+ char c = recvq[qpos];
switch (c)
{
case '\0':
@@ -263,25 +270,14 @@ void UserIOHandler::OnDataReady()
break;
case '\r':
continue;
- case '\n':
- eol_found = true;
- break;
}
- if (eol_found)
- break;
-
- if (line.length() < maxmessage)
- line.push_back(c);
+ line.push_back(c);
}
- // if we return here, we haven't found a newline and make no modifications to recvq
- // so we can wait for more data
- if (!eol_found)
- return;
-
// just found a newline. Terminate the string, and pull it out of recvq
- recvq.erase(0, qpos);
+ recvq.erase(0, eolpos + 1);
+ checked_until = 0;
// TODO should this be moved to when it was inserted in recvq?
ServerInstance->stats.Recv += qpos;