mirror of
https://github.com/anope/anope.git
synced 2026-07-09 17:03:13 +02:00
Added service argument to OnPreCommand, added OnPostCommand event, changed the following modules to use On[Pre|Post]Command instead of hooking into existing commands: hs_request, ns_maxemail, and os_info.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2242 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
+11
-2
@@ -506,11 +506,20 @@ class CoreExport Module
|
||||
|
||||
/** Called before a command is due to be executed.
|
||||
* @param u The user executing the command
|
||||
* @param service The service the command is associated with
|
||||
* @param command The command the user is executing
|
||||
* @param params The parameters the user is sending
|
||||
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it
|
||||
*/
|
||||
virtual EventReturn OnPreCommand(User *u, const std::string &command, const std::vector<std::string> ¶ms) { return EVENT_CONTINUE; }
|
||||
virtual EventReturn OnPreCommand(User *u, const std::string &service, const std::string &command, const std::vector<std::string> ¶ms) { return EVENT_CONTINUE; }
|
||||
|
||||
/** Called after a command has been executed.
|
||||
* @param u The user executing the command
|
||||
* @param service The service the command is associated with
|
||||
* @param command The command the user executed
|
||||
* @param params The parameters the user sent
|
||||
*/
|
||||
virtual void OnPostCommand(User *u, const std::string &service, const std::string &command, const std::vector<std::string> ¶ms) { }
|
||||
|
||||
/** Called when anope saves databases.
|
||||
* NOTE: This event is deprecated pending new database handling.
|
||||
@@ -531,7 +540,7 @@ enum Implementation
|
||||
{
|
||||
I_BEGIN,
|
||||
I_OnUserKicked, I_OnReload, I_OnBotAssign, I_OnBotUnAssign, I_OnUserConnect, I_OnServerConnect,
|
||||
I_OnPreCommand,
|
||||
I_OnPreCommand, I_OnPostCommand,
|
||||
I_OnSaveDatabase, I_OnBackupDatabase,
|
||||
I_END
|
||||
};
|
||||
|
||||
+3
-1
@@ -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));
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
+34
-47
@@ -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;
|
||||
|
||||
+29
-53
@@ -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()
|
||||
|
||||
+40
-64
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user