]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/command_parse.cpp
Make error messages on failure to load command more useful
[user/henk/code/inspircd.git] / src / command_parse.cpp
index 9cef16ef40cdbcbd1203aa8e12331f86daf18c20..e751db6d338e55dcdd74950b9a1827ca8d5a2112 100644 (file)
@@ -217,12 +217,15 @@ bool CommandParser::IsValidCommand(const std::string &commandname, int pcnt, use
        {
                if ((pcnt>=n->second->min_params) && (n->second->source != "<core>"))
                {
-                       if ((!n->second->flags_needed) || (user->IsModeSet(n->second->flags_needed)))
+                       if (IS_LOCAL(user) && n->second->flags_needed)
                        {
-                               if (n->second->flags_needed)
+                               if (user->IsModeSet(n->second->flags_needed))
                                {
-                                       return ((user->HasPermission(commandname)) || (ServerInstance->ULine(user->server)));
+                                       return (user->HasPermission(commandname));
                                }
+                       }
+                       else
+                       {
                                return true;
                        }
                }
@@ -249,20 +252,29 @@ CmdResult CommandParser::CallHandler(const std::string &commandname,const char**
        {
                if (pcnt >= n->second->min_params)
                {
-                       if ((!n->second->flags_needed) || (user->IsModeSet(n->second->flags_needed)))
+                       bool bOkay = false;
+
+                       if (IS_LOCAL(user) && n->second->flags_needed)
                        {
-                               if (n->second->flags_needed)
-                               {
-                                       if ((user->HasPermission(commandname)) || (!IS_LOCAL(user)))
-                                       {
-                                               return n->second->Handle(parameters,pcnt,user);
-                                       }
-                               }
-                               else
+                               /* if user is local, and flags are needed .. */
+
+                               if (user->IsModeSet(n->second->flags_needed))
                                {
-                                       return n->second->Handle(parameters,pcnt,user);
+                                       /* if user has the flags, and now has the permissions, go ahead */
+                                       if (user->HasPermission(commandname))
+                                               bOkay = true;
                                }
                        }
+                       else
+                       {
+                               /* remote or no flags required anyway */
+                               bOkay = true;
+                       }
+
+                       if (bOkay)
+                       {
+                               return n->second->Handle(parameters,pcnt,user);
+                       }
                }
        }
        return CMD_INVALID;
@@ -346,8 +358,7 @@ void CommandParser::ProcessCommand(userrec *user, std::string &cmd)
                                        return;
 
                                /*
-                                * WARNING: nothing should come after this, as the user may be on a cull list to
-                                * be nuked next loop iteration. be sensible.
+                                * WARNING: be careful, the user may be deleted soon
                                 */
                                CmdResult result = cm->second->Handle(command_p,items,user);
 
@@ -414,7 +425,7 @@ void CommandParser::ProcessBuffer(std::string &buffer,userrec *user)
        {
                if (!user->muted)
                {
-                       ServerInstance->Log(DEBUG,"C[%d] -> :%s %s",user->GetFd(), user->nick, buffer.c_str());
+                       ServerInstance->Log(DEBUG,"C[%d] I :%s %s",user->GetFd(), user->nick, buffer.c_str());
                        this->ProcessCommand(user,buffer);
                }
        }
@@ -447,13 +458,13 @@ CommandParser::CommandParser(InspIRCd* Instance) : ServerInstance(Instance)
        para.resize(128);
 }
 
-bool CommandParser::FindSym(void** v, void* h)
+bool CommandParser::FindSym(void** v, void* h, const std::string &name)
 {
        *v = dlsym(h, "init_command");
        const char* err = dlerror();
        if (err && !(*v))
        {
-               ServerInstance->Log(SPARSE, "Error loading core command: %s\n", err);
+               ServerInstance->Log(SPARSE, "Error loading core command %s: %s\n", name, err);
                return false;
        }
        return true;
@@ -535,11 +546,11 @@ const char* CommandParser::LoadCommand(const char* name)
        if (!h)
        {
                const char* n = dlerror();
-               ServerInstance->Log(SPARSE, "Error loading core command: %s", n);
+               ServerInstance->Log(SPARSE, "Error loading core command %s: %s", name, n);
                return n;
        }
 
-       if (this->FindSym((void **)&cmd_factory_func, h))
+       if (this->FindSym((void **)&cmd_factory_func, h, name))
        {
                command_t* newcommand = cmd_factory_func(ServerInstance);
                this->CreateCommand(newcommand, h);
@@ -597,21 +608,66 @@ void CommandParser::SetupCommandTable(userrec* user)
 int CommandParser::TranslateUIDs(TranslateType to, const std::string &source, std::string &dest)
 {
        userrec* user = NULL;
+       std::string item;
+       int translations = 0;
+
        switch (to)
        {
                case TR_NICK:
                        /* Translate single nickname */
+                       ServerInstance->Log(DEBUG,"TR_NICK");
                        user = ServerInstance->FindNick(source);
                        if (user)
+                       {
+                               ServerInstance->Log(DEBUG,"Managed UUID");
                                dest = user->uuid;
+                               translations++;
+                       }
                        else
+                       {
+                               ServerInstance->Log(DEBUG,"Had to use source.. (%s)", source.c_str());
                                dest = source;
+                       }
                break;
                case TR_NICKLIST:
+               {
                        /* Translate comma seperated list of nicknames */
+                       irc::commasepstream items(source);
+                       while (items.GetToken(item))
+                       {
+                               user = ServerInstance->FindNick(item);
+                               if (user)
+                               {
+                                       dest.append(user->uuid);
+                                       translations++;
+                               }
+                               else
+                                       dest.append(source);
+                               dest.append(",");
+                       }
+                       if (!dest.empty())
+                               dest.erase(dest.end() - 1);
+               }
                break;
                case TR_SPACENICKLIST:
+               {
                        /* Translate space seperated list of nicknames */
+                       irc::spacesepstream items(source);
+                       while (items.GetToken(item))
+                       {
+                               user = ServerInstance->FindNick(item);
+                               if (user)
+                               {
+                                       dest.append(user->uuid);
+                                       translations++;
+                               }
+                               else
+                                       dest.append(source);
+                               dest.append(" ");
+                       }
+                       if (!dest.empty())
+                               dest.erase(dest.end() - 1);
+               }
                break;
                case TR_END:
                case TR_TEXT:
@@ -620,5 +676,7 @@ int CommandParser::TranslateUIDs(TranslateType to, const std::string &source, st
                        dest = source;
                break;
        }
+
+       return translations;
 }