+static bool ReadCGIIRCExt(const char* extname, User* user, const std::string*& out)
+{
+ ExtensionItem* wiext = ServerInstance->Extensions.GetItem(extname);
+ if (!wiext)
+ return false;
+
+ if (wiext->creator->ModuleSourceFile != "m_cgiirc.so")
+ return false;
+
+ StringExtItem* stringext = static_cast<StringExtItem*>(wiext);
+ std::string* addr = stringext->get(user);
+ if (!addr)
+ return false;
+
+ out = addr;
+ return true;
+}
+
+class AccountExtItemImpl : public AccountExtItem
+{
+ public:
+ AccountExtItemImpl(Module* mod)
+ : AccountExtItem("accountname", mod)
+ {
+ }
+
+ void unserialize(SerializeFormat format, Extensible* container, const std::string& value)
+ {
+ User* user = dynamic_cast<User*>(container);
+ if (!user)
+ return;
+
+ StringExtItem::unserialize(format, container, value);
+ if (!value.empty())
+ {
+ // Logged in
+ if (IS_LOCAL(user))
+ {
+ const std::string* host = &user->dhost;
+ if (user->registered != REG_ALL)
+ {
+ if (!ReadCGIIRCExt("cgiirc_webirc_hostname", user, host))
+ {
+ ReadCGIIRCExt("cgiirc_webirc_ip", user, host);
+ }
+ }
+
+ user->WriteNumeric(900, "%s!%s@%s %s :You are now logged in as %s",
+ user->nick.c_str(), user->ident.c_str(), host->c_str(), value.c_str(), value.c_str());
+ }
+
+ AccountEvent(creator, user, value).Send();
+ }
+ else
+ {
+ // Logged out
+ AccountEvent(creator, user, "").Send();
+ }
+ }
+};
+