/* * mo_set - SET command handler * set options while running */ static int mo_set(struct Client *source_p, int parc, char *parv[]) { int n; int newval; const char *strarg = NULL; const char *intarg = NULL; if (!HasOFlag(source_p, OPER_FLAG_SET)) { sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "set"); return 0; } if (parc > 1) { /* * Go through all the commands in set_cmd_table, until one is * matched. */ for (const struct SetStruct *tab = set_cmd_table; tab->handler; ++tab) { if (irccmp(tab->name, parv[1])) continue; /* * Command found; now execute the code */ n = 2; if (tab->wants_char) strarg = parv[n++]; if (tab->wants_int) intarg = parv[n++]; if ((n - 1) > parc) sendto_one_notice(source_p, &me, ":SET %s expects (\"%s%s\") args", tab->name, (tab->wants_char ? "string, " : ""), (tab->wants_int ? "int" : "")); if (parc <= 2) { strarg = NULL; intarg = NULL; } if (tab->wants_int && parc > 2) { if (intarg) { if (!irccmp(intarg, "yes") || !irccmp(intarg, "on")) newval = 1; else if (!irccmp(intarg, "no") || !irccmp(intarg, "off")) newval = 0; else newval = atoi(intarg); } else newval = -1; if (newval < 0) { sendto_one_notice(source_p, &me, ":Value less than 0 illegal for %s", tab->name); return 0; } } else newval = -1; tab->handler(source_p, strarg, newval); return 0; } /* * Code here will be executed when a /QUOTE SET command is not * found within set_cmd_table. */ sendto_one_notice(source_p, &me, ":Variable not found."); return 0; } list_quote_commands(source_p); return 0; }
/* * mo_set - SET command handler * set options while running */ static void mo_set(struct Client *client_p, struct Client *source_p, int parc, char *parv[]) { int i; int n; int newval; const char *arg = NULL; const char *intarg = NULL; if (parc > 1) { /* Go through all the commands in set_cmd_table, until one is * matched. I realize strcmp() is more intensive than a numeric * lookup, but at least it's better than a big-ass switch/case * statement. */ for (i = 0; set_cmd_table[i].handler; i++) { if (irccmp(set_cmd_table[i].name, parv[1]) == 0) { /* * Command found; now execute the code */ n = 2; if (set_cmd_table[i].wants_char) { arg = parv[n++]; } if (set_cmd_table[i].wants_int) { intarg = parv[n++]; } if ((n - 1) > parc) { if (parc > 2) sendto_one(source_p, ":%s NOTICE %s :SET %s expects (\"%s%s\") args", me.name, source_p->name, set_cmd_table[i].name, (set_cmd_table[i].wants_char ? "string, " : ""), (set_cmd_table[i].wants_char ? "int" : "") ); } if (parc <= 2) { arg = NULL; intarg = NULL; } if (!strcmp(set_cmd_table[i].name, "AUTOCONN") && (parc < 4)) { sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "SET"); return; } if (set_cmd_table[i].wants_int && (parc > 2)) { if (intarg) { if (irccmp(intarg, "yes") == 0 || irccmp(intarg, "on") == 0) newval = 1; else if (irccmp(intarg, "no") == 0|| irccmp(intarg, "off") == 0) newval = 0; else newval = atoi(intarg); } else { newval = -1; } if (newval < 0) { sendto_one(source_p, ":%s NOTICE %s :Value less than 0 illegal for %s", me.name, source_p->name, set_cmd_table[i].name); return; } } else newval = -1; if (set_cmd_table[i].wants_char) { if (set_cmd_table[i].wants_int) set_cmd_table[i].handler(source_p, arg, newval); else set_cmd_table[i].handler(source_p, arg); return; } else { if (set_cmd_table[i].wants_int) set_cmd_table[i].handler(source_p, newval); else /* Just in case someone actually wants a * set function that takes no args.. *shrug* */ set_cmd_table[i].handler(source_p); return; } } } /* * Code here will be executed when a /QUOTE SET command is not * found within set_cmd_table. */ sendto_one(source_p, ":%s NOTICE %s :Variable not found.", me.name, source_p->name); return; } list_quote_commands(source_p); }
/* * mo_set - SET command handler * set options while running */ static void mo_set(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { int newval; int i, n; const char *arg = NULL; const char *intarg = NULL; if(parc > 1) { /* * Go through all the commands in set_cmd_table, until one is * matched. I realize strcmp() is more intensive than a numeric * lookup, but at least it's better than a big-ass switch/case * statement. */ for (i = 0; set_cmd_table[i].handler; i++) { if(!irccmp(set_cmd_table[i].name, parv[1])) { /* * Command found; now execute the code */ n = 2; if(set_cmd_table[i].wants_char) { arg = parv[n++]; } if(set_cmd_table[i].wants_int) { intarg = parv[n++]; } if((n - 1) > parc) { sendto_one_notice(source_p, ":SET %s expects (\"%s%s\") args", set_cmd_table[i].name, (set_cmd_table[i]. wants_char ? "string, " : ""), (set_cmd_table[i]. wants_char ? "int" : "")); return; } if(parc <= 2) { arg = NULL; intarg = NULL; } if(set_cmd_table[i].wants_int && (parc > 2)) { if(intarg) { if(!irccmp(intarg, "yes") || !irccmp(intarg, "on")) newval = 1; else if(!irccmp(intarg, "no") || !irccmp(intarg, "off")) newval = 0; else newval = atoi(intarg); } else { newval = -1; } if(newval < 0) { sendto_one_notice(source_p, ":Value less than 0 illegal for %s", set_cmd_table[i].name); return; } } else newval = -1; set_cmd_table[i].handler(source_p, arg, newval); return; } } /* * Code here will be executed when a /QUOTE SET command is not * found within set_cmd_table. */ sendto_one_notice(source_p, ":Variable not found."); return; } list_quote_commands(source_p); }