1
0
mirror of https://github.com/anope/anope.git synced 2026-07-03 20:03:12 +02:00

Rewrote how commands are handled within Anope.

This allows naming commands and having spaces within command names.
This commit is contained in:
Adam
2011-07-14 02:31:12 -04:00
parent 924f6849fe
commit f858164dee
227 changed files with 8808 additions and 12352 deletions
+133 -144
View File
@@ -12,43 +12,43 @@
/*************************************************************************/
#include "module.h"
#include "chanserv.h"
class AccessListCallback : public NumberList
{
protected:
CommandSource &source;
ChannelInfo *ci;
bool SentHeader;
public:
AccessListCallback(CommandSource &_source, const Anope::string &numlist) : NumberList(numlist, false), source(_source), SentHeader(false)
AccessListCallback(CommandSource &_source, ChannelInfo *_ci, const Anope::string &numlist) : NumberList(numlist, false), source(_source), ci(_ci), SentHeader(false)
{
}
~AccessListCallback()
{
if (SentHeader)
source.Reply(_("End of access list."), source.ci->name.c_str());
source.Reply(_("End of access list."), ci->name.c_str());
else
source.Reply(_("No matching entries on %s access list."), source.ci->name.c_str());
source.Reply(_("No matching entries on %s access list."), ci->name.c_str());
}
virtual void HandleNumber(unsigned Number)
{
if (!Number || Number > source.ci->GetAccessCount())
if (!Number || Number > ci->GetAccessCount())
return;
if (!SentHeader)
{
SentHeader = true;
source.Reply(_(CHAN_ACCESS_LIST_HEADER), source.ci->name.c_str());
source.Reply(CHAN_ACCESS_LIST_HEADER, ci->name.c_str());
}
DoList(source, Number - 1, source.ci->GetAccess(Number - 1));
DoList(source, ci, Number - 1, ci->GetAccess(Number - 1));
}
static void DoList(CommandSource &source, unsigned Number, ChanAccess *access)
static void DoList(CommandSource &source, ChannelInfo *ci, unsigned Number, ChanAccess *access)
{
if (source.ci->HasFlag(CI_XOP))
if (ci->HasFlag(CI_XOP))
{
Anope::string xop = get_xop_level(access->level);
source.Reply(_(" %3d %s %s"), Number + 1, xop.c_str(), access->GetMask().c_str());
@@ -61,27 +61,26 @@ class AccessListCallback : public NumberList
class AccessViewCallback : public AccessListCallback
{
public:
AccessViewCallback(CommandSource &_source, const Anope::string &numlist) : AccessListCallback(_source, numlist)
AccessViewCallback(CommandSource &_source, ChannelInfo *_ci, const Anope::string &numlist) : AccessListCallback(_source, _ci, numlist)
{
}
void HandleNumber(unsigned Number)
{
if (!Number || Number > source.ci->GetAccessCount())
if (!Number || Number > ci->GetAccessCount())
return;
if (!SentHeader)
{
SentHeader = true;
source.Reply(_(CHAN_ACCESS_LIST_HEADER), source.ci->name.c_str());
source.Reply(CHAN_ACCESS_LIST_HEADER, ci->name.c_str());
}
DoList(source, Number - 1, source.ci->GetAccess(Number - 1));
DoList(source, ci, Number - 1, ci->GetAccess(Number - 1));
}
static void DoList(CommandSource &source, unsigned Number, ChanAccess *access)
static void DoList(CommandSource &source, ChannelInfo *ci, unsigned Number, ChanAccess *access)
{
ChannelInfo *ci = source.ci;
Anope::string timebuf;
if (ci->c && nc_on_chan(ci->c, access->nc))
timebuf = "Now";
@@ -93,52 +92,52 @@ class AccessViewCallback : public AccessListCallback
if (ci->HasFlag(CI_XOP))
{
Anope::string xop = get_xop_level(access->level);
source.Reply(_(CHAN_ACCESS_VIEW_XOP_FORMAT), Number + 1, xop.c_str(), access->GetMask().c_str(), access->creator.c_str(), timebuf.c_str());
source.Reply(CHAN_ACCESS_VIEW_XOP_FORMAT, Number + 1, xop.c_str(), access->GetMask().c_str(), access->creator.c_str(), timebuf.c_str());
}
else
source.Reply(_(CHAN_ACCESS_VIEW_AXS_FORMAT), Number + 1, access->level, access->GetMask().c_str(), access->creator.c_str(), timebuf.c_str());
source.Reply(CHAN_ACCESS_VIEW_AXS_FORMAT, Number + 1, access->level, access->GetMask().c_str(), access->creator.c_str(), timebuf.c_str());
}
};
class AccessDelCallback : public NumberList
{
CommandSource &source;
ChannelInfo *ci;
Command *c;
unsigned Deleted;
Anope::string Nicks;
bool Denied;
bool override;
public:
AccessDelCallback(CommandSource &_source, Command *_c, const Anope::string &numlist) : NumberList(numlist, true), source(_source), c(_c), Deleted(0), Denied(false)
AccessDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, const Anope::string &numlist) : NumberList(numlist, true), source(_source), ci(_ci), c(_c), Deleted(0), Denied(false)
{
if (!check_access(source.u, source.ci, CA_ACCESS_CHANGE) && source.u->HasPriv("chanserv/access/modify"))
if (!check_access(source.u, ci, CA_ACCESS_CHANGE) && source.u->HasPriv("chanserv/access/modify"))
this->override = true;
}
~AccessDelCallback()
{
if (Denied && !Deleted)
source.Reply(_(ACCESS_DENIED));
source.Reply(ACCESS_DENIED);
else if (!Deleted)
source.Reply(_("No matching entries on %s access list."), source.ci->name.c_str());
source.Reply(_("No matching entries on %s access list."), ci->name.c_str());
else
{
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, c, source.ci) << "for user" << (Deleted == 1 ? " " : "s ") << Nicks;
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, c, ci) << "for user" << (Deleted == 1 ? " " : "s ") << Nicks;
if (Deleted == 1)
source.Reply(_("Deleted 1 entry from %s access list."), source.ci->name.c_str());
source.Reply(_("Deleted 1 entry from %s access list."), ci->name.c_str());
else
source.Reply(_("Deleted %d entries from %s access list."), Deleted, source.ci->name.c_str());
source.Reply(_("Deleted %d entries from %s access list."), Deleted, ci->name.c_str());
}
}
void HandleNumber(unsigned Number)
{
if (!Number || Number > source.ci->GetAccessCount())
if (!Number || Number > ci->GetAccessCount())
return;
User *u = source.u;
ChannelInfo *ci = source.ci;
ChanAccess *access = ci->GetAccess(Number - 1);
@@ -164,10 +163,9 @@ class AccessDelCallback : public NumberList
class CommandCSAccess : public Command
{
CommandReturn DoAdd(CommandSource &source, const std::vector<Anope::string> &params)
void DoAdd(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> &params)
{
User *u = source.u;
ChannelInfo *ci = source.ci;
Anope::string mask = params[2];
int level = ACCESS_INVALID;
@@ -182,19 +180,19 @@ class CommandCSAccess : public Command
int16 u_level = u_access ? u_access->level : 0;
if (level >= u_level && !u->HasPriv("chanserv/access/modify"))
{
source.Reply(_(ACCESS_DENIED));
return MOD_CONT;
source.Reply(ACCESS_DENIED);
return;
}
if (!level)
{
source.Reply(_("Access level must be non-zero."));
return MOD_CONT;
return;
}
else if (level <= ACCESS_INVALID || level >= ACCESS_FOUNDER)
{
source.Reply(_(CHAN_ACCESS_LEVEL_RANGE), ACCESS_INVALID + 1, ACCESS_FOUNDER - 1);
return MOD_CONT;
source.Reply(CHAN_ACCESS_LEVEL_RANGE, ACCESS_INVALID + 1, ACCESS_FOUNDER - 1);
return;
}
bool override = !check_access(u, ci, CA_ACCESS_CHANGE) || level >= u_level;
@@ -209,13 +207,13 @@ class CommandCSAccess : public Command
/* Don't allow lowering from a level >= u_level */
if (access->level >= u_level && !u->HasPriv("chanserv/access/modify"))
{
source.Reply(_(ACCESS_DENIED));
return MOD_CONT;
source.Reply(ACCESS_DENIED);
return;
}
if (access->level == level)
{
source.Reply(_("Access level for \002%s\002 on %s unchanged from \002%d\002."), access->GetMask().c_str(), ci->name.c_str(), level);
return MOD_CONT;
return;
}
access->level = level;
@@ -223,13 +221,13 @@ class CommandCSAccess : public Command
Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "ADD " << mask << " (level: " << level << ") as level " << u_level;
source.Reply(_("Access level for \002%s\002 on %s changed to \002%d\002."), access->GetMask().c_str(), ci->name.c_str(), level);
return MOD_CONT;
return;
}
if (ci->GetAccessCount() >= Config->CSAccessMax)
{
source.Reply(_("Sorry, you can only have %d access entries on a channel."), Config->CSAccessMax);
return MOD_CONT;
return;
}
access = ci->AddAccess(mask, level, u->nick);
@@ -239,13 +237,12 @@ class CommandCSAccess : public Command
Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "ADD " << mask << " (level: " << level << ") as level " << u_level;
source.Reply(_("\002%s\002 added to %s access list at level \002%d\002."), access->GetMask().c_str(), ci->name.c_str(), level);
return MOD_CONT;
return;
}
CommandReturn DoDel(CommandSource &source, const std::vector<Anope::string> &params)
void DoDel(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> &params)
{
User *u = source.u;
ChannelInfo *ci = source.ci;
const Anope::string &mask = params[2];
@@ -253,7 +250,7 @@ class CommandCSAccess : public Command
source.Reply(_("%s access list is empty."), ci->name.c_str());
else if (isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos)
{
AccessDelCallback list(source, this, mask);
AccessDelCallback list(source, ci, this, mask);
list.Process();
}
else
@@ -264,7 +261,7 @@ class CommandCSAccess : public Command
if (!access)
source.Reply(_("\002%s\002 not found on %s access list."), mask.c_str(), ci->name.c_str());
else if (access->nc != u->Account() && check_access(u, ci, CA_NOJOIN) && u_level <= access->level && !u->HasPriv("chanserv/access/modify"))
source.Reply(_(ACCESS_DENIED));
source.Reply(ACCESS_DENIED);
else
{
source.Reply(_("\002%s\002 deleted from %s access list."), access->GetMask().c_str(), ci->name.c_str());
@@ -277,20 +274,18 @@ class CommandCSAccess : public Command
}
}
return MOD_CONT;
return;
}
CommandReturn DoList(CommandSource &source, const std::vector<Anope::string> &params)
void DoList(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> &params)
{
ChannelInfo *ci = source.ci;
const Anope::string &nick = params.size() > 2 ? params[2] : "";
if (!ci->GetAccessCount())
source.Reply(_("%s access list is empty."), ci->name.c_str());
else if (!nick.empty() && nick.find_first_not_of("1234567890,-") == Anope::string::npos)
{
AccessListCallback list(source, nick);
AccessListCallback list(source, ci, nick);
list.Process();
}
else
@@ -307,10 +302,10 @@ class CommandCSAccess : public Command
if (!SentHeader)
{
SentHeader = true;
source.Reply(_(CHAN_ACCESS_LIST_HEADER), ci->name.c_str());
source.Reply(CHAN_ACCESS_LIST_HEADER, ci->name.c_str());
}
AccessListCallback::DoList(source, i, access);
AccessListCallback::DoList(source, ci, i, access);
}
if (SentHeader)
@@ -319,20 +314,18 @@ class CommandCSAccess : public Command
source.Reply(_("No matching entries on %s access list."), ci->name.c_str());
}
return MOD_CONT;
return;
}
CommandReturn DoView(CommandSource &source, const std::vector<Anope::string> &params)
void DoView(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> &params)
{
ChannelInfo *ci = source.ci;
const Anope::string &nick = params.size() > 2 ? params[2] : "";
if (!ci->GetAccessCount())
source.Reply(_("%s access list is empty."), ci->name.c_str());
else if (!nick.empty() && nick.find_first_not_of("1234567890,-") == Anope::string::npos)
{
AccessViewCallback list(source, nick);
AccessViewCallback list(source, ci, nick);
list.Process();
}
else
@@ -349,10 +342,10 @@ class CommandCSAccess : public Command
if (!SentHeader)
{
SentHeader = true;
source.Reply(_(CHAN_ACCESS_LIST_HEADER), ci->name.c_str());
source.Reply(CHAN_ACCESS_LIST_HEADER, ci->name.c_str());
}
AccessViewCallback::DoList(source, i, access);
AccessViewCallback::DoList(source, ci, i, access);
}
if (SentHeader)
@@ -361,16 +354,15 @@ class CommandCSAccess : public Command
source.Reply(_("No matching entries on %s access list."), ci->name.c_str());
}
return MOD_CONT;
return;
}
CommandReturn DoClear(CommandSource &source)
void DoClear(CommandSource &source, ChannelInfo *ci)
{
User *u = source.u;
ChannelInfo *ci = source.ci;
if (!IsFounder(u, ci) && !u->HasPriv("chanserv/access/modify"))
source.Reply(_(ACCESS_DENIED));
source.Reply(ACCESS_DENIED);
else
{
ci->ClearAccess();
@@ -383,23 +375,33 @@ class CommandCSAccess : public Command
Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "CLEAR";
}
return MOD_CONT;
return;
}
public:
CommandCSAccess() : Command("ACCESS", 2, 4)
CommandCSAccess(Module *creator) : Command(creator, "chanserv/access", 2, 4)
{
this->SetDesc(_("Modify the list of privileged users"));
this->SetSyntax(_("\037channel\037 ADD \037mask\037 \037level\037"));
this->SetSyntax(_("\037channel\037 DEL {\037mask\037 | \037entry-num\037 | \037list\037}"));
this->SetSyntax(_("\037channel\037 LIST [\037mask\037 | \037list\037]"));
this->SetSyntax(_("\037channel\037 VIEW [\037mask\037 | \037list\037]"));
this->SetSyntax(_("\037channel\037 CLEAR\002"));
}
CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> &params)
void Execute(CommandSource &source, const std::vector<Anope::string> &params)
{
const Anope::string &cmd = params[1];
const Anope::string &nick = params.size() > 2 ? params[2] : "";
const Anope::string &s = params.size() > 3 ? params[3] : "";
User *u = source.u;
ChannelInfo *ci = source.ci;
ChannelInfo *ci = cs_findchan(params[0]);
if (ci == NULL)
{
source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
return;
}
bool is_list = cmd.equals_ci("LIST") || cmd.equals_ci("VIEW");
bool is_clear = cmd.equals_ci("CLEAR");
@@ -425,54 +427,49 @@ class CommandCSAccess : public Command
if (is_list || is_clear ? 0 : (cmd.equals_ci("DEL") ? (nick.empty() || !s.empty()) : s.empty()))
this->OnSyntaxError(source, cmd);
else if (!has_access)
source.Reply(_(ACCESS_DENIED));
source.Reply(ACCESS_DENIED);
/* We still allow LIST and CLEAR in xOP mode, but not others */
else if (ci->HasFlag(CI_XOP) && !is_list && !is_clear)
{
if (ModeManager::FindChannelModeByName(CMODE_HALFOP))
source.Reply(_("You can't use this command. \n"
"Use the AOP, SOP, HOP and VOP commands instead.\n"
"Type \002%s%s HELP \037command\037\002 for more information."), Config->UseStrictPrivMsgString.c_str(), Config->s_ChanServ.c_str());
"Type \002%s%s HELP \037command\037\002 for more information."), Config->UseStrictPrivMsgString.c_str(), source.owner->nick.c_str());
else
source.Reply(_("You can't use this command. \n"
"Use the AOP, SOP and VOP commands instead.\n"
"Type \002%s%s HELP \037command\037\002 for more information."), Config->UseStrictPrivMsgString.c_str(), Config->s_ChanServ.c_str());
"Type \002%s%s HELP \037command\037\002 for more information."), Config->UseStrictPrivMsgString.c_str(), source.owner->nick.c_str());
}
else if (readonly && !is_list)
source.Reply(_("Sorry, channel access list modification is temporarily disabled."));
else if (cmd.equals_ci("ADD"))
this->DoAdd(source, params);
this->DoAdd(source, ci, params);
else if (cmd.equals_ci("DEL"))
this->DoDel(source, params);
this->DoDel(source, ci, params);
else if (cmd.equals_ci("LIST"))
this->DoList(source, params);
this->DoList(source, ci, params);
else if (cmd.equals_ci("VIEW"))
this->DoView(source, params);
this->DoView(source, ci, params);
else if (cmd.equals_ci("CLEAR"))
this->DoClear(source);
this->DoClear(source, ci);
else
this->OnSyntaxError(source, "");
return MOD_CONT;
return;
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand)
{
source.Reply(_("Syntax: \002ACCESS \037channel\037 ADD \037mask\037 \037level\037\002\n"
" \002ACCESS \037channel\037 DEL {\037mask\037 | \037entry-num\037 | \037list\037}\002\n"
" \002ACCESS \037channel\037 LIST [\037mask\037 | \037list\037]\002\n"
" \002ACCESS \037channel\037 VIEW [\037mask\037 | \037list\037]\002\n"
" \002ACCESS \037channel\037 CLEAR\002\n"
" \n"
"Maintains the \002access list\002 for a channel. The access\n"
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Maintains the \002access list\002 for a channel. The access\n"
"list specifies which users are allowed chanop status or\n"
"access to %s commands on the channel. Different\n"
"user levels allow for access to different subsets of\n"
"privileges; \002%s%s HELP ACCESS LEVELS\002 for more\n"
"specific information. Any nick not on the access list has\n"
"a user level of 0.\n"
" \n"
"The \002ACCESS ADD\002 command adds the given mask to the\n"
"privileges. Any nick not on the access list has\n"
"a user level of 0."));
source.Reply(" ");
source.Reply(_("The \002ACCESS ADD\002 command adds the given mask to the\n"
"access list with the given user level; if the mask is\n"
"already present on the list, its access level is changed to\n"
"the level specified in the command. The \037level\037 specified\n"
@@ -481,15 +478,15 @@ class CommandCSAccess : public Command
"access level of that nick must be less than the access level\n"
"of the user giving the command. When a user joins the channel\n"
"the access they receive is from the highest level entry in the\n"
"access list.\n"
" \n"
"The \002ACCESS DEL\002 command removes the given nick from the\n"
"access list."));
source.Reply(" ");
source.Reply(_("The \002ACCESS DEL\002 command removes the given nick from the\n"
"access list. If a list of entry numbers is given, those\n"
"entries are deleted. (See the example for LIST below.)\n"
"You may remove yourself from an access list, even if you\n"
"do not have access to modify that list otherwise.\n"
" \n"
"The \002ACCESS LIST\002 command displays the access list. If\n"
"do not have access to modify that list otherwise."));
source.Reply(" ");
source.Reply(_("The \002ACCESS LIST\002 command displays the access list. If\n"
"a wildcard mask is given, only those entries matching the\n"
"mask are displayed. If a list of entry numbers is given,\n"
"only those entries are shown; for example:\n"
@@ -502,7 +499,7 @@ class CommandCSAccess : public Command
" \n"
"The \002ACCESS CLEAR\002 command clears all entries of the\n"
"access list."),
Config->s_ChanServ.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->s_ChanServ.c_str());
source.owner->nick.c_str());
source.Reply(_("\002User access levels\002\n"
" \n"
"By default, the following access levels are defined:\n"
@@ -521,22 +518,16 @@ class CommandCSAccess : public Command
" \n"
"These levels may be changed, or new ones added, using the\n"
"\002LEVELS\002 command; type \002%s%s HELP LEVELS\002 for\n"
"information."), Config->s_ChanServ.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->s_ChanServ.c_str());
"information."), source.owner->nick.c_str(), Config->UseStrictPrivMsgString.c_str(), source.owner->nick.c_str());
return true;
}
void OnSyntaxError(CommandSource &source, const Anope::string &subcommand)
{
SyntaxError(source, "ACCESS", _("ACCESS \037channel\037 {ADD|DEL|LIST|VIEW|CLEAR} [\037mask\037 [\037level\037] | \037entry-list\037]"));
}
};
class CommandCSLevels : public Command
{
CommandReturn DoSet(CommandSource &source, const std::vector<Anope::string> &params)
void DoSet(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> &params)
{
User *u = source.u;
ChannelInfo *ci = source.ci;
const Anope::string &what = params[2];
const Anope::string &lev = params[3];
@@ -555,7 +546,7 @@ class CommandCSLevels : public Command
catch (const ConvertException &)
{
this->OnSyntaxError(source, "SET");
return MOD_CONT;
return;
}
}
@@ -577,20 +568,19 @@ class CommandCSLevels : public Command
source.Reply(_("Level for %s on channel %s changed to founder only."), levelinfo[i].name.c_str(), ci->name.c_str());
else
source.Reply(_("Level for \002%s\002 on channel %s changed to \002%d\002."), levelinfo[i].name.c_str(), ci->name.c_str(), level);
return MOD_CONT;
return;
}
}
source.Reply(_("Setting \002%s\002 not known. Type \002%s%s HELP LEVELS \002 for a list of valid settings."), what.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->s_ChanServ.c_str());
source.Reply(_("Setting \002%s\002 not known. Type \002%s%s HELP LEVELS \002 for a list of valid settings."), what.c_str(), Config->UseStrictPrivMsgString.c_str(), source.owner->nick.c_str());
}
return MOD_CONT;
return;
}
CommandReturn DoDisable(CommandSource &source, const std::vector<Anope::string> &params)
void DoDisable(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> &params)
{
User *u = source.u;
ChannelInfo *ci = source.ci;
const Anope::string &what = params[2];
@@ -607,19 +597,17 @@ class CommandCSLevels : public Command
Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "DISABLE " << levelinfo[i].name;
source.Reply(_("\002%s\002 disabled on channel %s."), levelinfo[i].name.c_str(), ci->name.c_str());
return MOD_CONT;
return;
}
}
source.Reply(_("Setting \002%s\002 not known. Type \002%s%s HELP LEVELS \002 for a list of valid settings."), what.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->s_ChanServ.c_str());
source.Reply(_("Setting \002%s\002 not known. Type \002%s%s HELP LEVELS \002 for a list of valid settings."), what.c_str(), Config->UseStrictPrivMsgString.c_str(), source.owner->nick.c_str());
return MOD_CONT;
return;
}
CommandReturn DoList(CommandSource &source)
void DoList(CommandSource &source, ChannelInfo *ci)
{
ChannelInfo *ci = source.ci;
source.Reply(_("Access level settings for channel %s:"), ci->name.c_str());
if (!levelinfo_maxwidth)
@@ -646,13 +634,12 @@ class CommandCSLevels : public Command
source.Reply(_(" %-*s %d"), levelinfo_maxwidth, levelinfo[i].name.c_str(), j);
}
return MOD_CONT;
return;
}
CommandReturn DoReset(CommandSource &source)
void DoReset(CommandSource &source, ChannelInfo *ci)
{
User *u = source.u;
ChannelInfo *ci = source.ci;
reset_levels(ci);
FOREACH_MOD(I_OnLevelChange, OnLevelChange(u, ci, -1, 0));
@@ -661,23 +648,33 @@ class CommandCSLevels : public Command
Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "RESET";
source.Reply(_("Access levels for \002%s\002 reset to defaults."), ci->name.c_str());
return MOD_CONT;
return;
}
public:
CommandCSLevels() : Command("LEVELS", 2, 4)
CommandCSLevels(Module *creator) : Command(creator, "chanserv/levels", 2, 4)
{
this->SetDesc(_("Redefine the meanings of access levels"));
this->SetSyntax(_("\037channel\037 SET \037type\037 \037level\037"));
this->SetSyntax(_("\037channel\037 {DIS | DISABLE} \037type\037"));
this->SetSyntax(_("\037channel\037 LIST"));
this->SetSyntax(_("\037channel\037 RESET"));
}
CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> &params)
void Execute(CommandSource &source, const std::vector<Anope::string> &params)
{
const Anope::string &cmd = params[1];
const Anope::string &what = params.size() > 2 ? params[2] : "";
const Anope::string &s = params.size() > 3 ? params[3] : "";
User *u = source.u;
ChannelInfo *ci = source.ci;
ChannelInfo *ci = cs_findchan(params[0]);
if (ci == NULL)
{
source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
return;
}
/* If SET, we want two extra parameters; if DIS[ABLE] or FOUNDER, we want only
* one; else, we want none.
@@ -687,19 +684,19 @@ class CommandCSLevels : public Command
else if (ci->HasFlag(CI_XOP))
source.Reply(_("Levels are not available as xOP is enabled on this channel."));
else if (!check_access(u, ci, CA_FOUNDER) && !u->HasPriv("chanserv/access/modify"))
source.Reply(_(ACCESS_DENIED));
source.Reply(ACCESS_DENIED);
else if (cmd.equals_ci("SET"))
this->DoSet(source, params);
this->DoSet(source, ci, params);
else if (cmd.equals_ci("DIS") || cmd.equals_ci("DISABLE"))
this->DoDisable(source, params);
this->DoDisable(source, ci, params);
else if (cmd.equals_ci("LIST"))
this->DoList(source);
this->DoList(source, ci);
else if (cmd.equals_ci("RESET"))
this->DoReset(source);
this->DoReset(source, ci);
else
this->OnSyntaxError(source, "");
return MOD_CONT;
return;
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand)
@@ -721,12 +718,10 @@ class CommandCSLevels : public Command
source.Reply(_(" %-*s %s"), levelinfo_maxwidth, levelinfo[i].name.c_str(), translate(source.u, levelinfo[i].desc));
}
else
source.Reply(_("Syntax: \002LEVELS \037channel\037 SET \037type\037 \037level\037\002\n"
" \002LEVELS \037channel\037 {DIS | DISABLE} \037type\037\002\n"
" \002LEVELS \037channel\037 LIST\002\n"
" \002LEVELS \037channel\037 RESET\002\n"
" \n"
"The \002LEVELS\002 command allows fine control over the meaning of\n"
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("The \002LEVELS\002 command allows fine control over the meaning of\n"
"the numeric access levels used for channels. With this\n"
"command, you can define the access level required for most\n"
"of %s's functions. (The \002SET FOUNDER\002 and this command\n"
@@ -744,14 +739,10 @@ class CommandCSLevels : public Command
"\002HELP ACCESS LEVELS\002).\n"
" \n"
"For a list of the features and functions whose levels can be\n"
"set, see \002HELP LEVELS DESC\002."), Config->s_ChanServ.c_str());
"set, see \002HELP LEVELS DESC\002."), source.owner->nick.c_str());
}
return true;
}
void OnSyntaxError(CommandSource &source, const Anope::string &subcommand)
{
SyntaxError(source, "LEVELS", _("LEVELS \037channel\037 {SET | DIS[ABLE] | LIST | RESET} [\037item\037 [\037level\037]]"));
}
};
class CSAccess : public Module
@@ -760,15 +751,13 @@ class CSAccess : public Module
CommandCSLevels commandcslevels;
public:
CSAccess(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE)
CSAccess(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
commandcsaccess(this), commandcslevels(this)
{
this->SetAuthor("Anope");
if (!chanserv)
throw ModuleException("ChanServ is not loaded!");
this->AddCommand(chanserv->Bot(), &commandcsaccess);
this->AddCommand(chanserv->Bot(), &commandcslevels);
ModuleManager::RegisterService(&commandcsaccess);
ModuleManager::RegisterService(&commandcslevels);
}
};