}
}
+static int hooksregistered;
+
static void __dbloaded(int hooknum, void *arg) {
int i;
nick *np;
+ if(hooksregistered)
+ return;
+ hooksregistered = 1;
+
registerhook(HOOK_NICK_NEWNICK, __newnick);
registerhook(HOOK_NICK_LOSTNICK, __lostnick);
}
void trusts_deregisterevents(void) {
- if(trustsdbloaded) {
- deregisterhook(HOOK_NICK_NEWNICK, __newnick);
- deregisterhook(HOOK_NICK_LOSTNICK, __lostnick);
+ deregisterhook(HOOK_TRUSTS_DB_LOADED, __dbloaded);
+
+ if(!hooksregistered)
+ return;
+ hooksregistered = 0;
+
+ deregisterhook(HOOK_NICK_NEWNICK, __newnick);
+ deregisterhook(HOOK_NICK_LOSTNICK, __lostnick);
/*
- deregisterhook(HOOK_TRUSTS_NEWNICK, __counthandler);
- deregisterhook(HOOK_TRUSTS_LOSTNICK, __counthandler);
+ deregisterhook(HOOK_TRUSTS_NEWNICK, __counthandler);
+ deregisterhook(HOOK_TRUSTS_LOSTNICK, __counthandler);
*/
- }
-
- deregisterhook(HOOK_TRUSTS_DB_LOADED, __dbloaded);
}
int trusts_migration_start(TrustDBMigrationCallback, void *);
void trusts_migration_stop(void);
-static void registercommands(void);
+static void registercommands(int hooknum, void *arg);
static void deregistercommands(void);
static void migrate_status(int errcode, void *tag) {
controlreply(np, "All functionality disabled, database unloaded -- please reload the module.");
} else {
controlreply(np, "Error %d occured during migration, commands reregistered.", errcode);
- registercommands();
+ registercommands(0, NULL);
}
}
return CMD_OK;
}
-static void dbloaded(int hooknum, void *arg) {
- registercommands();
+static int commandsregistered;
+
+static void registercommands(int hooknum, void *arg) {
+ if(commandsregistered)
+ return;
+ commandsregistered = 1;
+
+ registercontrolhelpcmd("trustmigrate", NO_DEVELOPER, 0, trusts_cmdmigrate, "Usage: trustmigrate\nCopies trust data from O and reloads the database.");
+ registercontrolhelpcmd("trustlist", NO_OPER, 1, trusts_cmdtrustlist, "Usage: trustlist <#id|name|id>\nShows trust data for the specified trust group.");
+}
+
+static void deregistercommands(void) {
+ if(!commandsregistered)
+ return;
+ commandsregistered = 0;
+
+ deregistercontrolcmd("trustmigrate", trusts_cmdmigrate);
+ deregistercontrolcmd("trustlist", trusts_cmdtrustlist);
}
void _init(void) {
- registerhook(HOOK_TRUSTS_DB_LOADED, dbloaded);
+ registerhook(HOOK_TRUSTS_DB_LOADED, registercommands);
if(trustsdbloaded)
- registercommands();
+ registercommands(0, NULL);
}
void _fini(void) {
- deregisterhook(HOOK_TRUSTS_DB_LOADED, dbloaded);
+ deregisterhook(HOOK_TRUSTS_DB_LOADED, registercommands);
deregistercommands();
trusts_migration_stop();
}
-static void registercommands(void) {
- registercontrolhelpcmd("trustmigrate", NO_DEVELOPER, 0, trusts_cmdmigrate, "Usage: trustmigrate\nCopies trust data from O and reloads the database.");
- registercontrolhelpcmd("trustlist", NO_OPER, 1, trusts_cmdtrustlist, "Usage: trustlist <#id|name|id>\nShows trust data for the specified trust group.");
-}
-
-static void deregistercommands(void) {
- if(!trustsdbloaded)
- return;
-
- deregistercontrolcmd("trustmigrate", trusts_cmdmigrate);
- deregistercontrolcmd("trustlist", trusts_cmdtrustlist);
-}