m_spanningtree Remove duplicate code for sending channel messages from RouteCommand()

This commit is contained in:
attilamolnar 2013-07-19 13:32:41 +02:00
parent 15f4e6b865
commit 67de413cad
3 changed files with 13 additions and 24 deletions

View File

@ -91,20 +91,9 @@ void SpanningTreeUtilities::RouteCommand(TreeServer* origin, CommandBase* thiscm
Channel* c = ServerInstance->FindChan(dest);
if (!c)
return;
TreeServerList list;
// TODO OnBuildExemptList hook was here
GetListOfServersForChannel(c,list,pfx, CUList());
std::string data = ":" + user->uuid + " " + sent_cmd;
for (unsigned int x = 0; x < params.size(); x++)
data += " " + params[x];
for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
{
TreeSocket* Sock = (*i)->GetSocket();
if (origin && origin->GetSocket() == Sock)
continue;
if (Sock)
Sock->WriteLine(data);
}
CUList exempts;
SendChannelMessage(user->uuid, c, parameters[1], pfx, exempts, sent_cmd.c_str(), origin ? origin->GetSocket() : NULL);
}
else if (dest[0] == '$')
{

View File

@ -162,7 +162,7 @@ SpanningTreeUtilities::~SpanningTreeUtilities()
}
/* returns a list of DIRECT servernames for a specific channel */
void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list)
void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeSocketSet& list, char status, const CUList& exempt_list)
{
unsigned int minrank = 0;
if (status)
@ -186,7 +186,7 @@ void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeServerLis
{
TreeServer* best = this->BestRouteTo(i->first->server);
if (best)
list.insert(best);
list.insert(best->GetSocket());
}
}
return;
@ -379,7 +379,7 @@ Link* SpanningTreeUtilities::FindLink(const std::string& name)
return NULL;
}
void SpanningTreeUtilities::SendChannelMessage(const std::string& prefix, Channel* target, const std::string &text, char status, const CUList& exempt_list, const char* message_type)
void SpanningTreeUtilities::SendChannelMessage(const std::string& prefix, Channel* target, const std::string& text, char status, const CUList& exempt_list, const char* message_type, TreeSocket* omit)
{
std::string raw(":");
raw.append(prefix).append(1, ' ').append(message_type).push_back(' ');
@ -387,12 +387,12 @@ void SpanningTreeUtilities::SendChannelMessage(const std::string& prefix, Channe
raw.push_back(status);
raw.append(target->name).append(" :").append(text);
TreeServerList list;
TreeSocketSet list;
this->GetListOfServersForChannel(target, list, status, exempt_list);
for (TreeServerList::iterator i = list.begin(); i != list.end(); ++i)
for (TreeSocketSet::iterator i = list.begin(); i != list.end(); ++i)
{
TreeSocket* Sock = (*i)->GetSocket();
if (Sock)
TreeSocket* Sock = *i;
if (Sock != omit)
Sock->WriteLine(raw);
}
}

View File

@ -40,8 +40,6 @@ extern SpanningTreeUtilities* Utils;
*/
typedef TR1NS::unordered_map<std::string, TreeServer*, irc::insensitive, irc::StrHashComp> server_hash;
typedef std::set<TreeServer*> TreeServerList;
/** Contains helper functions and variables for this module,
* and keeps them out of the global namespace
*/
@ -54,6 +52,8 @@ class SpanningTreeUtilities : public classbase
CacheRefreshTimer RefreshTimer;
public:
typedef std::set<TreeSocket*> TreeSocketSet;
/** Creator module
*/
ModuleSpanningTree* Creator;
@ -150,7 +150,7 @@ class SpanningTreeUtilities : public classbase
/** Compile a list of servers which contain members of channel c
*/
void GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list);
void GetListOfServersForChannel(Channel* c, TreeSocketSet& list, char status, const CUList& exempt_list);
/** Find a server by name
*/
@ -178,7 +178,7 @@ class SpanningTreeUtilities : public classbase
/** Sends a PRIVMSG or a NOTICE to a channel obeying an exempt list and an optional prefix
*/
void SendChannelMessage(const std::string& prefix, Channel* target, const std::string &text, char status, const CUList& exempt_list, const char* message_type);
void SendChannelMessage(const std::string& prefix, Channel* target, const std::string& text, char status, const CUList& exempt_list, const char* message_type, TreeSocket* omit = NULL);
};
inline void SpanningTreeUtilities::DoOneToMany(const std::string& prefix, const std::string& command, const parameterlist& params)