From f3ebd00f119f322f2887f88c37d3fce7743d9587 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Wed, 11 Jun 2014 14:30:17 +0200 Subject: m_spanningtree Send, parse and translate IJOINs with membership ids --- src/modules/m_spanningtree/commands.h | 2 +- src/modules/m_spanningtree/compat.cpp | 10 ++++++++-- src/modules/m_spanningtree/ijoin.cpp | 13 +++++++++---- src/modules/m_spanningtree/main.cpp | 1 + 4 files changed, 19 insertions(+), 7 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_spanningtree/commands.h b/src/modules/m_spanningtree/commands.h index d2d138ab2..110b3d93d 100644 --- a/src/modules/m_spanningtree/commands.h +++ b/src/modules/m_spanningtree/commands.h @@ -181,7 +181,7 @@ class CommandFName : public UserOnlyServerCommand class CommandIJoin : public UserOnlyServerCommand { public: - CommandIJoin(Module* Creator) : UserOnlyServerCommand(Creator, "IJOIN", 1) { } + CommandIJoin(Module* Creator) : UserOnlyServerCommand(Creator, "IJOIN", 2) { } CmdResult HandleRemote(RemoteUser* user, std::vector& params); }; diff --git a/src/modules/m_spanningtree/compat.cpp b/src/modules/m_spanningtree/compat.cpp index ca9fbfa6a..dc4315cb7 100644 --- a/src/modules/m_spanningtree/compat.cpp +++ b/src/modules/m_spanningtree/compat.cpp @@ -47,11 +47,17 @@ void TreeSocket::WriteLine(const std::string& original_line) if (command == "IJOIN") { // Convert - // : IJOIN [ []] + // : IJOIN [ []] // to // : FJOIN + [], std::string::size_type c = line.find(' ', b + 1); if (c == std::string::npos) + return; + + std::string::size_type d = line.find(' ', c + 1); + // Erase membership id first + line.erase(c, d-c); + if (d == std::string::npos) { // No TS or modes in the command // :22DAAAAAB IJOIN #chan @@ -66,7 +72,7 @@ void TreeSocket::WriteLine(const std::string& original_line) } else { - std::string::size_type d = line.find(' ', c + 1); + d = line.find(' ', c + 1); if (d == std::string::npos) { // TS present, no modes diff --git a/src/modules/m_spanningtree/ijoin.cpp b/src/modules/m_spanningtree/ijoin.cpp index 34bd44a9b..78e05db93 100644 --- a/src/modules/m_spanningtree/ijoin.cpp +++ b/src/modules/m_spanningtree/ijoin.cpp @@ -38,17 +38,22 @@ CmdResult CommandIJoin::HandleRemote(RemoteUser* user, std::vector& } bool apply_modes; - if (params.size() > 1) + if (params.size() > 2) { - time_t RemoteTS = ServerCommand::ExtractTS(params[1]); + time_t RemoteTS = ServerCommand::ExtractTS(params[2]); if (RemoteTS < chan->age) throw ProtocolException("Attempted to lower TS via IJOIN. LocalTS=" + ConvToStr(chan->age)); - apply_modes = ((params.size() > 2) && (RemoteTS == chan->age)); + apply_modes = ((params.size() > 3) && (RemoteTS == chan->age)); } else apply_modes = false; - chan->ForceJoin(user, apply_modes ? ¶ms[2] : NULL); + // Join the user and set the membership id to what they sent + Membership* memb = chan->ForceJoin(user, apply_modes ? ¶ms[3] : NULL); + if (!memb) + return CMD_FAILURE; + + memb->id = Membership::IdFromString(params[1]); return CMD_SUCCESS; } diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 6fa494809..6a21ca4f6 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -527,6 +527,7 @@ void ModuleSpanningTree::OnUserJoin(Membership* memb, bool sync, bool created_by { CmdBuilder params(memb->user, "IJOIN"); params.push_back(memb->chan->name); + params.push_int(memb->id); if (!memb->modes.empty()) { params.push_back(ConvToStr(memb->chan->age)); -- cgit v1.3.1-10-gc9f91