summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorAdam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864>2009-10-13 21:26:38 +0000
committerAdam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864>2009-10-13 21:26:38 +0000
commitd3d64c27b199622c90075d6f59dd08e44acbb378 (patch)
tree68029e10dc754271235e2a4e3d04b3fb19ddd15c /src/core
parent1fd66851320e239b531720c27614a5ad4c604c97 (diff)
Complete rewrite of everything associated with modes, this breaks saving and reading mlocked modes from the databases until the new databases are implemented
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2560 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/core')
-rw-r--r--src/core/cs_access.c2
-rw-r--r--src/core/cs_akick.c3
-rw-r--r--src/core/cs_ban.c4
-rw-r--r--src/core/cs_clear.c111
-rw-r--r--src/core/cs_drop.c4
-rw-r--r--src/core/cs_forbid.c21
-rw-r--r--src/core/cs_getkey.c5
-rw-r--r--src/core/cs_info.c7
-rw-r--r--src/core/cs_modes.c138
-rw-r--r--src/core/cs_register.c11
-rw-r--r--src/core/cs_set.c100
-rw-r--r--src/core/cs_xop.c4
-rw-r--r--src/core/os_chanlist.c29
-rw-r--r--src/core/os_clearmodes.c107
-rw-r--r--src/core/os_userlist.c27
15 files changed, 257 insertions, 316 deletions
diff --git a/src/core/cs_access.c b/src/core/cs_access.c
index 59f772dee..2fbca088a 100644
--- a/src/core/cs_access.c
+++ b/src/core/cs_access.c
@@ -112,7 +112,7 @@ class CommandCSAccess : public Command
/* We still allow LIST in xOP mode, but not others */
else if ((ci->flags & CI_XOP) && !is_list)
{
- if (ircd->halfop)
+ if (ModeManager::FindChannelModeByName(CMODE_HALFOP))
notice_lang(s_ChanServ, u, CHAN_ACCESS_XOP_HOP, s_ChanServ);
else
notice_lang(s_ChanServ, u, CHAN_ACCESS_XOP, s_ChanServ);
diff --git a/src/core/cs_akick.c b/src/core/cs_akick.c
index bd928b316..a9e38fbd2 100644
--- a/src/core/cs_akick.c
+++ b/src/core/cs_akick.c
@@ -229,7 +229,8 @@ class CommandCSAKick : public Command
}
/* Check excepts BEFORE we get this far */
- if (ircd->except) {
+ if (ModeManager::FindChannelModeByName(CMODE_EXCEPT))
+ {
if (is_excepted_mask(ci, mask) == 1) {
notice_lang(s_ChanServ, u, CHAN_EXCEPTED, mask, chan);
if (freemask)
diff --git a/src/core/cs_ban.c b/src/core/cs_ban.c
index bd65f1ac8..9901479ae 100644
--- a/src/core/cs_ban.c
+++ b/src/core/cs_ban.c
@@ -62,9 +62,9 @@ class CommandCSBan : public Command
* Dont ban/kick the user on channels where he is excepted
* to prevent services <-> server wars.
*/
- } else if (ircd->except && is_excepted(ci, u2)) {
+ } else if (ModeManager::FindChannelModeByName(CMODE_EXCEPT) && is_excepted(ci, u2)) {
notice_lang(s_ChanServ, u, CHAN_EXCEPTED, u2->nick, ci->name);
- } else if (ircd->protectedumode && is_protected(u2)) {
+ } else if (is_protected(u2)) {
notice_lang(s_ChanServ, u, ACCESS_DENIED);
} else {
const char *av[3];
diff --git a/src/core/cs_clear.c b/src/core/cs_clear.c
index f9e9ab8bd..699c70a2f 100644
--- a/src/core/cs_clear.c
+++ b/src/core/cs_clear.c
@@ -29,6 +29,11 @@ class CommandCSClear : public Command
ci::string what = params[1];
Channel *c = findchan(chan);
ChannelInfo *ci;
+ ChannelMode *owner, *admin;
+ std::string modebuf;
+
+ owner = ModeManager::FindChannelModeByName(CMODE_OWNER);
+ admin = ModeManager::FindChannelModeByName(CMODE_PROTECT);
if (c)
ci = c->ci;
@@ -38,90 +43,22 @@ class CommandCSClear : public Command
} else if (!u || !check_access(u, ci, CA_CLEAR)) {
notice_lang(s_ChanServ, u, ACCESS_DENIED);
} else if (what == "bans") {
- const char *av[2];
- Entry *ban, *bnext;
-
- if (c->bans && c->bans->count) {
- for (ban = c->bans->entries; ban; ban = bnext) {
- bnext = ban->next;
- av[0] = "-b";
- av[1] = ban->mask;
- ircdproto->SendMode(whosends(ci), chan, "-b %s", ban->mask);
- chan_set_modes(whosends(ci)->nick, c, 2, av, 0);
- }
- }
+ c->ClearBans();
notice_lang(s_ChanServ, u, CHAN_CLEARED_BANS, chan);
- } else if (ircd->except && what == "excepts") {
- const char *av[2];
- Entry *except, *bnext;
-
- if (c->excepts && c->excepts->count) {
- for (except = c->excepts->entries; except; except = bnext) {
- bnext = except->next;
- av[0] = "-e";
- av[1] = except->mask;
- ircdproto->SendMode(whosends(ci), chan, "-e %s", except->mask);
- chan_set_modes(whosends(ci)->nick, c, 2, av, 0);
- }
- }
+ } else if (ModeManager::FindChannelModeByName(CMODE_EXCEPT) && what == "excepts") {
+ c->ClearExcepts();
+
notice_lang(s_ChanServ, u, CHAN_CLEARED_EXCEPTS, chan);
- } else if (ircd->invitemode && what == "invites") {
- const char *av[2];
- Entry *invite, *bnext;
-
- if (c->invites && c->invites->count) {
- for (invite = c->invites->entries; invite; invite = bnext) {
- bnext = invite->next;
- av[0] = "-I";
- av[1] = invite->mask;
- ircdproto->SendMode(whosends(ci), chan, "-I %s", invite->mask);
- chan_set_modes(whosends(ci)->nick, c, 2, av, 0);
- }
- }
+ } else if (ModeManager::FindChannelModeByName(CMODE_INVITE) && what == "invites") {
+ c->ClearInvites();
+
notice_lang(s_ChanServ, u, CHAN_CLEARED_INVITES, chan);
} else if (what == "modes") {
- const char *argv[2];
-
- if (c->mode) {
- /* Clear modes the bulk of the modes */
- ircdproto->SendMode(whosends(ci), c->name, "%s",
- ircd->modestoremove);
- argv[0] = ircd->modestoremove;
- chan_set_modes(whosends(ci)->nick, c, 1, argv, 0);
-
- /* to prevent the internals from complaining send -k, -L, -f by themselves if we need
- to send them - TSL */
- if (c->key) {
- ircdproto->SendMode(whosends(ci), c->name, "-k %s", c->key);
- argv[0] = "-k";
- argv[1] = c->key;
- chan_set_modes(whosends(ci)->nick, c, 2, argv, 0);
- }
- if (ircd->Lmode && c->redirect) {
- ircdproto->SendMode(whosends(ci), c->name, "-L %s",
- c->redirect);
- argv[0] = "-L";
- argv[1] = c->redirect;
- chan_set_modes(whosends(ci)->nick, c, 2, argv, 0);
- }
- if (ircd->fmode && c->flood) {
- if (flood_mode_char_remove) {
- ircdproto->SendMode(whosends(ci), c->name, "%s %s",
- flood_mode_char_remove, c->flood);
- argv[0] = flood_mode_char_remove;
- argv[1] = c->flood;
- chan_set_modes(whosends(ci)->nick, c, 2, argv, 0);
- } else {
- if (debug) {
- alog("debug: flood_mode_char_remove was not set unable to remove flood/throttle modes");
- }
- }
- }
- check_modes(c);
- }
+ c->ClearModes();
+ check_modes(c);
notice_lang(s_ChanServ, u, CHAN_CLEARED_MODES, chan);
} else if (what == "ops") {
@@ -133,11 +70,17 @@ class CommandCSClear : public Command
if (ircd->svsmode_ucmode) {
av[0] = chan;
ircdproto->SendSVSModeChan(av[0], "-o", NULL);
- if (ircd->owner) {
- ircdproto->SendSVSModeChan(av[0], ircd->ownerunset, NULL);
+ if (owner) {
+ modebuf = '-';
+ modebuf += owner->ModeChar;
+
+ ircdproto->SendSVSModeChan(av[0], modebuf.c_str(), NULL);
}
- if (ircd->protect || ircd->admin) {
- ircdproto->SendSVSModeChan(av[0], ircd->adminunset, NULL);
+ if (admin) {
+ modebuf = '-';
+ modebuf += admin->ModeChar;
+
+ ircdproto->SendSVSModeChan(av[0], modebuf.c_str(), NULL);
}
for (cu = c->users; cu; cu = bnext) {
bnext = cu->next;
@@ -150,7 +93,7 @@ class CommandCSClear : public Command
continue;
snprintf(tmp, BUFSIZE, "-%s%s%s", (isop ? "o" : ""), (isadmin ?
- ircd->adminunset+1 : ""), (isown ? ircd->ownerunset+1 : ""));
+ &admin->ModeChar : ""), (isown ? &owner->ModeChar : ""));
if (ircdcap->tsmode) {
snprintf(buf, BUFSIZE - 1, "%ld", static_cast<long>(time(NULL)));
@@ -183,7 +126,7 @@ class CommandCSClear : public Command
continue;
snprintf(tmp, BUFSIZE, "-%s%s%s", (isop ? "o" : ""), (isadmin ?
- ircd->adminunset+1 : ""), (isown ? ircd->ownerunset+1 : ""));
+ &admin->ModeChar : ""), (isown ? &owner->ModeChar : ""));
/* We need to send the IRCd a nick for every mode.. - Viper */
snprintf(tmp2, BUFSIZE, "%s %s %s", (isop ? cu->user->nick : ""),
(isadmin ? cu->user->nick : ""), (isown ? cu->user->nick : ""));
@@ -212,7 +155,7 @@ class CommandCSClear : public Command
}
}
notice_lang(s_ChanServ, u, CHAN_CLEARED_OPS, chan);
- } else if (ircd->halfop && what == "hops") {
+ } else if (ModeManager::FindChannelModeByName(CMODE_HALFOP) && what == "hops") {
const char *av[4];
int ac;
char buf[BUFSIZE];
diff --git a/src/core/cs_drop.c b/src/core/cs_drop.c
index 13534232d..a8b838f1f 100644
--- a/src/core/cs_drop.c
+++ b/src/core/cs_drop.c
@@ -59,9 +59,9 @@ class CommandCSDrop : public Command
if (ci->c)
{
- if (ircd->regmode)
+ if (ModeManager::FindChannelModeByName(CMODE_REGISTERED))
{
- ci->c->mode &= ~ircd->regmode;
+ ci->c->RemoveMode(CMODE_REGISTERED);
ircdproto->SendMode(whosends(ci), ci->name, "-r");
}
}
diff --git a/src/core/cs_forbid.c b/src/core/cs_forbid.c
index d1ce0d119..587232794 100644
--- a/src/core/cs_forbid.c
+++ b/src/core/cs_forbid.c
@@ -29,7 +29,6 @@ class CommandCSForbid : public Command
const char *reason = params.size() > 1 ? params[1].c_str() : NULL;
Channel *c;
- Entry *cur, *enext;
if (ForceForbidReason && !reason)
{
@@ -78,24 +77,8 @@ class CommandCSForbid : public Command
/* Before banning everyone, it might be prudent to clear +e and +I lists..
* to prevent ppl from rejoining.. ~ Viper */
- if (ircd->except && c->excepts && c->excepts->count) {
- for (cur = c->excepts->entries; cur; cur = enext) {
- enext = cur->next;
- av[0] = "-e";
- av[1] = cur->mask;
- ircdproto->SendMode(whosends(ci), chan, "-e %s", cur->mask);
- chan_set_modes(whosends(ci)->nick, c, 2, av, 0);
- }
- }
- if (ircd->invitemode && c->invites && c->invites->count) {
- for (cur = c->invites->entries; cur; cur = enext) {
- enext = cur->next;
- av[0] = "-I";
- av[1] = cur->mask;
- ircdproto->SendMode(whosends(ci), chan, "-I %s", cur->mask);
- chan_set_modes(whosends(ci)->nick, c, 2, av, 0);
- }
- }
+ c->ClearExcepts();
+ c->ClearInvites();
for (cu = c->users; cu; cu = nextu)
{
diff --git a/src/core/cs_getkey.c b/src/core/cs_getkey.c
index 7d1fa8637..8c1e127ee 100644
--- a/src/core/cs_getkey.c
+++ b/src/core/cs_getkey.c
@@ -26,6 +26,7 @@ class CommandCSGetKey : public Command
{
const char *chan = params[0].c_str();
ChannelInfo *ci;
+ std::string key;
ci = cs_findchan(chan);
@@ -35,13 +36,13 @@ class CommandCSGetKey : public Command
return MOD_CONT;
}
- if (!ci->c || !ci->c->key)
+ if (!ci->c || !ci->c->GetParam(CMODE_KEY, &key))
{
notice_lang(s_ChanServ, u, CHAN_GETKEY_NOKEY, chan);
return MOD_CONT;
}
- notice_lang(s_ChanServ, u, CHAN_GETKEY_KEY, chan, ci->c->key);
+ notice_lang(s_ChanServ, u, CHAN_GETKEY_KEY, chan, key.c_str());
return MOD_CONT;
}
diff --git a/src/core/cs_info.c b/src/core/cs_info.c
index 77e840d36..8a13b73a2 100644
--- a/src/core/cs_info.c
+++ b/src/core/cs_info.c
@@ -47,6 +47,7 @@ class CommandCSInfo : public Command
bool has_auspex = u->nc && u->nc->HasPriv("chanserv/auspex");
int show_all = 0;
time_t expt;
+ ChannelMode *cm;
ci = cs_findchan(chan);
@@ -80,10 +81,12 @@ class CommandCSInfo : public Command
tm = localtime(&ci->last_used);
strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm);
notice_lang(s_ChanServ, u, CHAN_INFO_LAST_USED, buf);
+
+ cm = ModeManager::FindChannelModeByName(CMODE_SECRET);
// XXX: yuck.
if (ci->last_topic &&
- (show_all || (!(ci->mlock_on & anope_get_secret_mode())
- && (!ci->c || !(ci->c->mode & anope_get_secret_mode())))))
+ (show_all || (!ci->HasMLock(cm->Name, true))
+ && (!ci->c || !(ci->c->HasMode(CMODE_SECRET)))))
{
notice_lang(s_ChanServ, u, CHAN_INFO_LAST_TOPIC, ci->last_topic);
notice_lang(s_ChanServ, u, CHAN_INFO_TOPIC_SET_BY, ci->last_topic_setter);
diff --git a/src/core/cs_modes.c b/src/core/cs_modes.c
index 13f2f0f82..4e8162c02 100644
--- a/src/core/cs_modes.c
+++ b/src/core/cs_modes.c
@@ -15,14 +15,24 @@
#include "module.h"
-/* do_util: not a command, but does the job of other */
-
-static CommandReturn do_util(User *u, CSModeUtil *util, const char *chan, const char *nick)
+/** do_util: not a command, but does the job of others
+ * @param u The user doing the command
+ * @param cm A channel mode class
+ * @param chan The channel its being set on
+ * @param nick The nick the modes being set on
+ * @param set Is the mode being set or removed
+ * @param level The acecss level required to set this mode on someone else
+ * @param levelself The access level required to set this mode on yourself
+ * @param name The name, eg "OP" or "HALFOP"
+ * @param notice Flag required on a channel to send a notice
+ */
+static CommandReturn do_util(User *u, ChannelMode *cm, const char *chan, const char *nick, bool set, int level, int levelself, const std::string &name, int32 notice)
{
const char *av[2];
Channel *c = findchan(chan);
ChannelInfo *ci;
User *u2;
+ char modebuf[3];
int is_same;
@@ -35,32 +45,34 @@ static CommandReturn do_util(User *u, CSModeUtil *util, const char *chan, const
if (c)
ci = c->ci;
- if (!c) {
+ if (!c)
notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
- } else if (is_same ? !(u2 = u) : !(u2 = finduser(nick))) {
+ else if (is_same ? !(u2 = u) : !(u2 = finduser(nick)))
notice_lang(s_ChanServ, u, NICK_X_NOT_IN_USE, nick);
- } else if (!is_on_chan(c, u2)) {
+ else if (!is_on_chan(c, u2))
notice_lang(s_ChanServ, u, NICK_X_NOT_ON_CHAN, u2->nick, c->name);
- } else if (is_same ? !check_access(u, ci, util->levelself) :
- !check_access(u, ci, util->level)) {
+ else if (is_same ? !check_access(u, ci, levelself) : !check_access(u, ci, level))
notice_lang(s_ChanServ, u, ACCESS_DENIED);
- } else if (*util->mode == '-' && !is_same && (ci->flags & CI_PEACE)
- && (get_access(u2, ci) >= get_access(u, ci))) {
+ else if (!set && !is_same && (ci->flags & CI_PEACE) && (get_access(u2, ci) >= get_access(u, ci)))
notice_lang(s_ChanServ, u, ACCESS_DENIED);
- } else if (*util->mode == '-' && is_protected(u2) && !is_same) {
+ else if (!set && is_protected(u2) && !is_same)
notice_lang(s_ChanServ, u, ACCESS_DENIED);
- } else {
- ircdproto->SendMode(whosends(ci), c->name, "%s %s", util->mode,
- u2->nick);
+ else
+ {
+ snprintf(modebuf, sizeof(modebuf), "%c%c", (set ? '+' : '-'), cm->ModeChar);
- av[0] = util->mode;
+ ircdproto->SendMode(whosends(ci), c->name, "%s %s", modebuf, u2->nick);
+
+ av[0] = modebuf;
av[1] = u2->nick;
+
chan_set_modes(s_ChanServ, c, 2, av, 3);
- if (util->notice && ci->flags & util->notice)
+ if (notice && ci->flags & notice)
ircdproto->SendMessage(whosends(ci), c->name, "%s command used for %s by %s",
- util->name, u2->nick, u->nick);
+ name.c_str(), u2->nick, u->nick);
}
+
return MOD_CONT;
}
@@ -75,7 +87,9 @@ class CommandCSOp : public Command
CommandReturn Execute(User *u, std::vector<ci::string> &params)
{
- return do_util(u, &csmodeutils[MUT_OP], (params.size() > 0 ? params[0].c_str() : NULL), (params.size() > 1 ? params[1].c_str() : NULL));
+ ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_OP);
+
+ return do_util(u, cm, (params.size() > 0 ? params[0].c_str() : NULL), (params.size() > 1 ? params[1].c_str() : NULL), true, CA_OPDEOP, CA_OPDEOPME, "OP", CI_OPNOTICE);
}
bool OnHelp(User *u, const ci::string &subcommand)
@@ -100,7 +114,9 @@ class CommandCSDeOp : public Command
CommandReturn Execute(User *u, std::vector<ci::string> &params)
{
- return do_util(u, &csmodeutils[MUT_DEOP], (params.size() > 0 ? params[0].c_str() : NULL), (params.size() > 1 ? params[1].c_str() : NULL));
+ ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_OP);
+
+ return do_util(u, cm, (params.size() > 0 ? params[0].c_str() : NULL), (params.size() > 1 ? params[1].c_str() : NULL), false, CA_OPDEOP, CA_OPDEOPME, "DEOP", CI_OPNOTICE);
}
bool OnHelp(User *u, const ci::string &subcommand)
@@ -125,7 +141,9 @@ class CommandCSVoice : public Command
CommandReturn Execute(User *u, std::vector<ci::string> &params)
{
- return do_util(u, &csmodeutils[MUT_VOICE], (params.size() > 0 ? params[0].c_str() : NULL), (params.size() > 1 ? params[1].c_str() : NULL));
+ ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_VOICE);
+
+ return do_util(u, cm, (params.size() > 0 ? params[0].c_str() : NULL), (params.size() > 1 ? params[1].c_str() : NULL), true, CA_VOICE, CA_VOICEME, "VOICE", 0);
}
bool OnHelp(User *u, const ci::string &subcommand)
@@ -150,7 +168,9 @@ class CommandCSDeVoice : public Command
CommandReturn Execute(User *u, std::vector<ci::string> &params)
{
- return do_util(u, &csmodeutils[MUT_DEVOICE], (params.size() > 0 ? params[0].c_str() : NULL), (params.size() > 1 ? params[1].c_str() : NULL));
+ ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_VOICE);
+
+ return do_util(u, cm, (params.size() > 0 ? params[0].c_str() : NULL), (params.size() > 1 ? params[1].c_str() : NULL), false, CA_VOICE, CA_VOICEME, "DEVOICE", 0);
}
bool OnHelp(User *u, const ci::string &subcommand)
@@ -175,12 +195,14 @@ class CommandCSHalfOp : public Command
CommandReturn Execute(User *u, std::vector<ci::string> &params)
{
- if (!ircd->halfop)
+ ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_HALFOP);
+
+ if (!cm)
{
return MOD_CONT;
}
- return do_util(u, &csmodeutils[MUT_HALFOP], (params.size() > 0 ? params[0].c_str() : NULL), (params.size() > 1 ? params[1].c_str() : NULL));
+ return do_util(u, cm, (params.size() > 0 ? params[0].c_str() : NULL), (params.size() > 1 ? params[1].c_str() : NULL), true, CA_HALFOP, CA_HALFOPME, "HALFOP", 0);
}
bool OnHelp(User *u, const ci::string &subcommand)
@@ -205,12 +227,15 @@ class CommandCSDeHalfOp : public Command
CommandReturn Execute(User *u, std::vector<ci::string> &params)
{
- if (!ircd->halfop)
+ ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_HALFOP);
+
+ if (!cm)
{
return MOD_CONT;
+
}
- return do_util(u, &csmodeutils[MUT_DEHALFOP], (params.size() > 0 ? params[0].c_str() : NULL), (params.size() > 1 ? params[1].c_str() : NULL));
+ return do_util(u, cm, (params.size() > 0 ? params[0].c_str() : NULL), (params.size() > 1 ? params[1].c_str() : NULL), false, CA_HALFOP, CA_HALFOPME, "DEHALFOP", 0);
}
bool OnHelp(User *u, const ci::string &subcommand)
@@ -235,12 +260,14 @@ class CommandCSProtect : public Command
CommandReturn Execute(User *u, std::vector<ci::string> &params)
{
- if (!ircd->protect && !ircd->admin)
+ ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_PROTECT);
+
+ if (!cm)
{
return MOD_CONT;
}
- return do_util(u, &csmodeutils[MUT_PROTECT], (params.size() > 0 ? params[0].c_str() : NULL), (params.size() > 1 ? params[1].c_str() : NULL));
+ return do_util(u, cm, (params.size() > 0 ? params[0].c_str() : NULL), (params.size() > 1 ? params[1].c_str() : NULL), true, CA_PROTECT, CA_PROTECTME, "PROTECT", 0);
}
bool OnHelp(User *u, const ci::string &subcommand)
@@ -255,8 +282,6 @@ class CommandCSProtect : public Command
}
};
-/*************************************************************************/
-
class CommandCSDeProtect : public Command
{
public:
@@ -266,12 +291,14 @@ class CommandCSDeProtect : public Command
CommandReturn Execute(User *u, std::vector<ci::string> &params)
{
- if (!ircd->protect && !ircd->admin)
+ ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_PROTECT);
+
+ if (!cm)
{
return MOD_CONT;
}
- return do_util(u, &csmodeutils[MUT_DEPROTECT], (params.size() > 0 ? params[0].c_str() : NULL), (params.size() > 1 ? params[1].c_str() : NULL));
+ return do_util(u, cm, (params.size() > 0 ? params[0].c_str() : NULL), (params.size() > 1 ? params[1].c_str() : NULL), false, CA_PROTECT, CA_PROTECTME, "DEPROTECT", 0);
}
bool OnHelp(User *u, const ci::string &subcommand)
@@ -286,8 +313,6 @@ class CommandCSDeProtect : public Command
}
};
-/*************************************************************************/
-
class CommandCSOwner : public Command
{
public:
@@ -297,7 +322,14 @@ class CommandCSOwner : public Command
CommandReturn Execute(User *u, std::vector<ci::string> &params)
{
- return do_util(u, &csmodeutils[MUT_OWNER], (params.size() > 0 ? params[0].c_str() : NULL), NULL);
+ ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_OWNER);
+
+ if (!cm)
+ {
+ return MOD_CONT;
+ }
+
+ return do_util(u, cm, (params.size() > 0 ? params[0].c_str() : NULL), NULL, true, ACCESS_FOUNDER, ACCESS_FOUNDER, "OWNER", 0);
}
bool OnHelp(User *u, const ci::string &subcommand)
@@ -312,8 +344,6 @@ class CommandCSOwner : public Command
}
};
-/*************************************************************************/
-
class CommandCSDeOwner : public Command
{
public:
@@ -323,7 +353,14 @@ class CommandCSDeOwner : public Command
CommandReturn Execute(User *u, std::vector<ci::string> &params)
{
- return do_util(u, &csmodeutils[MUT_DEOWNER], (params.size() > 0 ? params[0].c_str() : NULL), NULL);
+ ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_OWNER);
+
+ if (!cm)
+ {
+ return MOD_CONT;
+ }
+
+ return do_util(u, cm, (params.size() > 0 ? params[0].c_str() : NULL), NULL, false, ACCESS_FOUNDER, ACCESS_FOUNDER, "OWNER", 0);
}
bool OnHelp(User *u, const ci::string &subcommand)
@@ -353,25 +390,19 @@ class CSModes : public Module
this->AddCommand(CHANSERV, new CommandCSVoice());
this->AddCommand(CHANSERV, new CommandCSDeVoice());
- if (ircd->halfop)
+ if (ModeManager::FindChannelModeByName(CMODE_HALFOP))
{
this->AddCommand(CHANSERV, new CommandCSHalfOp());
this->AddCommand(CHANSERV, new CommandCSDeHalfOp());
}
- if (ircd->protect)
- {
- this->AddCommand(CHANSERV, new CommandCSProtect());
- this->AddCommand(CHANSERV, new CommandCSDeProtect());
- }
-
- if (ircd->admin)
+ if (ModeManager::FindChannelModeByName(CMODE_PROTECT))
{
this->AddCommand(CHANSERV, new CommandCSProtect());
this->AddCommand(CHANSERV, new CommandCSDeProtect());
}
- if (ircd->owner)
+ if (ModeManager::FindChannelModeByName(CMODE_OWNER))
{
this->AddCommand(CHANSERV, new CommandCSOwner());
this->AddCommand(CHANSERV, new CommandCSDeOwner());
@@ -379,24 +410,27 @@ class CSModes : public Module
}
void ChanServHelp(User *u)
{
- if (ircd->owner) {
+ if (ModeManager::FindChannelModeByName(CMODE_OWNER))
+ {
notice_lang(s_ChanServ, u, CHAN_HELP_CMD_OWNER);
notice_lang(s_ChanServ, u, CHAN_HELP_CMD_DEOWNER);
}
- if (ircd->protect) {
+
+ if (ModeManager::FindChannelModeByName(CMODE_PROTECT))
+ {
notice_lang(s_ChanServ, u, CHAN_HELP_CMD_PROTECT);
notice_lang(s_ChanServ, u, CHAN_HELP_CMD_DEPROTECT);
- } else if (ircd->admin) {
- notice_lang(s_ChanServ, u, CHAN_HELP_CMD_ADMIN);
- notice_lang(s_ChanServ, u, CHAN_HELP_CMD_DEADMIN);
}
notice_lang(s_ChanServ, u, CHAN_HELP_CMD_OP);
notice_lang(s_ChanServ, u, CHAN_HELP_CMD_DEOP);
- if (ircd->halfop) {
+
+ if (ModeManager::FindChannelModeByName(CMODE_HALFOP))
+ {
notice_lang(s_ChanServ, u, CHAN_HELP_CMD_HALFOP);
notice_lang(s_ChanServ, u, CHAN_HELP_CMD_DEHALFOP);
}
+
notice_lang(s_ChanServ, u, CHAN_HELP_CMD_VOICE);
notice_lang(s_ChanServ, u, CHAN_HELP_CMD_DEVOICE);
}
diff --git a/src/core/cs_register.c b/src/core/cs_register.c
index 5726859b6..89985fb93 100644
--- a/src/core/cs_register.c
+++ b/src/core/cs_register.c
@@ -33,6 +33,7 @@ class CommandCSRegister : public Command
struct u_chaninfolist *uc;
char founderpass[PASSMAX];
char tmp_pass[PASSMAX];
+ ChannelMode *cm;
if (readonly)
{
@@ -83,7 +84,7 @@ class CommandCSRegister : public Command
ci->c = c;
ci->bantype = CSDefBantype;
ci->flags = CSDefFlags;
- ci->mlock_on = ircd->defmlock;
+ ci->mlock_on = ircd->DefMLock;
ci->memos.memomax = MSMaxMemos;
ci->last_used = ci->time_registered;
ci->founder = u->nc;
@@ -116,10 +117,10 @@ class CommandCSRegister : public Command
/* Implement new mode lock */
check_modes(c);
/* On most ircds you do not receive the admin/owner mode till its registered */
- if (ircd->admin)
- ircdproto->SendMode(findbot(s_ChanServ), chan, "%s %s", ircd->adminset, u->nick);
- if (ircd->owner && ircd->ownerset)
- ircdproto->SendMode(findbot(s_ChanServ), chan, "%s %s", ircd->ownerset, u->nick);
+ if ((cm = ModeManager::FindChannelModeByName(CMODE_OWNER)))
+ ircdproto->SendMode(findbot(s_ChanServ), chan, "+%c %s", cm->ModeChar, u->nick);
+ else if ((cm = ModeManager::FindChannelModeByName(CMODE_PROTECT)))
+ ircdproto->SendMode(findbot(s_ChanServ), chan, "+%c %s", cm->ModeChar, u->nick);
FOREACH_MOD(I_OnChanRegistered, OnChanRegistered(ci));
}
diff --git a/src/core/cs_set.c b/src/core/cs_set.c
index eed1e535a..0036a752a 100644
--- a/src/core/cs_set.c
+++ b/src/core/cs_set.c
@@ -190,27 +190,20 @@ class CommandCSSet : public Command
{
int add = -1; /* 1 if adding, 0 if deleting, -1 if neither */
unsigned char mode;
- CBMode *cbm;
+ ChannelMode *cm;
+ ChannelModeParam *cmp;
if (checkDefCon(DEFCON_NO_MLOCK_CHANGE)) {
notice_lang(s_ChanServ, u, OPER_DEFCON_DENIED);
return MOD_CONT;
}
- /* Reinitialize everything */
- if (ircd->chanreg) {
- ci->mlock_on = ircd->regmode;
- } else {
- ci->mlock_on = 0;
- }
- ci->mlock_off = ci->mlock_limit = 0;
- ci->mlock_key = NULL;
- if (ircd->fmode) {
- ci->mlock_flood = NULL;
- }
- if (ircd->Lmode) {
- ci->mlock_redirect = NULL;
- }
+ ci->ClearMLock();
+
+ if (ModeManager::FindChannelModeByName(CMODE_REGISTERED))
+ ci->SetMLock(CMODE_REGISTERED, true);
+
+ ci->ClearParams();
std::string params(modes ? modes : ""), param;
unsigned space = params.find(' ');
@@ -235,48 +228,67 @@ class CommandCSSet : public Command
continue;
}
- if (static_cast<int>(mode) < 128 && (cbm = &cbmodes[static_cast<int>(mode)])->flag != 0) {
- if ((cbm->flags & CBM_NO_MLOCK)
- || ((cbm->flags & CBM_NO_USER_MLOCK) && !is_oper(u))) {
- notice_lang(s_ChanServ, u, CHAN_SET_MLOCK_IMPOSSIBLE_CHAR,
- mode);
- } else if (add) {
- ci->mlock_on |= cbm->flag;
- ci->mlock_off &= ~cbm->flag;
- if (cbm->cssetvalue)
+ if ((cm = ModeManager::FindChannelModeByChar(mode)))
+ {
+ if (!cm->CanSet(u))
+ {
+ notice_lang(s_ChanServ, u, CHAN_SET_MLOCK_IMPOSSIBLE_CHAR, mode);
+ }
+ else if (add)
+ {
+ if (cm->Type == MODE_PARAM)
{
- modeparams.GetToken(param);
- cbm->cssetvalue(ci, param.c_str());
+ cmp = static_cast<ChannelModeParam *>(cm);
+
+ if (!modeparams.GetToken(param))
+ continue;
+
+ if (!cmp->IsValid(param.c_str()))
+ continue;
+
+ ci->SetParam(cmp->Name, param);
}
- } else {
- ci->mlock_off |= cbm->flag;
- if (ci->mlock_on & cbm->flag) {
- ci->mlock_on &= ~cbm->flag;
- if (cbm->cssetvalue)
- cbm->cssetvalue(ci, NULL);
+
+ ci->SetMLock(cm->Name, true);
+ ci->RemoveMLock(cm->Name, false);
+ }
+ else
+ {
+ ci->SetMLock(cm->Name, false);
+
+ if (ci->HasMLock(cm->Name, true))
+ {
+ ci->RemoveMLock(cm->Name, true);
+
+ if (cm->Type == MODE_PARAM)
+ {
+ cmp = static_cast<ChannelModeParam *>(cm);
+
+ ci->UnsetParam(cmp->Name);
+ }
}
}
- } else {
- notice_lang(s_ChanServ, u, CHAN_SET_MLOCK_UNKNOWN_CHAR, mode);
}
+ else
+ notice_lang(s_ChanServ, u, CHAN_SET_MLOCK_UNKNOWN_CHAR, mode);
} /* while (*modes) */
- if (ircd->Lmode) {
+ if (ModeManager::FindChannelModeByName(CMODE_REDIRECT)) {
/* We can't mlock +L if +l is not mlocked as well. */
- if ((ci->mlock_on & ircd->chan_lmode)
- && !(ci->mlock_on & anope_get_limit_mode())) {
- ci->mlock_on &= ~ircd->chan_lmode;
- delete [] ci->mlock_redirect;
+ if (ci->HasMLock(CMODE_REDIRECT, true) && !ci->HasMLock(CMODE_LIMIT, true))
+ {
+ ci->RemoveMLock(CMODE_REDIRECT, true);
+ ci->UnsetParam(CMODE_REDIRECT);
notice_lang(s_ChanServ, u, CHAN_SET_MLOCK_L_REQUIRED);
}
}
/* Some ircd we can't set NOKNOCK without INVITE */
/* So check if we need there is a NOKNOCK MODE and that we need INVITEONLY */
- if (ircd->noknock && ircd->knock_needs_i) {
- if ((ci->mlock_on & ircd->noknock)
- && !(ci->mlock_on & anope_get_invite_mode())) {
- ci->mlock_on &= ~ircd->noknock;
+ if (ModeManager::FindChannelModeByName(CMODE_NOKNOCK) && ircd->knock_needs_i) {
+ if (ci->HasMLock(CMODE_NOKNOCK, true) && !ci->HasMLock(CMODE_INVITE, true))
+ {
+ ci->RemoveMLock(CMODE_NOKNOCK, true);
notice_lang(s_ChanServ, u, CHAN_SET_MLOCK_K_REQUIRED);
}
}
@@ -474,7 +486,7 @@ class CommandCSSet : public Command
} else if (CHECKLEV(CA_AUTOOP) || CHECKLEV(CA_OPDEOP)
|| CHECKLEV(CA_OPDEOPME)) {
access->level = ACCESS_AOP;
- } else if (ircd->halfop) {
+ } else if (ModeManager::FindChannelModeByName(CMODE_HALFOP)) {
if (CHECKLEV(CA_AUTOHALFOP) || CHECKLEV(CA_HALFOP)
|| CHECKLEV(CA_HALFOPME)) {
access->level = ACCESS_HOP;
diff --git a/src/core/cs_xop.c b/src/core/cs_xop.c
index 3c077e1f1..4fd3bcd7a 100644
--- a/src/core/cs_xop.c
+++ b/src/core/cs_xop.c
@@ -498,7 +498,7 @@ class CSXOP : public Module
this->SetType(CORE);
this->AddCommand(CHANSERV, new CommandCSAOP());
- if (ircd->halfop)
+ if (ModeManager::FindChannelModeByName(CMODE_HALFOP))
this->AddCommand(CHANSERV, new CommandCSHOP());
this->AddCommand(CHANSERV, new CommandCSSOP());
this->AddCommand(CHANSERV, new CommandCSVOP());
@@ -507,7 +507,7 @@ class CSXOP : public Module
{
notice_lang(s_ChanServ, u, CHAN_HELP_CMD_SOP);
notice_lang(s_ChanServ, u, CHAN_HELP_CMD_AOP);
- if (ircd->halfop)
+ if (ModeManager::FindChannelModeByName(CMODE_HALFOP))
notice_lang(s_ChanServ, u, CHAN_HELP_CMD_HOP);
notice_lang(s_ChanServ, u, CHAN_HELP_CMD_VOP);
}
diff --git a/src/core/os_chanlist.c b/src/core/os_chanlist.c
index 8eb5a5f77..e92e4ca8d 100644
--- a/src/core/os_chanlist.c
+++ b/src/core/os_chanlist.c
@@ -26,12 +26,14 @@ class CommandOSChanList : public Command
{
const char *pattern = params.size() > 0 ? params[0].c_str() : NULL;
ci::string opt = params.size() > 1 ? params[1] : "";
-
- int modes = 0;
+ std::list<ChannelModeName> Modes;
User *u2;
if (!opt.empty() && opt == "SECRET")
- modes |= (anope_get_secret_mode() | anope_get_private_mode());
+ {
+ Modes.push_back(CMODE_SECRET);
+ Modes.push_back(CMODE_PRIVATE);
+ }
if (pattern && (u2 = finduser(pattern)))
{
@@ -41,8 +43,15 @@ class CommandOSChanList : public Command
for (uc = u2->chans; uc; uc = uc->next)
{
- if (modes && !(uc->chan->mode & modes))
- continue;
+ if (!Modes.empty())
+ {
+ for (std::list<ChannelModeName>::iterator it = Modes.begin(); it != Modes.end(); ++it)