#define KEY_BADWORD_MASK "mask"
#define KEY_BADWORD_TRIGGERED "count"
#define KEY_BADWORD_ACTION "action"
+#define KEY_CHANNELS "channel"
static const struct message_entry msgtab[] = {
{ "WDMSG_NULL", "null." },
{ NULL, NULL }
};
+DECLARE_LIST(shitList, struct badword*);
+DEFINE_LIST(shitList, struct badword*)
+
struct badword {
char *badword_mask;
unsigned int triggered : 29;
unsigned int action : 3;
};
-DECLARE_LIST(shitList, struct badword*);
-DEFINE_LIST(shitList, struct badword*)
+struct watchdog_channel {
+ struct chanNode *channel;
+ //struct shitList *shitlist;
+};
/* badword.action fields */
#define BADACTION_KICK 1
static struct module *watchdog_module;
static struct service *watchdog_service;
static struct shitList shitlist;
+static dict_t chanlist;
static struct log_type *MS_LOG;
return 1;
}
+static MODCMD_FUNC(cmd_register)
+{
+ //to be continued...
+ return 1;
+}
+
+static MODCMD_FUNC(cmd_unregister)
+{
+ //to be continued...
+ return 1;
+}
+
static void
watchdog_channel_message(struct userNode *user, struct chanNode *chan, const char *text, struct userNode *bot, unsigned int is_notice)
{
free(badword);
}
+static struct watchdog_channel*
+add_channel(const char *name)
+{
+ struct watchdog_channel *wc;
+
+ wc = calloc(1, sizeof(*wc));
+ if (!wc)
+ return NULL;
+
+ wc->channel = AddChannel(name, now, NULL, NULL);
+ AddChannelUser(watchdog, wc->channel)->modes |= MODE_CHANOP;
+ dict_insert(chanlist, wc->channel->name, wc);
+ return wc;
+}
+
+static void
+free_chanlist_entry(void *data)
+{
+ struct watchdog_channel *wc = data;
+
+ free(wc);
+}
+
static void
watchdog_conf_read(void)
{
return 0;
}
+static int
+watchdog_saxdb_read_chanlist(const char *name, void *data, UNUSED_ARG(void *extra))
+{
+ struct record_data *rd = data;
+
+ if (rd->type == RECDB_OBJECT) {
+ dict_t obj = GET_RECORD_OBJECT(rd);
+ /* nothing in here, yet */
+
+ add_channel(name);
+ return 1;
+ } else
+ return 0;
+}
+
static int
watchdog_saxdb_read(struct dict *db)
{
struct dict *object;
if ((object = database_get_data(db, KEY_BADWORDS, RECDB_OBJECT)))
dict_foreach(object, watchdog_saxdb_read_shitlist, NULL);
+ if ((object = database_get_data(db, KEY_CHANNELS, RECDB_OBJECT)))
+ dict_foreach(object, watchdog_saxdb_read_chanlist, NULL);
return 1;
}
struct badword *badword;
char str[17];
unsigned int id = 0, ii;
+ dict_iterator_t it;
saxdb_start_record(ctx, KEY_BADWORDS, 1);
for (ii = 0; ii < shitlist.used; ++ii) {
}
saxdb_end_record(ctx);
+ if (dict_size(chanlist)) {
+ saxdb_start_record(ctx, KEY_CHANNELS, 1);
+ for (it = dict_first(chanlist); it; it = iter_next(it)) {
+ struct watchdog_channel *wc = iter_data(it);
+ saxdb_start_record(ctx, wc->channel->name, 0);
+ //anything else?
+ saxdb_end_record(ctx);
+ }
+ saxdb_end_record(ctx);
+ }
+
return 0;
}
while (shitlist.used)
delete_badword(shitlist.list[0]);
shitList_clean(&shitlist);
+ dict_delete(chanlist);
}
int
watchdog_init(void)
{
MS_LOG = log_register_type("Watchdog", "file:watchdog.log");
+
shitList_init(&shitlist);
+ /* set up chanlist dict */
+ dict_delete(chanlist);
+ chanlist = dict_new();
+ dict_set_free_data(chanlist, free_chanlist_entry);
+
conf_register_reload(watchdog_conf_read);
reg_exit_func(watchdog_cleanup);
saxdb_register("Watchdog", watchdog_saxdb_read, watchdog_saxdb_write);
modcmd_register(watchdog_module, "delbad", cmd_delbad, 1, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL);
modcmd_register(watchdog_module, "editbad", cmd_editbad, 1, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL);
modcmd_register(watchdog_module, "listbad", cmd_listbad, 1, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL);
+ modcmd_register(watchdog_module, "register", cmd_register, 1, MODCMD_REQUIRE_AUTHED, "flags", "+helping", NULL);
+ modcmd_register(watchdog_module, "unregister", cmd_unregister, 1, MODCMD_REQUIRE_AUTHED, "flags", "+helping", NULL);
message_register_table(msgtab);
return 1;