diff options
-rw-r--r-- | include/events.h | 4 | ||||
-rw-r--r-- | include/modules.h | 33 | ||||
-rw-r--r-- | src/bots.cpp | 13 | ||||
-rw-r--r-- | src/datafiles.c | 2 | ||||
-rw-r--r-- | src/modules/os_ignore_db.c | 4 |
5 files changed, 42 insertions, 14 deletions
diff --git a/include/events.h b/include/events.h index b9d0c8d63..e98ad2118 100644 --- a/include/events.h +++ b/include/events.h @@ -13,19 +13,17 @@ */ #define EVENT_START "start" -#define EVENT_STOP "stop" +//#define EVENT_STOP "stop" #define EVENT_DB_SAVING "db_saving" #define EVENT_DB_BACKUP "db_backup" #define EVENT_NEWNICK "newnick" -#define EVENT_BOT_UNASSIGN "bot_unassign" #define EVENT_BOT_JOIN "bot_join" #define EVENT_BOT_CREATE "bot_create" #define EVENT_BOT_CHANGE "bot_change" #define EVENT_BOT_FANTASY "bot_command" #define EVENT_BOT_FANTASY_NO_ACCESS "bot_command_no_access" #define EVENT_BOT_DEL "bot_del" -#define EVENT_BOT_ASSIGN "bot_assign" #define EVENT_BOT_KICK "bot_kick" #define EVENT_BOT_BAN "bot_ban" #define EVENT_TOPIC_UPDATED "chan_topic_updated" diff --git a/include/modules.h b/include/modules.h index dbf6636e7..728387609 100644 --- a/include/modules.h +++ b/include/modules.h @@ -40,6 +40,15 @@ #define MODULE_EXT ".so" #endif +/** Possible return types from events. + */ +enum EventReturn +{ + EVENT_STOP, + EVENT_CONTINUE, + EVENT_ALLOW +}; + /** * This #define allows us to call a method in all @@ -72,15 +81,15 @@ #define FOREACH_RESULT(y,x) \ do { \ std::vector<Module*>::iterator safei; \ - MOD_RESULT = 0; \ + MOD_RESULT = EVENT_CONTINUE; \ for (std::vector<Module*>::iterator _i = ModuleManager::EventHandlers[y].begin(); _i != ModuleManager::EventHandlers[y].end(); ) \ { \ safei = _i; \ ++safei; \ try \ { \ - int res = (*_i)->x ; \ - if (res != 0) { \ + EventReturn res = (*_i)->x ; \ + if (res != EVENT_CONTINUE) { \ MOD_RESULT = res; \ break; \ } \ @@ -104,7 +113,7 @@ enum Priority { PRIORITY_FIRST, PRIORITY_DONTCARE, PRIORITY_LAST, PRIORITY_BEFOR enum Implementation { I_BEGIN, - I_OnUserKicked, I_OnReload, + I_OnUserKicked, I_OnReload, I_OnBotAssign, I_OnBotUnAssign, I_END }; @@ -495,8 +504,22 @@ class CoreExport Module * @param startup True if Services is starting for the first time, false otherwise. */ virtual void OnReload(bool startup) {} -}; + /** Called before a bot is assigned to a channel. + * @param sender The user assigning the bot + * @param ci The channel the bot is to be assigned to. + * @param bi The bot being assigned. + * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the assign. + */ + virtual EventReturn OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) { return EVENT_CONTINUE; } + + /** Called before a bot is unassigned from a channel. + * @param sender The user unassigning the bot + * @param ci The channel the bot is being removed from + * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the unassign. + */ + virtual EventReturn OnBotUnAssign(User *sender, ChannelInfo *ci) { return EVENT_CONTINUE; } +}; diff --git a/src/bots.cpp b/src/bots.cpp index 0ba119ed9..095d16167 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -10,6 +10,7 @@ */ #include "services.h" +#include "modules.h" BotInfo::BotInfo(const char *nnick) { @@ -89,6 +90,11 @@ void BotInfo::RejoinAll() void BotInfo::Assign(User *u, ChannelInfo *ci) { + EventReturn MOD_RESULT = EVENT_CONTINUE; + FOREACH_RESULT(I_OnBotAssign, OnBotAssign(u, ci, this)); + if (MOD_RESULT == EVENT_STOP) + return; + if (ci->bi) { if (u) @@ -101,13 +107,14 @@ void BotInfo::Assign(User *u, ChannelInfo *ci) this->chancount++; if (ci->c && ci->c->usercount >= BSMinUsers) bot_join(ci); - - send_event(EVENT_BOT_ASSIGN, 2, ci->name, this->nick); } void BotInfo::UnAssign(User *u, ChannelInfo *ci) { - send_event(EVENT_BOT_UNASSIGN, 2, ci->name, ci->bi->nick); + EventReturn MOD_RESULT = EVENT_CONTINUE; + FOREACH_RESULT(I_OnBotUnAssign, OnBotUnAssign(u, ci)); + if (MOD_RESULT == EVENT_STOP) + return; if (u && ci->c && ci->c->usercount >= BSMinUsers) ircdproto->SendPart(ci->bi, ci->name, "UNASSIGN from %s", u->nick); diff --git a/src/datafiles.c b/src/datafiles.c index 58deb31e7..57dd856ec 100644 --- a/src/datafiles.c +++ b/src/datafiles.c @@ -694,7 +694,7 @@ void backup_databases() rename_database(OperDBName, ext); rename_database(NewsDBName, ext); rename_database(ExceptionDBName, ext); - send_event(EVENT_DB_BACKUP, 1, EVENT_STOP); + send_event(EVENT_DB_BACKUP, 1, "stop"); } } diff --git a/src/modules/os_ignore_db.c b/src/modules/os_ignore_db.c index 7881d7d22..bfb2bf903 100644 --- a/src/modules/os_ignore_db.c +++ b/src/modules/os_ignore_db.c @@ -138,7 +138,7 @@ void load_config() { * When anope saves her databases, we do the same. **/ int save_ignoredb(int argc, char **argv) { - if ((argc >= 1) && (!stricmp(argv[0], EVENT_STOP))) + if ((argc >= 1) && (!stricmp(argv[0], "stop"))) save_ignore_db(); return MOD_CONT; @@ -149,7 +149,7 @@ int save_ignoredb(int argc, char **argv) { * When anope backs her databases up, we do the same. **/ int backup_ignoredb(int argc, char **argv) { - if ((argc >= 1) && (!stricmp(argv[0], EVENT_STOP))) { + if ((argc >= 1) && (!stricmp(argv[0], "stop"))) { if (debug) alog("[os_ignore_db] debug: Backing up %s database...", IgnoreDB); ModuleDatabaseBackup(IgnoreDB); |