]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Added clever code to propogate module's special commands (SAJOIN, KNOCK etc) transpar...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 1 Dec 2005 19:24:53 +0000 (19:24 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 1 Dec 2005 19:24:53 +0000 (19:24 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2084 e03df62e-2008-0410-955e-edbf42e46eb7

include/inspircd.h
include/modules.h
src/inspircd.cpp
src/modules.cpp
src/modules/m_spanningtree.cpp

index 9bf0b88784c8998e66e8b8305de6dd59e50c46bf..05a76f48ef9f04ba57178dd2696a7f59cbfab4d4 100644 (file)
@@ -95,6 +95,7 @@ void force_nickchange(userrec* user,const char* newnick);
 void kill_link(userrec *user,const char* r);
 void kill_link_silent(userrec *user,const char* r);
 void call_handler(const char* commandname,char **parameters, int pcnt, userrec *user);
+bool is_valid_cmd(const char* commandname, int pcnt, userrec * user);
 std::string GetRevision();
 int loop_call(handlerfunc fn, char **parameters, int pcnt, userrec *u, int start, int end, int joins);
 void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason);
index ec49c90dc2cd1085f3e8897a6d02c2d41b4efa4c..9e3206736039d5baecaec0ddb871a11f48ca223f 100644 (file)
@@ -978,6 +978,8 @@ class Server : public classbase
         * used for privilage checks, etc.
         */
        virtual void CallCommandHandler(std::string commandname, char** parameters, int pcnt, userrec* user);
+
+       virtual bool IsValidModuleCommand(std::string commandname, int pcnt, userrec* user);
        
        /** Change displayed hostname of a user.
         * You should always call this method to change a user's host rather than writing directly to the
index a946abbbbe696033669d75ff8c71f761e7e7c065..2e300df95449e2c803caccf8ea66eecdbf8a0e19 100644 (file)
@@ -1560,6 +1560,27 @@ void handle_version(char **parameters, int pcnt, userrec *user)
 }
 
 
+bool is_valid_cmd(const char* commandname, int pcnt, userrec * user)
+{
+       for (unsigned int i = 0; i < cmdlist.size(); i++)
+       {
+               if (!strcasecmp(cmdlist[i].command,commandname))
+               {
+                       if (cmdlist[i].handler_function)
+                       {
+                               if (pcnt>=cmdlist[i].min_params)
+                               {
+                                       if (strchr(user->modes,cmdlist[i].flags_needed))
+                                       {
+                                               return true;
+                                       }
+                               }
+                       }
+               }
+       }
+       return false;
+}
+
 // calls a handler function for a command
 
 void call_handler(const char* commandname,char **parameters, int pcnt, userrec *user)
index 2dda2daf5e5c5fb5faeed082f95a48ae9c01a391..e199bcbcc8ccf4efdc9a944415c389429b6d05b2 100644 (file)
@@ -464,6 +464,11 @@ void Server::CallCommandHandler(std::string commandname, char** parameters, int
        call_handler(commandname.c_str(),parameters,pcnt,user);
 }
 
+bool Server::IsValidModuleCommand(std::string commandname, int pcnt, userrec* user)
+{
+       return is_valid_cmd(commandname, pcnt, user)
+}
+
 void Server::Log(int level, std::string s)
 {
        log(level,"%s",s.c_str());
index bb2231306817f7c0e84e4b947e43b9845ba7f198..fbdc6f1f5a5aa6aa5c1ee0e91772939da701cc38 100644 (file)
@@ -1418,6 +1418,28 @@ class ModuleSpanningTree : public Module
                        this->HandleLinks(parameters,pcnt,user);
                        return 1;
                }
+               else if (Srv->IsValidModuleCommand(command, pcnt, user))
+               {
+                       // this bit of code cleverly routes all module commands
+                       // to all remote severs *automatically* so that modules
+                       // can just handle commands locally, without having
+                       // to have any special provision in place for remote
+                       // commands and linking protocols.
+                       std::deque<std::string> params;
+                       params.clear();
+                       for (int j = 0; j < pcnt; j++)
+                       {
+                               if (strchr(parameters[j],' '))
+                               {
+                                       params.push_back(":" + std::string(parameters[j]));
+                               }
+                               else
+                               {
+                                       params.push_back(std::string(parameters[j]));
+                               }
+                       }
+                       DoOneToMany(user->nick,command,params);
+               }
                return 0;
        }