diff options
author | attilamolnar <attilamolnar@hush.com> | 2012-07-04 23:11:01 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-04-12 21:03:05 +0200 |
commit | da28fe0b8c0bec9ab111044b1004f24cbf2d742e (patch) | |
tree | aa2b3e206af49087e9ecafba600ce7802f4b82fb /src | |
parent | a04e586eb51b90d71cb76a2605ca9e194fb21b30 (diff) |
m_spanningtree Introduce new function to send channel messages
Use it from the protocol interface and PRIVMSG/NOTICE handlers
Unite OnUserNotice and OnUserMessage code into LocalMessage()
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/m_spanningtree/main.cpp | 99 | ||||
-rw-r--r-- | src/modules/m_spanningtree/main.h | 1 | ||||
-rw-r--r-- | src/modules/m_spanningtree/protocolinterface.cpp | 23 | ||||
-rw-r--r-- | src/modules/m_spanningtree/utils.cpp | 18 | ||||
-rw-r--r-- | src/modules/m_spanningtree/utils.h | 4 |
5 files changed, 45 insertions, 100 deletions
diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index ac1d12423..f1c6ce521 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -467,108 +467,45 @@ void ModuleSpanningTree::OnWallops(User* user, const std::string &text) } } -void ModuleSpanningTree::OnUserNotice(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list) +void ModuleSpanningTree::LocalMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list, const char* message_type) { - /* Server origin */ - if (user == NULL) + /* Server or remote origin, dest should always be non-null */ + if ((!user) || (!IS_LOCAL(user)) || (!dest)) return; if (target_type == TYPE_USER) { - User* d = (User*)dest; - if (!IS_LOCAL(d) && IS_LOCAL(user)) + User* d = (User*) dest; + if (!IS_LOCAL(d)) { parameterlist params; params.push_back(d->uuid); params.push_back(":"+text); - Utils->DoOneToOne(user->uuid,"NOTICE",params,d->server); + Utils->DoOneToOne(user->uuid, message_type, params, d->server); } } else if (target_type == TYPE_CHANNEL) { - if (IS_LOCAL(user)) - { - Channel *c = (Channel*)dest; - if (c) - { - std::string cname = c->name; - if (status) - cname = status + cname; - TreeServerList list; - Utils->GetListOfServersForChannel(c,list,status,exempt_list); - for (TreeServerList::iterator i = list.begin(); i != list.end(); i++) - { - TreeSocket* Sock = (*i)->GetSocket(); - if (Sock) - Sock->WriteLine(":"+std::string(user->uuid)+" NOTICE "+cname+" :"+text); - } - } - } + Utils->SendChannelMessage(user->uuid, (Channel*)dest, text, status, exempt_list, message_type); } else if (target_type == TYPE_SERVER) { - if (IS_LOCAL(user)) - { - char* target = (char*)dest; - parameterlist par; - par.push_back(target); - par.push_back(":"+text); - Utils->DoOneToMany(user->uuid,"NOTICE",par); - } + char* target = (char*) dest; + parameterlist par; + par.push_back(target); + par.push_back(":"+text); + Utils->DoOneToMany(user->uuid, message_type, par); } } -void ModuleSpanningTree::OnUserMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list) +void ModuleSpanningTree::OnUserNotice(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list) { - /* Server origin */ - if (user == NULL) - return; + LocalMessage(user, dest, target_type, text, status, exempt_list, "NOTICE"); +} - if (target_type == TYPE_USER) - { - // route private messages which are targetted at clients only to the server - // which needs to receive them - User* d = (User*)dest; - if (!IS_LOCAL(d) && (IS_LOCAL(user))) - { - parameterlist params; - params.push_back(d->uuid); - params.push_back(":"+text); - Utils->DoOneToOne(user->uuid,"PRIVMSG",params,d->server); - } - } - else if (target_type == TYPE_CHANNEL) - { - if (IS_LOCAL(user)) - { - Channel *c = (Channel*)dest; - if (c) - { - std::string cname = c->name; - if (status) - cname = status + cname; - TreeServerList list; - Utils->GetListOfServersForChannel(c,list,status,exempt_list); - for (TreeServerList::iterator i = list.begin(); i != list.end(); i++) - { - TreeSocket* Sock = (*i)->GetSocket(); - if (Sock) - Sock->WriteLine(":"+std::string(user->uuid)+" PRIVMSG "+cname+" :"+text); - } - } - } - } - else if (target_type == TYPE_SERVER) - { - if (IS_LOCAL(user)) - { - char* target = (char*)dest; - parameterlist par; - par.push_back(target); - par.push_back(":"+text); - Utils->DoOneToMany(user->uuid,"PRIVMSG",par); - } - } +void ModuleSpanningTree::OnUserMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list) +{ + LocalMessage(user, dest, target_type, text, status, exempt_list, "PRIVMSG"); } void ModuleSpanningTree::OnBackgroundTimer(time_t curtime) diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h index fc59a3c7d..fe5683246 100644 --- a/src/modules/m_spanningtree/main.h +++ b/src/modules/m_spanningtree/main.h @@ -52,6 +52,7 @@ class Autoconnect; class ModuleSpanningTree : public Module { SpanningTreeCommands* commands; + void LocalMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list, const char* message_type); public: SpanningTreeUtilities* Utils; diff --git a/src/modules/m_spanningtree/protocolinterface.cpp b/src/modules/m_spanningtree/protocolinterface.cpp index 0440823e6..aacf5ce8d 100644 --- a/src/modules/m_spanningtree/protocolinterface.cpp +++ b/src/modules/m_spanningtree/protocolinterface.cpp @@ -135,31 +135,16 @@ void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", p, target->server); } -void SpanningTreeProtocolInterface::SendChannel(Channel* target, char status, const std::string &text) -{ - std::string cname = target->name; - if (status) - cname = status + cname; - TreeServerList list; - CUList exempt_list; - Utils->GetListOfServersForChannel(target,list,status,exempt_list); - for (TreeServerList::iterator i = list.begin(); i != list.end(); i++) - { - TreeSocket* Sock = (*i)->GetSocket(); - if (Sock) - Sock->WriteLine(text); - } -} - - void SpanningTreeProtocolInterface::SendChannelPrivmsg(Channel* target, char status, const std::string &text) { - SendChannel(target, status, ":" + ServerInstance->Config->GetSID()+" PRIVMSG "+target->name+" :"+text); + CUList exempt_list; + Utils->SendChannelMessage(ServerInstance->Config->GetSID(), target, text, status, exempt_list, "PRIVMSG"); } void SpanningTreeProtocolInterface::SendChannelNotice(Channel* target, char status, const std::string &text) { - SendChannel(target, status, ":" + ServerInstance->Config->GetSID()+" NOTICE "+target->name+" :"+text); + CUList exempt_list; + Utils->SendChannelMessage(ServerInstance->Config->GetSID(), target, text, status, exempt_list, "NOTICE"); } void SpanningTreeProtocolInterface::SendUserPrivmsg(User* target, const std::string &text) diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index 7941970da..344c8138f 100644 --- a/src/modules/m_spanningtree/utils.cpp +++ b/src/modules/m_spanningtree/utils.cpp @@ -421,3 +421,21 @@ 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) +{ + std::string raw(":"); + raw.append(prefix).append(1, ' ').append(message_type).push_back(' '); + if (status) + raw.push_back(status); + raw.append(target->name).append(" :").append(text); + + TreeServerList list; + this->GetListOfServersForChannel(target, list, status, exempt_list); + for (TreeServerList::iterator i = list.begin(); i != list.end(); ++i) + { + TreeSocket* Sock = (*i)->GetSocket(); + if (Sock) + Sock->WriteLine(raw); + } +} diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h index fc1d49733..f67a0d3c1 100644 --- a/src/modules/m_spanningtree/utils.h +++ b/src/modules/m_spanningtree/utils.h @@ -169,4 +169,8 @@ class SpanningTreeUtilities : public classbase /** Refresh the IP cache used for allowing inbound connections */ void RefreshIPCache(); + + /** 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); }; |