summaryrefslogtreecommitdiff
path: root/include/modules/chanserv/mode.h
blob: 9e1181214f0650bed88b378120ab20905bd4be04 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 * Anope IRC Services
 *
 * Copyright (C) 2013-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

class ModeLock : public Serialize::Object
{
 protected:
	using Serialize::Object::Object;

 public:
	static constexpr const char *const NAME = "modelock";
	 
	virtual ChanServ::Channel *GetChannel() anope_abstract;
	virtual void SetChannel(ChanServ::Channel *) anope_abstract;

	virtual bool GetSet() anope_abstract;
	virtual void SetSet(const bool &) anope_abstract;

	virtual Anope::string GetName() anope_abstract;
	virtual void SetName(const Anope::string &) anope_abstract;

	virtual Anope::string GetParam() anope_abstract;
	virtual void SetParam(const Anope::string &) anope_abstract;

	virtual Anope::string GetSetter() anope_abstract;
	virtual void SetSetter(const Anope::string &) anope_abstract;

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

class ModeLocks : public Service
{
 public:
	static constexpr const char *NAME = "mlocks";
	
	ModeLocks(Module *me) : Service(me, NAME) { }

	typedef std::vector<ModeLock *> ModeList;

	/** Check if a mode is mlocked
	 * @param mode The mode
	 * @param An optional param
	 * @param status True to check mlock on, false for mlock off
	 * @return true on success, false on fail
	 */
	virtual bool HasMLock(ChanServ::Channel *, ChannelMode *mode, const Anope::string &param, bool status) const anope_abstract;

	/** Set a mlock
	 * @param mode The mode
	 * @param status True for mlock on, false for mlock off
	 * @param param An optional param arg for + mlocked modes
	 * @param setter Who is setting the mlock
	 * @param created When the mlock was created
	 * @return true on success, false on failure (module blocking)
	 */
	virtual bool SetMLock(ChanServ::Channel *, ChannelMode *mode, bool status, const Anope::string &param = "", Anope::string setter = "", time_t created = Anope::CurTime) anope_abstract;

	/** Remove a mlock
	 * @param mode The mode
	 * @param status True for mlock on, false for mlock off
	 * @param param The param of the mode, required if it is a list or status mode
	 * @return true on success, false on failure
	 */
	virtual bool RemoveMLock(ChanServ::Channel *, ChannelMode *mode, bool status, const Anope::string &param = "") anope_abstract;

	/** Clear all mlocks on the channel
	 */
	virtual void ClearMLock(ChanServ::Channel *) anope_abstract;

	/** Get all of the mlocks for this channel
	 * @return The mlocks
	 */
	virtual ModeList GetMLock(ChanServ::Channel *) const anope_abstract;

	/** Get a list of mode locks on a channel
	 * @param name The mode name to get a list of
	 * @return a list of mlocks for the given mode
	 */
	virtual std::list<ModeLock *> GetModeLockList(ChanServ::Channel *, const Anope::string &name) anope_abstract;

	/** Get details for a specific mlock
	 * @param mname The mode name
 	 * @param An optional param to match with
	 * @return The MLock, if any
	 */
	virtual ModeLock *GetMLock(ChanServ::Channel *, const Anope::string &mname, const Anope::string &param = "") anope_abstract;

	/** Get the current mode locks as a string
	 * @param complete True to show mlock parameters as well
	 * @return A string of mode locks, eg: +nrt
	 */
	virtual Anope::string GetMLockAsString(ChanServ::Channel *, bool complete) const anope_abstract;
};

namespace ChanServ
{

class Mode : public Serialize::Object
{
 public:
	static constexpr const char *const NAME = "mlockmode";

	using Serialize::Object::Object;

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

	virtual Anope::string GetMode() anope_abstract;
	virtual void SetMode(const Anope::string &) anope_abstract;

	virtual Anope::string GetParam() anope_abstract;
	virtual void SetParam(const Anope::string &) anope_abstract;
};

} // namespace ChanServ

namespace Event
{
	struct CoreExport MLockEvents : Events
	{
		static constexpr const char *NAME = "mlockevents";

		using Events::Events;

		/** Called when a mode is about to be mlocked
		 * @param ci The channel the mode is being locked on
		 * @param lock The mode lock
		 * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the mlock.
		 */
		virtual EventReturn OnMLock(ChanServ::Channel *ci, ModeLock *lock) anope_abstract;

		/** Called when a mode is about to be unlocked
		 * @param ci The channel the mode is being unlocked from
		 * @param lock The mode lock
		 * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the mlock.
		 */
		virtual EventReturn OnUnMLock(ChanServ::Channel *ci, ModeLock *lock) anope_abstract;
	};
}