diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commands.c | 4 | ||||
-rw-r--r-- | src/modules/hs_request.c | 81 | ||||
-rw-r--r-- | src/modules/ns_maxemail.c | 82 | ||||
-rw-r--r-- | src/modules/os_info.c | 104 |
4 files changed, 106 insertions, 165 deletions
diff --git a/src/commands.c b/src/commands.c index e7f5522ed..399d8e332 100644 --- a/src/commands.c +++ b/src/commands.c @@ -121,11 +121,13 @@ void mod_run_cmd(char *service, User * u, CommandHash * cmdTable[], const char * } EventReturn MOD_RESULT = EVENT_CONTINUE; - FOREACH_RESULT(I_OnPreCommand, OnPreCommand(u, c->name, params)); + FOREACH_RESULT(I_OnPreCommand, OnPreCommand(u, c->service, c->name, params)); if (MOD_RESULT == EVENT_STOP) return; retVal = c->Execute(u, params); + + FOREACH_MOD(I_OnPostCommand, OnPostCommand(u, c->service, c->name, params)); } /*************************************************************************/ diff --git a/src/modules/hs_request.c b/src/modules/hs_request.c index a5e8a016a..9d043e6d0 100644 --- a/src/modules/hs_request.c +++ b/src/modules/hs_request.c @@ -366,27 +366,6 @@ class HSListBase : public Command } }; -class CommandHSList : public HSListBase -{ - public: - CommandHSList() : HSListBase("LIST", 0, 1) - { - } - - CommandReturn Execute(User *u, std::vector<std::string> ¶ms) - { - const char *key = params.size() ? params[0].c_str() : NULL; - - if (!key) - return MOD_CONT; - - if (stricmp(key, "+req")) - return MOD_CONT; - - return this->DoList(u, params); - } -}; - class CommandHSWaiting : public HSListBase { public: @@ -412,29 +391,6 @@ class CommandHSWaiting : public HSListBase } }; -class CommandNSDrop : public Command -{ - public: - CommandNSDrop() : Command("DROP", 0, 0) - { - } - - CommandReturn Execute(User *u, std::vector<std::string> ¶ms) - { - HostCore *tmp; - bool found = false; - NickAlias *na; - - na = findnick(u->nick); - tmp = findHostCore(hs_request_head, u->nick, &found); - - if (found && na) - hs_request_head = deleteHostCore(hs_request_head, tmp); - - return MOD_CONT; - } -}; - class HSRequest : public Module { public: @@ -446,10 +402,8 @@ class HSRequest : public Module this->AddCommand(HOSTSERV, new CommandHSActivate(), MOD_HEAD); this->AddCommand(HOSTSERV, new CommandHSReject(), MOD_HEAD); this->AddCommand(HOSTSERV, new CommandHSWaiting(), MOD_HEAD); - this->AddCommand(HOSTSERV, new CommandHSList(), MOD_HEAD); - - this->AddCommand(NICKSERV, new CommandNSDrop(), MOD_HEAD); + ModuleManager::Attach(I_OnPreCommand, this); ModuleManager::Attach(I_OnSaveDatabase, this); ModuleManager::Attach(I_OnBackupDatabase, this); @@ -731,6 +685,39 @@ class HSRequest : public Module delete [] HSRequestDBName; } + EventReturn OnPreCommand(User *u, const std::string &service, const std::string &command, const std::vector<std::string> ¶ms) + { + if (service == s_HostServ) + { + if (command == "LIST") + { + const char *key = params.size() ? params[0].c_str() : NULL; + + if (key && !stricmp(key, "+req")) + { + std::vector<std::string> emptyParams; + Command *c = findCommand(HOSTSERV, "WAITING"); + c->Execute(u, emptyParams); + return EVENT_STOP; + } + } + } + else if (service == s_NickServ) + { + if (command == "DROP") + { + bool found = false; + NickAlias *na = findnick(u->nick); + HostCore *tmp = findHostCore(hs_request_head, u->nick, &found); + + if (found && na) + hs_request_head = deleteHostCore(hs_request_head, tmp); + } + } + + return EVENT_CONTINUE; + } + void OnSaveDatabase() { FILE *fp; diff --git a/src/modules/ns_maxemail.c b/src/modules/ns_maxemail.c index 8af24416f..ccb624947 100644 --- a/src/modules/ns_maxemail.c +++ b/src/modules/ns_maxemail.c @@ -20,7 +20,7 @@ void my_load_config(); void my_add_languages(); -CommandReturn check_email_limit_reached(const char *email, User * u); +bool check_email_limit_reached(const char *email, User * u); int NSEmailMax = 0; @@ -30,50 +30,6 @@ int NSEmailMax = 0; static Module *me; -// XXX: This should probably use an event one day. -class CommandNSRegister : public Command -{ - public: - CommandNSRegister() : Command("REGISTER", 1, 2) - { - this->SetFlag(CFLAG_ALLOW_UNREGISTERED); - } - - CommandReturn Execute(User *u, std::vector<std::string> ¶ms) - { - return check_email_limit_reached(params.size() > 1 ? params[1].c_str() : NULL, u); - } - - void OnSyntaxError(User *u) - { - // no-op - } -}; - -class CommandNSSet : public Command -{ - public: - CommandNSSet() : Command("SET", 1, 3) - { - } - - CommandReturn Execute(User *u, std::vector<std::string> ¶ms) - { - const char *set = params[0].c_str(); - const char *email = params[1].size() > 1 ? params[1].c_str() : NULL; - - if (!stricmp(set, "email")) - return MOD_CONT; - - return check_email_limit_reached(email, u); - } - - void OnSyntaxError(User *u) - { - // no-op - } -}; - class NSMaxEmail : public Module { public: @@ -85,10 +41,8 @@ class NSMaxEmail : public Module this->SetVersion(VERSION); this->SetType(SUPPORTED); - this->AddCommand(NICKSERV, new CommandNSRegister(), MOD_HEAD); - this->AddCommand(NICKSERV, new CommandNSSet(), MOD_HEAD); - - ModuleManager::Attach(I_OnReload, this); + ModuleManager::Attach(I_OnReload, this); + ModuleManager::Attach(I_OnPreCommand, this); my_load_config(); @@ -146,6 +100,28 @@ class NSMaxEmail : public Module { my_load_config(); } + + EventReturn OnPreCommand(User *u, const std::string &service, const std::string &command, const std::vector<std::string> ¶ms) + { + if (service == s_NickServ) + { + if (command == "REGISTER") + { + if (check_email_limit_reached(params.size() > 1 ? params[1].c_str() : NULL, u)) + return EVENT_STOP; + } + else if (command == "SET") + { + const char *set = params[0].c_str(); + const char *email = params[1].size() > 1 ? params[1].c_str() : NULL; + + if (!stricmp(set, "email") && check_email_limit_reached(email, u)) + return EVENT_STOP; + } + } + + return EVENT_CONTINUE; + } }; @@ -170,20 +146,20 @@ int count_email_in_use(const char *email, User * u) return count; } -CommandReturn check_email_limit_reached(const char *email, User * u) +bool check_email_limit_reached(const char *email, User * u) { if (NSEmailMax < 1 || !email || is_services_admin(u)) - return MOD_CONT; + return false; if (count_email_in_use(email, u) < NSEmailMax) - return MOD_CONT; + return false; if (NSEmailMax == 1) me->NoticeLang(s_NickServ, u, LNG_NSEMAILMAX_REACHED_ONE); else me->NoticeLang(s_NickServ, u, LNG_NSEMAILMAX_REACHED, NSEmailMax); - return MOD_STOP; + return true; } void my_load_config() diff --git a/src/modules/os_info.c b/src/modules/os_info.c index 4e1ef087d..74f5ab34d 100644 --- a/src/modules/os_info.c +++ b/src/modules/os_info.c @@ -141,37 +141,6 @@ class CommandNSOInfo : public Command } }; -class CommandNSInfo : public Command -{ - public: - CommandNSInfo() : Command("INFO", 1, 1) - { - } - - CommandReturn Execute(User *u, std::vector<std::string> ¶ms) - { - const char *nick = params[0].c_str(); - NickAlias *na = NULL; - - if (is_oper(u)) /* Only show our goodies to opers */ - { - if ((na = findnick(nick))) /* ok we've found the user */ - { - /* If we have any info on this user */ - char *c; - if (na->nc->GetExt("os_info", c)) - u->SendMessage(s_NickServ, " OperInfo: %s", c); - } - } - return MOD_CONT; - } - - void OnSyntaxError(User *u) - { - // no-op - } -}; - class CommandCSOInfo : public Command { private: @@ -259,37 +228,6 @@ class CommandCSOInfo : public Command } }; -class CommandCSInfo : public Command -{ - public: - CommandCSInfo() : Command("INFO", 1, 1) - { - } - - CommandReturn Execute(User *u, std::vector<std::string> ¶ms) - { - const char *chan = params[0].c_str(); - ChannelInfo *ci = NULL; - - if (is_oper(u)) /* Only show our goodies to opers */ - { - if ((ci = cs_findchan(chan))) - { - /* If we have any info on this channel */ - char *c; - if (ci->GetExt("os_info", c)) - u->SendMessage(s_ChanServ, " OperInfo: %s", c); - } - } - return MOD_CONT; - } - - void OnSyntaxError(User *u) - { - // no-op - } -}; - class OSInfo : public Module { public: @@ -307,11 +245,10 @@ class OSInfo : public Module throw ModuleException("Unable to load config"); status = this->AddCommand(NICKSERV, new CommandNSOInfo(), MOD_HEAD); - status = this->AddCommand(NICKSERV, new CommandNSInfo(), MOD_TAIL); status = this->AddCommand(CHANSERV, new CommandCSOInfo(), MOD_HEAD); - status = this->AddCommand(CHANSERV, new CommandCSInfo(), MOD_TAIL); + ModuleManager::Attach(I_OnPostCommand, this); ModuleManager::Attach(I_OnSaveDatabase, this); ModuleManager::Attach(I_OnBackupDatabase, this); @@ -567,6 +504,45 @@ class OSInfo : public Module alog("os_info.c: ERROR: An error has occured while reloading the configuration file"); } + void OnPostCommand(User *u, const std::string &service, const std::string &command, const std::vector<std::string> ¶ms) + { + if (command == "INFO") + { + if (service == s_NickServ) + { + const char *nick = params[0].c_str(); + NickAlias *na = NULL; + + if (is_oper(u)) /* Only show our goodies to opers */ + { + if ((na = findnick(nick))) /* ok we've found the user */ + { + /* If we have any info on this user */ + char *c; + if (na->nc->GetExt("os_info", c)) + u->SendMessage(s_NickServ, " OperInfo: %s", c); + } + } + } + else if (service == s_ChanServ) + { + const char *chan = params[0].c_str(); + ChannelInfo *ci = NULL; + + if (is_oper(u)) /* Only show our goodies to opers */ + { + if ((ci = cs_findchan(chan))) + { + /* If we have any info on this channel */ + char *c; + if (ci->GetExt("os_info", c)) + u->SendMessage(s_ChanServ, " OperInfo: %s", c); + } + } + } + } + } + void OnSaveDatabase() { ChannelInfo *ci = NULL; |