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

Add keepmodes setting

This commit is contained in:
Adam
2013-08-01 14:07:56 +00:00
parent 1e625b6837
commit 83e4b183ea
6 changed files with 291 additions and 8 deletions
+4
View File
@@ -87,6 +87,8 @@ module
* - topiclock: Disallow the topic to be changed except with ChanServ's TOPIC command
* - persist: Keep the channel open at all times
* - noautoop: Disables autoop on the channel
* - cs_keepmodes: Enables keep modes on the channel, which retains modes when the channel is
* not in use.
* - none: No defaults
*
* This directive is optional, if left blank, the options will default to keeptopic, cs_secure, securefounder,
@@ -1086,6 +1088,7 @@ cs_seen
* chanserv/set/bantype - Used for controlling what format of bans are placed on channels.
* chanserv/set/description - Used for changing channels descriptions.
* chanserv/set/founder - Used for changing a channel's founder.
* chanserv/set/keepmodes - Used for enabling or disabling keepmodes, which retains channel modes.
* chanserv/set/peace - Used for configuring if users are able to kick other users with higher access than them.
* chanserv/set/persist - Used for setting whether ChanServ should stay in channels after the last user leaves.
* chanserv/set/restricted - Used for setting whether users not on a channel's access list can join.
@@ -1121,6 +1124,7 @@ command { service = "ChanServ"; name = "SET BANTYPE"; command = "chanserv/set/ba
command { service = "ChanServ"; name = "SET DESCRIPTION"; command = "chanserv/set/description"; }
command { service = "ChanServ"; name = "SET DESC"; command = "chanserv/set/description"; }
command { service = "ChanServ"; name = "SET FOUNDER"; command = "chanserv/set/founder"; }
command { service = "ChanServ"; name = "SET KEEPMODES"; command = "chanserv/set/keepmodes"; }
command { service = "ChanServ"; name = "SET PEACE"; command = "chanserv/set/peace"; }
command { service = "ChanServ"; name = "SET PERSIST"; command = "chanserv/set/persist"; }
command { service = "ChanServ"; name = "SET RESTRICTED"; command = "chanserv/set/restricted"; }
+5
View File
@@ -105,6 +105,7 @@ module
* - autoop: User will be automatically opped in channels they enter and have access to
* - msg: Services messages will be sent as PRIVMSGs instead of NOTICEs, requires
* options:useprivmsg to be enabled as well
* - ns_keepmodes: Enables keepmodes, which retains user modes across sessions
*
* This directive is optional, if left blank, the options will default to ns_secure, memo_signon, and
* memo_receive. If you really want no defaults, use "none" by itself as the option.
@@ -471,6 +472,7 @@ command { service = "NickServ"; name = "RESETPASS"; command = "nickserv/resetpas
* nickserv/set/autoop, nickserv/saset/autoop - Determines whether or not modes are automatically set users when joining a channel.
* nickserv/set/display, nickserv/saset/display - Used for setting a users display name.
* nickserv/set/email, nickserv/saset/email - Used for setting a users email address.
* nickserv/set/keepmodes, nickserv/saset/keepmodes - Configure whether or not services should retain a user's modes across sessions.
* nickserv/set/kill, nickserv/saset/kill - Used for configuring nickname protection.
* nickserv/set/language, nickserv/saset/language - Used for configuring what language services use.
* nickserv/set/message, nickserv/saset/message - Used to configure how services send messages to you.
@@ -503,6 +505,9 @@ command { service = "NickServ"; name = "SASET DISPLAY"; command = "nickserv/sase
command { service = "NickServ"; name = "SET EMAIL"; command = "nickserv/set/email"; }
command { service = "NickServ"; name = "SASET EMAIL"; command = "nickserv/saset/email"; permission = "nickserv/saset/email"; }
command { service = "NickServ"; name = "SET KEEPMODES"; command = "nickserv/set/keepmodes"; }
command { service = "NickServ"; name = "SASET KEEPMODES"; command = "nickserv/saset/keepmodes"; permission = "nickserv/saset/keepmodes"; }
command { service = "NickServ"; name = "SET KILL"; command = "nickserv/set/kill"; }
command { service = "NickServ"; name = "SASET KILL"; command = "nickserv/saset/kill"; permission = "nickserv/saset/kill"; }
+1
View File
@@ -120,6 +120,7 @@ class CoreExport NickCore : public Serializable, public Extensible
* on if NI_SECURE is set and what (if any) kill protection is enabled. */
std::vector<Anope::string> access;
MemoInfo memos;
std::map<Anope::string, Anope::string> last_modes;
/* Nicknames registered that are grouped to this account.
* for n in aliases, n->nc == this.
+2
View File
@@ -68,6 +68,8 @@ class CoreExport ChannelInfo : public Serializable, public Extensible
Anope::string last_topic_setter; /* Setter */
time_t last_topic_time; /* Time */
Channel::ModeList last_modes; /* The last modes set on this channel */
int16_t bantype;
MemoInfo memos;
+115 -4
View File
@@ -292,6 +292,51 @@ class CommandCSSetFounder : public Command
}
};
class CommandCSSetKeepModes : public Command
{
public:
CommandCSSetKeepModes(Module *creator, const Anope::string &cname = "chanserv/set/keepmodes") : Command(creator, cname, 2, 2)
{
this->SetDesc(_("Retain modes when channel is not in use"));
this->SetSyntax(_("\037channel\037 {ON | OFF}"));
}
void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
{
ChannelInfo *ci = ChannelInfo::Find(params[0]);
if (ci == NULL)
{
source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
return;
}
EventReturn MOD_RESULT;
FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1]));
if (MOD_RESULT == EVENT_STOP)
return;
if (MOD_RESULT != EVENT_ALLOW && !source.AccessFor(ci).HasPriv("SET") && source.permission.empty() && !source.HasPriv("chanserv/administration"))
{
source.Reply(ACCESS_DENIED);
return;
}
if (params[1].equals_ci("ON"))
{
Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to enable keep modes";
ci->Extend<bool>("CS_KEEP_MODES");
source.Reply(_("Keep modes for %s is now \002on\002."), ci->name.c_str());
}
else if (params[1].equals_ci("OFF"))
{
Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to disable keep modes";
ci->Shrink<bool>("CS_KEEP_MODES");
source.Reply(_("Keep modes for %s is now \002off\002."), ci->name.c_str());
}
else
this->OnSyntaxError(source, "PEACE");
}
};
class CommandCSSetPeace : public Command
{
public:
@@ -938,11 +983,57 @@ class CSSet : public Module
SerializableExtensibleItem<bool> persist, noautoop, peace, securefounder,
restricted, secure, secureops, signkick, signkick_level, noexpire;
struct KeepModes : SerializableExtensibleItem<bool>
{
KeepModes(Module *m, const Anope::string &n) : SerializableExtensibleItem<bool>(m, n) { }
void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const anope_override
{
SerializableExtensibleItem<bool>::ExtensibleSerialize(e, s, data);
if (s->GetSerializableType()->GetName() != "ChannelInfo")
return;
const ChannelInfo *ci = anope_dynamic_static_cast<const ChannelInfo *>(s);
Anope::string modes;
for (Channel::ModeList::const_iterator it = ci->last_modes.begin(); it != ci->last_modes.end(); ++it)
{
if (!modes.empty())
modes += " ";
modes += it->first;
if (!it->second.empty())
modes += "," + it->second;
}
data["last_modes"] << modes;
}
void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) anope_override
{
SerializableExtensibleItem<bool>::ExtensibleUnserialize(e, s, data);
if (s->GetSerializableType()->GetName() != "ChannelInfo")
return;
ChannelInfo *ci = anope_dynamic_static_cast<ChannelInfo *>(s);
Anope::string modes;
data["last_modes"] >> modes;
for (spacesepstream sep(modes); sep.GetToken(modes);)
{
size_t c = modes.find(',');
if (c == Anope::string::npos)
ci->last_modes.insert(std::make_pair(modes, ""));
else
ci->last_modes.insert(std::make_pair(modes.substr(0, c), modes.substr(c + 1)));
}
}
} keep_modes;
CommandCSSet commandcsset;
CommandCSSetAutoOp commandcssetautoop;
CommandCSSetBanType commandcssetbantype;
CommandCSSetDescription commandcssetdescription;
CommandCSSetFounder commandcssetfounder;
CommandCSSetKeepModes commandcssetkeepmodes;
CommandCSSetPeace commandcssetpeace;
CommandCSSetPersist commandcssetpersist;
CommandCSSetRestricted commandcssetrestricted;
@@ -959,9 +1050,10 @@ class CSSet : public Module
securefounder(this, "SECUREFOUNDER"), restricted(this, "RESTRICTED"),
secure(this, "CS_SECURE"), secureops(this, "SECUREOPS"), signkick(this, "SIGNKICK"),
signkick_level(this, "SIGNKICK_LEVEL"), noexpire(this, "CS_NO_EXPIRE"),
keep_modes(this, "CS_KEEP_MODES"),
commandcsset(this), commandcssetautoop(this), commandcssetbantype(this),
commandcssetdescription(this), commandcssetfounder(this),
commandcssetdescription(this), commandcssetfounder(this), commandcssetkeepmodes(this),
commandcssetpeace(this), commandcssetpersist(this), commandcssetrestricted(this),
commandcssetsecure(this), commandcssetsecurefounder(this), commandcssetsecureops(this), commandcssetsignkick(this),
commandcssetsuccessor(this), commandcssetnoexpire(this)
@@ -973,6 +1065,16 @@ class CSSet : public Module
ci->bantype = Config->GetModule(this)->Get<int>("defbantype", "2");
}
void OnChannelCreate(Channel *c) anope_override
{
if (c->ci && keep_modes.HasExt(c->ci))
{
Channel::ModeList ml = c->ci->last_modes;
for (Channel::ModeList::iterator it = ml.begin(); it != ml.end(); ++it)
c->SetMode(c->ci->WhoSends(), it->first, it->second);
}
}
EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) anope_override
{
if (!c->ci || !restricted.HasExt(c->ci) || c->MatchesList(u, "EXCEPT"))
@@ -993,10 +1095,14 @@ class CSSet : public Module
EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) anope_override
{
/* Channel mode +P or so was set, mark this channel as persistent */
if (mode->name == "PERM" && c->ci)
if (c->ci)
{
persist.Set(c->ci, true);
/* Channel mode +P or so was set, mark this channel as persistent */
if (mode->name == "PERM")
persist.Set(c->ci, true);
if (mode->type != MODE_STATUS)
c->ci->last_modes = c->GetModes();
}
return EVENT_CONTINUE;
@@ -1016,6 +1122,9 @@ class CSSet : public Module
}
}
if (c->ci && mode->type != MODE_STATUS)
c->ci->last_modes = c->GetModes();
return EVENT_CONTINUE;
}
@@ -1075,6 +1184,8 @@ class CSSet : public Module
info.AddOption(_("Persistent"));
if (noexpire.HasExt(ci))
info.AddOption(_("No expire"));
if (keep_modes.HasExt(ci))
info.AddOption(_("Keep modes"));
time_t chanserv_expire = Config->GetModule(this)->Get<time_t>("expire", "14d");
if (!noexpire.HasExt(ci) && chanserv_expire && !Anope::NoExpire)
+164 -4
View File
@@ -502,6 +502,87 @@ class CommandNSSASetEmail : public CommandNSSetEmail
}
};
class CommandNSSetKeepModes : public Command
{
public:
CommandNSSetKeepModes(Module *creator, const Anope::string &sname = "nickserv/set/keepmodes", size_t min = 1) : Command(creator, sname, min, min + 1)
{
this->SetDesc(_("Enable or disable keep modes"));
this->SetSyntax(_("{ON | OFF}"));
}
void Run(CommandSource &source, const Anope::string &user, const Anope::string &param)
{
const NickAlias *na = NickAlias::Find(user);
if (!na)
{
source.Reply(NICK_X_NOT_REGISTERED, user.c_str());
return;
}
NickCore *nc = na->nc;
EventReturn MOD_RESULT;
FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, nc, param));
if (MOD_RESULT == EVENT_STOP)
return;
if (param.equals_ci("ON"))
{
Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to enable keepmodes for " << nc->display;
nc->Extend<bool>("NS_KEEP_MODES");
source.Reply(_("Keep modes for %s is now \002on\002."), nc->display.c_str());
}
else if (param.equals_ci("OFF"))
{
Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to disable keepmodes for " << nc->display;
nc->Shrink<bool>("NS_KEEP_MODES");
source.Reply(_("Keep modes for %s is now \002off\002."), nc->display.c_str());
}
else
this->OnSyntaxError(source, "");
}
void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
{
this->Run(source, source.nc->display, params[0]);
}
bool OnHelp(CommandSource &source, const Anope::string &) anope_override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Enables or disables keepmodes for your nick. If keep\n"
"modes is enabled, services will remember your usermodes\n"
"and attempt to re-set them the next time you authenticate."));
return true;
}
};
class CommandNSSASetKeepModes : public CommandNSSetKeepModes
{
public:
CommandNSSASetKeepModes(Module *creator) : CommandNSSetKeepModes(creator, "nickserv/saset/keepmodes", 2)
{
this->ClearSyntax();
this->SetSyntax(_("\037nickname\037 {ON | OFF}"));
}
void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
{
this->Run(source, params[0], params[1]);
}
bool OnHelp(CommandSource &source, const Anope::string &) anope_override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Enables or disables keepmodes for the given nick. If keep\n"
"modes is enabled, services will remember users' usermodes\n"
"and attempt to re-set them the next time they authenticate."));
return true;
}
};
class CommandNSSetKill : public Command
{
public:
@@ -605,12 +686,12 @@ class CommandNSSASetKill : public CommandNSSetKill
public:
CommandNSSASetKill(Module *creator) : CommandNSSetKill(creator, "nickserv/saset/kill", 2)
{
this->ClearSyntax();
this->SetSyntax(_("\037nickname\037 {ON | QUICK | IMMED | OFF}"));
}
void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
{
this->ClearSyntax();
this->Run(source, params[0], params[1]);
}
@@ -979,6 +1060,9 @@ class NSSet : public Module
CommandNSSetEmail commandnssetemail;
CommandNSSASetEmail commandnssasetemail;
CommandNSSetKeepModes commandnssetkeepmodes;
CommandNSSASetKeepModes commandnssasetkeepmodes;
CommandNSSetKill commandnssetkill;
CommandNSSASetKill commandnssasetkill;
@@ -998,6 +1082,51 @@ class NSSet : public Module
SerializableExtensibleItem<bool> autoop, killprotect, kill_quick, kill_immed,
message, secure, noexpire;
struct KeepModes : SerializableExtensibleItem<bool>
{
KeepModes(Module *m, const Anope::string &n) : SerializableExtensibleItem<bool>(m, n) { }
void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const anope_override
{
SerializableExtensibleItem<bool>::ExtensibleSerialize(e, s, data);
if (s->GetSerializableType()->GetName() != "NickCore")
return;
const NickCore *nc = anope_dynamic_static_cast<const NickCore *>(s);
Anope::string modes;
for (User::ModeList::const_iterator it = nc->last_modes.begin(); it != nc->last_modes.end(); ++it)
{
if (!modes.empty())
modes += " ";
modes += it->first;
if (!it->second.empty())
modes += "," + it->second;
}
data["last_modes"] << modes;
}
void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) anope_override
{
SerializableExtensibleItem<bool>::ExtensibleUnserialize(e, s, data);
if (s->GetSerializableType()->GetName() != "NickCore")
return;
NickCore *nc = anope_dynamic_static_cast<NickCore *>(s);
Anope::string modes;
data["last_modes"] >> modes;
for (spacesepstream sep(modes); sep.GetToken(modes);)
{
size_t c = modes.find(',');
if (c == Anope::string::npos)
nc->last_modes.insert(std::make_pair(modes, ""));
else
nc->last_modes.insert(std::make_pair(modes.substr(0, c), modes.substr(c + 1)));
}
}
} keep_modes;
/* email, passcode */
PrimitiveExtensibleItem<std::pair<Anope::string, Anope::string > > ns_set_email;
@@ -1008,6 +1137,7 @@ class NSSet : public Module
commandnssetautoop(this), commandnssasetautoop(this),
commandnssetdisplay(this), commandnssasetdisplay(this),
commandnssetemail(this), commandnssasetemail(this),
commandnssetkeepmodes(this), commandnssasetkeepmodes(this),
commandnssetkill(this), commandnssasetkill(this),
commandnssetlanguage(this), commandnssasetlanguage(this),
commandnssetmessage(this), commandnssasetmessage(this),
@@ -1015,11 +1145,12 @@ class NSSet : public Module
commandnssetsecure(this), commandnssasetsecure(this),
commandnssasetnoexpire(this),
autoop(this, "AUTOOP"), killprotect(this, "KILLPROTECT"),
kill_quick(this, "KILL_QUICK"), kill_immed(this, "KILL_IMMED"), message(this, "MSG"),
autoop(this, "AUTOOP"),
killprotect(this, "KILLPROTECT"), kill_quick(this, "KILL_QUICK"),
kill_immed(this, "KILL_IMMED"), message(this, "MSG"),
secure(this, "NS_SECURE"), noexpire(this, "NS_NO_EXPIRE"),
ns_set_email(this, "ns_set_email")
keep_modes(this, "NS_KEEP_MODES"), ns_set_email(this, "ns_set_email")
{
}
@@ -1077,6 +1208,35 @@ class NSSet : public Module
info.AddOption(_("Auto-op"));
if (noexpire.HasExt(na))
info.AddOption(_("No expire"));
if (keep_modes.HasExt(na->nc))
info.AddOption(_("Keep modes"));
}
void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) anope_override
{
if (u->Account() && setter.GetUser() == u)
u->Account()->last_modes = u->GetModeList();
}
void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) anope_override
{
if (u->Account() && setter.GetUser() == u)
u->Account()->last_modes = u->GetModeList();
}
void OnUserLogin(User *u) anope_override
{
if (keep_modes.HasExt(u->Account()))
{
User::ModeList modes = u->Account()->last_modes;
for (User::ModeList::iterator it = modes.begin(); it != modes.end(); ++it)
{
UserMode *um = ModeManager::FindUserModeByName(it->first);
/* if the null user can set the mode, then it's probably safe */
if (um && um->CanSet(NULL))
u->SetMode(NULL, it->first, it->second);
}
}
}
};