summaryrefslogtreecommitdiff
path: root/include/access.h
blob: 18499b60292a4e6a54f364e0fdbcb075fb21c3dd (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
/*
 *
 * (C) 2003-2012 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.
 *
 *
 */

#ifndef ACCESS_H
#define ACCESS_H

#include "services.h"
#include "anope.h"
#include "serialize.h"
#include "service.h"

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

struct CoreExport Privilege
{
	Anope::string name;
	Anope::string desc;
	int rank;

	Privilege(const Anope::string &n, const Anope::string &d, int r);
	bool operator==(const Privilege &other) const;
};

class CoreExport PrivilegeManager
{
	static std::vector<Privilege> privs;
 public:
	static void AddPrivilege(Privilege p);
	static void RemovePrivilege(Privilege &p);
	static Privilege *FindPrivilege(const Anope::string &name);
	static std::vector<Privilege> &GetPrivileges();
	static void ClearPrivileges();
};


class CoreExport AccessProvider : public Service
{
 public:
	AccessProvider(Module *o, const Anope::string &n);
	virtual ~AccessProvider();
	virtual ChanAccess *Create() = 0;
};

class CoreExport ChanAccess : public Serializable
{
 public:
	AccessProvider *provider;
	serialize_obj<ChannelInfo> ci;
	Anope::string mask;
	Anope::string creator;
	time_t last_seen;
	time_t created;

	ChanAccess(AccessProvider *p);
	virtual ~ChanAccess();

	const Anope::string serialize_name() const anope_override;
	Serialize::Data serialize() const anope_override;
	static Serializable* unserialize(Serializable *obj, Serialize::Data &);

	virtual bool Matches(const User *u, const NickCore *nc) const;
	virtual bool HasPriv(const Anope::string &name) const = 0;
	virtual Anope::string Serialize() const = 0;
	virtual void Unserialize(const Anope::string &data) = 0;

	bool operator>(const ChanAccess &other) const;
	bool operator<(const ChanAccess &other) const;
	bool operator>=(const ChanAccess &other) const;
	bool operator<=(const ChanAccess &other) const;
};

class CoreExport AccessGroup : public std::vector<ChanAccess *>
{
 public:
 	const ChannelInfo *ci;
	const NickCore *nc;
	bool SuperAdmin, Founder;
	AccessGroup();
	bool HasPriv(const Anope::string &priv) const;
	const ChanAccess *Highest() const;
	bool operator>(const AccessGroup &other) const;
	bool operator<(const AccessGroup &other) const;
	bool operator>=(const AccessGroup &other) const;
	bool operator<=(const AccessGroup &other) const;
};

#endif