1 /* Modular support
2  *
3  * (C) 2003-2020 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  */
11 
12 #include "serialize.h"
13 
14 #ifndef MODULES_H
15 #define MODULES_H
16 
17 #include "base.h"
18 #include "modes.h"
19 #include "timers.h"
20 #include "logger.h"
21 #include "extensible.h"
22 #include "version.h"
23 
24 /** This definition is used as shorthand for the various classes
25  * and functions needed to make a module loadable by the OS.
26  * It defines the class factory and external AnopeInit and AnopeFini functions.
27  */
28 #ifdef _WIN32
29 # define MODULE_INIT(x) \
30 	extern "C" DllExport Module *AnopeInit(const Anope::string &, const Anope::string &); \
31 	extern "C" Module *AnopeInit(const Anope::string &modname, const Anope::string &creator) \
32 	{ \
33 		return new x(modname, creator); \
34 	} \
35 	BOOLEAN WINAPI DllMain(HINSTANCE, DWORD, LPVOID) \
36 	{ \
37 		return TRUE; \
38 	} \
39 	extern "C" DllExport void AnopeFini(x *); \
40 	extern "C" void AnopeFini(x *m) \
41 	{ \
42 		delete m; \
43 	} \
44 	extern "C" DllExport ModuleVersionC AnopeVersion() \
45 	{ \
46 		ModuleVersionC ver; \
47 		ver.version_major = VERSION_MAJOR; \
48 		ver.version_minor = VERSION_MINOR; \
49 		ver.version_patch = VERSION_PATCH; \
50 		return ver; \
51 	}
52 #else
53 # define MODULE_INIT(x) \
54 	extern "C" DllExport Module *AnopeInit(const Anope::string &modname, const Anope::string &creator) \
55 	{ \
56 		return new x(modname, creator); \
57 	} \
58 	extern "C" DllExport void AnopeFini(x *m) \
59 	{ \
60 		delete m; \
61 	} \
62 	extern "C" DllExport ModuleVersionC AnopeVersion() \
63 	{ \
64 		ModuleVersionC ver; \
65 		ver.version_major = VERSION_MAJOR; \
66 		ver.version_minor = VERSION_MINOR; \
67 		ver.version_patch = VERSION_PATCH; \
68 		return ver; \
69 	}
70 #endif
71 
72 /**
73  * This #define allows us to call a method in all
74  * loaded modules in a readable simple way, e.g.:
75  *
76  * FOREACH_MOD(OnUserConnect, (user, exempt));
77  */
78 #define FOREACH_MOD(ename, args) \
79 if (true) \
80 { \
81 	std::vector<Module *> &_modules = ModuleManager::EventHandlers[I_ ## ename]; \
82 	for (std::vector<Module *>::iterator _i = _modules.begin(); _i != _modules.end();) \
83 	{ \
84 		try \
85 		{ \
86 			(*_i)->ename args; \
87 		} \
88 		catch (const ModuleException &modexcept) \
89 		{ \
90 			Log() << "Exception caught: " << modexcept.GetReason(); \
91 		} \
92 		catch (const NotImplementedException &) \
93 		{ \
94 			_i = _modules.erase(_i); \
95 			continue; \
96 		} \
97 		++_i; \
98 	} \
99 } \
100 else \
101 	static_cast<void>(0)
102 
103 /**
104  * This define is similar to the one above but returns a result.
105  * The first module to return a result other than EVENT_CONTINUE is the value to be accepted,
106  * and any modules after are ignored. This is used like:
107  *
108  * EventReturn MOD_RESULT;
109  * FOREACH_RESULT(OnUserConnect, MOD_RESULT, (user, exempt));
110  */
111 #define FOREACH_RESULT(ename, ret, args) \
112 if (true) \
113 { \
114 	ret = EVENT_CONTINUE; \
115 	std::vector<Module *> &_modules = ModuleManager::EventHandlers[I_ ## ename]; \
116 	for (std::vector<Module *>::iterator _i = _modules.begin(); _i != _modules.end();) \
117 	{ \
118 		try \
119 		{ \
120 			EventReturn res = (*_i)->ename args; \
121 			if (res != EVENT_CONTINUE) \
122 			{ \
123 				ret = res; \
124 				break; \
125 			} \
126 		} \
127 		catch (const ModuleException &modexcept) \
128 		{ \
129 			Log() << "Exception caught: " << modexcept.GetReason(); \
130 		} \
131 		catch (const NotImplementedException &) \
132 		{ \
133 			_i = _modules.erase(_i); \
134 			continue; \
135 		} \
136 		++_i; \
137 	} \
138 } \
139 else \
140 	static_cast<void>(0)
141 
142 
143 /** Possible return types from events.
144  */
145 enum EventReturn
146 {
147 	EVENT_STOP,
148 	EVENT_CONTINUE,
149 	EVENT_ALLOW
150 };
151 
152 enum ModuleReturn
153 {
154 	MOD_ERR_OK,
155 	MOD_ERR_PARAMS,
156 	MOD_ERR_EXISTS,
157 	MOD_ERR_NOEXIST,
158 	MOD_ERR_NOLOAD,
159 	MOD_ERR_UNKNOWN,
160 	MOD_ERR_FILE_IO,
161 	MOD_ERR_EXCEPTION,
162 	MOD_ERR_VERSION
163 };
164 
165 /** Priority types which can be returned from Module::Prioritize()
166  */
167 enum Priority { PRIORITY_FIRST, PRIORITY_DONTCARE, PRIORITY_LAST, PRIORITY_BEFORE, PRIORITY_AFTER };
168 /* Module types, in the order in which they are unloaded. The order these are in is IMPORTANT */
169 enum
170 {
171 	MT_BEGIN,
172 	/* Module is 3rd party. All 3rd party modules should set this. Mutually exclusive to VENDOR. */
173 	THIRD = 1 << 0,
174 	/* A vendor module, which is made and shipped by Anope. Mutually exclusive to THIRD. */
175 	VENDOR = 1 << 1,
176 	/* Extra module not required for standard use. Probably requires external dependencies.
177 	 * This module does something extreme enough that we want it to show in the default /os modlist command
178 	 */
179 	EXTRA = 1 << 2,
180 	/* Module provides access to a database */
181 	DATABASE = 1 << 3,
182 	/* Module provides encryption */
183 	ENCRYPTION = 1 << 4,
184 	/* Module provides a pseudoclient */
185 	PSEUDOCLIENT = 1 << 5,
186 	/* Module provides IRCd protocol support */
187 	PROTOCOL = 1 << 6,
188 	MT_END = 1 << 7
189 };
190 typedef unsigned short ModType;
191 
192 struct ModuleVersionC
193 {
194 	int version_major, version_minor, version_patch;
195 };
196 
197 /** Returned by Module::GetVersion, used to see what version of Anope
198  * a module is compiled against.
199  */
200 class ModuleVersion
201 {
202  private:
203 	int version_major;
204 	int version_minor;
205 	int version_patch;
206 
207  public:
208 	ModuleVersion(const ModuleVersionC &);
209 
210 	/** Get the major version of Anope this was built against
211 	 * @return The major version
212 	 */
213 	int GetMajor() const;
214 
215 	/** Get the minor version of Anope this was built against
216 	 * @return The minor version
217 	 */
218 	int GetMinor() const;
219 
220 	/** Get the patch version this was built against
221 	 * @return The patch version
222 	 */
223 	int GetPatch() const;
224 };
225 
226 class NotImplementedException : public CoreException { };
227 
228 /** Every module in Anope is actually a class.
229  */
230 class CoreExport Module : public Extensible
231 {
232  private:
233 	bool permanent;
234  public:
235 	/** The module name (e.g. os_modload)
236 	 */
237 	Anope::string name;
238 
239 	/** What type this module is
240 	 */
241 	ModType type;
242 
243 	/** The temporary path/filename
244 	 */
245 	Anope::string filename;
246 
247 	/** Handle for this module, obtained from dlopen()
248 	 */
249 	void *handle;
250 
251 	/** Time this module was created
252 	 */
253 	time_t created;
254 
255 	/** Version of this module
256 	 */
257 	Anope::string version;
258 
259 	/** Author of the module
260 	 */
261 	Anope::string author;
262 
263 	/** Creates and initialises a new module.
264 	 * @param modname The module name
265 	 * @param loadernick The nickname of the user loading the module.
266 	 * @param type The module type
267 	 */
268 	Module(const Anope::string &modname, const Anope::string &loadernick, ModType type = THIRD);
269 
270 	/** Destroys a module, freeing resources it has allocated.
271 	 */
272 	virtual ~Module();
273 
274 	/** Toggles the permanent flag on a module. If a module is permanent,
275 	 * then it may not be unloaded.
276 	 *
277 	 * Naturally, this setting should be used sparingly!
278 	 *
279 	 * @param state True if this module should be permanent, false else.
280 	 */
281 	void SetPermanent(bool state);
282 
283 	/** Retrieves whether or not a given module is permanent.
284 	 * @return true if the module is permanent, false else.
285 	 */
286 	bool GetPermanent() const;
287 
288 	/** Set the modules version info.
289 	 * @param version the version of the module
290 	 */
291 	void SetVersion(const Anope::string &version);
292 
293 	/** Set the modules author info
294 	 * @param author the author of the module
295 	 */
296 	void SetAuthor(const Anope::string &author);
297 
298 	virtual void Prioritize();
299 
300 	/* Everything below here are events. Modules must ModuleManager::Attach to these events
301 	 * before they will be called.
302 	 */
303 
304 	/** Called on startup after database load, but before
305 	 * connecting to the uplink.
306 	 */
OnPostInit()307 	virtual void OnPostInit() { throw NotImplementedException(); }
308 
309 	/** Called before a user has been kicked from a channel.
310 	 * @param source The kicker
311 	 * @param cu The user, channel, and status of the user being kicked
312 	 * @param kickmsg The reason for the kick.
313 	 */
OnPreUserKicked(const MessageSource & source,ChanUserContainer * cu,const Anope::string & kickmsg)314 	virtual void OnPreUserKicked(const MessageSource &source, ChanUserContainer *cu, const Anope::string &kickmsg) { throw NotImplementedException(); }
315 
316 	/** Called when a user has been kicked from a channel.
317 	 * @param source The kicker
318 	 * @param target The user being kicked
319 	 * @param channel The channel the user was kicked from, which may no longer exist
320 	 * @param status The status the kicked user had on the channel before they were kicked
321 	 * @param kickmsg The reason for the kick.
322 	 */
OnUserKicked(const MessageSource & source,User * target,const Anope::string & channel,ChannelStatus & status,const Anope::string & kickmsg)323 	virtual void OnUserKicked(const MessageSource &source, User *target, const Anope::string &channel, ChannelStatus &status, const Anope::string &kickmsg) { throw NotImplementedException(); }
324 
325 	/** Called when Services' configuration is being (re)loaded.
326 	 * @param conf The config that is being built now and will replace the global Config object
327 	 * @throws A ConfigException to abort the config (re)loading process.
328 	 */
OnReload(Configuration::Conf * conf)329 	virtual void OnReload(Configuration::Conf *conf) { throw NotImplementedException(); }
330 
331 	/** Called before a bot is assigned to a channel.
332 	 * @param sender The user assigning the bot
333 	 * @param ci The channel the bot is to be assigned to.
334 	 * @param bi The bot being assigned.
335 	 * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the assign.
336 	 */
OnPreBotAssign(User * sender,ChannelInfo * ci,BotInfo * bi)337 	virtual EventReturn OnPreBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) { throw NotImplementedException(); }
338 
339 	/** Called when a bot is assigned ot a channel
340 	 */
OnBotAssign(User * sender,ChannelInfo * ci,BotInfo * bi)341 	virtual void OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) { throw NotImplementedException(); }
342 
343 	/** Called before a bot is unassigned from a channel.
344 	 * @param sender The user unassigning the bot
345 	 * @param ci The channel the bot is being removed from
346 	 * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the unassign.
347 	 */
OnBotUnAssign(User * sender,ChannelInfo * ci)348 	virtual EventReturn OnBotUnAssign(User *sender, ChannelInfo *ci) { throw NotImplementedException(); }
349 
350 	/** Called when a new user connects to the network.
351 	 * @param u The connecting user.
352 	 * @param exempt set to true/is true if the user should be excepted from bans etc
353 	 */
OnUserConnect(User * u,bool & exempt)354 	virtual void OnUserConnect(User *u, bool &exempt) { throw NotImplementedException(); }
355 
356 	/** Called when a new server connects to the network.
357 	 * @param s The server that has connected to the network
358 	 */
OnNewServer(Server * s)359 	virtual void OnNewServer(Server *s) { throw NotImplementedException(); }
360 
361 	/** Called after a user changed the nick
362 	 * @param u The user.
363 	 * @param oldnick The old nick of the user
364 	 */
OnUserNickChange(User * u,const Anope::string & oldnick)365 	virtual void OnUserNickChange(User *u, const Anope::string &oldnick) { throw NotImplementedException(); }
366 
367 	/** Called when someone uses the generic/help command
368 	 * @param source Command source
369 	 * @param params Params
370 	 * @return EVENT_STOP to stop processing
371 	 */
OnPreHelp(CommandSource & source,const std::vector<Anope::string> & params)372 	virtual EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) { throw NotImplementedException(); }
373 
374 	/** Called when someone uses the generic/help command
375 	 * @param source Command source
376 	 * @param params Params
377 	 */
OnPostHelp(CommandSource & source,const std::vector<Anope::string> & params)378 	virtual void OnPostHelp(CommandSource &source, const std::vector<Anope::string> &params) { throw NotImplementedException(); }
379 
380 	/** Called before a command is due to be executed.
381 	 * @param source The source of the command
382 	 * @param command The command the user is executing
383 	 * @param params The parameters the user is sending
384 	 * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it
385 	 */
OnPreCommand(CommandSource & source,Command * command,std::vector<Anope::string> & params)386 	virtual EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) { throw NotImplementedException(); }
387 
388 	/** Called after a command has been executed.
389 	 * @param source The source of the command
390 	 * @param command The command the user executed
391 	 * @param params The parameters the user sent
392 	 */
OnPostCommand(CommandSource & source,Command * command,const std::vector<Anope::string> & params)393 	virtual void OnPostCommand(CommandSource &source, Command *command, const std::vector<Anope::string> &params) { throw NotImplementedException(); }
394 
395 	/** Called when the databases are saved
396 	 */
OnSaveDatabase()397 	virtual void OnSaveDatabase() { throw NotImplementedException(); }
398 
399 	/** Called when the databases are loaded
400 	 * @return EVENT_CONTINUE to let other modules continue loading, EVENT_STOP to stop
401 	 */
OnLoadDatabase()402 	virtual EventReturn OnLoadDatabase() { throw NotImplementedException(); }
403 
404 	/** Called when anope needs to check passwords against encryption
405 	 *  see src/encrypt.c for detailed informations
406 	 */
OnEncrypt(const Anope::string & src,Anope::string & dest)407 	virtual EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) { throw NotImplementedException(); }
OnDecrypt(const Anope::string & hashm,const Anope::string & src,Anope::string & dest)408 	virtual EventReturn OnDecrypt(const Anope::string &hashm, const Anope::string &src, Anope::string &dest) { throw NotImplementedException(); }
409 
410 	/** Called on fantasy command
411 	 * @param source The source of the command
412 	 * @param c The command
413 	 * @param ci The channel it's being used in
414 	 * @param params The params
415 	 * @return EVENT_STOP to halt processing and not run the command, EVENT_ALLOW to allow the command to be executed
416 	 */
OnBotFantasy(CommandSource & source,Command * c,ChannelInfo * ci,const std::vector<Anope::string> & params)417 	virtual EventReturn OnBotFantasy(CommandSource &source, Command *c, ChannelInfo *ci, const std::vector<Anope::string> &params) { throw NotImplementedException(); }
418 
419 	/** Called on fantasy command without access
420 	 * @param source The source of the command
421 	 * @param c The command
422 	 * @param ci The channel it's being used in
423 	 * @param params The params
424 	 * @return EVENT_STOP to halt processing and not run the command, EVENT_ALLOW to allow the command to be executed
425 	 */
OnBotNoFantasyAccess(CommandSource & source,Command * c,ChannelInfo * ci,const std::vector<Anope::string> & params)426 	virtual EventReturn OnBotNoFantasyAccess(CommandSource &source, Command *c, ChannelInfo *ci, const std::vector<Anope::string> &params) { throw NotImplementedException(); }
427 
428 	/** Called when a bot places a ban
429 	 * @param u User being banned
430 	 * @param ci Channel the ban is placed on
431 	 * @param mask The mask being banned
432 	 */
OnBotBan(User * u,ChannelInfo * ci,const Anope::string & mask)433 	virtual void OnBotBan(User *u, ChannelInfo *ci, const Anope::string &mask) { throw NotImplementedException(); }
434 
435 	/** Called before a badword is added to the badword list
436 	 * @param ci The channel
437 	 * @param bw The badword
438 	 */
OnBadWordAdd(ChannelInfo * ci,const BadWord * bw)439 	virtual void OnBadWordAdd(ChannelInfo *ci, const BadWord *bw) { throw NotImplementedException(); }
440 
441 	/** Called before a badword is deleted from a channel
442 	 * @param ci The channel
443 	 * @param bw The badword
444 	 */
OnBadWordDel(ChannelInfo * ci,const BadWord * bw)445 	virtual void OnBadWordDel(ChannelInfo *ci, const BadWord *bw) { throw NotImplementedException(); }
446 
447 	/** Called when a bot is created or destroyed
448 	 */
OnCreateBot(BotInfo * bi)449 	virtual void OnCreateBot(BotInfo *bi) { throw NotImplementedException(); }
OnDelBot(BotInfo * bi)450 	virtual void OnDelBot(BotInfo *bi) { throw NotImplementedException(); }
451 
452 	/** Called before a bot kicks a user
453 	 * @param bi The bot sending the kick
454 	 * @param c The channel the user is being kicked on
455 	 * @param u The user being kicked
456 	 * @param reason The reason
457 	 * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it
458 	 */
OnBotKick(BotInfo * bi,Channel * c,User * u,const Anope::string & reason)459 	virtual EventReturn OnBotKick(BotInfo *bi, Channel *c, User *u, const Anope::string &reason) { throw NotImplementedException(); }
460 
461 	/** Called before a user parts a channel
462 	 * @param u The user
463 	 * @param c The channel
464 	 */
OnPrePartChannel(User * u,Channel * c)465 	virtual void OnPrePartChannel(User *u, Channel *c) {}
466 
467 	/** Called when a user parts a channel
468 	 * @param u The user
469 	 * @param c The channel, may be NULL if the channel no longer exists
470 	 * @param channel The channel name
471 	 * @param msg The part reason
472 	 */
OnPartChannel(User * u,Channel * c,const Anope::string & channel,const Anope::string & msg)473 	virtual void OnPartChannel(User *u, Channel *c, const Anope::string &channel, const Anope::string &msg) { throw NotImplementedException(); }
474 
475 	/** Called when a user leaves a channel.
476 	 * From either parting, being kicked, or quitting/killed!
477 	 * @param u The user
478 	 * @param c The channel
479 	 */
OnLeaveChannel(User * u,Channel * c)480 	virtual void OnLeaveChannel(User *u, Channel *c) { throw NotImplementedException(); }
481 
482 	/** Called after a user joins a channel
483 	 * If this event triggers the user is allowed to be in the channel, and will
484 	 * not be kicked for restricted/akick/forbidden, etc. If you want to kick the user,
485 	 * use the CheckKick event instead.
486 	 * @param u The user
487 	 * @param channel The channel
488 	 */
OnJoinChannel(User * u,Channel * c)489 	virtual void OnJoinChannel(User *u, Channel *c) { throw NotImplementedException(); }
490 
491 	/** Called when a new topic is set
492 	 * @param source The user changing the topic, if any
493 	 * @param c The channel
494 	 * @param setter The user who set the new topic, if there is no source
495 	 * @param topic The new topic
496 	 */
OnTopicUpdated(User * source,Channel * c,const Anope::string & user,const Anope::string & topic)497 	virtual void OnTopicUpdated(User *source, Channel *c, const Anope::string &user, const Anope::string &topic) { throw NotImplementedException(); }
498 
499 	/** Called before a channel expires
500 	 * @param ci The channel
501 	 * @param expire Set to true to allow the chan to expire
502 	 */
OnPreChanExpire(ChannelInfo * ci,bool & expire)503 	virtual void OnPreChanExpire(ChannelInfo *ci, bool &expire) { throw NotImplementedException(); }
504 
505 	/** Called before a channel expires
506 	 * @param ci The channel
507 	 */
OnChanExpire(ChannelInfo * ci)508 	virtual void OnChanExpire(ChannelInfo *ci) { throw NotImplementedException(); }
509 
510 	/** Called before Anope connecs to its uplink
511 	 */
OnPreServerConnect()512 	virtual void OnPreServerConnect() { throw NotImplementedException(); }
513 
514 	/** Called when Anope connects to its uplink
515 	 */
OnServerConnect()516 	virtual void OnServerConnect() { throw NotImplementedException(); }
517 
518 	/** Called when we are almost done synching with the uplink, just before we send the EOB
519 	 */
OnPreUplinkSync(Server * serv)520 	virtual void OnPreUplinkSync(Server *serv) { throw NotImplementedException(); }
521 
522 	/** Called when Anope disconnects from its uplink, before it tries to reconnect
523 	 */
OnServerDisconnect()524 	virtual void OnServerDisconnect() { throw NotImplementedException(); }
525 
526 	/** Called when services restart
527 	*/
OnRestart()528 	virtual void OnRestart() { throw NotImplementedException(); }
529 
530 	/** Called when services shutdown
531 	 */
OnShutdown()532 	virtual void OnShutdown() { throw NotImplementedException(); }
533 
534 	/** Called before a nick expires
535 	 * @param na The nick
536 	 * @param expire Set to true to allow the nick to expire
537 	 */
OnPreNickExpire(NickAlias * na,bool & expire)538 	virtual void OnPreNickExpire(NickAlias *na, bool &expire) { throw NotImplementedException(); }
539 
540 	/** Called when a nick drops
541 	 * @param na The nick
542 	 */
OnNickExpire(NickAlias * na)543 	virtual void OnNickExpire(NickAlias *na) { throw NotImplementedException(); }
544 
545 	/** Called when defcon level changes
546 	 * @param level The level
547 	 */
OnDefconLevel(int level)548 	virtual void OnDefconLevel(int level) { throw NotImplementedException(); }
549 
550 	/** Called after an exception has been added
551 	 * @param ex The exception
552 	 * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it
553 	 */
OnExceptionAdd(Exception * ex)554 	virtual EventReturn OnExceptionAdd(Exception *ex) { throw NotImplementedException(); }
555 
556 	/** Called before an exception is deleted
557 	 * @param source The source deleting it
558 	 * @param ex The exceotion
559 	 */
OnExceptionDel(CommandSource & source,Exception * ex)560 	virtual void OnExceptionDel(CommandSource &source, Exception *ex) { throw NotImplementedException(); }
561 
562 	/** Called before a XLine is added
563 	 * @param source The source of the XLine
564 	 * @param x The XLine
565 	 * @param xlm The xline manager it was added to
566 	 * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it
567 	 */
OnAddXLine(CommandSource & source,const XLine * x,XLineManager * xlm)568 	virtual EventReturn OnAddXLine(CommandSource &source, const XLine *x, XLineManager *xlm) { throw NotImplementedException(); }
569 
570 	/** Called before a XLine is deleted
571 	 * @param source The source of the XLine
572 	 * @param x The XLine
573 	 * @param xlm The xline manager it was deleted from
574 	 */
OnDelXLine(CommandSource & source,const XLine * x,XLineManager * xlm)575 	virtual void OnDelXLine(CommandSource &source, const XLine *x, XLineManager *xlm) { throw NotImplementedException(); }
576 
577 	/** Called when a user is checked for whether they are a services oper
578 	 * @param u The user
579 	 * @return EVENT_ALLOW to allow, anything else to deny
580 	 */
IsServicesOper(User * u)581 	virtual EventReturn IsServicesOper(User *u) { throw NotImplementedException(); }
582 
583 	/** Called when a server quits
584 	 * @param server The server
585 	 */
OnServerQuit(Server * server)586 	virtual void OnServerQuit(Server *server) { throw NotImplementedException(); }
587 
588 	/** Called when a user quits, or is killed
589 	 * @param u The user
590 	 * @param msg The quit message
591 	 */
OnUserQuit(User * u,const Anope::string & msg)592 	virtual void OnUserQuit(User *u, const Anope::string &msg) { throw NotImplementedException(); }
593 
594 	/** Called when a user is quit, before and after being internally removed from
595 	 * This is different from OnUserQuit, which takes place at the time of the quit.
596 	 * This happens shortly after when all message processing is finished.
597 	 * all lists (channels, user list, etc)
598 	 * @param u The user
599 	 */
OnPreUserLogoff(User * u)600 	virtual void OnPreUserLogoff(User *u) { throw NotImplementedException(); }
OnPostUserLogoff(User * u)601 	virtual void OnPostUserLogoff(User *u) { throw NotImplementedException(); }
602 
603 	/** Called when a new bot is made
604 	 * @param bi The bot
605 	 */
OnBotCreate(BotInfo * bi)606 	virtual void OnBotCreate(BotInfo *bi) { throw NotImplementedException(); }
607 
608 	/** Called when a bot is changed
609 	 * @param bi The bot
610 	 */
OnBotChange(BotInfo * bi)611 	virtual void OnBotChange(BotInfo *bi) { throw NotImplementedException(); }
612 
613 	/** Called when a bot is deleted
614 	 * @param bi The bot
615 	 */
OnBotDelete(BotInfo * bi)616 	virtual void OnBotDelete(BotInfo *bi) { throw NotImplementedException(); }
617 
618 	/** Called after an access entry is deleted from a channel
619 	 * @param ci The channel
620 	 * @param source The source of the command
621 	 * @param access The access entry that was removed
622 	 */
OnAccessDel(ChannelInfo * ci,CommandSource & source,ChanAccess * access)623 	virtual void OnAccessDel(ChannelInfo *ci, CommandSource &source, ChanAccess *access) { throw NotImplementedException(); }
624 
625 	/** Called when access is added
626 	 * @param ci The channel
627 	 * @param source The source of the command
628 	 * @param access The access changed
629 	 */
OnAccessAdd(ChannelInfo * ci,CommandSource & source,ChanAccess * access)630 	virtual void OnAccessAdd(ChannelInfo *ci, CommandSource &source, ChanAccess *access) { throw NotImplementedException(); }
631 
632 	/** Called when the access list is cleared
633 	 * @param ci The channel
634 	 * @param u The user who cleared the access
635 	 */
OnAccessClear(ChannelInfo * ci,CommandSource & source)636 	virtual void OnAccessClear(ChannelInfo *ci, CommandSource &source) { throw NotImplementedException(); }
637 
638 	/** Called when a level for a channel is changed
639 	 * @param source The source of the command
640 	 * @param ci The channel the level was changed on
641 	 * @param priv The privilege changed
642 	 * @param what The new level
643 	 */
OnLevelChange(CommandSource & source,ChannelInfo * ci,const Anope::string & priv,int16_t what)644 	virtual void OnLevelChange(CommandSource &source, ChannelInfo *ci, const Anope::string &priv, int16_t what) { throw NotImplementedException(); }
645 
646 	/** Called right before a channel is dropped
647 	 * @param source The user dropping the channel
648 	 * @param ci The channel
649 	 */
OnChanDrop(CommandSource & source,ChannelInfo * ci)650 	virtual EventReturn OnChanDrop(CommandSource &source, ChannelInfo *ci) { throw NotImplementedException(); }
651 
652 	/** Called when a channel is registered
653 	 * @param ci The channel
654 	 */
OnChanRegistered(ChannelInfo * ci)655 	virtual void OnChanRegistered(ChannelInfo *ci) { throw NotImplementedException(); }
656 
657 	/** Called when a channel is suspended
658 	 * @param ci The channel
659 	 */
OnChanSuspend(ChannelInfo * ci)660 	virtual void OnChanSuspend(ChannelInfo *ci) { throw NotImplementedException(); }
661 
662 	/** Called when a channel is unsuspended
663 	 * @param ci The channel
664 	 */
OnChanUnsuspend(ChannelInfo * ci)665 	virtual void OnChanUnsuspend(ChannelInfo *ci) { throw NotImplementedException(); }
666 
667 	/** Called when a channel is being created, for any reason
668 	 * @param ci The channel
669 	 */
OnCreateChan(ChannelInfo * ci)670 	virtual void OnCreateChan(ChannelInfo *ci) { throw NotImplementedException(); }
671 
672 	/** Called when a channel is being deleted, for any reason
673 	 * @param ci The channel
674 	 */
OnDelChan(ChannelInfo * ci)675 	virtual void OnDelChan(ChannelInfo *ci) { throw NotImplementedException(); }
676 
677 	/** Called when a new channel is created
678 	 * Note that this channel may not be introduced to the uplink at this point.
679 	 * @param c The channel
680 	 */
OnChannelCreate(Channel * c)681 	virtual void OnChannelCreate(Channel *c) { throw NotImplementedException(); }
682 
683 	/** Called when a channel is deleted
684 	 * @param c The channel
685 	 */
OnChannelDelete(Channel * c)686 	virtual void OnChannelDelete(Channel *c) { throw NotImplementedException(); }
687 
688 	/** Called after adding an akick to a channel
689 	 * @param source The source of the command
690 	 * @param ci The channel
691 	 * @param ak The akick
692 	 */
OnAkickAdd(CommandSource & source,ChannelInfo * ci,const AutoKick * ak)693 	virtual void OnAkickAdd(CommandSource &source, ChannelInfo *ci, const AutoKick *ak) { throw NotImplementedException(); }
694 
695 	/** Called before removing an akick from a channel
696 	 * @param source The source of the command
697 	 * @param ci The channel
698 	 * @param ak The akick
699 	 */
OnAkickDel(CommandSource & source,ChannelInfo * ci,const AutoKick * ak)700 	virtual void OnAkickDel(CommandSource &source, ChannelInfo *ci, const AutoKick *ak) { throw NotImplementedException(); }
701 
702 	/** Called after a user join a channel when we decide whether to kick them or not
703 	 * @param u The user
704 	 * @param c The channel
705 	 * @param kick Set to true to kick
706 	 * @param mask The mask to ban, if any
707 	 * @param reason The reason for the kick
708 	 * @return EVENT_STOP to prevent the user from joining by kicking/banning the user
709 	 */
OnCheckKick(User * u,Channel * c,Anope::string & mask,Anope::string & reason)710 	virtual EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) { throw NotImplementedException(); }
711 
712 	/** Called when a user requests info for a channel
713 	 * @param source The user requesting info
714 	 * @param ci The channel the user is requesting info for
715 	 * @param info Data to show the user requesting information
716 	 * @param show_hidden true if we should show the user everything
717 	 */
OnChanInfo(CommandSource & source,ChannelInfo * ci,InfoFormatter & info,bool show_hidden)718 	virtual void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_hidden) { throw NotImplementedException(); }
719 
720 	/** Checks if access has the channel privilege 'priv'.
721 	 * @param access THe access struct
722 	 * @param priv The privilege being checked for
723 	 * @return EVENT_ALLOW for yes, EVENT_STOP to stop all processing
724 	 */
OnCheckPriv(const ChanAccess * access,const Anope::string & priv)725 	virtual EventReturn OnCheckPriv(const ChanAccess *access, const Anope::string &priv) { throw NotImplementedException(); }
726 
727 	/** Check whether an access group has a privilege
728 	 * @param group The group
729 	 * @param priv The privilege
730 	 * @return MOD_ALLOW to allow, MOD_STOP to stop
731 	 */
OnGroupCheckPriv(const AccessGroup * group,const Anope::string & priv)732 	virtual EventReturn OnGroupCheckPriv(const AccessGroup *group, const Anope::string &priv) { throw NotImplementedException(); }
733 
734 	/** Called when a nick is dropped
735 	 * @param source The source of the command
736 	 * @param na The nick
737 	 */
OnNickDrop(CommandSource & source,NickAlias * na)738 	virtual void OnNickDrop(CommandSource &source, NickAlias *na) { throw NotImplementedException(); }
739 
740 	/** Called when a user groups their nick
741 	 * @param u The user grouping
742 	 * @param target The target they're grouping to
743 	 */
OnNickGroup(User * u,NickAlias * target)744 	virtual void OnNickGroup(User *u, NickAlias *target) { throw NotImplementedException(); }
745 
746 	/** Called when a user identifies to a nick
747 	 * @param u The user
748 	 */
OnNickIdentify(User * u)749 	virtual void OnNickIdentify(User *u) { throw NotImplementedException(); }
750 
751 	/** Called when a user is logged into an account
752 	 * @param u The user
753 	 */
OnUserLogin(User * u)754 	virtual void OnUserLogin(User *u) { throw NotImplementedException(); }
755 
756 	/** Called when a nick logs out
757 	 * @param u The nick
758 	 */
OnNickLogout(User * u)759 	virtual void OnNickLogout(User *u) { throw NotImplementedException(); }
760 
761 	/** Called when a nick is registered
762 	 * @param user The user registering the nick, of any
763 	 * @param The nick
764 	 * @param pass The password of the newly registered nick
765 	 */
OnNickRegister(User * user,NickAlias * na,const Anope::string & pass)766 	virtual void OnNickRegister(User *user, NickAlias *na, const Anope::string &pass) { throw NotImplementedException(); }
767 
768 	/** Called when a nick is confirmed. This will never be called if registration confirmation is not enabled.
769 	 * @param user The user confirming the nick
770 	 * @param The account being confirmed
771 	 */
OnNickConfirm(User * user,NickCore *)772 	virtual void OnNickConfirm(User *user, NickCore *) { throw NotImplementedException(); }
773 
774 	/** Called when a nick is suspended
775 	 * @param na The nick alias
776 	 */
OnNickSuspend(NickAlias * na)777 	virtual void OnNickSuspend(NickAlias *na) { throw NotImplementedException(); }
778 
779 	/** Called when a nick is unsuspneded
780 	 * @param na The nick alias
781 	 */
OnNickUnsuspended(NickAlias * na)782 	virtual void OnNickUnsuspended(NickAlias *na) { throw NotImplementedException(); }
783 
784 	/** Called on delnick()
785 	 * @ param na pointer to the nickalias
786 	 */
OnDelNick(NickAlias * na)787 	virtual void OnDelNick(NickAlias *na) { throw NotImplementedException(); }
788 
789 	/** Called when a nickcore is created
790 	 * @param nc The nickcore
791 	 */
OnNickCoreCreate(NickCore * nc)792 	virtual void OnNickCoreCreate(NickCore *nc) { throw NotImplementedException(); }
793 
794 	/** Called on delcore()
795 	 * @param nc pointer to the NickCore
796 	 */
OnDelCore(NickCore * nc)797 	virtual void OnDelCore(NickCore *nc) { throw NotImplementedException(); }
798 
799 	/** Called on change_core_display()
800 	 * @param nc pointer to the NickCore
801 	 * @param newdisplay the new display
802 	 */
OnChangeCoreDisplay(NickCore * nc,const Anope::string & newdisplay)803 	virtual void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay) { throw NotImplementedException(); }
804 
805 	/** called from NickCore::ClearAccess()
806 	 * @param nc pointer to the NickCore
807 	 */
OnNickClearAccess(NickCore * nc)808 	virtual void OnNickClearAccess(NickCore *nc) { throw NotImplementedException(); }
809 
810 	/** Called when a user adds an entry to their access list
811 	 * @param nc The nick
812 	 * @param entry The entry
813 	 */
OnNickAddAccess(NickCore * nc,const Anope::string & entry)814 	virtual void OnNickAddAccess(NickCore *nc, const Anope::string &entry) { throw NotImplementedException(); }
815 
816 	/** Called from NickCore::EraseAccess()
817 	 * @param nc pointer to the NickCore
818 	 * @param entry The access mask
819 	 */
OnNickEraseAccess(NickCore * nc,const Anope::string & entry)820 	virtual void OnNickEraseAccess(NickCore *nc, const Anope::string &entry) { throw NotImplementedException(); }
821 
822 	/** called from NickCore::ClearCert()
823 	 * @param nc pointer to the NickCore
824 	 */
OnNickClearCert(NickCore * nc)825 	virtual void OnNickClearCert(NickCore *nc) { throw NotImplementedException(); }
826 
827 	/** Called when a user adds an entry to their cert list
828 	 * @param nc The nick
829 	 * @param entry The entry
830 	 */
OnNickAddCert(NickCore * nc,const Anope::string & entry)831 	virtual void OnNickAddCert(NickCore *nc, const Anope::string &entry) { throw NotImplementedException(); }
832 
833 	/** Called from NickCore::EraseCert()
834 	 * @param nc pointer to the NickCore
835 	 * @param entry The fingerprint
836 	 */
OnNickEraseCert(NickCore * nc,const Anope::string & entry)837 	virtual void OnNickEraseCert(NickCore *nc, const Anope::string &entry) { throw NotImplementedException(); }
838 
839 	/** Called when a user requests info for a nick
840 	 * @param source The user requesting info
841 	 * @param na The nick the user is requesting info from
842 	 * @param info Data to show the user requesting information
843 	 * @param show_hidden true if we should show the user everything
844 	 */
OnNickInfo(CommandSource & source,NickAlias * na,InfoFormatter & info,bool show_hidden)845 	virtual void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) { throw NotImplementedException(); }
846 
847 	/** Called when a user uses botserv/info on a bot or channel.
848 	 */
OnBotInfo(CommandSource & source,BotInfo * bi,ChannelInfo * ci,InfoFormatter & info)849 	virtual void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) { throw NotImplementedException(); }
850 
851 	/** Check whether a username and password is correct
852 	 * @param u The user trying to identify, if applicable.
853 	 * @param req The login request
854 	 */
OnCheckAuthentication(User * u,IdentifyRequest * req)855 	virtual void OnCheckAuthentication(User *u, IdentifyRequest *req) { throw NotImplementedException(); }
856 
857 	/** Called when a user does /ns update
858 	 * @param u The user
859 	 */
OnNickUpdate(User * u)860 	virtual void OnNickUpdate(User *u) { throw NotImplementedException(); }
861 
862 	/** Called when we get informed about a users SSL fingerprint
863 	 *  when we call this, the fingerprint should already be stored in the user struct
864 	 * @param u pointer to the user
865 	 */
OnFingerprint(User * u)866 	virtual void OnFingerprint(User *u) { throw NotImplementedException(); }
867 
868 	/** Called when a user becomes (un)away
869 	 * @param message The message, is .empty() if unaway
870 	 */
OnUserAway(User * u,const Anope::string & message)871 	virtual void OnUserAway(User *u, const Anope::string &message) { throw NotImplementedException(); }
872 
873 	/** Called when a user invites one of our users to a channel
874 	 * @param source The user doing the inviting
875 	 * @param c The channel the user is inviting to
876 	 * @param targ The user being invited
877 	 */
OnInvite(User * source,Channel * c,User * targ)878 	virtual void OnInvite(User *source, Channel *c, User *targ) { throw NotImplementedException(); }
879 
880 	/** Called when a vhost is deleted
881 	 * @param na The nickalias of the vhost
882 	 */
OnDeleteVhost(NickAlias * na)883 	virtual void OnDeleteVhost(NickAlias *na) { throw NotImplementedException(); }
884 
885 	/** Called when a vhost is set
886 	 * @param na The nickalias of the vhost
887 	 */
OnSetVhost(NickAlias * na)888 	virtual void OnSetVhost(NickAlias *na) { throw NotImplementedException(); }
889 
890 	/** Called when a users host changes
891 	 * @param u The user
892 	 */
OnSetDisplayedHost(User *)893 	virtual void OnSetDisplayedHost(User *) { throw NotImplementedException(); }
894 
895 	/** Called when a memo is sent
896 	 * @param source The source of the memo
897 	 * @param target The target of the memo
898 	 * @param mi Memo info for target
899 	 * @param m The memo
900 	 */
OnMemoSend(const Anope::string & source,const Anope::string & target,MemoInfo * mi,Memo * m)901 	virtual void OnMemoSend(const Anope::string &source, const Anope::string &target, MemoInfo *mi, Memo *m) { throw NotImplementedException(); }
902 
903 	/** Called when a memo is deleted
904 	 * @param target The target the memo is being deleted from (nick or channel)
905 	 * @param mi The memo info
906 	 * @param m The memo
907 	 */
OnMemoDel(const Anope::string & target,MemoInfo * mi,const Memo * m)908 	virtual void OnMemoDel(const Anope::string &target, MemoInfo *mi, const Memo *m) { throw NotImplementedException(); }
909 
910 	/** Called when a mode is set on a channel
911 	 * @param c The channel
912 	 * @param setter The user or server that is setting the mode
913 	 * @param mode The mode
914 	 * @param param The mode param, if there is one
915 	 * @return EVENT_STOP to make mlock/secureops etc checks not happen
916 	 */
OnChannelModeSet(Channel * c,MessageSource & setter,ChannelMode * mode,const Anope::string & param)917 	virtual EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) { throw NotImplementedException(); }
918 
919 	/** Called when a mode is unset on a channel
920 	 * @param c The channel
921 	 * @param setter The user or server that is unsetting the mode
922 	 * @param mode The mode
923 	 * @param param The mode param, if there is one
924 	 * @return EVENT_STOP to make mlock/secureops etc checks not happen
925 	 */
OnChannelModeUnset(Channel * c,MessageSource & setter,ChannelMode * mode,const Anope::string & param)926 	virtual EventReturn OnChannelModeUnset(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) { throw NotImplementedException(); }
927 
928 	/** Called when a mode is set on a user
929 	 * @param setter who/what is setting the mode
930 	 * @param u The user
931 	 * @param mname The mode name
932 	 */
OnUserModeSet(const MessageSource & setter,User * u,const Anope::string & mname)933 	virtual void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) { throw NotImplementedException(); }
934 
935 	/** Called when a mode is unset from a user
936 	 * @param setter who/what is setting the mode
937 	 * @param u The user
938 	 * @param mname The mode name
939 	 */
OnUserModeUnset(const MessageSource & setter,User * u,const Anope::string & mname)940 	virtual void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) { throw NotImplementedException(); }
941 
942 	/** Called when a channel mode is introducted into Anope
943 	 * @param cm The mode
944 	 */
OnChannelModeAdd(ChannelMode * cm)945 	virtual void OnChannelModeAdd(ChannelMode *cm) { throw NotImplementedException(); }
946 
947 	/** Called when a user mode is introducted into Anope
948 	 * @param um The mode
949 	 */
OnUserModeAdd(UserMode * um)950 	virtual void OnUserModeAdd(UserMode *um) { throw NotImplementedException(); }
951 
952 	/** Called when a mode is about to be mlocked
953 	 * @param ci The channel the mode is being locked on
954 	 * @param lock The mode lock
955 	 * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the mlock.
956 	 */
OnMLock(ChannelInfo * ci,ModeLock * lock)957 	virtual EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) { throw NotImplementedException(); }
958 
959 	/** Called when a mode is about to be unlocked
960 	 * @param ci The channel the mode is being unlocked from
961 	 * @param lock The mode lock
962 	 * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the mlock.
963 	 */
OnUnMLock(ChannelInfo * ci,ModeLock * lock)964 	virtual EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) { throw NotImplementedException(); }
965 
966 	/** Called after a module is loaded
967 	 * @param u The user loading the module, can be NULL
968 	 * @param m The module
969 	 */
OnModuleLoad(User * u,Module * m)970 	virtual void OnModuleLoad(User *u, Module *m) { throw NotImplementedException(); }
971 
972 	/** Called before a module is unloaded
973 	 * @param u The user, can be NULL
974 	 * @param m The module
975 	 */
OnModuleUnload(User * u,Module * m)976 	virtual void OnModuleUnload(User *u, Module *m) { throw NotImplementedException(); }
977 
978 	/** Called when a server is synced
979 	 * @param s The server, can be our uplink server
980 	 */
OnServerSync(Server * s)981 	virtual void OnServerSync(Server *s) { throw NotImplementedException(); }
982 
983 	/** Called when we sync with our uplink
984 	 * @param s Our uplink
985 	 */
OnUplinkSync(Server * s)986 	virtual void OnUplinkSync(Server *s) { throw NotImplementedException(); }
987 
988 	/** Called when we receive a PRIVMSG for one of our clients
989 	 * @param u The user sending the PRIVMSG
990 	 * @param bi The target of the PRIVMSG
991 	 * @param message The message
992 	 * @return EVENT_STOP to halt processing
993 	 */
OnBotPrivmsg(User * u,BotInfo * bi,Anope::string & message)994 	virtual EventReturn OnBotPrivmsg(User *u, BotInfo *bi, Anope::string &message) { throw NotImplementedException(); }
995 
996 	/** Called when we receive a NOTICE for one of our clients
997 	 * @param u The user sending the NOTICE
998 	 * @param bi The target of the NOTICE
999 	 * @param message The message
1000 	 */
OnBotNotice(User * u,BotInfo * bi,Anope::string & message)1001 	virtual void OnBotNotice(User *u, BotInfo *bi, Anope::string &message) { throw NotImplementedException(); }
1002 
1003 	/** Called when we receive a PRIVMSG for a registered channel we are in
1004 	 * @param u The source of the message
1005 	 * @param c The channel
1006 	 * @param msg The message
1007 	 */
OnPrivmsg(User * u,Channel * c,Anope::string & msg)1008 	virtual void OnPrivmsg(User *u, Channel *c, Anope::string &msg) { throw NotImplementedException(); }
1009 
1010 	/** Called when a message is logged
1011 	 * @param l The log message
1012 	 */
OnLog(Log * l)1013 	virtual void OnLog(Log *l) { throw NotImplementedException(); }
1014 
1015 	/** Called when a log message is actually logged to a given log info
1016 	 * The message has already passed validation checks by the LogInfo
1017 	 * @param li The loginfo whee the message is being logged
1018 	 * @param l The log message
1019 	 * @param msg The final formatted message, derived from 'l'
1020 	 */
OnLogMessage(LogInfo * li,const Log * l,const Anope::string & msg)1021 	virtual void OnLogMessage(LogInfo *li, const Log *l, const Anope::string &msg) { throw NotImplementedException(); }
1022 
1023 	/** Called when a DNS request (question) is received.
1024 	 * @param req The dns request
1025 	 * @param reply The reply that will be sent
1026 	 */
OnDnsRequest(DNS::Query & req,DNS::Query * reply)1027 	virtual void OnDnsRequest(DNS::Query &req, DNS::Query *reply) { throw NotImplementedException(); }
1028 
1029 	/** Called when a channels modes are being checked to see if they are allowed,
1030 	 * mostly to ensure mlock/+r are set.
1031 	 * @param c The channel
1032 	 */
OnCheckModes(Reference<Channel> & c)1033 	virtual void OnCheckModes(Reference<Channel> &c) { throw NotImplementedException(); }
1034 
1035 	/** Called when a channel is synced.
1036 	 * Channels are synced after a sjoin is finished processing
1037 	 * for a newly created channel to set the correct modes, topic,
1038 	 * set.
1039 	 */
OnChannelSync(Channel * c)1040 	virtual void OnChannelSync(Channel *c) { throw NotImplementedException(); }
1041 
1042 	/** Called to set the correct modes on the user on the given channel
1043 	 * @param user The user
1044 	 * @param chan The channel
1045 	 * @param access The user's access on the channel
1046 	 * @param give_modes If giving modes is desired
1047 	 * @param take_modes If taking modes is desired
1048 	 */
OnSetCorrectModes(User * user,Channel * chan,AccessGroup & access,bool & give_modes,bool & take_modes)1049 	virtual void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool &give_modes, bool &take_modes) { throw NotImplementedException(); }
1050 
OnSerializeCheck(Serialize::Type *)1051 	virtual void OnSerializeCheck(Serialize::Type *) { throw NotImplementedException(); }
OnSerializableConstruct(Serializable *)1052 	virtual void OnSerializableConstruct(Serializable *) { throw NotImplementedException(); }
OnSerializableDestruct(Serializable *)1053 	virtual void OnSerializableDestruct(Serializable *) { throw NotImplementedException(); }
OnSerializableUpdate(Serializable *)1054 	virtual void OnSerializableUpdate(Serializable *) { throw NotImplementedException(); }
OnSerializeTypeCreate(Serialize::Type *)1055 	virtual void OnSerializeTypeCreate(Serialize::Type *) { throw NotImplementedException(); }
1056 
1057 	/** Called when a chanserv/set command is used
1058 	 * @param source The source of the command
1059 	 * @param cmd The command
1060 	 * @param ci The channel the command was used on
1061 	 * @param setting The setting passed to the command. Probably ON/OFF.
1062 	 * @return EVENT_ALLOW to bypass access checks, EVENT_STOP to halt immediately.
1063 	 */
OnSetChannelOption(CommandSource & source,Command * cmd,ChannelInfo * ci,const Anope::string & setting)1064 	virtual EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChannelInfo *ci, const Anope::string &setting) { throw NotImplementedException(); }
1065 
1066 	/** Called when a nickserv/set command is used.
1067 	 * @param source The source of the command
1068 	 * @param cmd The command
1069 	 * @param nc The nickcore being modifed
1070 	 * @param setting The setting passed to the command. Probably ON/OFF.
1071 	 * @return EVENT_STOP to halt immediately
1072 	 */
OnSetNickOption(CommandSource & source,Command * cmd,NickCore * nc,const Anope::string & setting)1073 	virtual EventReturn OnSetNickOption(CommandSource &source, Command *cmd, NickCore *nc, const Anope::string &setting) { throw NotImplementedException(); }
1074 
1075 	/** Called whenever a message is received from the uplink
1076 	 * @param source The source of the message
1077 	 * @param command The command being executed
1078 	 * @param params Parameters
1079 	 * @return EVENT_STOP to prevent the protocol module from processing this message
1080 	 */
OnMessage(MessageSource & source,Anope::string & command,std::vector<Anope::string> & param)1081 	virtual EventReturn OnMessage(MessageSource &source, Anope::string &command, std::vector<Anope::string> &param) { throw NotImplementedException(); }
1082 
1083 	/** Called to determine if a chnanel mode can be set by a user
1084 	 * @param u The user
1085 	 * @param cm The mode
1086 	 */
OnCanSet(User * u,const ChannelMode * cm)1087 	virtual EventReturn OnCanSet(User *u, const ChannelMode *cm) { throw NotImplementedException(); }
1088 
OnCheckDelete(Channel *)1089 	virtual EventReturn OnCheckDelete(Channel *) { throw NotImplementedException(); }
1090 
1091 	/** Called every options:expiretimeout seconds. Should be used to expire nicks,
1092 	 * channels, etc.
1093 	 */
OnExpireTick()1094 	virtual void OnExpireTick() { throw NotImplementedException(); }
1095 
1096 	/** Called when a nick is validated. That is, to determine if a user is permissted
1097 	 * to be on the given nick.
1098 	 * @param u The user
1099 	 * @param na The nick they are on
1100 	 * @return EVENT_STOP to force the user off of the nick
1101 	 */
OnNickValidate(User * u,NickAlias * na)1102 	virtual EventReturn OnNickValidate(User *u, NickAlias *na) { throw NotImplementedException(); }
1103 };
1104 
1105 enum Implementation
1106 {
1107 	I_OnPostInit,
1108 	I_OnPreUserKicked, I_OnUserKicked, I_OnReload, I_OnPreBotAssign, I_OnBotAssign, I_OnBotUnAssign, I_OnUserConnect,
1109 	I_OnNewServer, I_OnUserNickChange, I_OnPreHelp, I_OnPostHelp, I_OnPreCommand, I_OnPostCommand, I_OnSaveDatabase,
1110 	I_OnLoadDatabase, I_OnEncrypt, I_OnDecrypt, I_OnBotFantasy, I_OnBotNoFantasyAccess, I_OnBotBan, I_OnBadWordAdd,
1111 	I_OnBadWordDel, I_OnCreateBot, I_OnDelBot, I_OnBotKick, I_OnPrePartChannel, I_OnPartChannel, I_OnLeaveChannel,
1112 	I_OnJoinChannel, I_OnTopicUpdated, I_OnPreChanExpire, I_OnChanExpire, I_OnPreServerConnect, I_OnServerConnect,
1113 	I_OnPreUplinkSync, I_OnServerDisconnect, I_OnRestart, I_OnShutdown, I_OnPreNickExpire, I_OnNickExpire, I_OnDefconLevel,
1114 	I_OnExceptionAdd, I_OnExceptionDel, I_OnAddXLine, I_OnDelXLine, I_IsServicesOper, I_OnServerQuit, I_OnUserQuit,
1115 	I_OnPreUserLogoff, I_OnPostUserLogoff, I_OnBotCreate, I_OnBotChange, I_OnBotDelete, I_OnAccessDel, I_OnAccessAdd,
1116 	I_OnAccessClear, I_OnLevelChange, I_OnChanDrop, I_OnChanRegistered, I_OnChanSuspend, I_OnChanUnsuspend,
1117 	I_OnCreateChan, I_OnDelChan, I_OnChannelCreate, I_OnChannelDelete, I_OnAkickAdd, I_OnAkickDel, I_OnCheckKick,
1118 	I_OnChanInfo, I_OnCheckPriv, I_OnGroupCheckPriv, I_OnNickDrop, I_OnNickGroup, I_OnNickIdentify,
1119 	I_OnUserLogin, I_OnNickLogout, I_OnNickRegister, I_OnNickConfirm, I_OnNickSuspend, I_OnNickUnsuspended, I_OnDelNick, I_OnNickCoreCreate,
1120 	I_OnDelCore, I_OnChangeCoreDisplay, I_OnNickClearAccess, I_OnNickAddAccess, I_OnNickEraseAccess, I_OnNickClearCert,
1121 	I_OnNickAddCert, I_OnNickEraseCert, I_OnNickInfo, I_OnBotInfo, I_OnCheckAuthentication, I_OnNickUpdate,
1122 	I_OnFingerprint, I_OnUserAway, I_OnInvite, I_OnDeleteVhost, I_OnSetVhost, I_OnSetDisplayedHost, I_OnMemoSend, I_OnMemoDel,
1123 	I_OnChannelModeSet, I_OnChannelModeUnset, I_OnUserModeSet, I_OnUserModeUnset, I_OnChannelModeAdd, I_OnUserModeAdd,
1124 	I_OnMLock, I_OnUnMLock, I_OnModuleLoad, I_OnModuleUnload, I_OnServerSync, I_OnUplinkSync, I_OnBotPrivmsg, I_OnBotNotice,
1125 	I_OnPrivmsg, I_OnLog, I_OnLogMessage, I_OnDnsRequest, I_OnCheckModes, I_OnChannelSync, I_OnSetCorrectModes,
1126 	I_OnSerializeCheck, I_OnSerializableConstruct, I_OnSerializableDestruct, I_OnSerializableUpdate,
1127 	I_OnSerializeTypeCreate, I_OnSetChannelOption, I_OnSetNickOption, I_OnMessage, I_OnCanSet, I_OnCheckDelete,
1128 	I_OnExpireTick, I_OnNickValidate,
1129 	I_SIZE
1130 };
1131 
1132 /** Used to manage modules.
1133  */
1134 class CoreExport ModuleManager
1135 {
1136  public:
1137 	/** Event handler hooks.
1138 	 */
1139 	static std::vector<Module *> EventHandlers[I_SIZE];
1140 
1141 	/** List of all modules loaded in Anope
1142 	 */
1143 	static std::list<Module *> Modules;
1144 
1145 #ifdef _WIN32
1146 	/** Clean up the module runtime directory
1147 	 */
1148 	static void CleanupRuntimeDirectory();
1149 #endif
1150 
1151 	/** Loads a given module.
1152 	 * @param m the module to load
1153 	 * @param u the user who loaded it, NULL for auto-load
1154 	 * @return MOD_ERR_OK on success, anything else on fail
1155 	 */
1156 	static ModuleReturn LoadModule(const Anope::string &modname, User *u);
1157 
1158 	/** Unload the given module.
1159 	 * @param m the module to unload
1160 	 * @param u the user who unloaded it
1161 	 * @return MOD_ERR_OK on success, anything else on fail
1162 	 */
1163 	static ModuleReturn UnloadModule(Module *m, User * u);
1164 
1165 	/** Find a module
1166 	 * @param name The module name
1167 	 * @return The module
1168 	 */
1169 	static Module *FindModule(const Anope::string &name);
1170 
1171 	/** Find the first module of a certain type
1172 	 * @param type The module type
1173 	 * @return The module
1174 	 */
1175 	static Module *FindFirstOf(ModType type);
1176 
1177 	/** Checks whether this version of Anope is at least major.minor.patch.build
1178 	 * Throws a ModuleException if not
1179 	 * @param major The major version
1180 	 * @param minor The minor vesion
1181 	 * @param patch The patch version
1182 	 */
1183 	static void RequireVersion(int major, int minor, int patch);
1184 
1185 	/** Change the priority of one event in a module.
1186 	 * Each module event has a list of modules which are attached to that event type. If you wish to be called before or after other specific modules, you may use this
1187 	 * method (usually within void Module::Prioritize()) to set your events priority. You may use this call in other methods too, however, this is not supported behaviour
1188 	 * for a module.
1189 	 * @param mod The module to change the priority of
1190 	 * @param i The event to change the priority of
1191 	 * @param s The state you wish to use for this event. Use one of
1192 	 * PRIO_FIRST to set the event to be first called, PRIO_LAST to set it to be the last called, or PRIO_BEFORE and PRIO_AFTER
1193 	 * to set it to be before or after one or more other modules.
1194 	 * @param modules If PRIO_BEFORE or PRIO_AFTER is set in parameter 's', then this contains a list of one or more modules your module must be
1195 	 * placed before or after. Your module will be placed before the highest priority module in this list for PRIO_BEFORE, or after the lowest
1196 	 * priority module in this list for PRIO_AFTER.
1197 	 * @param sz The number of modules being passed for PRIO_BEFORE and PRIO_AFTER. Defaults to 1, as most of the time you will only want to prioritize your module
1198 	 * to be before or after one other module.
1199 	 */
1200 	static bool SetPriority(Module *mod, Implementation i, Priority s, Module **modules = NULL, size_t sz = 1);
1201 
1202 	/** Change the priority of all events in a module.
1203 	 * @param mod The module to set the priority of
1204 	 * @param s The priority of all events in the module.
1205 	 * Note that with this method, it is not possible to effectively use PRIO_BEFORE or PRIO_AFTER, you should use the more fine tuned
1206 	 * SetPriority method for this, where you may specify other modules to be prioritized against.
1207 	 */
1208 	static bool SetPriority(Module *mod, Priority s);
1209 
1210 	/** Detach all events from a module (used on unload)
1211 	 * @param mod Module to detach from
1212 	 */
1213 	static void DetachAll(Module *mod);
1214 
1215 	/** Unloading all modules except the protocol module.
1216 	 */
1217 	static void UnloadAll();
1218 
1219  private:
1220 	/** Call the module_delete function to safely delete the module
1221 	 * @param m the module to delete
1222 	 * @return MOD_ERR_OK on success, anything else on fail
1223 	 */
1224 	static ModuleReturn DeleteModule(Module *m);
1225 
1226 	/** Get the version of Anope the module was compiled against
1227 	 * @return The version
1228 	 */
1229 	static ModuleVersion GetVersion(void *handle);
1230 };
1231 
1232 #endif // MODULES_H
1233