- for (unsigned int i = 0; i != cmdlist.size(); i++)
- {
- if ((xcommand.length() >= cmdlist[i]->command.length()) && (xcommand == cmdlist[i]->command))
- {
- if (user)
- {
- /* activity resets the ping pending timer */
- user->nping = TIME + user->pingmax;
- if ((items) < cmdlist[i]->min_params)
- {
- log(DEBUG,"not enough parameters: %s %s",user->nick,command);
- WriteServ(user->fd,"461 %s %s :Not enough parameters",user->nick,command);
- return;
- }
- if ((!strchr(user->modes,cmdlist[i]->flags_needed)) && (cmdlist[i]->flags_needed))
- {
- log(DEBUG,"permission denied: %s %s",user->nick,command);
- WriteServ(user->fd,"481 %s :Permission Denied- You do not have the required operator privilages",user->nick);
- cmd_found = 1;
- return;
- }
- if ((cmdlist[i]->flags_needed) && (!user->HasPermission(xcommand)))
- {
- log(DEBUG,"permission denied: %s %s",user->nick,command);
- WriteServ(user->fd,"481 %s :Permission Denied- Oper type %s does not have access to command %s",user->nick,user->oper,command);
- cmd_found = 1;
- return;
- }
- /* if the command isnt USER, PASS, or NICK, and nick is empty,
- * deny command! */
- if ((strncmp(command,"USER",4)) && (strncmp(command,"NICK",4)) && (strncmp(command,"PASS",4)))
- {
- if ((!isnick(user->nick)) || (user->registered != 7))
- {
- log(DEBUG,"not registered: %s %s",user->nick,command);
- WriteServ(user->fd,"451 %s :You have not registered",command);
- return;
- }
- }
- if ((user->registered == 7) && (!strchr(user->modes,'o')))
- {
- std::stringstream dcmds(Config->DisabledCommands);
- while (!dcmds.eof())
- {
- std::string thiscmd;
- dcmds >> thiscmd;
- if (!strcasecmp(thiscmd.c_str(),command))
- {
- // command is disabled!
- WriteServ(user->fd,"421 %s %s :This command has been disabled.",user->nick,command);
- return;
- }
- }
- }
- if ((user->registered == 7) || (!strncmp(command,"USER",4)) || (!strncmp(command,"NICK",4)) || (!strncmp(command,"PASS",4)))
- {
- /* ikky /stats counters */
- if (temp)
- {
- cmdlist[i]->use_count++;
- cmdlist[i]->total_bytes+=strlen(temp);
- }
-
- int MOD_RESULT = 0;
- FOREACH_RESULT(OnPreCommand(command,command_p,items,user,true));
- if (MOD_RESULT == 1) {
- return;
- }
-
- /* WARNING: nothing may come after the
- * command handler call, as the handler
- * may free the user structure! */
-
- cmdlist[i]->Handle(command_p,items,user);
- return;
- }
- else
- {
- WriteServ(user->fd,"451 %s :You have not registered",command);
- return;
- }
- }
- cmd_found = 1;
- }
- }
- if ((!cmd_found) && (user))
- {
- ServerInstance->stats->statsUnknown++;
- WriteServ(user->fd,"421 %s %s :Unknown command",user->nick,command);
- }
+ if (cm != cmdlist.end())
+ {
+ if (user)
+ {
+ /* activity resets the ping pending timer */
+ user->nping = ServerInstance->Time() + user->pingmax;
+ if (cm->second->flags_needed)
+ {
+ if (!user->IsModeSet(cm->second->flags_needed))
+ {
+ user->WriteServ("481 %s :Permission Denied- You do not have the required operator privileges",user->nick);
+ return;
+ }
+ if (!user->HasPermission(command))
+ {
+ user->WriteServ("481 %s :Permission Denied- Oper type %s does not have access to command %s",user->nick,user->oper,command.c_str());
+ return;
+ }
+ }
+ if ((user->registered == REG_ALL) && (!*user->oper) && (cm->second->IsDisabled()))
+ {
+ /* command is disabled! */
+ user->WriteServ("421 %s %s :This command has been disabled.",user->nick,command.c_str());
+ return;
+ }
+ if (items < cm->second->min_params)
+ {
+ user->WriteServ("461 %s %s :Not enough parameters.", user->nick, command.c_str());
+ /* If syntax is given, display this as the 461 reply */
+ if ((ServerInstance->Config->SyntaxHints) && (cm->second->syntax.length()))
+ user->WriteServ("304 %s :SYNTAX %s %s", user->nick, cm->second->command.c_str(), cm->second->syntax.c_str());
+ return;
+ }
+ if ((user->registered == REG_ALL) || (cm->second->WorksBeforeReg()))
+ {
+ /* ikky /stats counters */
+ cm->second->use_count++;
+ cm->second->total_bytes += cmd.length();
+
+ int MOD_RESULT = 0;
+ FOREACH_RESULT(I_OnPreCommand,OnPreCommand(command,command_p,items,user,true,cmd));
+ if (MOD_RESULT == 1)
+ return;
+
+ /*
+ * WARNING: nothing may come after the
+ * command handler call, as the handler
+ * may free the user structure!
+ */
+ CmdResult result = cm->second->Handle(command_p,items,user);
+
+ if (result != CMD_USER_DELETED)
+ {
+ FOREACH_MOD(I_OnPostCommand,OnPostCommand(command, command_p, items, user, result,cmd));
+ }
+ return;
+ }
+ else
+ {
+ user->WriteServ("451 %s :You have not registered",command.c_str());
+ return;
+ }
+ }
+ }
+ else if (user)
+ {
+ ServerInstance->stats->statsUnknown++;
+ user->WriteServ("421 %s %s :Unknown command",user->nick,command.c_str());
+ }