mirror of
https://github.com/anope/anope.git
synced 2026-07-02 20:43:12 +02:00
Remove capability for commands to hook existing commands, add an OnPreCommand event instead. Tidies up a lot of stuff. Also remove a bunch of dead code.
NOTE: This will break some stuff. git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2241 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
+10
-14
@@ -281,13 +281,7 @@ class CoreExport Command
|
||||
int core; /* Can this command be deleted? */
|
||||
char *mod_name; /* Name of the module who owns us, NULL for core's */
|
||||
char *service; /* Service we provide this command for */
|
||||
int (*all_help)(User *u);
|
||||
int (*regular_help)(User *u);
|
||||
int (*oper_help)(User *u);
|
||||
int (*admin_help)(User *u);
|
||||
int (*root_help)(User *u);
|
||||
|
||||
Command *next; /* Next command responsible for the same command */
|
||||
Command *next;
|
||||
};
|
||||
/** Every module in Anope is actually a class.
|
||||
*/
|
||||
@@ -510,6 +504,14 @@ class CoreExport Module
|
||||
*/
|
||||
virtual void OnServerConnect(Server *s) { }
|
||||
|
||||
/** Called before a command is due to be executed.
|
||||
* @param u The user executing the command
|
||||
* @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; }
|
||||
|
||||
/** Called when anope saves databases.
|
||||
* NOTE: This event is deprecated pending new database handling.
|
||||
* XXX.
|
||||
@@ -529,6 +531,7 @@ enum Implementation
|
||||
{
|
||||
I_BEGIN,
|
||||
I_OnUserKicked, I_OnReload, I_OnBotAssign, I_OnBotUnAssign, I_OnUserConnect, I_OnServerConnect,
|
||||
I_OnPreCommand,
|
||||
I_OnSaveDatabase, I_OnBackupDatabase,
|
||||
I_END
|
||||
};
|
||||
@@ -678,14 +681,7 @@ int encryption_module_init(); /* Load the encryption module */
|
||||
int protocol_module_init(); /* Load the IRCD Protocol Module up*/
|
||||
void moduleCallBackPrepForUnload(const char *mod_name);
|
||||
MDE void moduleCallBackDeleteEntry(ModuleCallBack * prev);
|
||||
MDE char *moduleGetLastBuffer();
|
||||
MDE void moduleDisplayHelp(int service, User *u);
|
||||
MDE int moduleAddHelp(Command * c, int (*func) (User * u));
|
||||
MDE int moduleAddRegHelp(Command * c, int (*func) (User * u));
|
||||
MDE int moduleAddOperHelp(Command * c, int (*func) (User * u));
|
||||
MDE int moduleAddAdminHelp(Command * c, int (*func) (User * u));
|
||||
MDE int moduleAddRootHelp(Command * c, int (*func) (User * u));
|
||||
extern MDE char *mod_current_buffer;
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
+1
-7
@@ -9,14 +9,9 @@ Command::Command(const std::string &sname, size_t min_params, size_t max_params)
|
||||
this->help_param3 = NULL;
|
||||
this->help_param4 = NULL;
|
||||
this->core = 0;
|
||||
this->next = NULL;
|
||||
this->mod_name = NULL;
|
||||
this->service = NULL;
|
||||
this->all_help = NULL;
|
||||
this->regular_help = NULL;
|
||||
this->oper_help = NULL;
|
||||
this->admin_help = NULL;
|
||||
this->root_help = NULL;
|
||||
this->next = NULL;
|
||||
}
|
||||
|
||||
Command::~Command()
|
||||
@@ -27,7 +22,6 @@ Command::~Command()
|
||||
if (this->service) {
|
||||
delete [] this->service;
|
||||
}
|
||||
this->next = NULL;
|
||||
}
|
||||
|
||||
/** Execute this command.
|
||||
|
||||
+7
-16
@@ -53,7 +53,7 @@ void mod_run_cmd(char *service, User * u, CommandHash * cmdTable[], const char *
|
||||
{
|
||||
Command *c = findCommand(cmdTable, cmd);
|
||||
int retVal = 0;
|
||||
Command *current;
|
||||
|
||||
|
||||
if (!c)
|
||||
{
|
||||
@@ -120,16 +120,12 @@ void mod_run_cmd(char *service, User * u, CommandHash * cmdTable[], const char *
|
||||
return;
|
||||
}
|
||||
|
||||
EventReturn MOD_RESULT = EVENT_CONTINUE;
|
||||
FOREACH_RESULT(I_OnPreCommand, OnPreCommand(u, c->name, params));
|
||||
if (MOD_RESULT == EVENT_STOP)
|
||||
return;
|
||||
|
||||
retVal = c->Execute(u, params);
|
||||
if (retVal == MOD_CONT)
|
||||
{
|
||||
current = c->next;
|
||||
while (current && retVal == MOD_CONT)
|
||||
{
|
||||
retVal = current->Execute(u, params);
|
||||
current = current->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
@@ -145,9 +141,6 @@ void mod_run_cmd(char *service, User * u, CommandHash * cmdTable[], const char *
|
||||
void mod_help_cmd(char *service, User * u, CommandHash * cmdTable[],
|
||||
const char *cmd)
|
||||
{
|
||||
bool has_had_help = false;
|
||||
int cont = MOD_CONT;
|
||||
|
||||
spacesepstream tokens(cmd);
|
||||
std::string token;
|
||||
tokens.GetToken(token);
|
||||
@@ -156,9 +149,7 @@ void mod_help_cmd(char *service, User * u, CommandHash * cmdTable[],
|
||||
|
||||
std::string subcommand = tokens.StreamEnd() ? "" : tokens.GetRemaining();
|
||||
|
||||
for (Command *current = c; current && cont == MOD_CONT; current = current->next)
|
||||
has_had_help = current->OnHelp(u, subcommand);
|
||||
if (!has_had_help)
|
||||
if (!c->OnHelp(u, subcommand))
|
||||
notice_lang(service, u, NO_HELP_AVAILABLE, cmd);
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -208,11 +208,10 @@ class CommandNSGList : public Command
|
||||
const char *nick = params.size() ? params[0].c_str() : NULL;
|
||||
|
||||
NickCore *nc = u->nc;
|
||||
int is_servadmin = is_services_admin(u);
|
||||
int nick_ided = nick_identified(u);
|
||||
int i;
|
||||
|
||||
if (nick ? (stricmp(nick, u->nick) ? !is_servadmin : !nick_ided) : !nick_ided)
|
||||
if (nick ? (stricmp(nick, u->nick) ? !u->nc->IsServicesOper() : !nick_ided) : !nick_ided)
|
||||
notice_lang(s_NickServ, u, nick_ided ? ACCESS_DENIED : NICK_IDENTIFY_REQUIRED, s_NickServ);
|
||||
else if (nick && (!findnick(nick) || !(nc = findnick(nick)->nc)))
|
||||
notice_lang(s_NickServ, u, !nick ? NICK_NOT_REGISTERED : NICK_X_NOT_REGISTERED, nick);
|
||||
@@ -237,7 +236,7 @@ class CommandNSGList : public Command
|
||||
tm = localtime(&expt);
|
||||
strftime_lang(buf, sizeof(buf), finduser(na2->nick), STRFTIME_DATE_TIME_FORMAT, tm);
|
||||
}
|
||||
notice_lang(s_NickServ, u, is_services_admin(u) && !wont_expire ? NICK_GLIST_REPLY_ADMIN : NICK_GLIST_REPLY, wont_expire ? '!' : ' ', na2->nick, buf);
|
||||
notice_lang(s_NickServ, u, u->nc->IsServicesOper() && !wont_expire ? NICK_GLIST_REPLY_ADMIN : NICK_GLIST_REPLY, wont_expire ? '!' : ' ', na2->nick, buf);
|
||||
}
|
||||
}
|
||||
notice_lang(s_NickServ, u, NICK_GLIST_FOOTER, nc->aliases.count);
|
||||
@@ -248,7 +247,7 @@ class CommandNSGList : public Command
|
||||
|
||||
bool OnHelp(User *u, const std::string &subcommand)
|
||||
{
|
||||
if (is_services_admin(u))
|
||||
if (u->nc && u->nc->IsServicesOper())
|
||||
notice_help(s_NickServ, u, NICK_SERVADMIN_HELP_GLIST);
|
||||
else
|
||||
notice_help(s_NickServ, u, NICK_HELP_GLIST);
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ class CommandNSHelp : public Command
|
||||
{
|
||||
notice_help(s_NickServ, u, NICK_HELP);
|
||||
moduleDisplayHelp(1, u);
|
||||
if (is_services_admin(u))
|
||||
if (u->nc && u->nc->IsServicesOper())
|
||||
notice_help(s_NickServ, u, NICK_SERVADMIN_HELP);
|
||||
if (NSExpire >= 86400)
|
||||
notice_help(s_NickServ, u, NICK_HELP_EXPIRES, NSExpire / 86400);
|
||||
|
||||
+5
-6
@@ -52,18 +52,17 @@ class CommandNSInfo : public Command
|
||||
NickAlias *na;
|
||||
NickRequest *nr = NULL;
|
||||
/* Being an oper is enough from now on -GD */
|
||||
int is_servadmin = is_services_oper(u);
|
||||
|
||||
if (!(na = findnick(nick)))
|
||||
{
|
||||
if ((nr = findrequestnick(nick)))
|
||||
{
|
||||
notice_lang(s_NickServ, u, NICK_IS_PREREG);
|
||||
if (param && !stricmp(param, "ALL") && is_servadmin)
|
||||
if (param && !stricmp(param, "ALL") && u->nc->IsServicesOper())
|
||||
notice_lang(s_NickServ, u, NICK_INFO_EMAIL, nr->email);
|
||||
else
|
||||
{
|
||||
if (is_servadmin)
|
||||
if (u->nc->IsServicesOper())
|
||||
notice_lang(s_NickServ, u, NICK_INFO_FOR_MORE, s_NickServ, nr->nick);
|
||||
}
|
||||
}
|
||||
@@ -93,7 +92,7 @@ class CommandNSInfo : public Command
|
||||
|
||||
/* Only show hidden fields to owner and sadmins and only when the ALL
|
||||
* parameter is used. -TheShadow */
|
||||
if (param && !stricmp(param, "ALL") && u->nc && (na->nc == u->nc || is_servadmin))
|
||||
if (param && !stricmp(param, "ALL") && u->nc && (na->nc == u->nc || u->nc->IsServicesOper()))
|
||||
show_hidden = 1;
|
||||
|
||||
notice_lang(s_NickServ, u, NICK_INFO_REALNAME, na->nick, na->last_realname);
|
||||
@@ -180,7 +179,7 @@ class CommandNSInfo : public Command
|
||||
notice_lang(s_NickServ, u, NICK_INFO_NO_EXPIRE);
|
||||
else
|
||||
{
|
||||
if (is_services_admin(u))
|
||||
if (u->nc->IsServicesOper())
|
||||
{
|
||||
expt = na->last_seen + NSExpire;
|
||||
tm = localtime(&expt);
|
||||
@@ -198,7 +197,7 @@ class CommandNSInfo : public Command
|
||||
|
||||
bool OnHelp(User *u, const std::string &subcommand)
|
||||
{
|
||||
if (is_services_admin(u))
|
||||
if (u->nc->IsServicesOper())
|
||||
notice_help(s_NickServ, u, NICK_SERVADMIN_HELP_INFO);
|
||||
else
|
||||
notice_help(s_NickServ, u, NICK_HELP_INFO);
|
||||
|
||||
+3
-3
@@ -45,7 +45,7 @@ class CommandNSList : public Command
|
||||
NickCore *mync;
|
||||
unsigned nnicks, i;
|
||||
char buf[BUFSIZE];
|
||||
int is_servadmin = is_services_admin(u);
|
||||
bool is_servadmin = u->nc->IsServicesOper();
|
||||
int16 matchflags = 0;
|
||||
NickRequest *nr = NULL;
|
||||
int nronly = 0;
|
||||
@@ -194,7 +194,7 @@ class CommandNSList : public Command
|
||||
|
||||
bool OnHelp(User *u, const std::string &subcommand)
|
||||
{
|
||||
if (is_services_admin(u))
|
||||
if (u->nc && u->nc->IsServicesOper())
|
||||
notice_help(s_NickServ, u, NICK_SERVADMIN_HELP_LIST);
|
||||
else
|
||||
notice_help(s_NickServ, u, NICK_HELP_LIST);
|
||||
@@ -204,7 +204,7 @@ class CommandNSList : public Command
|
||||
|
||||
void OnSyntaxError(User *u)
|
||||
{
|
||||
if (is_services_admin(u))
|
||||
if (u->nc->IsServicesOper())
|
||||
syntax_error(s_NickServ, u, "LIST", NICK_LIST_SERVADMIN_SYNTAX);
|
||||
else
|
||||
syntax_error(s_NickServ, u, "LIST", NICK_LIST_SYNTAX);
|
||||
|
||||
@@ -91,7 +91,6 @@ const char version_build[] =
|
||||
/* the space is needed cause if you build with nothing it will complain */
|
||||
const char version_flags[] = " " VER_OS VER_MYSQL VER_MODULE;
|
||||
|
||||
extern char *mod_current_buffer;
|
||||
|
||||
/******** Local variables! ********/
|
||||
|
||||
@@ -211,8 +210,6 @@ static void services_shutdown()
|
||||
ircdproto->SendSquit(ServerName, quitmsg);
|
||||
if (uplink)
|
||||
delete [] uplink;
|
||||
if (mod_current_buffer)
|
||||
delete [] mod_current_buffer;
|
||||
if (ircd->chanmodes) {
|
||||
delete [] ircd->chanmodes;
|
||||
}
|
||||
|
||||
+5
-115
@@ -211,35 +211,15 @@ static int internal_addCommand(Module *m, CommandHash * cmdTable[], Command * c,
|
||||
&& (!strcmp(c->service, current->c->service) == 0)) {
|
||||
continue;
|
||||
}
|
||||
if ((stricmp(c->name.c_str(), current->name) == 0)) { /* the cmd exist's we are a addHead */
|
||||
if (pos == 1) {
|
||||
c->next = current->c;
|
||||
current->c = c;
|
||||
if (debug)
|
||||
alog("debug: existing cmd: (0x%p), new cmd (0x%p)",
|
||||
static_cast<void *>(c->next), static_cast<void *>(c));
|
||||
return MOD_ERR_OK;
|
||||
} else if (pos == 2) {
|
||||
|
||||
tail = current->c;
|
||||
while (tail->next)
|
||||
tail = tail->next;
|
||||
if (debug)
|
||||
alog("debug: existing cmd: (0x%p), new cmd (0x%p)",
|
||||
static_cast<void *>(tail), static_cast<void *>(c));
|
||||
tail->next = c;
|
||||
c->next = NULL;
|
||||
|
||||
return MOD_ERR_OK;
|
||||
} else
|
||||
return MOD_ERR_EXISTS;
|
||||
if ((stricmp(c->name.c_str(), current->name) == 0))
|
||||
{
|
||||
/* the cmd exists, throw an error */
|
||||
return MOD_ERR_EXISTS;
|
||||
}
|
||||
lastHash = current;
|
||||
}
|
||||
|
||||
if (!(newHash = new CommandHash)) {
|
||||
fatal("Out of memory");
|
||||
}
|
||||
newHash = new CommandHash;
|
||||
newHash->next = NULL;
|
||||
newHash->name = sstrdup(c->name.c_str());
|
||||
newHash->c = c;
|
||||
@@ -805,96 +785,6 @@ void moduleCallBackPrepForUnload(const char *mod_name)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a copy of the complete last buffer.
|
||||
* This is needed for modules who cant trust the strtok() buffer, as we dont know who will have already messed about with it.
|
||||
* @reutrn a pointer to a copy of the last buffer - DONT mess with this, copy if first if you must do things to it.
|
||||
**/
|
||||
char *moduleGetLastBuffer()
|
||||
{
|
||||
char *tmp = NULL;
|
||||
if (mod_current_buffer) {
|
||||
tmp = strchr(mod_current_buffer, ' ');
|
||||
if (tmp) {
|
||||
tmp++;
|
||||
}
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Module HELP Functions
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* Add help for Root admins.
|
||||
* @param c the Command to add help for
|
||||
* @param func the function to run when this help is asked for
|
||||
**/
|
||||
int moduleAddRootHelp(Command * c, int (*func) (User * u))
|
||||
{
|
||||
if (c) {
|
||||
c->root_help = func;
|
||||
return MOD_STOP;
|
||||
}
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add help for Admins.
|
||||
* @param c the Command to add help for
|
||||
* @param func the function to run when this help is asked for
|
||||
**/
|
||||
int moduleAddAdminHelp(Command * c, int (*func) (User * u))
|
||||
{
|
||||
if (c) {
|
||||
c->admin_help = func;
|
||||
return MOD_STOP;
|
||||
}
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add help for opers..
|
||||
* @param c the Command to add help for
|
||||
* @param func the function to run when this help is asked for
|
||||
**/
|
||||
int moduleAddOperHelp(Command * c, int (*func) (User * u))
|
||||
{
|
||||
if (c) {
|
||||
c->oper_help = func;
|
||||
return MOD_STOP;
|
||||
}
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add help for registered users
|
||||
* @param c the Command to add help for
|
||||
* @param func the function to run when this help is asked for
|
||||
**/
|
||||
int moduleAddRegHelp(Command * c, int (*func) (User * u))
|
||||
{
|
||||
if (c) {
|
||||
c->regular_help = func;
|
||||
return MOD_STOP;
|
||||
}
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add help for all users
|
||||
* @param c the Command to add help for
|
||||
* @param func the function to run when this help is asked for
|
||||
**/
|
||||
int moduleAddHelp(Command * c, int (*func) (User * u))
|
||||
{
|
||||
if (c) {
|
||||
c->all_help = func;
|
||||
return MOD_STOP;
|
||||
}
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
void Module::SetNickHelp(void (*func)(User *))
|
||||
{
|
||||
this->nickHelp = func;
|
||||
|
||||
@@ -351,16 +351,6 @@ void process()
|
||||
alog("debug: av[0] = NULL");
|
||||
}
|
||||
|
||||
if (mod_current_buffer) {
|
||||
delete [] mod_current_buffer;
|
||||
}
|
||||
|
||||
if (ac >= 1) {
|
||||
mod_current_buffer = (ac > 1 ? sstrdup(av[1]) : sstrdup(av[0]));
|
||||
} else {
|
||||
mod_current_buffer = NULL;
|
||||
}
|
||||
|
||||
/* Do something with the message. */
|
||||
m = find_message(cmd);
|
||||
if (m) {
|
||||
|
||||
Reference in New Issue
Block a user