diff options
author | Attila Molnar <attilamolnar@hush.com> | 2014-06-11 14:37:42 +0200 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2014-06-11 14:37:42 +0200 |
commit | ce82bc069d42b0eb1076ddc4c3ec94db415c3eb0 (patch) | |
tree | 6b13fd5651de3f09d13b6f10556751e2fb60c258 | |
parent | f3ebd00f119f322f2887f88c37d3fce7743d9587 (diff) |
m_spanningtree Add CmdBuilder specialization for FJOIN
-rw-r--r-- | src/modules/m_spanningtree/commands.h | 13 | ||||
-rw-r--r-- | src/modules/m_spanningtree/fjoin.cpp | 32 | ||||
-rw-r--r-- | src/modules/m_spanningtree/netburst.cpp | 20 |
3 files changed, 53 insertions, 12 deletions
diff --git a/src/modules/m_spanningtree/commands.h b/src/modules/m_spanningtree/commands.h index 110b3d93d..e26b2b8eb 100644 --- a/src/modules/m_spanningtree/commands.h +++ b/src/modules/m_spanningtree/commands.h @@ -134,6 +134,19 @@ class CommandFJoin : public ServerCommand public: CommandFJoin(Module* Creator) : ServerCommand(Creator, "FJOIN", 3) { } CmdResult Handle(User* user, std::vector<std::string>& params); + + class Builder : public CmdBuilder + { + static const size_t maxline = 480; + std::string::size_type pos; + + public: + Builder(Channel* chan); + void add(Membership* memb); + bool has_room(Membership* memb) const; + void clear(); + const std::string& finalize(); + }; }; class CommandFMode : public ServerCommand diff --git a/src/modules/m_spanningtree/fjoin.cpp b/src/modules/m_spanningtree/fjoin.cpp index 26c3413f9..7deb04b31 100644 --- a/src/modules/m_spanningtree/fjoin.cpp +++ b/src/modules/m_spanningtree/fjoin.cpp @@ -257,3 +257,35 @@ void CommandFJoin::LowerTS(Channel* chan, time_t TS, const std::string& newname) chan->setby.clear(); chan->topicset = 0; } + +CommandFJoin::Builder::Builder(Channel* chan) + : CmdBuilder("FJOIN") +{ + push(chan->name).push_int(chan->age).push_raw(" +"); + pos = str().size(); + push_raw(chan->ChanModes(true)).push_raw(" :"); +} + +void CommandFJoin::Builder::add(Membership* memb) +{ + push_raw(memb->modes).push_raw(',').push_raw(memb->user->uuid); + push_raw(' '); +} + +bool CommandFJoin::Builder::has_room(Membership* memb) const +{ + return ((str().size() + memb->modes.size() + UIDGenerator::UUID_LENGTH + 2) <= maxline); +} + +void CommandFJoin::Builder::clear() +{ + content.erase(pos); + push_raw(" :"); +} + +const std::string& CommandFJoin::Builder::finalize() +{ + if (*content.rbegin() == ' ') + content.erase(content.size()-1); + return str(); +} diff --git a/src/modules/m_spanningtree/netburst.cpp b/src/modules/m_spanningtree/netburst.cpp index a33cf8a13..093ab89eb 100644 --- a/src/modules/m_spanningtree/netburst.cpp +++ b/src/modules/m_spanningtree/netburst.cpp @@ -159,25 +159,21 @@ void TreeSocket::SendServers(TreeServer* Current, TreeServer* s) */ void TreeSocket::SendFJoins(Channel* c) { - std::string line(":"); - line.append(ServerInstance->Config->GetSID()).append(" FJOIN ").append(c->name).append(1, ' ').append(ConvToStr(c->age)).append(" +"); - std::string::size_type erase_from = line.length(); - line.append(c->ChanModes(true)).append(" :"); - + CommandFJoin::Builder fjoin(c); const UserMembList *ulist = c->GetUsers(); for (UserMembCIter i = ulist->begin(); i != ulist->end(); ++i) { - const std::string& modestr = i->second->modes; - if ((line.length() + modestr.length() + UIDGenerator::UUID_LENGTH + 2) > 480) + Membership* memb = i->second; + if (!fjoin.has_room(memb)) { - this->WriteLine(line); - line.erase(erase_from); - line.append(" :"); + // No room for this user, send the line and prepare a new one + this->WriteLine(fjoin.finalize()); + fjoin.clear(); } - line.append(modestr).append(1, ',').append(i->first->uuid).push_back(' '); + fjoin.add(memb); } - this->WriteLine(line); + this->WriteLine(fjoin.finalize()); } /** Send all XLines we know about */ |