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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
|
/* Modular support
*
* (C) 2003-2010 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for furhter details.
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
*
* $Id$
*/
#ifndef MODULES_H
#define MODULES_H
#include <time.h>
#include "services.h"
#include <stdio.h>
#include "timers.h"
#include "hashcomp.h"
#include "version.h"
/* Cross OS compatibility macros */
#ifdef _WIN32
typedef HMODULE ano_module_t;
#define dlopen(file, unused) LoadLibrary(file)
E const char *dlerror();
#define dlsym(file, symbol) (HMODULE)GetProcAddress(file, symbol)
#define dlclose(file) FreeLibrary(file) ? 0 : 1
#define ano_modclearerr() SetLastError(0)
#define MODULE_EXT ".so"
#else
typedef void * ano_module_t;
/* We call dlerror() here because it clears the module error after being
* called. This previously read 'errno = 0', but that didn't work on
* all POSIX-compliant architectures. This way the error is guaranteed
* to be cleared, POSIX-wise. -GD
*/
#define ano_modclearerr() dlerror()
#define MODULE_EXT ".so"
#endif
/** Possible return types from events.
*/
enum EventReturn
{
EVENT_STOP,
EVENT_CONTINUE,
EVENT_ALLOW
};
/**
* This #define allows us to call a method in all
* loaded modules in a readable simple way, e.g.:
* 'FOREACH_MOD(I_OnConnect,OnConnect(user));'
*/
#define FOREACH_MOD(y,x) do { \
std::vector<Module*>::iterator safei; \
for (std::vector<Module*>::iterator _i = ModuleManager::EventHandlers[y].begin(); _i != ModuleManager::EventHandlers[y].end(); ) \
{ \
safei = _i; \
++safei; \
try \
{ \
(*_i)->x ; \
} \
catch (CoreException& modexcept) \
{ \
Alog() << "Exception caught: " << modexcept.GetReason(); \
} \
_i = safei; \
} \
} while (0);
/**
* This define is similar to the one above but returns a result in MOD_RESULT.
* The first module to return a nonzero result is the value to be accepted,
* and any modules after are ignored.
*/
#define FOREACH_RESULT(y,x) \
do { \
std::vector<Module*>::iterator safei; \
MOD_RESULT = EVENT_CONTINUE; \
for (std::vector<Module*>::iterator _i = ModuleManager::EventHandlers[y].begin(); _i != ModuleManager::EventHandlers[y].end(); ) \
{ \
safei = _i; \
++safei; \
try \
{ \
EventReturn res = (*_i)->x ; \
if (res != EVENT_CONTINUE) { \
MOD_RESULT = res; \
break; \
} \
} \
catch (CoreException& modexcept) \
{ \
Alog() << "Exception caught: " << modexcept.GetReason(); \
} \
_i = safei; \
} \
} while(0);
/** Priority types which can be returned from Module::Prioritize()
*/
enum Priority { PRIORITY_FIRST, PRIORITY_DONTCARE, PRIORITY_LAST, PRIORITY_BEFORE, PRIORITY_AFTER };
/*************************************************************************/
#define CMD_HASH(x) (((x)[0]&31)<<5 | ((x)[1]&31)) /* Will gen a hash from a string :) */
#define MAX_CMD_HASH 1024
/** The return value from commands.
*/
enum CommandReturn
{
MOD_CONT,
MOD_STOP
};
#define HOSTSERV HS_cmdTable /* using HOSTSERV etc. looks nicer than HS_cmdTable for modules */
#define BOTSERV BS_cmdTable
#define MEMOSERV MS_cmdTable
#define NICKSERV NS_cmdTable
#define CHANSERV CS_cmdTable
#define OPERSERV OS_cmdTable
#define IRCD IRCD_cmdTable
#define MODULE_HASH Module_table
#define EVENT EVENT_cmdTable
#define EVENTHOOKS HOOK_cmdTable
/**********************************************************************
* Module Returns
**********************************************************************/
#define MOD_ERR_OK 0
#define MOD_ERR_MEMORY 1
#define MOD_ERR_PARAMS 2
#define MOD_ERR_EXISTS 3
#define MOD_ERR_NOEXIST 4
#define MOD_ERR_NOUSER 5
#define MOD_ERR_NOLOAD 6
#define MOD_ERR_NOUNLOAD 7
#define MOD_ERR_SYNTAX 8
#define MOD_ERR_NODELETE 9
#define MOD_ERR_UNKNOWN 10
#define MOD_ERR_FILE_IO 11
#define MOD_ERR_NOSERVICE 12
#define MOD_ERR_NO_MOD_NAME 13
/*************************************************************************/
/* Macros to export the Module API functions/variables */
#ifndef _WIN32
#define MDE
#else
#ifndef MODULE_COMPILE
#define MDE __declspec(dllexport)
#else
#define MDE __declspec(dllimport)
#endif
#endif
/*************************************************************************/
#if !defined(_WIN32)
#include <dlfcn.h>
/* Define these for systems without them */
#ifndef RTLD_NOW
#define RTLD_NOW 0
#endif
#ifndef RTLD_LAZY
#define RTLD_LAZY RTLD_NOW
#endif
#ifndef RTLD_GLOBAL
#define RTLD_GLOBAL 0
#endif
#ifndef RTLD_LOCAL
#define RTLD_LOCAL 0
#endif
#else
const char *ano_moderr();
#endif
typedef enum { CORE,PROTOCOL,THIRD,SUPPORTED,QATESTED,ENCRYPTION,DATABASE } MODType;
typedef enum { MOD_OP_LOAD, MOD_OP_UNLOAD } ModuleOperation;
/*************************************************************************/
/* Structure for information about a *Serv command. */
struct CommandHash;
typedef struct ModuleLang_ ModuleLang;
typedef struct ModuleHash_ ModuleHash;
typedef struct Message_ Message;
typedef struct MessageHash_ MessageHash;
/*************************************************************************/
extern MDE CommandHash *HOSTSERV[MAX_CMD_HASH];
extern MDE CommandHash *BOTSERV[MAX_CMD_HASH];
extern MDE CommandHash *MEMOSERV[MAX_CMD_HASH];
extern MDE CommandHash *NICKSERV[MAX_CMD_HASH];
extern MDE CommandHash *CHANSERV[MAX_CMD_HASH];
extern MDE CommandHash *OPERSERV[MAX_CMD_HASH];
extern MDE MessageHash *IRCD[MAX_CMD_HASH];
extern MDE ModuleHash *MODULE_HASH[MAX_CMD_HASH];
struct ModuleLang_ {
int argc;
char **argv;
};
enum CommandFlag
{
CFLAG_ALLOW_UNREGISTERED,
CFLAG_ALLOW_FORBIDDEN,
CFLAG_ALLOW_SUSPENDED,
CFLAG_ALLOW_UNREGISTEREDCHANNEL,
CFLAG_STRIP_CHANNEL,
CFLAG_DISABLE_FANTASY
};
/** Every services command is a class, inheriting from Command.
*/
class CoreExport Command : public Flags<CommandFlag>
{
public:
size_t MaxParams;
size_t MinParams;
std::string name;
std::string permission;
/** Create a new command.
* @param min_params The minimum number of parameters the parser will require to execute this command
* @param max_params The maximum number of parameters the parser will create, after max_params, all will be combined into the last argument.
* NOTE: If max_params is not set (default), there is no limit to the max number of params.
*/
Command(const std::string &sname, size_t min_params, size_t max_params = 0, const std::string &spermission = "");
virtual ~Command();
/** Execute this command.
* @param u The user executing the command.
*/
virtual CommandReturn Execute(User *u, const std::vector<ci::string> &);
/** Requested when the user is requesting help on this command. Help on this command should be sent to the user.
* @param u The user requesting help
* @param subcommand The subcommand the user is requesting help on, or an empty string. (e.g. /ns help set foo bar lol gives a subcommand of "FOO BAR LOL")
* @return true if help was provided to the user, false otherwise.
*/
virtual bool OnHelp(User *u, const ci::string &subcommand);
/** Requested when the user provides bad syntax to this command (not enough params, etc).
* @param u The user executing the command.
* @param subcommand The subcommand the user tried to use
*/
virtual void OnSyntaxError(User *u, const ci::string &subcommand);
/** Set which command permission (e.g. chanserv/forbid) is required for this command.
* @param reststr The permission required to successfully execute this command
*/
void SetPermission(const std::string &reststr);
/* Module related stuff */
int core; /* Can this command be deleted? */
char *mod_name; /* Name of the module who owns us, NULL for core's */
char *service; /* Service we provide this command for */
Command *next;
};
class Version
{
private:
unsigned Major;
unsigned Minor;
unsigned Build;
public:
/** Constructor
* @param vMajor The major version numbber
* @param vMinor The minor version numbber
* @param vBuild The build version numbber
*/
Version(unsigned vMajor, unsigned vMinor, unsigned vBuild);
/** Destructor
*/
virtual ~Version();
/** Get the major version of Anope this was built against
* @return The major version
*/
const unsigned GetMajor();
/** Get the minor version of Anope this was built against
* @return The minor version
*/
const unsigned GetMinor();
/** Get the build version this was built against
* @return The build version
*/
const unsigned GetBuild();
};
/* Forward declaration of CallBack class for the Module class */
class CallBack;
/** Every module in Anope is actually a class.
*/
class CoreExport Module
{
private:
bool permanent;
public:
/** The module name (e.g. os_modload)
*/
std::string name;
/** The temporary path/filename
*/
std::string filename;
/** Callbacks used in this module
*/
std::list<CallBack *> CallBacks;
ano_module_t handle;
time_t created;
std::string version;
std::string author;
MODType type;
MessageHash *msgList[MAX_CMD_HASH];
ModuleLang lang[NUM_LANGS];
/** Creates and initialises a new module.
* @param loadernick The nickname of the user loading the module.
*/
Module(const std::string &modname, const std::string &loadernick);
/** Destroys a module, freeing resources it has allocated.
*/
virtual ~Module();
/** Sets a given type (CORE,PROTOCOL,3RD etc) on a module.
* @param type The type to set the module as.
*/
void SetType(MODType type);
/** Toggles the permanent flag on a module. If a module is permanent,
* then it may not be unloaded.
*
* Naturally, this setting should be used sparingly!
*
* @param state True if this module should be permanent, false else.
*/
void SetPermanent(bool state);
/** Retrieves whether or not a given module is permanent.
* @return true if the module is permanent, false else.
*/
bool GetPermanent();
/** Set the modules version info.
* @param version the version of the module
*/
void SetVersion(const std::string &version);
/** Set the modules author info
* @param author the author of the module
*/
void SetAuthor(const std::string &author);
/** Get the version of Anope this module was
* compiled against
* @return The version
*/
virtual Version GetVersion() { return Version(VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD); }
/**
* Allow a module to add a set of language strings to anope
* @param langNumber the language number for the strings
* @param ac The language count for the strings
* @param av The language sring list.
**/
void InsertLanguage(int langNumber, int ac, const char **av);
/**
* Delete a language from a module
* @param langNumber the language Number to delete
**/
void DeleteLanguage(int langNumber);
/**
* Get the text of the given lanugage string in the corrent language, or
* in english.
* @param u The user to send the message to
* @param number The message number
**/
const char *GetLangString(User *u, int number);
/**
* Send a notice to the user in the correct language, or english.
* @param source Who sends the notice
* @param u The user to send the message to
* @param number The message number
* @param ... The argument list
**/
void NoticeLang(const char *source, User * u, int number, ...);
/**
* Add a module provided command to the given service.
* e.g. AddCommand(NICKSERV,c,MOD_HEAD);
* @param cmdTable the services to add the command to
* @param c the command to add
* @return MOD_ERR_OK on successfully adding the command
*/
int AddCommand(CommandHash *cmdTable[], Command * c);
/**
* Delete a command from the service given.
* @param cmdTable the cmdTable for the services to remove the command from
* @param name the name of the command to delete from the service
* @return returns MOD_ERR_OK on success
*/
int DelCommand(CommandHash * cmdTable[], const char *name);
/** Called on NickServ HELP
* @param u The user requesting help
*/
virtual void OnNickServHelp(User *u) { }
/** Called on ChanServ HELP
* @param u The user requesting help
*/
virtual void OnChanServHelp(User *u) { }
/** Called on Botserv HELP
* @param u The user requesting help
*/
virtual void OnBotServHelp(User *u) { }
/** Called on HostServ HELP
* @param u The user requesting help
*/
virtual void OnHostServHelp(User *u) { }
/** Called on OperServ HELP
* @param u The user requesting help
*/
virtual void OnOperServHelp(User *u) { }
/** Called on MemoServ HELP
* @param u The user requesting help
*/
virtual void OnMemoServHelp(User *u) { }
/** Called when the ircd notifies that a user has been kicked from a channel.
* @param c The channel the user has been kicked from.
* @param target The user that has been kicked.
* @param source The nick of the sender.
* @param kickmsg The reason for the kick.
*/
virtual void OnUserKicked(Channel *c, User *target, const std::string &source, const std::string &kickmsg) { }
/** Called when Services' configuration has been loaded.
* @param startup True if Services is starting for the first time, false otherwise.
*/
virtual void OnReload(bool startup) {}
/** Called before a bot is assigned to a channel.
* @param sender The user assigning the bot
* @param ci The channel the bot is to be assigned to.
* @param bi The bot being assigned.
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the assign.
*/
virtual EventReturn OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) { return EVENT_CONTINUE; }
/** Called before a bot is unassigned from a channel.
* @param sender The user unassigning the bot
* @param ci The channel the bot is being removed from
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the unassign.
*/
virtual EventReturn OnBotUnAssign(User *sender, ChannelInfo *ci) { return EVENT_CONTINUE; }
/** Called after a user has been introduced, but before any type
* of checking has been done (akills, defcon, s*lines, etc)
* return EVENT_STOP here to allow the user to get by untouched,
* or kill them then return EVENT_STOP to tell Anope the user no
* longer exists
* @param u The user
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to stop processing
*/
virtual EventReturn OnPreUserConnect(User *u) { return EVENT_CONTINUE; }
/** Called when a new user connects to the network.
* @param u The connecting user.
*/
virtual void OnUserConnect(User *u) { }
/** Called when a new server connects to the network.
* @param s The server that has connected to the network
*/
virtual void OnNewServer(Server *s) { }
/** Called after a user changed the nick
* @param u The user.
* @param oldnick the old nick of the user
*/
virtual void OnUserNickChange(User *u, const char *oldnick) { }
/** Called immediatly when a user tries to run a command
* @param service The service
* @param u The user
* @param cmd The command
* @param c The command class (if it exists)
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it
*/
virtual EventReturn OnPreCommandRun(const std::string &service, User *u, const char *cmd, Command *c) { return EVENT_CONTINUE; }
/** Called before a command is due to be executed.
* @param u The user executing the command
* @param service The service the command is associated with
* @param command The command the user is executing
* @param params The parameters the user is sending
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it
*/
virtual EventReturn OnPreCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> ¶ms) { return EVENT_CONTINUE; }
/** Called after a command has been executed.
* @param u The user executing the command
* @param service The service the command is associated with
* @param command The command the user executed
* @param params The parameters the user sent
*/
virtual void OnPostCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> ¶ms) { }
/** Called after the core has finished loading the databases, but before
* we connect to the server
*/
virtual void OnPostLoadDatabases() { }
/** Called when the databases are saved
* @return EVENT_CONTINUE to let other modules continue saving, EVENT_STOP to stop
*/
virtual EventReturn OnSaveDatabase() { return EVENT_CONTINUE; }
/** Called when the databases are loaded
* @return EVENT_CONTINUE to let other modules continue saving, EVENT_STOP to stop
*/
virtual EventReturn OnLoadDatabase() { return EVENT_CONTINUE; }
/** Called when anope backs up databases.
* NOTE: This event is deprecated pending new database handling.
*/
virtual void OnBackupDatabase() MARK_DEPRECATED { }
/** Called when anope needs to check passwords against encryption
* see src/encrypt.c for detailed informations
*/
virtual EventReturn OnEncrypt(const std::string &src, std::string &dest) { return EVENT_CONTINUE; }
virtual EventReturn OnEncryptInPlace(std::string &buf) { return EVENT_CONTINUE; }
virtual EventReturn OnDecrypt(const std::string &hashm, const std::string &src, std::string &dest) { return EVENT_CONTINUE; }
virtual EventReturn OnCheckPassword(const std::string &hashm, std::string &plaintext, std::string &password) { return EVENT_CONTINUE; }
/** Called on fantasy command
* @param command The command
* @param u The user using the command
* @param ci The channel it's being used in
* @param params The params
*/
virtual void OnBotFantasy(char *command, User *u, ChannelInfo *ci, char *params) { }
/** Called on fantasy command without access
* @param command The command
* @param u The user using the command
* @param ci The channel it's being used in
* @param params The params
*/
virtual void OnBotNoFantasyAccess(const char *command, User *u, ChannelInfo *ci, const char *params) { }
/** Called after a bot joins a channel
* @param ci The channael
* @param bi The bot
*/
virtual void OnBotJoin(ChannelInfo *ci, BotInfo *bi) { }
/** Called when a bot places a ban
* @param u User being banned
* @param ci Channel the ban is placed on
* @param mask The mask being banned
*/
virtual void OnBotBan(User *u, ChannelInfo *ci, const char *mask) { }
/** Called before a bot kicks a user
* @param bi The bot sending the kick
* @param c The channel the user is being kicked on
* @param u The user being kicked
* @param reason The reason
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it
*/
virtual EventReturn OnBotKick(BotInfo *bi, Channel *c, User *u, const std::string &reason) { return EVENT_CONTINUE; }
/** Called before a user parts a channel
* @param u The user
* @param c The channel
*/
virtual void OnPrePartChannel(User *u, Channel *c) {}
/** Called when a user parts a channel
* @param u The user
* @param c The channel, may be NULL if the channel no longer exists
* @param channel The channel name
* @param msg The part reason
*/
virtual void OnPartChannel(User *u, Channel *c, const std::string &channel, const std::string &msg) { }
/** Called before a user joins a channel
* @param u The user
* @param c The channel
* @return EVENT_STOP to allow the user to join the channel through restrictions, EVENT_CONTINUE to let other modules decide
*/
virtual EventReturn OnPreJoinChannel(User *u, Channel *c) { return EVENT_CONTINUE; }
/** Called when a user joins a channel
* @param u The user
* @param channel The channel
*/
virtual void OnJoinChannel(User *u, Channel *c) { }
/** Called when a new topic is set
* @param c The channel
* @param topic The new topic
*/
virtual void OnTopicUpdated(Channel *c, const char *topic) { }
/** Called before a channel expires
* @param ci The channel
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it
*/
virtual EventReturn OnPreChanExpire(ChannelInfo *ci) { return EVENT_CONTINUE; }
/** Called when a channel expires
* @param chname The channel name
*/
virtual void OnChanExpire(const char *chname) { }
/** Called before anope connects to its uplink
*/
virtual void OnPreServerConnect() { }
/** Called when anope connects to its uplink
*/
virtual void OnServerConnect() { }
/** Called before the database expire routines are called
* Note: Code that is in seperate expiry routines should just be done
* when we save the DB, theres no need to have both
*/
virtual void OnPreDatabaseExpire() MARK_DEPRECATED { }
/** Called when the database expire routines are called
*/
virtual void OnDatabaseExpire() MARK_DEPRECATED { }
/** Called when the flatfile dbs are being written
* @param Write A callback to the function used to insert a line into the database
*/
virtual void OnDatabaseWrite(void (*Write)(const std::string &)) { }
/** Called when a line is read from the database
* @param params The params from the database
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to stop processing
*/
virtual EventReturn OnDatabaseRead(const std::vector<std::string> ¶ms) { return EVENT_CONTINUE; }
/** Called when nickcore metadata is read from the database
* @param nc The nickcore
* @param key The metadata key
* @param params The params from the database
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to stop processing
*/
virtual EventReturn OnDatabaseReadMetadata(NickCore *nc, const std::string &key, const std::vector<std::string> ¶ms) { return EVENT_CONTINUE; }
/** Called when nickcore metadata is read from the database
* @param na The nickalias
* @param key The metadata key
* @param params The params from the database
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to stop processing
*/
virtual EventReturn OnDatabaseReadMetadata(NickAlias *na, const std::string &key, const std::vector<std::string> ¶ms) { return EVENT_CONTINUE; }
/** Called when botinfo metadata is read from the database
* @param bi The botinfo
* @param key The metadata key
* @param params The params from the database
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to stop processing
*/
virtual EventReturn OnDatabaseReadMetadata(BotInfo *bi, const std::string &key, const std::vector<std::string> ¶ms) { return EVENT_CONTINUE; }
/** Called when chaninfo metadata is read from the database
* @param ci The chaninfo
* @param key The metadata key
* @param params The params from the database
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to stop processing
*/
virtual EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const std::string &key, const std::vector<std::string> ¶ms) { return EVENT_CONTINUE; }
/** Called when we are writing metadata for a nickcore
* @param WriteMetata A callback function used to insert the metadata
* @param nc The nickcore
*/
virtual void OnDatabaseWriteMetadata(void (*WriteMetadata)(const std::string &, const std::string &), NickCore *nc) { }
/** Called when we are wrting metadata for a nickalias
* @param WriteMetata A callback function used to insert the metadata
* @param na The nick alias
*/
virtual void OnDatabaseWriteMetadata(void (*WriteMetadata)(const std::string &, const std::string &), NickAlias *na) { }
/** Called when we are writing metadata for a botinfo
* @param WriteMetata A callback function used to insert the metadata
* @param bi The botinfo
*/
virtual void OnDatabaseWriteMetadata(void (*WriteMetadata)(const std::string &, const std::string &), BotInfo *bi) { }
/** Called when are are writing metadata for a channelinfo
* @param WriteMetata A callback function used to insert the metadata
* @param bi The channelinfo
*/
virtual void OnDatabaseWriteMetadata(void (*WriteMetadata)(const std::string &, const std::string &), ChannelInfo *ci) { }
/** Called before services restart
*/
virtual void OnPreRestart() { }
/** Called when services restart
*/
virtual void OnRestart() { }
/** Called before services shutdown
*/
virtual void OnPreShutdown() { }
/** Called when services shutdown
*/
virtual void OnShutdown() { }
/** Called on signal
* @param msg The quitmsg
*/
virtual void OnSignal(const char *msg) { }
/** Called before a nick expires
* @param na The nick
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it
*/
virtual EventReturn OnPreNickExpire(NickAlias *na) { return EVENT_CONTINUE; }
/** Called when a nick drops
* @param nick The nick
*/
virtual void OnNickExpire(const char *nick) { }
/** Called when defcon level changes
* @param level The level
*/
virtual void OnDefconLevel(int level) { }
/** Called when a server quits
* @param server The server
*/
virtual void OnServerQuit(Server *server) { }
/** Called on a QUIT
* @param u The user
* @param msg The quit message
*/
virtual void OnUserQuit(User *u, const std::string &msg) { }
/** Called when a user disconnects
* @param u The user
*/
virtual void OnUserLogoff(User *u) { }
/** Called when a new bot is made
* @param bi The bot
*/
virtual void OnBotCreate(BotInfo *bi) { }
/** Called when a bot is changed
* @param bi The bot
*/
virtual void OnBotChange(BotInfo *bi) { }
/** Called when a bot is deleted
* @param bi The bot
*/
virtual void OnBotDelete(BotInfo *bi) { }
/** Called when access is deleted from a channel
* @param ci The channel
* @param u The user who removed the access
* @param nick The name of the user whos access was removed
*/
virtual void OnAccessDel(ChannelInfo *ci, User *u, const char *nick) { }
/** Called when access is changed
* @param ci The channel
* @param u The user who changed the access
* @param nick The nick whos access was changed
* @param level The level of the new access
*/
virtual void OnAccessChange(ChannelInfo *ci, User *u, const char *nick, int level) { }
/** Called when access is added
* @param ci The channel
* @param u The user who added the access
* @param nick The nick who was added to access
* @param level The level they were added at
*/
virtual void OnAccessAdd(ChannelInfo *ci, User *u, const char *nick, int level) { }
/** Called when the access list is cleared
* @param ci The channel
* @param u The user who cleared the access
*/
virtual void OnAccessClear(ChannelInfo *ci, User *u) { }
/** Called when a channel is dropped
* @param chname The channel name
*/
virtual void OnChanDrop(const char *chname) { }
/** Called when a channel is forbidden
* @param ci The channel
*/
virtual void OnChanForbidden(ChannelInfo *ci) { }
/** Called when a channel is registered
* @param ci The channel
*/
virtual void OnChanRegistered(ChannelInfo *ci) { }
/** Called when a channel is suspended
* @param ci The channel
*/
virtual void OnChanSuspend(ChannelInfo *ci) { }
/** Called when a channel is unsuspended
* @param ci The channel
*/
virtual void OnChanUnsuspend(ChannelInfo *ci) { }
/** Called when a channel is being deleted, for any reason
* @param ci The channel
*/
virtual void OnDelChan(ChannelInfo *ci) { }
/** Called when a new channel is created
* @param c The channel
*/
virtual void OnChannelCreate(Channel *c) { }
/** Called when a channel is deleted
* @param c The channel
*/
virtual void OnChannelDelete(Channel *c) { }
/** Called when a nick is dropped
* @param nick The nick
*/
virtual void OnNickDrop(const char *nick) { }
/** Called when a nick is forbidden
* @param na The nick alias of the forbidden nick
*/
virtual void OnNickForbidden(NickAlias *na) { }
/** Called when a user groups their nick
* @param u The user grouping
* @param target The target they're grouping to
*/
virtual void OnNickGroup(User *u, NickAlias *target) { }
/** Called when a user identifies
* @param u The user
*/
virtual void OnNickIdentify(User *u) { }
/** Called when a nick logs out
* @param u The nick
*/
virtual void OnNickLogout(User *u) { }
/** Called when a nick is registered
* @param The nick
*/
virtual void OnNickRegister(NickAlias *na) { }
/** Called when a nick is suspended
* @param na The nick alias
*/
virtual void OnNickSuspend(NickAlias *na) { }
/** Called when a nick is unsuspneded
* @param na The nick alias
*/
virtual void OnNickUnsuspended(NickAlias *na) { }
/** Called on finduser()
* @param u pointer to the user
*/
virtual void OnFindUser(User *u) { }
/** Called on findnick()
* @param nick nickname to be searched for
*/
virtual void OnFindNick(const std::string &nick) { }
/** Called on delnick()
* @ param na pointer to the nickalias
*/
virtual void OnDelNick(NickAlias *na) { }
/** Called on findcore()
* @param nick nickname to be searched for (nc->display)
*/
virtual void OnFindCore(const std::string &nick) { }
/** Called on delcore()
* @param nc pointer to the NickCore
*/
virtual void OnDelCore(NickCore *nc) { }
/** Called on change_core_display()
* @param nc pointer to the NickCore
* @param newdisplay the new display
*/
virtual void OnChangeCoreDisplay(NickCore *nc, const std::string &newdisplay) { }
/** Called on findrequestnick()
* @param nick nicname to be searched for
*/
virtual void OnFindRequestNick(const std::string &nick) { }
/** called from ns_register.c, after the NickRequest have been created
* @param nr pointer to the NickRequest
*/
virtual void OnMakeNickRequest(NickRequest *nr) { }
/** called on delnickrequest()
* @param nr pointer to the NickRequest
*/
virtual void OnDelNickRequest(NickRequest *nr) { }
/** called from NickCore::ClearAccess()
* @param nc pointer to the NickCore
*/
virtual void OnNickClearAccess(NickCore *nc) { }
/** called from NickCore::EraseAccess()
* @param nc pointer to the NickCore
* @param entry The access mask
*/
virtual void OnNickEraseAccess(NickCore *nc, const std::string &entry) { }
/** called when a vhost is deleted
* @param na The nickalias of the vhost
*/
virtual void OnDeleteVhost(NickAlias *na) { }
/** Called when a vhost is set
* @param na The nickalias of the vhost
*/
virtual void OnSetVhost(NickAlias *na) { }
/** Called when a mode is set on a channel
* @param c The channel
* @param Name The mode name
* @param param The mode param, if there is one
* @return EVENT_STOP to make mlock/secureops etc checks not happen
*/
virtual EventReturn OnChannelModeSet(Channel *c, ChannelModeName Name, const std::string ¶m) { return EVENT_CONTINUE; }
/** Called when a mode is unset on a channel
* @param c The channel
* @param Name The mode name
* @param param The mode param, if there is one
* @return EVENT_STOP to make mlock/secureops etc checks not happen
*/
virtual EventReturn OnChannelModeUnset(Channel *c, ChannelModeName Name, const std::string ¶m) { return EVENT_CONTINUE; }
/** Called when a mode is set on a user
* @param u The user
* @param Name The mode name
*/
virtual void OnUserModeSet(User *u, UserModeName Name) { }
/** Called when a mode is unset from a user
* @param u The user
* @param Name The mode name
*/
virtual void OnUserModeUnset(User *u, UserModeName Name) { }
/** Called when a channel mode is introducted into Anope
* @param cm The mode
*/
virtual void OnChannelModeAdd(ChannelMode *cm) { }
/** Called when a user mode is introducted into Anope
* @param um The mode
*/
virtual void OnUserModeAdd(UserMode *um) { }
/** Called when a mode is about to be mlocked
* @param Name The mode being mlocked
* @param status true if its being mlocked +, false for -
* @param param The param, if there is one and if status is true
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the mlock.
*/
virtual EventReturn OnMLock(ChannelModeName Name, bool status, const std::string ¶m) { return EVENT_CONTINUE; }
/** Called when a mode is about to be unlocked
* @param Name The mode being mlocked
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the mlock.
*/
virtual EventReturn OnUnMLock(ChannelModeName Name) { return EVENT_CONTINUE; }
/** Called after a module is loaded
* @param u The user loading the module, can be NULL
* @param m The module
*/
virtual void OnModuleLoad(User *u, Module *m) { }
/** Called before a module is unloaded
* @param u The user, can be NULL
* @param m The module
*/
virtual void OnModuleUnload(User *u, Module *m) { }
};
/** Implementation-specific flags which may be set in ModuleManager::Attach()
*/
enum Implementation
{
I_BEGIN,
/* NickServ */
I_OnNickServHelp, I_OnPreNickExpire, I_OnNickExpire, I_OnNickForbidden, I_OnNickGroup, I_OnNickLogout, I_OnNickIdentify, I_OnNickDrop,
I_OnNickRegister, I_OnNickSuspended, I_OnNickUnsuspended,
I_OnFindUser, I_OnFindNick, I_OnDelNick, I_OnFindCore, I_OnDelCore, I_OnChangeCoreDisplay,
I_OnFindRequestNick, I_OnDelNickRequest, I_OnMakeNickRequest, I_OnNickClearAccess, I_OnNickEraseAccess,
/* ChanServ */
I_OnChanServHelp, I_OnChanForbidden, I_OnChanSuspend, I_OnChanDrop, I_OnPreChanExpire, I_OnChanExpire, I_OnAccessAdd, I_OnAccessChange,
I_OnAccessDel, I_OnAccessClear, I_OnChanRegistered, I_OnChanUnsuspend, I_OnDelChan, I_OnChannelCreate,
I_OnChannelDelete,
/* BotServ */
I_OnBotServHelp, I_OnBotJoin, I_OnBotKick, I_OnBotCreate, I_OnBotChange, I_OnBotDelete, I_OnBotAssign, I_OnBotUnAssign,
I_OnUserKicked, I_OnBotFantasy, I_OnBotNoFantasyAccess, I_OnBotBan, I_OnBotPreLoad,
/* HostServ */
I_OnHostServHelp, I_OnSetVhost, I_OnDeleteVhost,
/* MemoServ */
I_OnMemoServHelp,
/* Users */
I_OnPreUserConnect, I_OnUserConnect, I_OnUserNickChange, I_OnUserQuit, I_OnUserLogoff, I_OnPreJoinChannel,
I_OnJoinChannel, I_OnPrePartChannel, I_OnPartChannel,
/* OperServ */
I_OnOperServHelp, I_OnDefconLevel,
/* Database */
I_OnPostLoadDatabases, I_OnSaveDatabase, I_OnLoadDatabase, I_OnBackupDatabase,
I_OnDatabaseExpire,
I_OnDatabaseWrite, I_OnDatabaseRead, I_OnDatabaseReadMetadata, I_OnDatabaseWriteMetadata,
/* Modules */
I_OnModuleLoad, I_OnModuleUnload,
/* Other */
I_OnReload, I_OnPreServerConnect, I_OnNewServer, I_OnServerConnect, I_OnPreCommandRun, I_OnPreCommand, I_OnPostCommand,
I_OnPreDatabaseExpire, I_OnPreRestart, I_OnRestart, I_OnPreShutdown, I_OnShutdown, I_OnSignal,
I_OnServerQuit, I_OnTopicUpdated,
I_OnEncrypt, I_OnEncryptInPlace, I_OnEncryptCheckLen, I_OnDecrypt, I_OnCheckPassword,
I_OnChannelModeSet, I_OnChannelModeUnset, I_OnUserModeSet, I_OnUserModeUnset, I_OnChannelModeAdd, I_OnUserModeAdd,
I_OnMLock, I_OnUnMLock,
I_END
};
/** Used to manage modules.
*/
class CoreExport ModuleManager
{
public:
/** Event handler hooks.
* This needs to be public to be used by FOREACH_MOD and friends.
*/
static std::vector<Module *> EventHandlers[I_END];
/** Load up a list of modules.
* @param module_list The list of modules to load
**/
static void LoadModuleList(std::list<std::string> &ModList);
/** Loads a given module.
* @param m the module to load
* @param u the user who loaded it, NULL for auto-load
* @return MOD_ERR_OK on success, anything else on fail
*/
static int LoadModule(const std::string &modname, User * u);
/** Unload the given module.
* @param m the module to unload
* @param u the user who unloaded it
* @return MOD_ERR_OK on success, anything else on fail
*/
static int UnloadModule(Module *m, User * u);
/** Change the priority of one event in a module.
* 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
* 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
* for a module.
* @param mod The module to change the priority of
* @param i The event to change the priority of
* @param s The state you wish to use for this event. Use one of
* 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
* to set it to be before or after one or more other modules.
* @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
* placed before or after. Your module will be placed before the highest priority module in this list for PRIO_BEFORE, or after the lowest
* priority module in this list for PRIO_AFTER.
* @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
* to be before or after one other module.
*/
static bool SetPriority(Module* mod, Implementation i, Priority s, Module** modules = NULL, size_t sz = 1);
/** Change the priority of all events in a module.
* @param mod The module to set the priority of
* @param s The priority of all events in the module.
* Note that with this method, it is not possible to effectively use PRIO_BEFORE or PRIO_AFTER, you should use the more fine tuned
* SetPriority method for this, where you may specify other modules to be prioritized against.
*/
static bool SetPriority(Module* mod, Priority s);
/** Attach an event to a module.
* You may later detatch the event with ModuleManager::Detach(). If your module is unloaded, all events are automatically detatched.
* @param i Event type to attach
* @param mod Module to attach event to
* @return True if the event was attached
*/
static bool Attach(Implementation i, Module* mod);
/** Detatch an event from a module.
* This is not required when your module unloads, as the core will automatically detatch your module from all events it is attached to.
* @param i Event type to detach
* @param mod Module to detach event from
* @param Detach true if the event was detached
*/
static bool Detach(Implementation i, Module* mod);
/** Detach all events from a module (used on unload)
* @param mod Module to detach from
*/
static void DetachAll(Module* mod);
/** Attach an array of events to a module
* @param i Event types (array) to attach
* @param mod Module to attach events to
*/
static void Attach(Implementation* i, Module* mod, size_t sz);
/** Delete all callbacks attached to a module
* @param m The module
*/
static void ClearCallBacks(Module *m);
private:
/** Call the module_delete function to safely delete the module
* @param m the module to delete
*/
static void DeleteModule(Module *m);
};
/** Class used for callbacks within modules
*/
class CallBack : public Timer
{
private:
Module *m;
public:
CallBack(Module *mod, long time_from_now, time_t now = time(NULL), bool repeating = false) : Timer(time_from_now, now, repeating), m(mod)
{
m->CallBacks.push_back(this);
}
virtual ~CallBack()
{
std::list<CallBack *>::iterator it = std::find(m->CallBacks.begin(), m->CallBacks.end(), this);
if (it != m->CallBacks.end())
{
m->CallBacks.erase(it);
}
}
};
struct ModuleHash_ {
char *name;
Module *m;
ModuleHash *next;
};
struct CommandHash {
char *name; /* Name of the command */
Command *c; /* Actual command */
CommandHash *next; /* Next command */
};
struct Message_ {
char *name;
int (*func)(const char *source, int ac, const char **av);
int core;
Message *next;
};
struct MessageHash_ {
char *name;
Message *m;
MessageHash *next;
};
/*************************************************************************/
/* Module Managment Functions */
MDE Module *findModule(const char *name); /* Find a module */
int protocol_module_init(); /* Load the IRCD Protocol Module up*/
/*************************************************************************/
/*************************************************************************/
/* Command Managment Functions */
MDE Command *findCommand(CommandHash *cmdTable[], const char *name); /* Find a command */
/*************************************************************************/
/* Message Managment Functions */
MDE Message *createMessage(const char *name,int (*func)(const char *source, int ac, const char **av));
Message *findMessage(MessageHash *msgTable[], const char *name); /* Find a Message */
MDE int addMessage(MessageHash *msgTable[], Message *m, int pos); /* Add a Message to a Message table */
MDE int addCoreMessage(MessageHash *msgTable[], Message *m); /* Add a Message to a Message table */
int delMessage(MessageHash *msgTable[], Message *m); /* Del a Message from a msg table */
int destroyMessage(Message *m); /* destroy a Message*/
/*************************************************************************/
MDE bool moduleMinVersion(int major,int minor,int patch,int build); /* Checks if the current version of anope is before or after a given verison */
/************************************************************************/
#endif
/* EOF */
|