X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcommand_parse.cpp;h=07b41c4cba644b4ead2fba50b4c4992f479c1fbd;hb=74c8913f72e6d48c88a01155ef5fe5ca20cc2bb1;hp=1545c8e1bfc5a49877f9751b30c603daf3d2e6c7;hpb=afd808e442bc4d6c4df0399518f0b58225d86de6;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 1545c8e1b..07b41c4cb 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -1,13 +1,10 @@ -/* +------------------------------------+ + /* +------------------------------------+ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. - * E-mail: - * - * + * InspIRCd: (C) 2002-2007 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits * - * Written by Craig Edwards, Craig McLure, and others. * This program is free but copyrighted software; see * the file COPYING for details. * @@ -24,7 +21,6 @@ #include "wildcard.h" #include "xline.h" #include "socketengine.h" -#include "userprocess.h" #include "socket.h" #include "command_parse.h" @@ -38,10 +34,10 @@ bool InspIRCd::ULine(const char* server) return (find(Config->ulines.begin(),Config->ulines.end(),server) != Config->ulines.end()); } -int InspIRCd::OperPassCompare(const char* data,const char* input) +int InspIRCd::OperPassCompare(const char* data,const char* input, int tagnumber) { int MOD_RESULT = 0; - FOREACH_RESULT_I(this,I_OnOperCompare,OnOperCompare(data,input)) + FOREACH_RESULT_I(this,I_OnOperCompare,OnOperCompare(data, input, tagnumber)) Log(DEBUG,"OperPassCompare: %d",MOD_RESULT); if (MOD_RESULT == 1) return 0; @@ -110,89 +106,6 @@ long InspIRCd::Duration(const char* str) return total; } -/* All other ircds when doing this check usually just look for a string of *@* or *. We're smarter than that, though. */ - -bool InspIRCd::HostMatchesEveryone(const std::string &mask, userrec* user) -{ - char buffer[MAXBUF]; - char itrigger[MAXBUF]; - long matches = 0; - - if (!Config->ConfValue(Config->config_data, "insane","trigger", 0, itrigger, MAXBUF)) - strlcpy(itrigger,"95.5",MAXBUF); - - if (Config->ConfValueBool(Config->config_data, "insane","hostmasks", 0)) - return false; - - for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++) - { - strlcpy(buffer,u->second->ident,MAXBUF); - charlcat(buffer,'@',MAXBUF); - strlcat(buffer,u->second->host,MAXBUF); - if (match(buffer,mask.c_str())) - matches++; - } - float percent = ((float)matches / (float)clientlist.size()) * 100; - if (percent > (float)atof(itrigger)) - { - WriteOpers("*** \2WARNING\2: %s tried to set a G/K/E line mask of %s, which covers %.2f%% of the network!",user->nick,mask.c_str(),percent); - return true; - } - return false; -} - -bool InspIRCd::IPMatchesEveryone(const std::string &ip, userrec* user) -{ - char itrigger[MAXBUF]; - long matches = 0; - - if (!Config->ConfValue(Config->config_data, "insane","trigger",0,itrigger,MAXBUF)) - strlcpy(itrigger,"95.5",MAXBUF); - - if (Config->ConfValueBool(Config->config_data, "insane","ipmasks",0)) - return false; - - for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++) - { - if (match(u->second->GetIPString(),ip.c_str(),true)) - matches++; - } - - float percent = ((float)matches / (float)clientlist.size()) * 100; - if (percent > (float)atof(itrigger)) - { - WriteOpers("*** \2WARNING\2: %s tried to set a Z line mask of %s, which covers %.2f%% of the network!",user->nick,ip.c_str(),percent); - return true; - } - return false; -} - -bool InspIRCd::NickMatchesEveryone(const std::string &nick, userrec* user) -{ - char itrigger[MAXBUF]; - long matches = 0; - - if (!Config->ConfValue(Config->config_data, "insane","trigger",0,itrigger,MAXBUF)) - strlcpy(itrigger,"95.5",MAXBUF); - - if (Config->ConfValueBool(Config->config_data, "insane","nickmasks",0)) - return false; - - for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++) - { - if (match(u->second->nick,nick.c_str())) - matches++; - } - - float percent = ((float)matches / (float)clientlist.size()) * 100; - if (percent > (float)atof(itrigger)) - { - WriteOpers("*** \2WARNING\2: %s tried to set a Q line mask of %s, which covers %.2f%% of the network!",user->nick,nick.c_str(),percent); - return true; - } - return false; -} - /* LoopCall is used to call a command classes handler repeatedly based on the contents of a comma seperated list. * There are two overriden versions of this method, one of which takes two potential lists and the other takes one. * We need a version which takes two potential lists for JOIN, because a JOIN may contain two lists of items at once, @@ -211,11 +124,17 @@ int CommandParser::LoopCall(userrec* user, command_t* CommandObj, const char** p if (!strchr(parameters[splithere],',')) return 0; + /** Some lame ircds will weed out dupes using some shitty O(n^2) algorithm. + * By using std::map (thanks for the idea w00t) we can cut this down a ton. + * ...VOOODOOOO! + */ + std::map dupes; + /* Create two lists, one for channel names, one for keys */ irc::commasepstream items1(parameters[splithere]); irc::commasepstream items2(parameters[extra]); - std::string item = ""; + std::string item = "*"; unsigned int max = 0; /* Attempt to iterate these lists and call the command objech @@ -224,10 +143,23 @@ int CommandParser::LoopCall(userrec* user, command_t* CommandObj, const char** p */ while (((item = items1.GetToken()) != "") && (max++ < ServerInstance->Config->MaxTargets)) { - std::string extrastuff = items2.GetToken(); - parameters[splithere] = item.c_str(); - parameters[extra] = extrastuff.c_str(); - CommandObj->Handle(parameters,pcnt,user); + if (dupes.find(item.c_str()) == dupes.end()) + { + const char* new_parameters[127]; + + for (int t = 0; (t < pcnt) && (t < 127); t++) + new_parameters[t] = parameters[t]; + + std::string extrastuff = items2.GetToken(); + + new_parameters[splithere] = item.c_str(); + new_parameters[extra] = extrastuff.c_str(); + + if (CommandObj->Handle(new_parameters,pcnt,user) == CMD_USER_DELETED) + return 1; + + dupes[item.c_str()] = true; + } } return 1; } @@ -240,9 +172,12 @@ int CommandParser::LoopCall(userrec* user, command_t* CommandObj, const char** p if (!strchr(parameters[splithere],',')) return 0; + std::map dupes; + /* Only one commasepstream here */ + ServerInstance->Log(DEBUG,"Splitting '%s'",parameters[splithere]); irc::commasepstream items1(parameters[splithere]); - std::string item = ""; + std::string item = "*"; unsigned int max = 0; /* Parse the commasepstream until there are no tokens remaining. @@ -251,8 +186,26 @@ int CommandParser::LoopCall(userrec* user, command_t* CommandObj, const char** p */ while (((item = items1.GetToken()) != "") && (max++ < ServerInstance->Config->MaxTargets)) { - parameters[splithere] = item.c_str(); - CommandObj->Handle(parameters,pcnt,user); + if (dupes.find(item.c_str()) == dupes.end()) + { + const char* new_parameters[127]; + + for (int t = 0; (t < pcnt) && (t < 127); t++) + new_parameters[t] = parameters[t]; + + new_parameters[splithere] = item.c_str(); + + parameters[splithere] = item.c_str(); + + /* Execute the command handler over and over. If someone pulls our user + * record out from under us (e.g. if we /kill a comma sep list, and we're + * in that list ourselves) abort if we're gone. + */ + if (CommandObj->Handle(new_parameters,pcnt,user) == CMD_USER_DELETED) + return 1; + + dupes[item.c_str()] = true; + } } /* By returning 1 we tell our caller that nothing is to be done, * as all the previous calls handled the data. This makes the parent @@ -282,6 +235,15 @@ bool CommandParser::IsValidCommand(const std::string &commandname, int pcnt, use return false; } +command_t* CommandParser::GetHandler(const std::string &commandname) +{ + nspace::hash_map::iterator n = cmdlist.find(commandname); + if (n != cmdlist.end()) + return n->second; + + return NULL; +} + // calls a handler function for a command CmdResult CommandParser::CallHandler(const std::string &commandname,const char** parameters, int pcnt, userrec *user) @@ -315,7 +277,6 @@ void CommandParser::ProcessCommand(userrec *user, std::string &cmd) { const char *command_p[127]; int items = 0; - std::string para[127]; irc::tokenstream tokens(cmd); std::string command = tokens.GetToken(); @@ -328,7 +289,7 @@ void CommandParser::ProcessCommand(userrec *user, std::string &cmd) std::transform(command.begin(), command.end(), command.begin(), ::toupper); int MOD_RESULT = 0; - FOREACH_RESULT(I_OnPreCommand,OnPreCommand(command,command_p,items,user,false)); + FOREACH_RESULT(I_OnPreCommand,OnPreCommand(command,command_p,items,user,false,cmd)); if (MOD_RESULT == 1) { return; } @@ -345,7 +306,7 @@ void CommandParser::ProcessCommand(userrec *user, std::string &cmd) { if (!user->IsModeSet(cm->second->flags_needed)) { - user->WriteServ("481 %s :Permission Denied- You do not have the required operator privilages",user->nick); + user->WriteServ("481 %s :Permission Denied- You do not have the required operator privileges",user->nick); return; } if (!user->HasPermission(command)) @@ -375,7 +336,7 @@ void CommandParser::ProcessCommand(userrec *user, std::string &cmd) cm->second->total_bytes += cmd.length(); int MOD_RESULT = 0; - FOREACH_RESULT(I_OnPreCommand,OnPreCommand(command,command_p,items,user,true)); + FOREACH_RESULT(I_OnPreCommand,OnPreCommand(command,command_p,items,user,true,cmd)); if (MOD_RESULT == 1) return; @@ -386,7 +347,10 @@ void CommandParser::ProcessCommand(userrec *user, std::string &cmd) */ CmdResult result = cm->second->Handle(command_p,items,user); - FOREACH_MOD(I_OnPostCommand,OnPostCommand(command, command_p, items, user, result)); + if (result != CMD_USER_DELETED) + { + FOREACH_MOD(I_OnPostCommand,OnPostCommand(command, command_p, items, user, result,cmd)); + } return; } else @@ -405,28 +369,33 @@ void CommandParser::ProcessCommand(userrec *user, std::string &cmd) bool CommandParser::RemoveCommands(const char* source) { - bool go_again = true; - - while (go_again) + nspace::hash_map::iterator i,safei; + for (i = cmdlist.begin(); i != cmdlist.end(); i++) { - go_again = false; - - for (nspace::hash_map::iterator i = cmdlist.begin(); i != cmdlist.end(); i++) + safei = i; + safei++; + if (safei != cmdlist.end()) { - command_t* x = i->second; - if (x->source == std::string(source)) - { - ServerInstance->Log(DEBUG,"removecommands(%s) Removing dependent command: %s",x->source.c_str(),x->command.c_str()); - cmdlist.erase(i); - go_again = true; - break; - } + RemoveCommand(safei, source); } } - + safei = cmdlist.begin(); + if (safei != cmdlist.end()) + { + RemoveCommand(safei, source); + } return true; } +void CommandParser::RemoveCommand(nspace::hash_map::iterator safei, const char* source) +{ + command_t* x = safei->second; + if (x->source == std::string(source)) + { + cmdlist.erase(safei); + } +} + void CommandParser::ProcessBuffer(std::string &buffer,userrec *user) { std::string::size_type a; @@ -474,6 +443,7 @@ bool CommandParser::CreateCommand(command_t *f, void* so_handle) CommandParser::CommandParser(InspIRCd* Instance) : ServerInstance(Instance) { + para.resize(128); this->SetupCommandTable(); } @@ -515,7 +485,7 @@ bool CommandParser::ReloadCommand(const char* cmd) dlclose(command->second); RFCCommands.erase(command); - sprintf(filename, "cmd_%s.so", commandname); + snprintf(filename, MAXBUF, "cmd_%s.so", commandname); this->LoadCommand(filename); return true; @@ -530,6 +500,7 @@ CmdResult cmd_reload::Handle(const char** parameters, int pcnt, userrec *user) if (ServerInstance->Parser->ReloadCommand(parameters[0])) { user->WriteServ("NOTICE %s :*** Successfully reloaded command '%s'", user->nick, parameters[0]); + ServerInstance->WriteOpers("*** RELOAD: %s reloaded the '%s' command.", user->nick, parameters[0]); return CMD_SUCCESS; } else