+static SPAMSERV_FUNC(cmd_addbad)
+{
+ struct chanInfo *cInfo = get_chanInfo(channel->name);
+ struct userData *uData;
+
+ if(!cInfo)
+ {
+ ss_reply("SSMSG_NOT_REGISTERED", channel->name);
+ return 0;
+ }
+
+ if(CHECK_SUSPENDED(cInfo))
+ {
+ ss_reply("SSMSG_SUSPENDED", channel->name);
+ return 0;
+ }
+
+ if(!check_user_level(channel,user,lvlSetters,1,0))
+ {
+ ss_reply("SSMSG_NO_ACCESS");
+ return 0;
+ }
+
+ dict_iterator_t it;
+ char *mask = unsplit_string(argv + 1, argc - 1, NULL);
+ for (it = dict_first(cInfo->badwords); it; it = iter_next(it)) {
+ struct badword *badword = iter_data(it);
+ if(match_ircglob(mask,badword->badword_mask)) {
+ reply("SSMSG_BADWORD_ALREADY_ADDED", mask, badword->id);
+ return 1;
+ }
+ }
+
+ struct badword *new_badword = add_badword(cInfo, mask, 0, BADACTION_KICK, NULL);
+ for (it = dict_first(cInfo->badwords); it; it = iter_next(it)) {
+ struct badword *badword = iter_data(it);
+ if(match_ircglob(badword->badword_mask, new_badword->badword_mask) && badword != new_badword) {
+ dict_remove(cInfo->badwords, badword->id);
+ }
+ }
+
+ reply("SSMSG_BADWORD_ADDED", new_badword->badword_mask, new_badword->id);
+ return 1;
+}
+
+static SPAMSERV_FUNC(cmd_delbad)
+{
+ struct chanInfo *cInfo = get_chanInfo(channel->name);
+ struct userData *uData;
+
+ if(!cInfo)
+ {
+ ss_reply("SSMSG_NOT_REGISTERED", channel->name);
+ return 0;
+ }
+
+ if(CHECK_SUSPENDED(cInfo))
+ {
+ ss_reply("SSMSG_SUSPENDED", channel->name);
+ return 0;
+ }
+
+ if(!check_user_level(channel,user,lvlSetters,1,0))
+ {
+ ss_reply("SSMSG_NO_ACCESS");
+ return 0;
+ }
+}
+
+static SPAMSERV_FUNC(cmd_setbad)
+{
+ struct chanInfo *cInfo = get_chanInfo(channel->name);
+ struct userData *uData;
+ struct badword *badword;
+
+ if(!cInfo)
+ {
+ ss_reply("SSMSG_NOT_REGISTERED", channel->name);
+ return 0;
+ }
+
+ if(CHECK_SUSPENDED(cInfo))
+ {
+ ss_reply("SSMSG_SUSPENDED", channel->name);
+ return 0;
+ }
+
+ if(!check_user_level(channel,user,lvlSetters,1,0))
+ {
+ ss_reply("SSMSG_NO_ACCESS");
+ return 0;
+ }
+
+ if ((badword = dict_find(cInfo->badwords, argv[1], NULL))) {
+ if (argc > 3) {
+ unsigned int ii;
+ char *setting = argv[2];
+ char *value = argv[3];
+ for( ii = 0; setting[ ii ]; ii++)
+ setting[ ii ] = toupper( setting[ ii ] );
+ for( ii = 0; value[ ii ]; ii++)
+ value[ ii ] = toupper( value[ ii ] );
+ if(!strcmp("MASK",setting)) {
+ free(badword->badword_mask);
+ badword->badword_mask = strdup(argv[3]);
+ badword->triggered = 0;
+ reply("SSMSG_BADWORD_SET_DONE");
+ }
+ else if(!strcmp("ACTION",setting)) {
+ if (!strcmp("1",value) || !strcmp("KICK",value)) {
+ badword->action = BADACTION_KICK;
+ reply("SSMSG_BADWORD_SET_DONE");
+ } else if (!strcmp("2",value) || !strcmp("BAN",value)) {
+ badword->action = BADACTION_BAN;
+ reply("SSMSG_BADWORD_SET_DONE");
+ } else if (!strcmp("3",value) || !strcmp("KILL",value)) {
+ badword->action = BADACTION_KILL;
+ reply("SSMSG_BADWORD_SET_DONE");
+ } else if (!strcmp("4",value) || !strcmp("GLINE",value)) {
+ badword->action = BADACTION_GLINE;
+ reply("SSMSG_BADWORD_SET_DONE");
+ } else {
+ reply("SSMSG_BADWORD_SET_INVALID", setting);
+ }
+ } else {
+ reply("SSMSG_BADWORD_SETTING_INVALID", setting);
+ }
+
+ } else {
+ reply("SSMSG_BADWORD_SET", badword->id);
+ reply("SSMSG_BADWORD_SET_MASK", badword->badword_mask);
+ switch(badword->action) {
+ case BADACTION_KICK:
+ reply("SSMSG_BADWORD_SET_ACTION", "KICK");
+ break;
+ case BADACTION_BAN:
+ reply("SSMSG_BADWORD_SET_ACTION", "BAN");
+ break;
+ case BADACTION_KILL:
+ reply("SSMSG_BADWORD_SET_ACTION", "KILL");
+ break;
+ case BADACTION_GLINE:
+ reply("SSMSG_BADWORD_SET_ACTION", "GLINE");
+ break;
+ default:
+ reply("SSMSG_BADWORD_SET_ACTION", "*undef*");
+ }
+ }
+ } else {
+ reply("SSMSG_BADWORD_NOT_FOUND", argv[1]);
+ return 0;
+ }
+ return 1;
+}
+
+int
+ss_badwords_sort(const void *pa, const void *pb)
+{
+ struct badword *a = *(struct badword**)pa;
+ struct badword *b = *(struct badword**)pb;
+
+ return strtoul(a->id, NULL, 0) - strtoul(b->id, NULL, 0);
+}
+
+static SPAMSERV_FUNC(cmd_listbad)
+{
+ struct helpfile_table tbl;
+ struct chanInfo *cInfo = get_chanInfo(channel->name);
+ struct userData *uData;
+ struct badword **badwords;
+ unsigned int count = 0, ii = 0;
+
+ if(!cInfo)
+ {
+ ss_reply("SSMSG_NOT_REGISTERED", channel->name);
+ return 0;
+ }
+
+ if(CHECK_SUSPENDED(cInfo))
+ {
+ ss_reply("SSMSG_SUSPENDED", channel->name);
+ return 0;
+ }
+
+ if(!check_user_level(channel,user,lvlSetters,1,0))
+ {
+ ss_reply("SSMSG_NO_ACCESS");
+ return 0;
+ }
+
+ dict_iterator_t it;
+ for (it = dict_first(cInfo->badwords); it; it = iter_next(it)) {
+ count++;
+ }
+
+ tbl.length = count+1;
+ tbl.width = 4;
+ tbl.flags = 0;
+ tbl.flags = TABLE_NO_FREE;
+ tbl.contents = malloc(tbl.length * sizeof(tbl.contents[0]));
+ tbl.contents[0] = malloc(tbl.width * sizeof(tbl.contents[0][0]));
+ tbl.contents[0][0] = "#";
+ tbl.contents[0][1] = "Badword";
+ tbl.contents[0][2] = "Action";
+ tbl.contents[0][3] = "(Triggered)";
+ if(!count)
+ {
+ table_send(cmd->parent->bot, user->nick, 0, NULL, tbl);
+ reply("MSG_NONE");
+ free(tbl.contents[0]);
+ free(tbl.contents);
+ return 0;
+ }
+ badwords = alloca(count * sizeof(badwords[0]));
+ for (it = dict_first(cInfo->badwords); it; it = iter_next(it)) {
+ struct badword *bw = iter_data(it);
+ badwords[ii++] = bw;
+ }
+
+ qsort(badwords, count, sizeof(badwords[0]), ss_badwords_sort);
+ for (ii = 1; ii <= count; ii++) {
+ struct badword *bw = badwords[ii-1];
+ tbl.contents[ii] = malloc(tbl.width * sizeof(tbl.contents[0][0]));
+ tbl.contents[ii][0] = strdup(bw->id);
+ tbl.contents[ii][1] = strdup(bw->badword_mask);
+ switch(bw->action) {
+ case BADACTION_KICK:
+ tbl.contents[ii][2] = "KICK";
+ break;
+ case BADACTION_BAN:
+ tbl.contents[ii][2] = "BAN";
+ break;
+ case BADACTION_KILL:
+ tbl.contents[ii][2] = "KILL";
+ break;
+ case BADACTION_GLINE:
+ tbl.contents[ii][2] = "GLINE";
+ break;
+ default:
+ tbl.contents[ii][2] = "*undef*";
+ }
+ tbl.contents[ii][3] = strtab(bw->triggered);
+ }
+
+ table_send(cmd->parent->bot, user->nick, 0, NULL, tbl);
+ for(ii = 1; ii < tbl.length; ++ii)
+ {
+ free(tbl.contents[ii]);
+ }
+ free(tbl.contents[0]);
+ free(tbl.contents);
+ return 1;
+}
+