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

Create persistent channels on startup, which used to work and got lost somewhere

Fix some oddities with using persistent channels with no botserv
Send list modes to uplink when bursting
Fix issues with persist + keepmodes
Fix /os modes clear all not clearing all status modes
Fix operwall on ratbox/plexus
Dont apply mlock in SetCorrectModes since that just recursively calls itself unncessarially
Change command logging to show the command name and not the service name
This commit is contained in:
Adam
2013-08-25 02:59:54 -04:00
parent 09046e3c99
commit 847cceaba3
16 changed files with 131 additions and 51 deletions
+2 -1
View File
@@ -220,7 +220,8 @@ template<typename T>
T* Extensible::Extend(const Anope::string &name, const T &what)
{
T* t = Extend<T>(name);
*t = what;
if (t)
*t = what;
return t;
}
+76 -30
View File
@@ -395,6 +395,13 @@ class CommandCSSetPeace : public Command
}
};
inline static Anope::string BotModes()
{
return Config->GetModule("botserv")->Get<Anope::string>("botmodes",
Config->GetModule("chanserv")->Get<Anope::string>("botmodes", "o")
);
}
class CommandCSSetPersist : public Command
{
public:
@@ -439,31 +446,11 @@ class CommandCSSetPersist : public Command
Channel *c = Channel::FindOrCreate(ci->name, created);
if (ci->bi)
{
ChannelStatus status(Config->GetModule("botserv")->Get<const Anope::string>("botmodes"));
ChannelStatus status(BotModes());
ci->bi->Join(c, &status);
}
}
/* No botserv bot, no channel mode, give them ChanServ.
* Yes, this works fine with no BotServ.
*/
if (!ci->bi && !cm)
{
BotInfo *ChanServ = Config->GetClient("ChanServ");
if (!ChanServ)
{
source.Reply(_("ChanServ is required to enable persist on this network."));
return;
}
ChanServ->Assign(NULL, ci);
if (!ci->c->FindUser(ChanServ))
{
ChannelStatus status(Config->GetModule("botserv")->Get<const Anope::string>("botmodes"));
ChanServ->Join(ci->c, &status);
}
}
/* Set the perm mode */
if (cm)
{
@@ -474,6 +461,25 @@ class CommandCSSetPersist : public Command
if (ml)
ml->SetMLock(cm, true);
}
/* No botserv bot, no channel mode, give them ChanServ.
* Yes, this works fine with no BotServ.
*/
else if (!ci->bi)
{
BotInfo *ChanServ = Config->GetClient("ChanServ");
if (!ChanServ)
{
source.Reply(_("ChanServ is required to enable persist on this network."));
return;
}
ChanServ->Assign(NULL, ci);
if (!ci->c->FindUser(ChanServ))
{
ChannelStatus status(BotModes());
ChanServ->Join(ci->c, &status);
}
}
}
Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to enable persist";
@@ -485,6 +491,9 @@ class CommandCSSetPersist : public Command
{
ci->Shrink<bool>("PERSIST");
BotInfo *ChanServ = Config->GetClient("ChanServ"),
*BotServ = Config->GetClient("BotServ");
/* Unset perm mode */
if (cm)
{
@@ -495,19 +504,17 @@ class CommandCSSetPersist : public Command
if (ml)
ml->RemoveMLock(cm, true);
}
/* No channel mode, no BotServ, but using ChanServ as the botserv bot
* which was assigned when persist was set on
*/
BotInfo *ChanServ = Config->GetClient("ChanServ"),
*BotServ = Config->GetClient("BotServ");
if (!cm && !BotServ && ci->bi)
else if (!cm && !BotServ && ci->bi)
{
if (!ChanServ)
{
source.Reply(_("ChanServ is required to enable persist on this network."));
return;
}
/* Unassign bot */
ChanServ->UnAssign(NULL, ci);
}
@@ -980,7 +987,7 @@ class CommandCSSetNoexpire : public Command
class CSSet : public Module
{
SerializableExtensibleItem<bool> persist, noautoop, peace, securefounder,
SerializableExtensibleItem<bool> noautoop, peace, securefounder,
restricted, secure, secureops, signkick, signkick_level, noexpire;
struct KeepModes : SerializableExtensibleItem<bool>
@@ -1028,6 +1035,40 @@ class CSSet : public Module
}
} keep_modes;
struct Persist : SerializableExtensibleItem<bool>
{
Persist(Module *m, const Anope::string &n) : SerializableExtensibleItem<bool>(m, n) { }
void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) anope_override
{
SerializableExtensibleItem<bool>::ExtensibleUnserialize(e, s, data);
if (s->GetSerializableType()->GetName() != "ChannelInfo" || !this->HasExt(e))
return;
ChannelInfo *ci = anope_dynamic_static_cast<ChannelInfo *>(s);
if (ci->c)
return;
bool created;
Channel *c = Channel::FindOrCreate(ci->name, created, ci->time_registered);
if (!ci->bi)
{
BotInfo *ChanServ = Config->GetClient("ChanServ");
if (ChanServ)
ChanServ->Assign(NULL, ci);
}
if (!ci->bi)
return;
if (!c->FindUser(ci->bi))
{
ChannelStatus status(BotModes());
ci->bi->Join(c, &status);
}
}
} persist;
CommandCSSet commandcsset;
CommandCSSetAutoOp commandcssetautoop;
CommandCSSetBanType commandcssetbantype;
@@ -1046,11 +1087,11 @@ class CSSet : public Module
public:
CSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
persist(this, "PERSIST"), noautoop(this, "NOAUTOOP"), peace(this, "PEACE"),
noautoop(this, "NOAUTOOP"), peace(this, "PEACE"),
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"),
keep_modes(this, "CS_KEEP_MODES"), persist(this, "PERSIST"),
commandcsset(this), commandcssetautoop(this), commandcssetbantype(this),
commandcssetdescription(this), commandcssetfounder(this), commandcssetkeepmodes(this),
@@ -1075,6 +1116,11 @@ class CSSet : public Module
}
}
void OnChannelSync(Channel *c) anope_override
{
OnChannelCreate(c);
}
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"))
@@ -1101,7 +1147,7 @@ class CSSet : public Module
if (mode->name == "PERM")
persist.Set(c->ci, true);
if (mode->type != MODE_STATUS)
if (mode->type != MODE_STATUS && !c->syncing && Me->IsSynced())
c->ci->last_modes = c->GetModes();
}
@@ -1122,7 +1168,7 @@ class CSSet : public Module
}
}
if (c->ci && mode->type != MODE_STATUS)
if (c->ci && mode->type != MODE_STATUS && !c->syncing && Me->IsSynced())
c->ci->last_modes = c->GetModes();
return EVENT_CONTINUE;
+2 -2
View File
@@ -48,8 +48,8 @@ class CommandOSMode : public Command
if (uc->user->HasMode("OPER"))
continue;
for (size_t i = 0; i < uc->status.Modes().length(); ++i)
c->RemoveMode(c->ci->WhoSends(), ModeManager::FindChannelModeByChar(uc->status.Modes()[i]), uc->user->GetUID(), false);
for (size_t i = uc->status.Modes().length(); i > 0; --i)
c->RemoveMode(c->ci->WhoSends(), ModeManager::FindChannelModeByChar(uc->status.Modes()[i - 1]), uc->user->GetUID(), false);
}
source.Reply(_("All modes cleared on %s."), c->name.c_str());
+3
View File
@@ -178,6 +178,9 @@ class BahamutIRCdProto : public IRCDProto
BotInfo *setter = BotInfo::Find(user->nick);
for (size_t i = 0; i < cs.Modes().length(); ++i)
c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
}
}
+3
View File
@@ -261,6 +261,9 @@ class InspIRCd12Proto : public IRCDProto
BotInfo *setter = BotInfo::Find(user->nick);
for (size_t i = 0; i < cs.Modes().length(); ++i)
c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
}
}
+3
View File
@@ -98,6 +98,9 @@ class ngIRCdProto : public IRCDProto
BotInfo *setter = BotInfo::Find(user->nick);
for (size_t i = 0; i < cs.Modes().length(); ++i)
c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
}
}
+8 -1
View File
@@ -36,7 +36,6 @@ class PlexusProto : public IRCDProto
void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { hybrid->SendGlobalNotice(bi, dest, msg); }
void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { hybrid->SendGlobalPrivmsg(bi, dest, msg); }
void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override { hybrid->SendGlobopsInternal(source, buf); }
void SendSQLine(User *u, const XLine *x) anope_override { hybrid->SendSQLine(u, x); }
void SendSQLineDel(const XLine *x) anope_override { hybrid->SendSQLineDel(x); }
void SendSGLineDel(const XLine *x) anope_override { hybrid->SendSGLineDel(x); }
@@ -48,6 +47,11 @@ class PlexusProto : public IRCDProto
void SendSVSHold(const Anope::string &nick, time_t t) anope_override { hybrid->SendSVSHold(nick, t); }
void SendSVSHoldDel(const Anope::string &nick) anope_override { hybrid->SendSVSHoldDel(nick); }
void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override
{
UplinkSocket::Message(source) << "OPERWALL :" << buf;
}
void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
{
UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " +" << c->GetModes(true, true) << " :" << user->GetUID();
@@ -65,6 +69,9 @@ class PlexusProto : public IRCDProto
BotInfo *setter = BotInfo::Find(user->nick);
for (size_t i = 0; i < cs.Modes().length(); ++i)
c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
}
}
+5 -1
View File
@@ -30,7 +30,6 @@ class RatboxProto : public IRCDProto
void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { hybrid->SendGlobalNotice(bi, dest, msg); }
void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { hybrid->SendGlobalPrivmsg(bi, dest, msg); }
void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override { hybrid->SendGlobopsInternal(source, buf); }
void SendSQLine(User *u, const XLine *x) anope_override { hybrid->SendSQLine(u, x); }
void SendSGLine(User *u, const XLine *x) anope_override { hybrid->SendSGLine(u, x); }
void SendSGLineDel(const XLine *x) anope_override { hybrid->SendSGLineDel(x); }
@@ -44,6 +43,11 @@ class RatboxProto : public IRCDProto
void SendTopic(const MessageSource &source, Channel *c) anope_override { hybrid->SendTopic(source, c); }
bool IsIdentValid(const Anope::string &ident) anope_override { return hybrid->IsIdentValid(ident); }
void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override
{
UplinkSocket::Message(source) << "OPERWALL :" << buf;
}
void SendConnect() anope_override
{
UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " TS 6 :" << Me->GetSID();
+3
View File
@@ -171,6 +171,9 @@ class UnrealIRCdProto : public IRCDProto
BotInfo *setter = BotInfo::Find(user->nick);
for (size_t i = 0; i < cs.Modes().length(); ++i)
c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
}
}
+1 -1
View File
@@ -288,7 +288,7 @@ class ChanServCore : public Module, public ChanServService
void OnChannelSync(Channel *c) anope_override
{
bool perm = c->HasMode("PERM") || (c->ci && persist && persist->Get(c->ci));
bool perm = c->HasMode("PERM") || (c->ci && persist && persist->HasExt(c->ci));
if (!perm && !c->botchannel && (c->users.empty() || (c->users.size() == 1 && c->users.begin()->second->user->server == Me)))
{
this->Hold(c);
+2 -2
View File
@@ -812,7 +812,7 @@ void Channel::SetCorrectModes(User *user, bool give_modes)
/* Always give op. If we have already given one mode, don't give more until it has a symbol */
if (cm->name == "OP" || !given || (giving && cm->symbol))
{
this->SetMode(NULL, cm, user->GetUID());
this->SetMode(NULL, cm, user->GetUID(), false);
/* Now if this contains a symbol don't give any more modes, to prevent setting +qaohv etc on users */
giving = !cm->symbol;
given = true;
@@ -824,7 +824,7 @@ void Channel::SetCorrectModes(User *user, bool give_modes)
if (cm->name == "VOICE")
take_modes = false;
else
this->RemoveMode(NULL, cm, user->GetUID());
this->RemoveMode(NULL, cm, user->GetUID(), false);
}
}
}
+3 -6
View File
@@ -148,8 +148,7 @@ Anope::string Log::BuildPrefix() const
if (!this->c && !(this->u || this->nc))
break;
buffer += "ADMIN: ";
size_t sl = this->c->name.find('/');
Anope::string cname = sl != Anope::string::npos ? this->c->name.substr(sl + 1) : this->c->name;
Anope::string cname = source != NULL ? source->command : this->c->name;
if (this->u)
buffer += this->u->GetMask() + " used " + cname + " ";
else if (this->nc)
@@ -163,8 +162,7 @@ Anope::string Log::BuildPrefix() const
if (!this->c && !(this->u || this->nc))
break;
buffer += "OVERRIDE: ";
size_t sl = this->c->name.find('/');
Anope::string cname = sl != Anope::string::npos ? this->c->name.substr(sl + 1) : this->c->name;
Anope::string cname = source != NULL ? source->command : this->c->name;
if (this->u)
buffer += this->u->GetMask() + " used " + cname + " ";
else if (this->nc)
@@ -178,8 +176,7 @@ Anope::string Log::BuildPrefix() const
if (!this->c)
break;
buffer += "COMMAND: ";
size_t sl = this->c->name.find('/');
Anope::string cname = sl != Anope::string::npos ? this->c->name.substr(sl + 1) : this->c->name;
Anope::string cname = source != NULL ? source->command : this->c->name;
if (this->u)
buffer += this->u->GetMask() + " used " + cname + " ";
else if (this->source)
+4 -2
View File
@@ -140,7 +140,6 @@ void NickAlias::Serialize(Serialize::Data &data) const
data.SetType("time_registered", Serialize::Data::DT_INT); data["time_registered"] << this->time_registered;
data.SetType("time_registered", Serialize::Data::DT_INT); data["last_seen"] << this->last_seen;
data["nc"] << this->nc->display;
Extensible::ExtensibleSerialize(this, this, data);
if (this->HasVhost())
{
@@ -149,6 +148,8 @@ void NickAlias::Serialize(Serialize::Data &data) const
data["vhost_creator"] << this->GetVhostCreator();
data["vhost_time"] << this->GetVhostCreated();
}
Extensible::ExtensibleSerialize(this, this, data);
}
Serializable* NickAlias::Unserialize(Serializable *obj, Serialize::Data &data)
@@ -189,7 +190,6 @@ Serializable* NickAlias::Unserialize(Serializable *obj, Serialize::Data &data)
data["last_realhost"] >> na->last_realhost;
data["time_registered"] >> na->time_registered;
data["last_seen"] >> na->last_seen;
Extensible::ExtensibleUnserialize(na, na, data);
Anope::string vhost_ident, vhost_host, vhost_creator;
time_t vhost_time;
@@ -201,6 +201,8 @@ Serializable* NickAlias::Unserialize(Serializable *obj, Serialize::Data &data)
na->SetVhost(vhost_ident, vhost_host, vhost_creator, vhost_time);
Extensible::ExtensibleUnserialize(na, na, data);
/* compat */
bool b;
b = false;
+3 -2
View File
@@ -68,12 +68,12 @@ void NickCore::Serialize(Serialize::Data &data) const
data["pass"] << this->pass;
data["email"] << this->email;
data["language"] << this->language;
Extensible::ExtensibleSerialize(this, this, data);
for (unsigned i = 0; i < this->access.size(); ++i)
data["access"] << this->access[i] << " ";
data["memomax"] << this->memos.memomax;
for (unsigned i = 0; i < this->memos.ignores.size(); ++i)
data["memoignores"] << this->memos.ignores[i] << " ";
Extensible::ExtensibleSerialize(this, this, data);
}
Serializable* NickCore::Unserialize(Serializable *obj, Serialize::Data &data)
@@ -92,7 +92,6 @@ Serializable* NickCore::Unserialize(Serializable *obj, Serialize::Data &data)
data["pass"] >> nc->pass;
data["email"] >> nc->email;
data["language"] >> nc->language;
Extensible::ExtensibleUnserialize(nc, nc, data);
{
Anope::string buf;
data["access"] >> buf;
@@ -111,6 +110,8 @@ Serializable* NickCore::Unserialize(Serializable *obj, Serialize::Data &data)
nc->memos.ignores.push_back(buf);
}
Extensible::ExtensibleUnserialize(nc, nc, data);
/* compat */
bool b;
b = false;
+4 -3
View File
@@ -220,7 +220,6 @@ void ChannelInfo::Serialize(Serialize::Data &data) const
data["last_topic_setter"] << this->last_topic_setter;
data.SetType("last_topic_time", Serialize::Data::DT_INT); data["last_topic_time"] << this->last_topic_time;
data.SetType("bantype", Serialize::Data::DT_INT); data["bantype"] << this->bantype;
Extensible::ExtensibleSerialize(this, this, data);
{
Anope::string levels_buffer;
for (Anope::map<int16_t>::const_iterator it = this->levels.begin(), it_end = this->levels.end(); it != it_end; ++it)
@@ -233,6 +232,8 @@ void ChannelInfo::Serialize(Serialize::Data &data) const
data["memomax"] << this->memos.memomax;
for (unsigned i = 0; i < this->memos.ignores.size(); ++i)
data["memoignores"] << this->memos.ignores[i] << " ";
Extensible::ExtensibleSerialize(this, this, data);
}
Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data)
@@ -251,8 +252,6 @@ Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data)
else
ci = new ChannelInfo(sname);
Extensible::ExtensibleUnserialize(ci, ci, data);
ci->SetFounder(NickCore::Find(sfounder));
ci->SetSuccessor(NickCore::Find(ssuccessor));
@@ -288,6 +287,8 @@ Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data)
ci->memos.ignores.push_back(buf);
}
Extensible::ExtensibleUnserialize(ci, ci, data);
/* compat */
bool b;
b = false;
+9
View File
@@ -109,11 +109,20 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano
for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
{
Channel *c = it->second;
if (c->users.empty())
IRCD->SendChannel(c);
else
for (Channel::ChanUserList::const_iterator cit = c->users.begin(), cit_end = c->users.end(); cit != cit_end; ++cit)
IRCD->SendJoin(cit->second->user, c, &cit->second->status);
for (Channel::ModeList::const_iterator it2 = c->GetModes().begin(); it2 != c->GetModes().end(); ++it2)
{
ChannelMode *cm = ModeManager::FindChannelModeByName(it2->first);
if (!cm || cm->type != MODE_LIST)
continue;
ModeManager::StackerAdd(c->ci->WhoSends(), c, cm, true, it2->second);
}
}
}
}