Add the type to the Extensible class.

This commit is contained in:
Sadie Powell 2022-01-31 02:04:43 +00:00
parent f6559895b2
commit 7d3055f8c3
7 changed files with 21 additions and 12 deletions

View File

@ -135,6 +135,9 @@ public:
/** Allows extensions to access the extension store. */
friend class ExtensionItem;
/** The type of extensible that this is. */
const ExtensionType extype:2;
~Extensible() override;
/** @copydoc Cullable::Cull */
@ -158,7 +161,7 @@ public:
void UnhookExtensions(const std::vector<ExtensionItem*>& items);
protected:
Extensible();
Extensible(ExtensionType exttype);
private:
/** The values for extensions which are set on this extensible. */

View File

@ -73,7 +73,12 @@ public:
* Call Channel::JoinUser() or ForceJoin() to make a user join a channel instead of constructing
* Membership objects directly.
*/
Membership(User* u, Channel* c) : user(u), chan(c) {}
Membership(User* u, Channel* c)
: Extensible(ExtensionType::MEMBERSHIP)
, user(u)
, chan(c)
{
}
/** Check if this member has a given prefix mode set
* @param pm Prefix mode to check

View File

@ -34,7 +34,8 @@ namespace
}
Channel::Channel(const std::string &cname, time_t ts)
: name(cname)
: Extensible(ExtensionType::CHANNEL)
, name(cname)
, age(ts)
{
if (!ServerInstance->Channels.GetChans().emplace(cname, this).second)

View File

@ -47,8 +47,9 @@ ExtensionItem* ExtensionManager::GetItem(const std::string& name)
return iter->second;
}
Extensible::Extensible()
: culled(false)
Extensible::Extensible(ExtensionType exttype)
: extype(exttype)
, culled(false)
{
}

View File

@ -851,9 +851,8 @@ void ModuleSpanningTree::OnShutdown(const std::string& reason)
void ModuleSpanningTree::OnDecodeMetaData(Extensible* target, const std::string& extname, const std::string& extdata)
{
// HACK: this should use automatically synced user metadata in v4.
User* dest = static_cast<User*>(target);
if (dest && (extname == "uniqueusername"))
dest->uniqueusername = (extdata != "0");
if (target->extype == ExtensionType::USER && irc::equals(extname, "uniqueusername"))
static_cast<User*>(target)->uniqueusername = (extdata != "0");
}
Cullable::Result ModuleSpanningTree::Cull()

View File

@ -143,9 +143,8 @@ public:
void OnDecodeMetaData(Extensible* target, const std::string& extname, const std::string&) override
{
User* dest = static_cast<User*>(target);
if (dest && (extname == "swhois"))
cmd.operblock.Unset(dest);
if (target->extype == ExtensionType::USER && irc::equals(extname, "swhois"))
cmd.operblock.Unset(static_cast<User*>(target));
}
};

View File

@ -77,7 +77,8 @@ std::string User::GetModeLetters(bool includeparams) const
}
User::User(const std::string& uid, Server* srv, Type type)
: age(ServerInstance->Time())
: Extensible(ExtensionType::USER)
, age(ServerInstance->Time())
, uuid(uid)
, server(srv)
, registered(REG_NONE)