summaryrefslogtreecommitdiff
path: root/include/modules/chanserv/chanaccess.h
blob: faaf48175543489c617473c885dcc7b9247f1871 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * Anope IRC Services
 *
 * Copyright (C) 2012-2016 Anope Team <team@anope.org>
 *
 * This file is part of Anope. Anope is free software; you can
 * redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software
 * Foundation, version 2.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see see <http://www.gnu.org/licenses/>.
 */

#pragma once

namespace ChanServ
{

enum
{
	ACCESS_INVALID = -10000,
	ACCESS_FOUNDER = 10001
};

/* Represents one entry of an access list on a channel. */
class CoreExport ChanAccess : public Serialize::Object
{
 public:
	static constexpr const char *const NAME = "access";

	Serialize::Storage<Channel *> channel;
	Serialize::Storage<Serialize::Object *> object;
	Serialize::Storage<Anope::string> creator, mask;
	Serialize::Storage<time_t> last_seen, created;

	using Serialize::Object::Object;

	virtual Channel *GetChannel() anope_abstract;
	virtual void SetChannel(Channel *ci) anope_abstract;

	virtual Anope::string GetCreator() anope_abstract;
	virtual void SetCreator(const Anope::string &c) anope_abstract;

	virtual time_t GetLastSeen() anope_abstract;
	virtual void SetLastSeen(const time_t &t) anope_abstract;

	virtual time_t GetCreated() anope_abstract;
	virtual void SetCreated(const time_t &t) anope_abstract;

	virtual Anope::string GetMask() anope_abstract;
	virtual void SetMask(const Anope::string &) anope_abstract;

	virtual Serialize::Object *GetObj() anope_abstract;
	virtual void SetObj(Serialize::Object *) anope_abstract;

	virtual Anope::string Mask() anope_abstract;
	virtual NickServ::Account *GetAccount() anope_abstract;

	/** Check if this access entry matches the given user or account
	 * @param u The user
	 * @param acc The account
	 */
	virtual bool Matches(const User *u, NickServ::Account *acc) anope_abstract;

	/** Check if this access entry has the given privilege.
	 * @param name The privilege name
	 */
	virtual bool HasPriv(const Anope::string &name) anope_abstract;

	/** Serialize the access given by this access entry into a human
	 * readable form. chanserv/access will return a number, chanserv/xop
	 * will be AOP, SOP, etc.
	 */
	virtual Anope::string AccessSerialize() anope_abstract;

	/** Unserialize this access entry from the given data. This data
	 * will be fetched from AccessSerialize.
	 */
	virtual void AccessUnserialize(const Anope::string &data) anope_abstract;

	/* Comparison operators to other Access entries */
	virtual bool operator>(ChanAccess &other)
	{
//		const std::vector<Privilege> &privs = service->GetPrivileges();
//		for (unsigned i = privs.size(); i > 0; --i)
//		{
//			bool this_p = this->HasPriv(privs[i - 1].name),
//				other_p = other.HasPriv(privs[i - 1].name);
//
//			if (!this_p && !other_p)
//				continue;
//
//			return this_p && !other_p;
//		}

		return false;
	}
#warning "move this out"

	virtual bool operator<(ChanAccess &other)
	{
//		const std::vector<Privilege> &privs = service->GetPrivileges();
//		for (unsigned i = privs.size(); i > 0; --i)
//		{
//			bool this_p = this->HasPriv(privs[i - 1].name),
//				other_p = other.HasPriv(privs[i - 1].name);
//
//			if (!this_p && !other_p)
//				continue;
//
//			return !this_p && other_p;
//		}

		return false;
	}

	bool operator>=(ChanAccess &other)
	{
		return !(*this < other);
	}

	bool operator<=(ChanAccess &other)
	{
		return !(*this > other);
	}
};

} // namespace ChanServ