summaryrefslogtreecommitdiff
path: root/modules/pseudoclients
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2015-10-27 13:21:24 -0400
committerAdam <Adam@anope.org>2015-10-27 13:21:24 -0400
commit162fdbe5815bbdf187f549fefac94ff476d72e62 (patch)
tree1c58968fd29dd90ef8ab6dc0f3013d88b313ce4e /modules/pseudoclients
parentc6a92296d4175a2d2276c2d5a46894af3d9085f4 (diff)
Beginning of new module dependency stuff, seems to compile and link. Move some of the madness in chanserv.h to the module.
Diffstat (limited to 'modules/pseudoclients')
-rw-r--r--modules/pseudoclients/chanserv/chanaccess.cpp127
-rw-r--r--modules/pseudoclients/chanserv/chanaccess.h30
-rw-r--r--modules/pseudoclients/chanserv/chanaccesstype.h21
-rw-r--r--modules/pseudoclients/chanserv/channel.h2
-rw-r--r--modules/pseudoclients/chanserv/chanserv.cpp52
5 files changed, 181 insertions, 51 deletions
diff --git a/modules/pseudoclients/chanserv/chanaccess.cpp b/modules/pseudoclients/chanserv/chanaccess.cpp
new file mode 100644
index 000000000..1601260c2
--- /dev/null
+++ b/modules/pseudoclients/chanserv/chanaccess.cpp
@@ -0,0 +1,127 @@
+#include "module.h"
+#include "chanaccess.h"
+#include "chanaccesstype.h"
+
+ChanServ::Channel *ChanAccessImpl::GetChannel()
+{
+ return Get(&ChanAccessType::ci);
+}
+
+void ChanAccessImpl::SetChannel(ChanServ::Channel *ci)
+{
+ Object::Set(&ChanAccessType::ci, ci);
+}
+
+Anope::string ChanAccessImpl::GetCreator()
+{
+ return Get(&ChanAccessType::creator);
+}
+
+void ChanAccessImpl::SetCreator(const Anope::string &c)
+{
+ Object::Set(&ChanAccessType::creator, c);
+}
+
+time_t ChanAccessImpl::GetLastSeen()
+{
+ return Get(&ChanAccessType::last_seen);
+}
+
+void ChanAccessImpl::SetLastSeen(const time_t &t)
+{
+ Object::Set(&ChanAccessType::last_seen, t);
+}
+
+time_t ChanAccessImpl::GetCreated()
+{
+ return Get(&ChanAccessType::created);
+}
+
+void ChanAccessImpl::SetCreated(const time_t &t)
+{
+ Object::Set(&ChanAccessType::created, t);
+}
+
+Anope::string ChanAccessImpl::GetMask()
+{
+ return Get(&ChanAccessType::mask);
+}
+
+void ChanAccessImpl::SetMask(const Anope::string &n)
+{
+ Object::Set(&ChanAccessType::mask, n);
+}
+
+Serialize::Object *ChanAccessImpl::GetObj()
+{
+ return Get(&ChanAccessType::obj);
+}
+
+void ChanAccessImpl::SetObj(Serialize::Object *o)
+{
+ Object::Set(&ChanAccessType::obj, o);
+}
+
+Anope::string ChanAccessImpl::Mask()
+{
+ if (NickServ::Account *acc = GetAccount())
+ return acc->GetDisplay();
+
+ return GetMask();
+}
+
+NickServ::Account *ChanAccessImpl::GetAccount()
+{
+ if (!GetObj() || GetObj()->GetSerializableType() != NickServ::account)
+ return nullptr;
+
+ return anope_dynamic_static_cast<NickServ::Account *>(GetObj());
+}
+
+bool ChanAccessImpl::Matches(const User *u, NickServ::Account *acc, Path &p)
+{
+ if (this->GetAccount())
+ return this->GetAccount() == acc;
+
+ if (u)
+ {
+ bool is_mask = this->Mask().find_first_of("!@?*") != Anope::string::npos;
+ if (is_mask && Anope::Match(u->nick, this->Mask()))
+ return true;
+ else if (Anope::Match(u->GetDisplayedMask(), this->Mask()))
+ return true;
+ }
+
+ if (acc)
+ for (NickServ::Nick *na : acc->GetRefs<NickServ::Nick *>(NickServ::nick))
+ if (Anope::Match(na->GetNick(), this->Mask()))
+ return true;
+
+ if (IRCD->IsChannelValid(this->Mask()))
+ {
+ ChanServ::Channel *tci = ChanServ::Find(this->Mask());
+ if (tci)
+ {
+ for (unsigned i = 0; i < tci->GetAccessCount(); ++i)
+ {
+ ChanServ::ChanAccess *a = tci->GetAccess(i);
+ std::pair<ChanServ::ChanAccess *, ChanServ::ChanAccess *> pair = std::make_pair(this, a);
+
+ std::pair<Set::iterator, Set::iterator> range = p.first.equal_range(this);
+ for (; range.first != range.second; ++range.first)
+ if (range.first->first == pair.first && range.first->second == pair.second)
+ goto cont;
+
+ p.first.insert(pair);
+ if (a->Matches(u, acc, p))
+ p.second.insert(pair);
+
+ cont:;
+ }
+
+ return p.second.count(this) > 0;
+ }
+ }
+
+ return false;
+}
diff --git a/modules/pseudoclients/chanserv/chanaccess.h b/modules/pseudoclients/chanserv/chanaccess.h
new file mode 100644
index 000000000..bb65f79c5
--- /dev/null
+++ b/modules/pseudoclients/chanserv/chanaccess.h
@@ -0,0 +1,30 @@
+
+class ChanAccessImpl : public ChanServ::ChanAccess
+{
+ public:
+ ChanAccessImpl(Serialize::TypeBase *type) : ChanServ::ChanAccess(type) { }
+ ChanAccessImpl(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::ChanAccess(type, id) { }
+
+ ChanServ::Channel *GetChannel() override;
+ void SetChannel(ChanServ::Channel *ci) override;
+
+ Anope::string GetCreator() override;
+ void SetCreator(const Anope::string &c) override;
+
+ time_t GetLastSeen() override;
+ void SetLastSeen(const time_t &t) override;
+
+ time_t GetCreated() override;
+ void SetCreated(const time_t &t) override;
+
+ Anope::string GetMask() override;
+ void SetMask(const Anope::string &) override;
+
+ Serialize::Object *GetObj() override;
+ void SetObj(Serialize::Object *) override;
+
+ Anope::string Mask() override;
+ NickServ::Account *GetAccount() override;
+
+ bool Matches(const User *u, NickServ::Account *acc, Path &p) override;
+};
diff --git a/modules/pseudoclients/chanserv/chanaccesstype.h b/modules/pseudoclients/chanserv/chanaccesstype.h
new file mode 100644
index 000000000..ca8dc1b79
--- /dev/null
+++ b/modules/pseudoclients/chanserv/chanaccesstype.h
@@ -0,0 +1,21 @@
+
+class ChanAccessType : public Serialize::AbstractType
+{
+ public:
+ Serialize::ObjectField<ChanServ::ChanAccess, ChanServ::Channel *> ci;
+ Serialize::Field<ChanServ::ChanAccess, Anope::string> mask;
+ Serialize::ObjectField<ChanServ::ChanAccess, Serialize::Object *> obj;
+ Serialize::Field<ChanServ::ChanAccess, Anope::string> creator;
+ Serialize::Field<ChanServ::ChanAccess, time_t> last_seen;
+ Serialize::Field<ChanServ::ChanAccess, time_t> created;
+
+ ChanAccessType(Module *me, const Anope::string &name) : Serialize::AbstractType(me, name)
+ , ci(this, "ci", true)
+ , mask(this, "mask")
+ , obj(this, "obj", true)
+ , creator(this, "creator")
+ , last_seen(this, "last_seen")
+ , created(this, "created")
+ {
+ }
+};
diff --git a/modules/pseudoclients/chanserv/channel.h b/modules/pseudoclients/chanserv/channel.h
index 995972ece..18a4be5d6 100644
--- a/modules/pseudoclients/chanserv/channel.h
+++ b/modules/pseudoclients/chanserv/channel.h
@@ -3,11 +3,9 @@
class ChannelImpl : public ChanServ::Channel
{
public:
- //using ChanServ::Channel::Channel;
ChannelImpl(Serialize::TypeBase *type) : ChanServ::Channel(type) { }
ChannelImpl(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::Channel(type, id) { }
ChannelImpl(Serialize::TypeBase *type, const Anope::string &chname);
- /*ChannelImpl(const ChanServ::Channel &ci);*/
~ChannelImpl();
void Delete() override;
diff --git a/modules/pseudoclients/chanserv/chanserv.cpp b/modules/pseudoclients/chanserv/chanserv.cpp
index 5dd83188f..420051252 100644
--- a/modules/pseudoclients/chanserv/chanserv.cpp
+++ b/modules/pseudoclients/chanserv/chanserv.cpp
@@ -19,6 +19,8 @@
#include "channeltype.h"
#include "leveltype.h"
#include "modetype.h"
+#include "chanaccesstype.h"
+#include "chanaccess.h"
class ChanServCore : public Module
, public ChanServ::ChanServService
@@ -52,7 +54,7 @@ class ChanServCore : public Module
std::vector<ChanServ::Privilege> Privileges;
ChanServ::registered_channel_map registered_channels;
ChannelType channel_type;
- ChanServ::ChanAccessType chanaccess_type;
+ ChanAccessType chanaccess_type;
LevelType level_type;
CSModeType mode_type;
@@ -189,54 +191,6 @@ class ChanServCore : public Module
Privileges.clear();
}
- bool Matches(ChanServ::ChanAccess *access, const User *u, NickServ::Account *acc, ChanServ::ChanAccess::Path &p) override
- {
- if (access->GetAccount())
- return access->GetAccount() == acc;
-
- if (u)
- {
- bool is_mask = access->Mask().find_first_of("!@?*") != Anope::string::npos;
- if (is_mask && Anope::Match(u->nick, access->Mask()))
- return true;
- else if (Anope::Match(u->GetDisplayedMask(), access->Mask()))
- return true;
- }
-
- if (acc)
- for (NickServ::Nick *na : acc->GetRefs<NickServ::Nick *>(NickServ::nick))
- if (Anope::Match(na->GetNick(), access->Mask()))
- return true;
-
- if (IRCD->IsChannelValid(access->Mask()))
- {
- ChanServ::Channel *tci = Find(access->Mask());
- if (tci)
- {
- for (unsigned i = 0; i < tci->GetAccessCount(); ++i)
- {
- ChanServ::ChanAccess *a = tci->GetAccess(i);
- std::pair<ChanServ::ChanAccess *, ChanServ::ChanAccess *> pair = std::make_pair(access, a);
-
- std::pair<Set::iterator, Set::iterator> range = p.first.equal_range(access);
- for (; range.first != range.second; ++range.first)
- if (range.first->first == pair.first && range.first->second == pair.second)
- goto cont;
-
- p.first.insert(pair);
- if (a->Matches(u, acc, p))
- p.second.insert(pair);
-
- cont:;
- }
-
- return p.second.count(access) > 0;
- }
- }
-
- return false;
- }
-
void OnReload(Configuration::Conf *conf) override
{
const Anope::string &channick = conf->GetModule(this)->Get<Anope::string>("client");