]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Clean up the protocol interface
authorattilamolnar <attilamolnar@hush.com>
Fri, 19 Jul 2013 11:55:02 +0000 (13:55 +0200)
committerattilamolnar <attilamolnar@hush.com>
Sun, 25 Aug 2013 11:41:36 +0000 (13:41 +0200)
include/protocol.h
src/commands/cmd_lusers.cpp
src/modules/m_chanlog.cpp
src/modules/m_httpd_stats.cpp
src/modules/m_permchannels.cpp
src/modules/m_spanningtree/main.cpp
src/modules/m_spanningtree/protocolinterface.cpp
src/modules/m_spanningtree/protocolinterface.h

index eedca50ecc228bc0d8574d1fad72190b1fefd09b..6af0ed21c65891e814008bc8c2cbde178f136d36 100644 (file)
@@ -26,23 +26,22 @@ class User;
 
 typedef std::vector<std::string> parameterlist;
 
-class ProtoServer
-{
- public:
-       std::string servername;
-       std::string parentname;
-       std::string gecos;
-       unsigned int usercount;
-       unsigned int opercount;
-       unsigned int latencyms;
-};
-
-typedef std::list<ProtoServer> ProtoServerList;
-
 class ProtocolInterface
 {
  public:
-       ProtocolInterface() { }
+       class ServerInfo
+       {
+        public:
+               std::string servername;
+               std::string parentname;
+               std::string gecos;
+               unsigned int usercount;
+               unsigned int opercount;
+               unsigned int latencyms;
+       };
+
+       typedef std::vector<ServerInfo> ServerList;
+
        virtual ~ProtocolInterface() { }
 
        /** Send an ENCAP message to one or more linked servers.
@@ -92,31 +91,39 @@ class ProtocolInterface
         * @param target The channel to message.
         * @param status The status character (e.g. %) required to recieve.
         * @param text The message to send.
+        * @param type The message type (MSG_PRIVMSG or MSG_NOTICE)
         */
-       virtual void SendChannelPrivmsg(Channel* target, char status, const std::string &text) { }
+       virtual void SendMessage(Channel* target, char status, const std::string& text, MessageType type = MSG_PRIVMSG) { }
 
-       /** Send a notice to a channel.
-        * @param target The channel to message.
-        * @param status The status character (e.g. %) required to recieve.
+       /** Send a message to a user.
+        * @param target The user to message.
         * @param text The message to send.
+        * @param type The message type (MSG_PRIVMSG or MSG_NOTICE)
         */
-       virtual void SendChannelNotice(Channel* target, char status, const std::string &text) { }
+       virtual void SendMessage(User* target, const std::string& text, MessageType type = MSG_PRIVMSG) { }
 
-       /** Send a message to a user.
-        * @param target The user to message.
+       /** Send a notice to a channel.
+        * @param target The channel to message.
+        * @param status The status character (e.g. %) required to recieve.
         * @param text The message to send.
         */
-       virtual void SendUserPrivmsg(User* target, const std::string &text) { }
+       void SendChannelNotice(Channel* target, char status, const std::string &text)
+       {
+               SendMessage(target, status, text, MSG_NOTICE);
+       }
 
        /** Send a notice to a user.
         * @param target The user to message.
         * @param text The message to send.
         */
-       virtual void SendUserNotice(User* target, const std::string &text) { }
+       void SendUserNotice(User* target, const std::string &text)
+       {
+               SendMessage(target, text, MSG_NOTICE);
+       }
 
        /** Fill a list of servers and information about them.
         * @param sl The list of servers to fill.
         * XXX: document me properly, this is shit.
         */
-       virtual void GetServerList(ProtoServerList &sl) { }
+       virtual void GetServerList(ServerList& sl) { }
 };
index ef35d1e19f4c9f0d6a3a967c372101daa9e6a82a..06419733d4ce0c699c828039015af8b0e8864fae 100644 (file)
@@ -73,11 +73,11 @@ class CommandLusers : public Command
 CmdResult CommandLusers::Handle (const std::vector<std::string>&, User *user)
 {
        unsigned int n_users = ServerInstance->Users->RegisteredUserCount();
-       ProtoServerList serverlist;
+       ProtocolInterface::ServerList serverlist;
        ServerInstance->PI->GetServerList(serverlist);
        unsigned int n_serv = serverlist.size();
        unsigned int n_local_servs = 0;
-       for(ProtoServerList::iterator i = serverlist.begin(); i != serverlist.end(); ++i)
+       for (ProtocolInterface::ServerList::const_iterator i = serverlist.begin(); i != serverlist.end(); ++i)
        {
                if (i->parentname == ServerInstance->Config->ServerName)
                        n_local_servs++;
index a62fbf9b2084381acc8457e6eec22d0fc6b2c4d9..dc5750ba66ff95be4d6aadbe470601adc8733302 100644 (file)
@@ -76,7 +76,7 @@ class ModuleChanLog : public Module
                        if (c)
                        {
                                c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), snotice.c_str());
-                               ServerInstance->PI->SendChannelPrivmsg(c, 0, snotice);
+                               ServerInstance->PI->SendMessage(c, 0, snotice);
                        }
                }
 
index df98ef3f535e51ea63ca5a6e100fd72a458b4692..022d91f1e7d0836b0f70819d72cdb07dfaaac0a6 100644 (file)
@@ -208,10 +208,10 @@ class ModuleHttpStats : public Module
 
                                data << "</userlist><serverlist>";
 
-                               ProtoServerList sl;
+                               ProtocolInterface::ServerList sl;
                                ServerInstance->PI->GetServerList(sl);
 
-                               for (ProtoServerList::iterator b = sl.begin(); b != sl.end(); ++b)
+                               for (ProtocolInterface::ServerList::const_iterator b = sl.begin(); b != sl.end(); ++b)
                                {
                                        data << "<server>";
                                        data << "<servername>" << b->servername << "</servername>";
index b8e5ea5e81802f5dee9dbfa0a1c75fb8ff266906..2a3dff6ee764fd58e50e0d68f7547f5ecf760c7b 100644 (file)
@@ -263,7 +263,7 @@ public:
                // Load only when there are no linked servers - we set the TS of the channels we
                // create to the current time, this can lead to desync because spanningtree has
                // no way of knowing what we do
-               ProtoServerList serverlist;
+               ProtocolInterface::ServerList serverlist;
                ServerInstance->PI->GetServerList(serverlist);
                if (serverlist.size() < 2)
                {
index 169a5cd90abb725b5f290bc8176f6106eb7d73d0..57fe2090cb8340e95383f7cb9ddd74f6f55c7d9f 100644 (file)
@@ -64,7 +64,7 @@ void ModuleSpanningTree::init()
        ServerInstance->Modules->AddService(commands->map);
 
        delete ServerInstance->PI;
-       ServerInstance->PI = new SpanningTreeProtocolInterface(Utils);
+       ServerInstance->PI = new SpanningTreeProtocolInterface;
        loopCall = false;
 
        // update our local user count
index 0f5c40cc10884269dd66646d5f78e292e5e602c3..5fd598d1d291e8a8265fdf48e65375c73b8c045d 100644 (file)
  * For documentation on this class, see include/protocol.h.
  */
 
-void SpanningTreeProtocolInterface::GetServerList(ProtoServerList &sl)
+void SpanningTreeProtocolInterface::GetServerList(ServerList& sl)
 {
-       sl.clear();
        for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
        {
-               ProtoServer ps;
+               ServerInfo ps;
                ps.servername = i->second->GetName();
                TreeServer* s = i->second->GetParent();
                ps.parentname = s ? s->GetName() : "";
@@ -127,30 +126,18 @@ void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string
        Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", p, target->server);
 }
 
-void SpanningTreeProtocolInterface::SendChannelPrivmsg(Channel* target, char status, const std::string &text)
+void SpanningTreeProtocolInterface::SendMessage(Channel* target, char status, const std::string& text, MessageType msgtype)
 {
+       const char* cmd = (msgtype == MSG_PRIVMSG ? "PRIVMSG" : "NOTICE");
        CUList exempt_list;
-       Utils->SendChannelMessage(ServerInstance->Config->GetSID(), target, text, status, exempt_list, "PRIVMSG");
+       Utils->SendChannelMessage(ServerInstance->Config->GetSID(), target, text, status, exempt_list, cmd);
 }
 
-void SpanningTreeProtocolInterface::SendChannelNotice(Channel* target, char status, const std::string &text)
-{
-       CUList exempt_list;
-       Utils->SendChannelMessage(ServerInstance->Config->GetSID(), target, text, status, exempt_list, "NOTICE");
-}
-
-void SpanningTreeProtocolInterface::SendUserPrivmsg(User* target, const std::string &text)
-{
-       parameterlist p;
-       p.push_back(target->uuid);
-       p.push_back(":" + text);
-       Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PRIVMSG", p, target->server);
-}
-
-void SpanningTreeProtocolInterface::SendUserNotice(User* target, const std::string &text)
+void SpanningTreeProtocolInterface::SendMessage(User* target, const std::string& text, MessageType msgtype)
 {
+       const char* cmd = (msgtype == MSG_PRIVMSG ? "PRIVMSG" : "NOTICE");
        parameterlist p;
        p.push_back(target->uuid);
        p.push_back(":" + text);
-       Utils->DoOneToOne(ServerInstance->Config->GetSID(), "NOTICE", p, target->server);
+       Utils->DoOneToOne(ServerInstance->Config->GetSID(), cmd, p, target->server);
 }
index 2b4c4371ff20b4f862b1470ea6358c0b1a167ccb..b48e4542580dae79ccfb87e033805e0f41de8f7e 100644 (file)
 
 #pragma once
 
-class SpanningTreeUtilities;
-class ModuleSpanningTree;
-
 class SpanningTreeProtocolInterface : public ProtocolInterface
 {
-       SpanningTreeUtilities* Utils;
  public:
-       SpanningTreeProtocolInterface(SpanningTreeUtilities* util) : Utils(util) { }
-
        bool SendEncapsulatedData(const parameterlist &encap);
        void SendMetaData(Extensible* target, const std::string &key, const std::string &data);
        void SendTopic(Channel* channel, std::string &topic);
        void SendMode(User* source, User* usertarget, Channel* chantarget, const parameterlist& modedata, const std::vector<TranslateType>& types);
        void SendSNONotice(const std::string &snomask, const std::string &text);
        void PushToClient(User* target, const std::string &rawline);
-       void SendChannelPrivmsg(Channel* target, char status, const std::string &text);
-       void SendChannelNotice(Channel* target, char status, const std::string &text);
-       void SendUserPrivmsg(User* target, const std::string &text);
-       void SendUserNotice(User* target, const std::string &text);
-       void GetServerList(ProtoServerList &sl);
+       void SendMessage(Channel* target, char status, const std::string& text, MessageType msgtype);
+       void SendMessage(User* target, const std::string& text, MessageType msgtype);
+       void GetServerList(ServerList& sl);
 };