aboutsummaryrefslogtreecommitdiff
path: root/src/modules/m_spanningtree/compat.cpp
diff options
context:
space:
mode:
authorGravatar Sadie Powell2024-02-19 17:40:54 +0000
committerGravatar Sadie Powell2024-02-19 17:40:54 +0000
commitbfa93165954ff2f95793fd90235b7f5036916a1b (patch)
tree329e2ad0d4630ff86a8bf6808d66257b7150ebea /src/modules/m_spanningtree/compat.cpp
parentAllow changing the case of cloak values in cloak_user. (diff)
Fix more issues with the v3 compat layer.
Diffstat (limited to 'src/modules/m_spanningtree/compat.cpp')
-rw-r--r--src/modules/m_spanningtree/compat.cpp33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/modules/m_spanningtree/compat.cpp b/src/modules/m_spanningtree/compat.cpp
index 5dd0c3d45..917b1e480 100644
--- a/src/modules/m_spanningtree/compat.cpp
+++ b/src/modules/m_spanningtree/compat.cpp
@@ -20,6 +20,17 @@
#include "inspircd.h"
#include "main.h"
+namespace
+{
+ size_t NextToken(const std::string& line, size_t start)
+ {
+ if (start == std::string::npos || start + 1 > line.length())
+ return std::string::npos;
+
+ return line.find(' ', start + 1);
+ }
+}
+
void TreeSocket::WriteLine(const std::string& original_line)
{
if (LinkState != CONNECTED || proto_version == PROTO_NEWEST)
@@ -34,17 +45,25 @@ void TreeSocket::WriteLine(const std::string& original_line)
size_t cmdstart = 0;
if (line[0] == '@') // Skip the tags.
- cmdstart = line.find(' ');
+ {
+ cmdstart = NextToken(line, 0);
+ if (cmdstart != std::string::npos)
+ cmdstart++;
+ }
- if (line[cmdstart + 1] == ':') // Skip the prefix.
- cmdstart = line.find(' ', cmdstart + 1);
+ if (line[cmdstart] == ':') // Skip the prefix.
+ {
+ cmdstart = NextToken(line, cmdstart);
+ if (cmdstart != std::string::npos)
+ cmdstart++;
+ }
// Find the end of the command.
- size_t cmdend = line.find(' ', cmdstart + 1);
+ size_t cmdend = NextToken(line, cmdstart);
if (cmdend == std::string::npos)
- cmdend = line.size();
+ cmdend = line.size() - 1;
- std::string command(line, cmdstart + 1, cmdend - cmdstart - 1);
+ std::string command(line, cmdstart, cmdend - cmdstart);
if (proto_version == PROTO_INSPIRCD_3)
{
if (irc::equals(command, "FRHOST"))
@@ -55,7 +74,7 @@ void TreeSocket::WriteLine(const std::string& original_line)
else if (irc::equals(command, "SQUERY"))
{
// SQUERY was introduced in PROTO_INSPIRCD_4; convert to PRIVMSG.
- line.replace(cmdstart + 1, cmdend - cmdstart - 1, "PRIVMSG");
+ line.replace(cmdstart, 6, "PRIVMSG");
}
}