summaryrefslogtreecommitdiff
path: root/modules/pseudoclients/nickserv
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2014-05-28 12:07:29 -0400
committerAdam <Adam@anope.org>2014-05-28 12:07:54 -0400
commitf29e1cf383529a1a29f02b0669d973f5ee0b7a66 (patch)
tree3c33db276dc9328235bbd572641521ed44458176 /modules/pseudoclients/nickserv
parent1253c70e0682fa1490c99c3d2869049a0e3fa2e0 (diff)
Move most of the core pseudoclient logic to modules
Diffstat (limited to 'modules/pseudoclients/nickserv')
-rw-r--r--modules/pseudoclients/nickserv/CMakeLists.txt1
-rw-r--r--modules/pseudoclients/nickserv/account.cpp264
-rw-r--r--modules/pseudoclients/nickserv/account.h22
-rw-r--r--modules/pseudoclients/nickserv/identifyrequest.cpp51
-rw-r--r--modules/pseudoclients/nickserv/identifyrequest.h13
-rw-r--r--modules/pseudoclients/nickserv/nick.cpp198
-rw-r--r--modules/pseudoclients/nickserv/nick.h18
-rw-r--r--modules/pseudoclients/nickserv/nickserv.cpp666
8 files changed, 1233 insertions, 0 deletions
diff --git a/modules/pseudoclients/nickserv/CMakeLists.txt b/modules/pseudoclients/nickserv/CMakeLists.txt
new file mode 100644
index 000000000..781f0ef1f
--- /dev/null
+++ b/modules/pseudoclients/nickserv/CMakeLists.txt
@@ -0,0 +1 @@
+build_subdir(${CMAKE_CURRENT_SOURCE_DIR})
diff --git a/modules/pseudoclients/nickserv/account.cpp b/modules/pseudoclients/nickserv/account.cpp
new file mode 100644
index 000000000..55c537a0c
--- /dev/null
+++ b/modules/pseudoclients/nickserv/account.cpp
@@ -0,0 +1,264 @@
+/*
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ *
+ */
+
+#include "module.h"
+#include "account.h"
+
+AccountImpl::AccountImpl(const Anope::string &coredisplay)
+{
+ if (coredisplay.empty())
+ throw CoreException("Empty display passed to NickServ::Account constructor");
+
+ this->o = NULL;
+ this->channelcount = 0;
+ this->lastmail = 0;
+
+ this->display = coredisplay;
+
+ NickServ::nickcore_map& map = NickServ::service->GetAccountList();
+ NickServ::Account* &nc = map[this->display];
+ if (nc)
+ Log(LOG_DEBUG) << "Duplicate account " << coredisplay << " in nickcore table?";
+ nc = this;
+
+ Event::OnNickCoreCreate(&Event::NickCoreCreate::OnNickCoreCreate, this);
+}
+
+AccountImpl::~AccountImpl()
+{
+ Event::OnDelCore(&Event::DelCore::OnDelCore, this);
+
+ if (!this->chanaccess->empty())
+ Log(LOG_DEBUG) << "Non-empty chanaccess list in destructor!";
+
+ for (std::list<User *>::iterator it = this->users.begin(); it != this->users.end();)
+ {
+ User *user = *it++;
+ user->Logout();
+ }
+ this->users.clear();
+
+ NickServ::nickcore_map& map = NickServ::service->GetAccountList();
+ map.erase(this->display);
+
+ this->ClearAccess();
+
+ if (memos)
+ {
+ for (unsigned i = 0, end = this->memos->memos->size(); i < end; ++i)
+ delete this->memos->GetMemo(i);
+ this->memos->memos->clear();
+ delete memos;
+ }
+}
+
+void AccountImpl::Serialize(Serialize::Data &data) const
+{
+ data["display"] << this->display;
+ data["pass"] << this->pass;
+ data["email"] << this->email;
+ data["language"] << this->language;
+ for (unsigned i = 0; i < this->access.size(); ++i)
+ data["access"] << this->access[i] << " ";
+ if (memos)
+ {
+ 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* AccountImpl::Unserialize(Serializable *obj, Serialize::Data &data)
+{
+ NickServ::Account *nc;
+
+ Anope::string sdisplay;
+
+ data["display"] >> sdisplay;
+
+ if (obj)
+ nc = anope_dynamic_static_cast<NickServ::Account *>(obj);
+ else
+ nc = new AccountImpl(sdisplay);
+
+ data["pass"] >> nc->pass;
+ data["email"] >> nc->email;
+ data["language"] >> nc->language;
+ {
+ Anope::string buf;
+ data["access"] >> buf;
+ spacesepstream sep(buf);
+ nc->access.clear();
+ while (sep.GetToken(buf))
+ nc->access.push_back(buf);
+ }
+ if (nc->memos)
+ {
+ data["memomax"] >> nc->memos->memomax;
+ {
+ Anope::string buf;
+ data["memoignores"] >> buf;
+ spacesepstream sep(buf);
+ nc->memos->ignores.clear();
+ while (sep.GetToken(buf))
+ nc->memos->ignores.push_back(buf);
+ }
+ }
+
+ Extensible::ExtensibleUnserialize(nc, nc, data);
+
+ /* compat */
+ bool b;
+ b = false;
+ data["extensible:SECURE"] >> b;
+ if (b)
+ nc->Extend<bool>("NS_SECURE");
+ b = false;
+ data["extensible:PRIVATE"] >> b;
+ if (b)
+ nc->Extend<bool>("NS_PRIVATE");
+ b = false;
+ data["extensible:AUTOOP"] >> b;
+ if (b)
+ nc->Extend<bool>("AUTOOP");
+ b = false;
+ data["extensible:HIDE_EMAIL"] >> b;
+ if (b)
+ nc->Extend<bool>("HIDE_EMAIL");
+ b = false;
+ data["extensible:HIDE_QUIT"] >> b;
+ if (b)
+ nc->Extend<bool>("HIDE_QUIT");
+ b = false;
+ data["extensible:MEMO_RECEIVE"] >> b;
+ if (b)
+ nc->Extend<bool>("MEMO_RECEIVE");
+ b = false;
+ data["extensible:MEMO_SIGNON"] >> b;
+ if (b)
+ nc->Extend<bool>("MEMO_SIGNON");
+ b = false;
+ data["extensible:KILLPROTECT"] >> b;
+ if (b)
+ nc->Extend<bool>("KILLPROTECT");
+ /* end compat */
+
+ return nc;
+}
+
+void AccountImpl::SetDisplay(const NickServ::Nick *na)
+{
+ if (na->nc != this || na->nick == this->display)
+ return;
+
+ Event::OnChangeCoreDisplay(&Event::ChangeCoreDisplay::OnChangeCoreDisplay, this, na->nick);
+
+ NickServ::nickcore_map& map = NickServ::service->GetAccountList();
+
+ /* Remove the core from the list */
+ map.erase(this->display);
+
+ this->display = na->nick;
+
+ NickServ::Account* &nc = map[this->display];
+ if (nc)
+ Log(LOG_DEBUG) << "Duplicate account " << display << " in nickcore table?";
+
+ nc = this;
+}
+
+bool AccountImpl::IsServicesOper() const
+{
+ return this->o != NULL;
+}
+
+void AccountImpl::AddAccess(const Anope::string &entry)
+{
+ this->access.push_back(entry);
+ Event::OnNickAddAccess(&Event::NickAddAccess::OnNickAddAccess, this, entry);
+}
+
+Anope::string AccountImpl::GetAccess(unsigned entry) const
+{
+ if (this->access.empty() || entry >= this->access.size())
+ return "";
+ return this->access[entry];
+}
+
+unsigned AccountImpl::GetAccessCount() const
+{
+ return this->access.size();
+}
+
+bool AccountImpl::FindAccess(const Anope::string &entry)
+{
+ for (unsigned i = 0, end = this->access.size(); i < end; ++i)
+ if (this->access[i] == entry)
+ return true;
+
+ return false;
+}
+
+void AccountImpl::EraseAccess(const Anope::string &entry)
+{
+ for (unsigned i = 0, end = this->access.size(); i < end; ++i)
+ if (this->access[i] == entry)
+ {
+ Event::OnNickEraseAccess(&Event::NickEraseAccess::OnNickEraseAccess, this, entry);
+ this->access.erase(this->access.begin() + i);
+ break;
+ }
+}
+
+void AccountImpl::ClearAccess()
+{
+ Event::OnNickClearAccess(&Event::NickClearAccess::OnNickClearAccess, this);
+ this->access.clear();
+}
+
+bool AccountImpl::IsOnAccess(const User *u) const
+{
+ Anope::string buf = u->GetIdent() + "@" + u->host, buf2, buf3;
+ if (!u->vhost.empty())
+ buf2 = u->GetIdent() + "@" + u->vhost;
+ if (!u->GetCloakedHost().empty())
+ buf3 = u->GetIdent() + "@" + u->GetCloakedHost();
+
+ for (unsigned i = 0, end = this->access.size(); i < end; ++i)
+ {
+ Anope::string a = this->GetAccess(i);
+ if (Anope::Match(buf, a) || (!buf2.empty() && Anope::Match(buf2, a)) || (!buf3.empty() && Anope::Match(buf3, a)))
+ return true;
+ }
+ return false;
+}
+
+void AccountImpl::AddChannelReference(ChanServ::Channel *ci)
+{
+ ++(*this->chanaccess)[ci];
+}
+
+void AccountImpl::RemoveChannelReference(ChanServ::Channel *ci)
+{
+ int& i = (*this->chanaccess)[ci];
+ if (--i <= 0)
+ this->chanaccess->erase(ci);
+}
+
+void AccountImpl::GetChannelReferences(std::deque<ChanServ::Channel *> &queue)
+{
+ queue.clear();
+ for (std::map<ChanServ::Channel *, int>::iterator it = this->chanaccess->begin(), it_end = this->chanaccess->end(); it != it_end; ++it)
+ queue.push_back(it->first);
+}
+
diff --git a/modules/pseudoclients/nickserv/account.h b/modules/pseudoclients/nickserv/account.h
new file mode 100644
index 000000000..ec154e8d0
--- /dev/null
+++ b/modules/pseudoclients/nickserv/account.h
@@ -0,0 +1,22 @@
+#include "modules/nickserv.h"
+
+class AccountImpl : public NickServ::Account
+{
+ public:
+ AccountImpl(const Anope::string &nickdisplay);
+ ~AccountImpl();
+ void Serialize(Serialize::Data &data) const override;
+ static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
+ void SetDisplay(const NickServ::Nick *na) override;
+ bool IsServicesOper() const override;
+ void AddAccess(const Anope::string &entry) override;
+ Anope::string GetAccess(unsigned entry) const override;
+ unsigned GetAccessCount() const override;
+ bool FindAccess(const Anope::string &entry) override;
+ void EraseAccess(const Anope::string &entry) override;
+ void ClearAccess() override;
+ bool IsOnAccess(const User *u) const override;
+ void AddChannelReference(ChanServ::Channel *ci);
+ void RemoveChannelReference(ChanServ::Channel *ci) override;
+ void GetChannelReferences(std::deque<ChanServ::Channel *> &queue) override;
+};
diff --git a/modules/pseudoclients/nickserv/identifyrequest.cpp b/modules/pseudoclients/nickserv/identifyrequest.cpp
new file mode 100644
index 000000000..4fc2f9989
--- /dev/null
+++ b/modules/pseudoclients/nickserv/identifyrequest.cpp
@@ -0,0 +1,51 @@
+#include "identifyrequest.h"
+
+IdentifyRequestImpl::IdentifyRequestImpl(NickServ::IdentifyRequestListener *li, Module *o, const Anope::string &acc, const Anope::string &pass) : NickServ::IdentifyRequest(li, o, acc, pass)
+{
+ std::set<NickServ::IdentifyRequest *> &requests = NickServ::service->GetIdentifyRequests();
+ requests.insert(this);
+}
+
+IdentifyRequestImpl::~IdentifyRequestImpl()
+{
+ std::set<NickServ::IdentifyRequest *> &requests = NickServ::service->GetIdentifyRequests();
+ requests.erase(this);
+ delete l;
+}
+
+void IdentifyRequestImpl::Hold(Module *m)
+{
+ holds.insert(m);
+}
+
+void IdentifyRequestImpl::Release(Module *m)
+{
+ holds.erase(m);
+ if (holds.empty() && dispatched)
+ {
+ if (!success)
+ l->OnFail(this);
+ delete this;
+ }
+}
+
+void IdentifyRequestImpl::Success(Module *m)
+{
+ if (!success)
+ {
+ l->OnSuccess(this);
+ success = true;
+ }
+}
+
+void IdentifyRequestImpl::Dispatch()
+{
+ if (holds.empty())
+ {
+ if (!success)
+ l->OnFail(this);
+ delete this;
+ }
+ else
+ dispatched = true;
+}
diff --git a/modules/pseudoclients/nickserv/identifyrequest.h b/modules/pseudoclients/nickserv/identifyrequest.h
new file mode 100644
index 000000000..e74d3129e
--- /dev/null
+++ b/modules/pseudoclients/nickserv/identifyrequest.h
@@ -0,0 +1,13 @@
+#include "modules/nickserv.h"
+
+class IdentifyRequestImpl : public NickServ::IdentifyRequest
+{
+ public:
+ IdentifyRequestImpl(NickServ::IdentifyRequestListener *, Module *o, const Anope::string &acc, const Anope::string &pass);
+ virtual ~IdentifyRequestImpl();
+
+ void Hold(Module *m) override;
+ void Release(Module *m) override;
+ void Success(Module *m) override;
+ void Dispatch() override;
+};
diff --git a/modules/pseudoclients/nickserv/nick.cpp b/modules/pseudoclients/nickserv/nick.cpp
new file mode 100644
index 000000000..acba58b1e
--- /dev/null
+++ b/modules/pseudoclients/nickserv/nick.cpp
@@ -0,0 +1,198 @@
+/*
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ *
+ */
+
+#include "module.h"
+#include "nick.h"
+
+NickImpl::NickImpl(const Anope::string &nickname, NickServ::Account* nickcore)
+{
+ if (nickname.empty())
+ throw CoreException("Empty nick passed to NickServ::Nick constructor");
+ else if (!nickcore)
+ throw CoreException("Empty nickcore passed to NickServ::Nick constructor");
+
+ this->time_registered = this->last_seen = Anope::CurTime;
+ this->nick = nickname;
+ this->nc = nickcore;
+ nickcore->aliases->push_back(this);
+
+ NickServ::nickalias_map &map = NickServ::service->GetNickList();
+ NickServ::Nick* &na = map[this->nick];
+ if (na)
+ Log(LOG_DEBUG) << "Duplicate nick " << nickname << " in nickalias table";
+ na = this;
+
+ if (this->nc->o == NULL)
+ {
+ Oper *o = Oper::Find(this->nick);
+ if (o == NULL)
+ o = Oper::Find(this->nc->display);
+ nickcore->o = o;
+ if (this->nc->o != NULL)
+ Log() << "Tied oper " << this->nc->display << " to type " << this->nc->o->ot->GetName();
+ }
+}
+
+NickImpl::~NickImpl()
+{
+ Event::OnDelNick(&Event::DelNick::OnDelNick, this);
+
+ /* Accept nicks that have no core, because of database load functions */
+ if (this->nc)
+ {
+ /* Next: see if our core is still useful. */
+ std::vector<NickServ::Nick *>::iterator it = std::find(this->nc->aliases->begin(), this->nc->aliases->end(), this);
+ if (it != this->nc->aliases->end())
+ this->nc->aliases->erase(it);
+ if (this->nc->aliases->empty())
+ {
+ delete this->nc;
+ this->nc = NULL;
+ }
+ else
+ {
+ /* Display updating stuff */
+ if (this->nick.equals_ci(this->nc->display))
+ this->nc->SetDisplay(this->nc->aliases->front());
+ }
+ }
+
+ /* Remove us from the aliases list */
+ NickServ::nickalias_map &map = NickServ::service->GetNickList();
+ map.erase(this->nick);
+}
+
+void NickImpl::SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created)
+{
+ this->vhost_ident = ident;
+ this->vhost_host = host;
+ this->vhost_creator = creator;
+ this->vhost_created = created;
+}
+
+void NickImpl::RemoveVhost()
+{
+ this->vhost_ident.clear();
+ this->vhost_host.clear();
+ this->vhost_creator.clear();
+ this->vhost_created = 0;
+}
+
+bool NickImpl::HasVhost() const
+{
+ return !this->vhost_host.empty();
+}
+
+const Anope::string &NickImpl::GetVhostIdent() const
+{
+ return this->vhost_ident;
+}
+
+const Anope::string &NickImpl::GetVhostHost() const
+{
+ return this->vhost_host;
+}
+
+const Anope::string &NickImpl::GetVhostCreator() const
+{
+ return this->vhost_creator;
+}
+
+time_t NickImpl::GetVhostCreated() const
+{
+ return this->vhost_created;
+}
+
+void NickImpl::Serialize(Serialize::Data &data) const
+{
+ data["nick"] << this->nick;
+ data["last_quit"] << this->last_quit;
+ data["last_realname"] << this->last_realname;
+ data["last_usermask"] << this->last_usermask;
+ data["last_realhost"] << this->last_realhost;
+ data.SetType("time_registered", Serialize::Data::DT_INT); data["time_registered"] << this->time_registered;
+ data.SetType("last_seen", Serialize::Data::DT_INT); data["last_seen"] << this->last_seen;
+ data["nc"] << this->nc->display;
+
+ if (this->HasVhost())
+ {
+ data["vhost_ident"] << this->GetVhostIdent();
+ data["vhost_host"] << this->GetVhostHost();
+ data["vhost_creator"] << this->GetVhostCreator();
+ data["vhost_time"] << this->GetVhostCreated();
+ }
+
+ Extensible::ExtensibleSerialize(this, this, data);
+}
+
+Serializable* NickImpl::Unserialize(Serializable *obj, Serialize::Data &data)
+{
+ Anope::string snc, snick;
+
+ data["nc"] >> snc;
+ data["nick"] >> snick;
+
+ NickServ::Account *core = NickServ::FindAccount(snc);
+ if (core == NULL)
+ return NULL;
+
+ NickServ::Nick *na;
+ if (obj)
+ na = anope_dynamic_static_cast<NickServ::Nick *>(obj);
+ else
+ na = new NickImpl(snick, core);
+
+ if (na->nc != core)
+ {
+ std::vector<NickServ::Nick *>::iterator it = std::find(na->nc->aliases->begin(), na->nc->aliases->end(), na);
+ if (it != na->nc->aliases->end())
+ na->nc->aliases->erase(it);
+
+ if (na->nc->aliases->empty())
+ delete na->nc;
+ else if (na->nick.equals_ci(na->nc->display))
+ na->nc->SetDisplay(na->nc->aliases->front());
+
+ na->nc = core;
+ core->aliases->push_back(na);
+ }
+
+ data["last_quit"] >> na->last_quit;
+ data["last_realname"] >> na->last_realname;
+ data["last_usermask"] >> na->last_usermask;
+ data["last_realhost"] >> na->last_realhost;
+ data["time_registered"] >> na->time_registered;
+ data["last_seen"] >> na->last_seen;
+
+ Anope::string vhost_ident, vhost_host, vhost_creator;
+ time_t vhost_time;
+
+ data["vhost_ident"] >> vhost_ident;
+ data["vhost_host"] >> vhost_host;
+ data["vhost_creator"] >> vhost_creator;
+ data["vhost_time"] >> vhost_time;
+
+ na->SetVhost(vhost_ident, vhost_host, vhost_creator, vhost_time);
+
+ Extensible::ExtensibleUnserialize(na, na, data);
+
+ /* compat */
+ bool b;
+ b = false;
+ data["extensible:NO_EXPIRE"] >> b;
+ if (b)
+ na->Extend<bool>("NS_NO_EXPIRE");
+ /* end compat */
+
+ return na;
+}
+
diff --git a/modules/pseudoclients/nickserv/nick.h b/modules/pseudoclients/nickserv/nick.h
new file mode 100644
index 000000000..76c948f1e
--- /dev/null
+++ b/modules/pseudoclients/nickserv/nick.h
@@ -0,0 +1,18 @@
+
+class NickImpl : public NickServ::Nick
+{
+ public:
+ NickImpl(const Anope::string &nickname, NickServ::Account *nickcore);
+ ~NickImpl();
+
+ void Serialize(Serialize::Data &data) const override;
+ static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
+
+ void SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created = Anope::CurTime);
+ void RemoveVhost();
+ bool HasVhost() const;
+ const Anope::string &GetVhostIdent() const override;
+ const Anope::string &GetVhostHost() const override;
+ const Anope::string &GetVhostCreator() const override;
+ time_t GetVhostCreated() const override;
+};
diff --git a/modules/pseudoclients/nickserv/nickserv.cpp b/modules/pseudoclients/nickserv/nickserv.cpp
new file mode 100644
index 000000000..b58fe3ccc
--- /dev/null
+++ b/modules/pseudoclients/nickserv/nickserv.cpp
@@ -0,0 +1,666 @@
+/* NickServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+#include "modules/ns_info.h"
+#include "modules/ns_group.h"
+#include "modules/ns_update.h"
+#include "modules/help.h"
+#include "modules/nickserv.h"
+#include "nick.h"
+#include "account.h"
+#include "identifyrequest.h"
+
+/** Timer for colliding nicks to force people off of nicknames
+ */
+class NickServCollide : public Timer
+{
+ NickServ::NickServService *service;
+ Reference<User> u;
+ time_t ts;
+ Reference<NickServ::Nick> na;
+
+ public:
+ NickServCollide(NickServ::NickServService *nss, User *user, NickServ::Nick *nick, time_t delay) : Timer(delay), service(nss), u(user), ts(user->timestamp), na(nick)
+ {
+ }
+
+ void Tick(time_t t) override
+ {
+ if (!u || !na)
+ return;
+ /* If they identified or don't exist anymore, don't kill them. */
+ if (u->Account() == na->nc || u->timestamp > ts)
+ return;
+
+ service->Collide(u, na);
+ }
+};
+
+/** Timer for removing HELD status from nicks.
+ */
+class NickServHeld : public Timer
+{
+ Reference<NickServ::Nick> na;
+ Anope::string nick;
+ public:
+ NickServHeld(NickServ::Nick *n, long l) : Timer(l), na(n), nick(na->nick)
+ {
+ n->Extend<bool>("HELD");
+ }
+
+ void Tick(time_t)
+ {
+ if (na)
+ na->Shrink<bool>("HELD");
+ }
+};
+
+class NickServRelease;
+static Anope::map<NickServRelease *> NickServReleases;
+
+/** Timer for releasing nicks to be available for use
+ */
+class NickServRelease : public User, public Timer
+{
+ Anope::string nick;
+
+ public:
+ NickServRelease(NickServ::Nick *na, time_t delay) : User(na->nick, Config->GetModule("nickserv")->Get<const Anope::string>("enforceruser", "user"),
+ Config->GetModule("nickserv")->Get<const Anope::string>("enforcerhost", "services.localhost.net"), "", "", Me, "Services Enforcer", Anope::CurTime, "", Servers::TS6_UID_Retrieve(), NULL), Timer(delay), nick(na->nick)
+ {
+ /* Erase the current release timer and use the new one */
+ Anope::map<NickServRelease *>::iterator nit = NickServReleases.find(this->nick);
+ if (nit != NickServReleases.end())
+ {
+ IRCD->SendQuit(nit->second, "");
+ delete nit->second;
+ }
+
+ NickServReleases.insert(std::make_pair(this->nick, this));
+
+ IRCD->SendClientIntroduction(this);
+ }
+
+ ~NickServRelease()
+ {
+ IRCD->SendQuit(this, "");
+ NickServReleases.erase(this->nick);
+ }
+
+ void Tick(time_t t) override { }
+};
+
+class NickServCore : public Module, public NickServ::NickServService
+ , public EventHook<Event::Shutdown>
+ , public EventHook<Event::Restart>
+ , public EventHook<Event::UserLogin>
+ , public EventHook<Event::DelNick>
+ , public EventHook<Event::DelCore>
+ , public EventHook<Event::ChangeCoreDisplay>
+ , public EventHook<Event::NickIdentify>
+ , public EventHook<Event::NickGroup>
+ , public EventHook<Event::NickUpdate>
+ , public EventHook<Event::UserConnect>
+ , public EventHook<Event::PostUserLogoff>
+ , public EventHook<Event::ServerSync>
+ , public EventHook<Event::UserNickChange>
+ , public EventHook<Event::UserModeSet>
+ , public EventHook<Event::Help>
+ , public EventHook<Event::ExpireTick>
+ , public EventHook<Event::NickInfo>
+ , public EventHook<Event::ModuleUnload>
+ , public EventHook<Event::NickCoreCreate>
+ , public EventHook<Event::UserQuit>
+{
+ Reference<BotInfo> NickServ;
+ std::vector<Anope::string> defaults;
+ ExtensibleItem<bool> held, collided;
+ EventHandlers<NickServ::Event::PreNickExpire> onprenickexpire;
+ EventHandlers<NickServ::Event::NickExpire> onnickexpire;
+ EventHandlers<NickServ::Event::NickRegister> onnickregister;
+ EventHandlers<NickServ::Event::NickValidate> onnickvalidate;
+ std::set<NickServ::IdentifyRequest *> identifyrequests;
+ Serialize::Checker<NickServ::nickalias_map> NickList;
+ Serialize::Checker<NickServ::nickcore_map> AccountList;
+ Serialize::Type nick_type, account_type;
+
+ void OnCancel(User *u, NickServ::Nick *na)
+ {
+ if (collided.HasExt(na))
+ {
+ collided.Unset(na);
+
+ new NickServHeld(na, Config->GetModule("nickserv")->Get<time_t>("releasetimeout", "1m"));
+
+ if (IRCD->CanSVSHold)
+ IRCD->SendSVSHold(na->nick, Config->GetModule("nickserv")->Get<time_t>("releasetimeout", "1m"));
+ else
+ new NickServRelease(na, Config->GetModule("nickserv")->Get<time_t>("releasetimeout", "1m"));
+ }
+ }
+
+ public:
+ NickServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR)
+ , NickServ::NickServService(this)
+ , EventHook<Event::Shutdown>("OnShutdown")
+ , EventHook<Event::Restart>("OnRestart")
+ , EventHook<Event::UserLogin>("OnUserLogin")
+ , EventHook<Event::DelNick>("OnDelNick")
+ , EventHook<Event::DelCore>("OnDelCore")
+ , EventHook<Event::ChangeCoreDisplay>("OnChangeCoreDisplay")
+ , EventHook<Event::NickIdentify>("OnNickIdentify")
+ , EventHook<Event::NickGroup>("OnNickGroup")
+ , EventHook<Event::NickUpdate>("OnNickUpdate")
+ , EventHook<Event::UserConnect>("OnUserConnect")
+ , EventHook<Event::PostUserLogoff>("OnPostUserLogoff")
+ , EventHook<Event::ServerSync>("OnServerSync")
+ , EventHook<Event::UserNickChange>("OnUserNickChange")
+ , EventHook<Event::UserModeSet>("OnUserModeSet")
+ , EventHook<Event::Help>("OnHelp")
+ , EventHook<Event::ExpireTick>("OnExpireTick")
+ , EventHook<Event::NickInfo>("OnNickInfo")
+ , EventHook<Event::ModuleUnload>("OnModuleUnload")
+ , EventHook<Event::NickCoreCreate>("OnNickCoreCreate")
+ , EventHook<Event::UserQuit>("OnUserQuit")
+ , held(this, "HELD")
+ , collided(this, "COLLIDED")
+ , onprenickexpire(this, "OnPreNickExpire")
+ , onnickexpire(this, "OnNickExpire")
+ , onnickregister(this, "OnNickRegister")
+ , onnickvalidate(this, "OnNickValidate")
+ , NickList("NickAlias")
+ , AccountList("NickCore")
+ , nick_type("NickAlias", NickImpl::Unserialize)
+ , account_type("NickCore", AccountImpl::Unserialize)
+ {
+ }
+
+ ~NickServCore()
+ {
+ OnShutdown();
+ }
+
+ void OnShutdown() override
+ {
+ /* On shutdown, restart, or mod unload, remove all of our holds for nicks (svshold or qlines)
+ * because some IRCds do not allow us to have these automatically expire
+ */
+ for (auto& it : *NickList)
+ this->Release(it.second);
+ }
+
+ void OnRestart() override
+ {
+ OnShutdown();
+ }
+
+ void Validate(User *u) override
+ {
+ NickServ::Nick *na = NickServ::FindNick(u->nick);
+ if (!na)
+ return;
+
+ EventReturn MOD_RESULT = this->onnickvalidate(&NickServ::Event::NickValidate::OnNickValidate, u, na);
+ if (MOD_RESULT == EVENT_STOP)
+ {
+ this->Collide(u, na);
+ return;
+ }
+ else if (MOD_RESULT == EVENT_ALLOW)
+ return;
+
+ if (!na->nc->HasExt("NS_SECURE") && u->IsRecognized())
+ {
+ na->last_seen = Anope::CurTime;
+ na->last_usermask = u->GetIdent() + "@" + u->GetDisplayedHost();
+ na->last_realname = u->realname;
+ return;
+ }
+
+ if (Config->GetModule("nickserv")->Get<bool>("nonicknameownership"))
+ return;
+
+ bool on_access = u->IsRecognized(false);
+
+ if (on_access || !na->nc->HasExt("KILL_IMMED"))
+ {
+ if (na->nc->HasExt("NS_SECURE"))
+ u->SendMessage(*NickServ, NICK_IS_SECURE, Config->StrictPrivmsg.c_str(), NickServ->nick.c_str());
+ else
+ u->SendMessage(*NickServ, NICK_IS_REGISTERED, Config->StrictPrivmsg.c_str(), NickServ->nick.c_str());
+ }
+ if (na->nc->HasExt("KILLPROTECT") && !on_access)
+ {
+ if (na->nc->HasExt("KILL_IMMED"))
+ {
+ u->SendMessage(*NickServ, FORCENICKCHANGE_NOW);
+ this->Collide(u, na);
+ }
+ else if (na->nc->HasExt("KILL_QUICK"))
+ {
+ time_t killquick = Config->GetModule("nickserv")->Get<time_t>("killquick", "20s");
+ u->SendMessage(*NickServ, _("If you do not change within %s, I will change your nick."), Anope::Duration(killquick, u->Account()).c_str());
+ new NickServCollide(this, u, na, killquick);
+ }
+ else
+ {
+ time_t kill = Config->GetModule("nickserv")->Get<time_t>("kill", "60s");
+ u->SendMessage(*NickServ, _("If you do not change within %s, I will change your nick."), Anope::Duration(kill, u->Account()).c_str());
+ new NickServCollide(this, u, na, kill);
+ }
+ }
+
+ }
+
+ void OnUserLogin(User *u) override
+ {
+ NickServ::Nick *na = NickServ::FindNick(u->nick);
+ if (na && *na->nc == u->Account() && !Config->GetModule("nickserv")->Get<bool>("nonicknameownership") && !na->nc->HasExt("UNCONFIRMED"))
+ u->SetMode(NickServ, "REGISTERED");
+
+ const Anope::string &modesonid = Config->GetModule(this)->Get<Anope::string>("modesonid");
+ if (!modesonid.empty())
+ u->SetModes(NickServ, "%s", modesonid.c_str());
+ }
+
+ void Collide(User *u, NickServ::Nick *na) override
+ {
+ if (na)
+ collided.Set(na);
+
+ if (IRCD->CanSVSNick)
+ {
+ unsigned nicklen = Config->GetBlock("networkinfo")->Get<unsigned>("nicklen");
+ const Anope::string &guestprefix = Config->GetModule("nickserv")->Get<const Anope::string>("guestnickprefix", "Guest");
+
+ Anope::string guestnick;
+
+ int i = 0;
+ do
+ {
+ guestnick = guestprefix + stringify(static_cast<uint16_t>(rand()));
+ if (guestnick.length() > nicklen)
+ guestnick = guestnick.substr(0, nicklen);
+ }
+ while (User::Find(guestnick) && i++ < 10);
+
+ if (i == 11)
+ u->Kill(NickServ ? NickServ->nick : "", "Services nickname-enforcer kill");
+ else
+ {
+ if (NickServ)
+ u->SendMessage(*NickServ, _("Your nickname is now being changed to \002%s\002"), guestnick.c_str());
+ IRCD->SendForceNickChange(u, guestnick, Anope::CurTime);
+ }
+ }
+ else
+ u->Kill(NickServ ? NickServ->nick : "", "Services nickname-enforcer kill");
+ }
+
+ void Release(NickServ::Nick *na) override
+ {
+ if (held.HasExt(na))
+ {
+ if (IRCD->CanSVSHold)
+ IRCD->SendSVSHoldDel(na->nick);
+ else
+ {
+ User *u = User::Find(na->nick);
+ if (u && u->server == Me)
+ {
+ u->Quit();
+ }
+ }
+
+ held.Unset(na);
+ }
+ }
+
+ NickServ::IdentifyRequest *CreateIdentifyRequest(NickServ::IdentifyRequestListener *l, Module *o, const Anope::string &acc, const Anope::string &pass) override
+ {
+ return new IdentifyRequestImpl(l, o, acc, pass);
+ }
+
+ std::set<NickServ::IdentifyRequest *>& GetIdentifyRequests() override
+ {
+ return identifyrequests;
+ }
+
+ NickServ::nickalias_map& GetNickList() override
+ {
+ return NickList;
+ }
+
+ NickServ::nickcore_map& GetAccountList() override
+ {
+ return AccountList;
+ }
+
+ NickServ::Nick *CreateNick(const Anope::string &nick, NickServ::Account *acc) override
+ {
+ return new NickImpl(nick, acc);
+ }
+
+ NickServ::Account *CreateAccount(const Anope::string &acc) override
+ {
+ return new AccountImpl(acc);
+ }
+
+ NickServ::Nick *FindNick(const Anope::string &nick) override
+ {
+ auto it = NickList->find(nick);
+ return it != NickList->end() ? it->second : nullptr;
+ }
+
+ NickServ::Account *FindAccount(const Anope::string &acc) override
+ {
+ auto it = AccountList->find(acc);
+ return it != AccountList->end() ? it->second : nullptr;
+ }
+
+ void OnReload(Configuration::Conf *conf) override
+ {
+ const Anope::string &nsnick = conf->GetModule(this)->Get<const Anope::string>("client");
+
+ if (nsnick.empty())
+ throw ConfigException(Module::name + ": <client> must be defined");
+
+ BotInfo *bi = BotInfo::Find(nsnick, true);
+ if (!bi)
+ throw ConfigException(Module::name + ": no bot named " + nsnick);
+
+ NickServ = bi;
+
+ spacesepstream(conf->GetModule(this)->Get<const Anope::string>("defaults", "ns_secure memo_signon memo_receive")).GetTokens(defaults);
+ if (defaults.empty())
+ {
+ defaults.push_back("NS_SECURE");
+ defaults.push_back("MEMO_SIGNON");
+ defaults.push_back("MEMO_RECEIVE");
+ }
+ else if (defaults[0].equals_ci("none"))
+ defaults.clear();
+ }
+
+ void OnDelNick(NickServ::Nick *na) override
+ {
+ User *u = User::Find(na->nick);
+ if (u && u->Account() == na->nc)
+ {
+ IRCD->SendLogout(u);
+ u->RemoveMode(NickServ, "REGISTERED");
+ u->Logout();
+ }
+ }
+
+ void OnDelCore(NickServ::Account *nc) override
+ {
+ Log(NickServ, "nick") << "Deleting nickname group " << nc->display;
+
+ /* Clean up this nick core from any users online */
+ for (std::list<User *>::iterator it = nc->users.begin(); it != nc->users.end();)
+ {
+ User *user = *it++;
+ IRCD->SendLogout(user);
+ user->RemoveMode(NickServ, "REGISTERED");
+ user->Logout();
+ Event::OnNickLogout(&Event::NickLogout::OnNickLogout, user);
+ }
+ nc->users.clear();
+ }
+
+ void OnChangeCoreDisplay(NickServ::Account *nc, const Anope::string &newdisplay) override
+ {
+ Log(LOG_NORMAL, "nick", NickServ) << "Changing " << nc->display << " nickname group display to " << newdisplay;
+ }
+
+ void OnNickIdentify(User *u) override
+ {
+ Configuration::Block *block = Config