- 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);
- }
+ nspace::hash_map<std::string,command_t*>::iterator cm = cmdlist.find(xcommand);
+
+ if (cm != cmdlist.end())
+ {
+ if (user)
+ {
+ /* activity resets the ping pending timer */
+ user->nping = TIME + user->pingmax;
+ if ((items) < cm->second->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,cm->second->flags_needed)) && (cm->second->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 ((cm->second->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) && (!*user->oper) && (*Config->DisabledCommands))
+ {
+ std::stringstream dcmds(Config->DisabledCommands);
+ std::string thiscmd;
+ while (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)
+ {
+ cm->second->use_count++;
+ cm->second->total_bytes+=strlen(temp);
+ }
+
+ int MOD_RESULT = 0;
+ FOREACH_RESULT(I_OnPreCommand,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!
+ */
+
+ cm->second->Handle(command_p,items,user);
+ return;
+ }
+ else
+ {
+ WriteServ(user->fd,"451 %s :You have not registered",command);
+ return;
+ }
+ }
+ }
+ else if (user)
+ {
+ ServerInstance->stats->statsUnknown++;
+ WriteServ(user->fd,"421 %s %s :Unknown command",user->nick,command);
+ }