summaryrefslogtreecommitdiff
path: root/docs/EVENTS
blob: 55184c1033b96c0fc97ef72a22a0c8ca91107cc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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
Anope Internal Events
---------------------

1) Intro
2) Complex Events
3) Triggered Events
4) Triggered Events List

1) Introduction to Internal Events

    Internal Events are setup to give module developers more information
    about what the core is doing at different times. This information can
    be as complex as data we are feeding to the uplink, to simple triggered
    events such as the databases being saved. A list of triggered  events
    can be found below. Additional there is a module included with the core
    which can  provide some clue as to how to use the code in your modules.
    The rest of this document assumes that you are used to writing modules.

2) Complex Events

    This type of events are based around what happens when we talk to the
    IRCd, much like MESSAGE events that the IRCD sends to us. The events
    are triggered when Anope writes to the ircd. To watch for these events
    you must have some knowledge of how the IRCd command system works. In
    our example we will trap for NICK events.

    A) All functions most be formatted as:

        int functioname(char *source, int ac, char **av);

    B) In AnopeInit you must declare EvtMessage in some fashion, it is into
       this variable that we will create the event handler. Here is what the
       base AnopeInit should look like at this point:
 
        int AnopeInit(int argc, char **argv)
        {
            EvtMessage *msg = NULL;
            int status;

            moduleAddAuthor(AUTHOR);
            moduleAddVersion(VERSION);
            return MOD_CONT;
        }

       Note that AUTHOR and VERSION should be defined above the AnopeInit
       function, just like you should do with any module.

    C) Pass "createEventHandler" the name of the message in this case NICK,
       and the function that was created in Step A. At this point you should
       assign the return of "createEventHandler" to the EvtMessage variable.

        msg = createEventHandler("NICK", my_nick);

    D) The Handler is not ready for use yet; now you must add it to the hash
       with "moduleAddEventHandler". You will want to pass to this function
       the return of "createEventHandler".

        status = moduleAddEventHandler(msg);

       It will return the same module error codes as adding a regular message,
       which you can use to confirm it was added correctly.

    E) With that setup in your function you will be passed 3 items. The source
       most of the time this will be set to ServerName or NULL; consult our
       IRCd documentation about how messages are formatted. AC is the count of
       variables you will find in AV.

        int my_nick(char *source, int ac, char **av)
        {
            alog("Internal Event - nick is %s",av[0]);
            return MOD_CONT;
        }

3) Triggered Events

    These events also known as "event hooks" are internal events such as
    expiring of nicks to the saving of databases.

    A) All functions most be formatted as:

        int functioname(int argc, char **argv);

    B) In AnopeInit you must declare EvtHook in some fashion; it is into
       this variable that we will create the event handler. Here is what
       the base AnopeInit should look like at this point:
 
        int AnopeInit(int argc, char **argv)
        {
            EvtHook *hook = NULL;
            int status;

            moduleAddAuthor(AUTHOR);
            moduleAddVersion(VERSION);
            return MOD_CONT;
        }

    C) Pass "createEventHook" the name of the event. In this case we are
       going to hook to the saving of databases, "EVENT_DB_SAVING".

        hook = createEventHook(EVENT_DB_SAVING, my_save);

    D) The Handler is not ready for use yet; now you must add it to the hash
       with "moduleAddEventHook". You will want to pass to this function the
       return of "createEventHook"

        status = moduleAddEventHook(hook);

       It will return the same module error codes as adding a regular message,
       which you can use to confirm it was added correctly.

    E) With that setup in your function you will be passed 1 item. The message
       is very simple; it could be as simple as a start, stop or message. In
       the case of saving it has a start and stop.

        int my_save(int argc, char **argv)
        {
            if (argc < 1) {
                return MOD_CONT;
            }

            if (!stricmp(argv[0], EVENT_START)) {
                alog("Saving the databases! has started");
            } else {
                alog("Saving the databases is complete");
            }
            return MOD_CONT;
        }

4) Triggered Events List

    Here's a list of all event hooks we currently offer, with a description
    of what argument is being passed to the event functions for this type of
    event. All arguments are plain-text strings (char *). The list is sorted
    in alphabetical order.

    Note that all events are emitted AFTER the action has taken place, so
    any deleted nick/channel/etc won't exist anymore and any created one will
    exist when your function is being run, unless noted otherwise.

    Also note that EVENT_START and EVENT_STOP should not be matched with an
    equal sign, but with string comparision. See the bundled events module for
    an example on how to do this.

    The arguments are given as av[0] for the first argument, av[1] for the
    second argument, and so on. If av[0] and av[1] are given, the event has
    two arguments, and argc should be 2.

    EVENT_ACCESS_ADD
        An user has been added to a channel access list.
        av[0]  Name of the channel the user has been added to.
        av[1]  The nickname of the user that has just added an entry to the
               access list.
        av[2]  The nickname of the user that has been added to the access
               list.
        av[3]  The level number the user has been added with.

    EVENT_ACCESS_CHANGE
        An user level has been changed on a channel access list.
        av[0]  Name of the channel the access list has been modified which.
        av[1]  The nickname of the user that has just modified the access
               list of the channel.
        av[2]  The nickname of the user wich his access level has just been
               modified.
        av[3]  The new access level for the user.

    EVENT_ACCESS_CLEAR
        A channel access list has been cleared.
        av[0]  Name of the channel the access list has been cleared of
        av[1]  The nickname of the user that has cleared the access list

    EVENT_ACCESS_DEL
        An user has been deleted of a channel access list.
        av[0]  Name of the channel the access entry has been deleted which.
        av[1]  The nickname of the user that has just deleted the access entry.
        av[2]  [OPTIONAL] The nickname of the user wich his access level has just
               been removed. Not present if numbers were used (e.g. /cs access
               del 7).

    EVENT_BOT_ASSIGN
        A BotServ bot has been assigned to a channel.
        av[0]  Name of the channel the bot has been assigned to.
        av[1]  The nickname of the bot that has been assigned to the channel.

    EVENT_BOT_BAN
        A BotServ bot has banned a user, e.g. kickers.
        av[0]  The nick of the user banned.
        av[1]  The Channel the user was banned from.
        av[2]  The mask that was banned.

    EVENT_BOT_CHANGE
        The properties of a BotServ bot have been changed.
        av[0]  The nickname of the bot involved.

    EVENT_BOT_CREATE
        A new BotServ bot has been created, and is ready to use.
        av[0]  The nickname of the newly created bot.

    EVENT_BOT_DEL
        A BotServ bot is being deleted from BotServ. This event is being sent
        just before the actual deletion is performed.
        av[0]  The nickname of the bot being deleted.

    EVENT_BOT_FANTASY
        A fantasy command of the bot has been triggered. This event should be
        used to create your own fantasy commands.
        av[0]  The fantasy command that has been triggered without leading '!'.
        av[1]  The nickname of the user that has triggered the fantasy
               command.
        av[2]  The name of the channel the fantasy command has been triggered
               on.
        av[3]  Contains any optional paramenters passed after the fantasy
               command. If none are present, this will not exist, and argc will
               will be 3.

    EVENT_BOT_FANTASY_NO_ACCESS
        A fantasy command of the bot has been triggered by someone without
        access to BotServ FANTASY commands on the channel. This will NOT
        trigger if someone with access has triggered a fantasy command; use
        EVENT_BOT_FANTASY for those. Hook to both events to catch both event
        triggers.
        av[0]  The fantasy command that has been triggered without leading '!'.
        av[1]  The nickname of the user that has triggered the fantasy
               command.
        av[2]  The name of the channel the fantasy command has been triggered
               on.
        av[3]  Contains any optional paramenters passed after the fantasy
               command. If none are present, this will not exist, and argc will
               will be 3.

    EVENT_BOT_JOIN
        A BotServ bot has joined a channel and opped itself.
        av[0]  The channel name the bot has just joined.
        av[1]  The nickname of the bot that has joined the channel.

    EVENT_BOT_KICK
        A BotServ bot has kicked a user from a channel.
        av[0]  The name of the user that has been kicked.
        av[1]  The name of the channel the user was kicked from.
        av[2]  The reason for the kick.

    EVENT_BOT_UNASSIGN
        A BotServ bot is being unassigned from a channel. This event is being
        sent before the actual removing of the bot is done.
        av[0]  The channel name the bot has been unassigned from.
        av[1]  The nickname of the bot that has been unassigned.

    EVENT_CHAN_DROP
        A channel has been dropped and deleted.
        av[0]  The name of the channel that has been dropped.

    EVENT_CHAN_EXPIRE
        A channel has been expired and will be deleted. The event will be
        emitted just before the actual channel deletion happens.
        av[0]  The name of the channel that has been expired.

    EVENT_CHAN_FORBIDDEN
        A channel has been forbidden (ChanServ FORBID).
        av[0]  The name of the channel that has been forbidden.

    EVENT_CHAN_KICK
        Someone has just been kicked from a channel.
        av[0]  The nick of the user that has been kicked.
        av[1]  The channel the user has been kicked from.

    EVENT_CHAN_REGISTERED
        A new channel has been registered.
        av[0]  The name of the channel that has been registered.

    EVENT_NICK_REQUESTED
        A new nick has been requested, and mail has been sent to confirm the nick.
        av[0]  The name of the nick that was requested

    EVENT_CHAN_SUSPENDED
        A channel has been suspended (ChanServ SUSPEND).
        av[0]  The name of the channel that has been suspended.

    EVENT_CHAN_UNSUSPEND
        A channel has been unsuspended (ChanServ UNSUSPEND).
        av[0]  The name of the channel that has been unsuspended.

    EVENT_CHANGE_NICK
        A user has just changed its nick.
        av[0]  The new nickname of the user. Event is called after the user has been changed
               to this nickname.
        av[1]  The old nickname of the user.

    EVENT_CONNECT
        This event is emitted when the connection to our uplink hub is being
        made.
        av[0]  EVENT_START or EVENT_STOP, to indicate if it's emitted before
               or after the connection has been made. EVENT_STOP is emitted
               before our burst is being sent over the link.

    EVENT_DB_EXPIRE
        This event is emitted when the expiry routines for all things that can
        expire in Anope are being run.
        av[0]  EVENT_START or EVENT_STOP, to indicate if it's being emitted
               before or after the expiry routines have been run.

    EVENT_DB_SAVING
        This event is emitted when the databases are being saved.
        av[0]  EVENT_START or EVENT_STOP, to indicate if it's emitted before
               or after the saving routines have been run.

    EVENT_DB_BACKUP
        This event is emitted when the databases are backed up.
        av[0]  EVENT_START when the backup commences, and EVENT_STOP when it
               finishes.

    EVENT_DEFCON_LEVEL
        The DefCon level has just been changed. This event is emitted before
        any DefCon-related action is taken. The internal DefConLevel has
        already been raised at this point.
        av[0]  The new level of DefCon being invoked.

    EVENT_GROUP
        A user has grouped its nickname to another user group.
        av[0]  The nickname of the user that joined the group.

    EVENT_JOIN_CHANNEL
        A user joins a channel.
        av[0]  EVENT_START or EVENT_STOP. EVENT_START when the user has passed
               all access checks and is allowed to join, but has not yet
               joined the channel. EVENT_STOP when the user has joined and all
               needed modes are set etc.
        av[1]  The nickname of the user joining the channel.
        av[2]  The name of the channel the user has joined.

    EVENT_NEWNICK
        A new user has been introduced on the network.
        av[0]  The nickname of the newly introduced user.

    EVENT_NICK_DROPPED
        A user's nick has just been dropped. Note that the nickname information
        has already been deleted!
        av[0]  The nickname of the user that has just been dropped.

    EVENT_NICK_EXPIRE
        A user's nick has just expired. Note that, as with EVENT_NICK_DROPPED,
        the nickname information has already been deleted!
        av[0]  The nickname of the user that has just expired.

    EVENT_NICK_FORBIDDEN
        A user's nick has just been forbidden.
        av[0]  The nickname that has just been forbidden.

    EVENT_CORE_DROPPED
        A NickCore will be dropped. Usually send when the last alias is dopped.
        This is send BEFORE the event that confirms deletion of the alias.
        Note that this event is send before the core data is removed.
        av[0]  The display nickname of the core that is being dropped.

    EVENT_CORE_NEWDISPLAY
        The display nick of a NickCore is being changed.
        This is send BEFORE the actual change is made in the database.
        av[0]  The old display nickname of the core.
        av[1]  The new display nickname of the core.

    EVENT_NICK_GHOSTED
        A user has just been ghosted.
        av[0]  EVENT_START or EVENT_STOP. EVENT_START when the user is about
               to be removed from the network, EVENT_STOP when this has been
               done.
        av[1]  The nickname of the user doing the ghosting.
        av[2]  The nickname being ghosted.

    EVENT_NICK_IDENTIFY
        A user has just identified for its nickname with NickServ.
        av[0]  The nickname of the user that just identified.

    EVENT_NICK_LOGOUT
        A user has just (been) logged out.
        av[0]  The nickname of the user that has (been) logged out.

    EVENT_NICK_RECOVERED
        A user's nickname has just been recovered.
        av[0]  EVENT_START or EVENT_STOP. EVENT_START when the user is about
               to be recovered, EVENT_STOP when this has been done.
        av[1]  The nickname of the user doing the recovery.
        av[2]  The nickname being recovered.

    EVENT_NICK_REGISTERED
        A new user has just registered its nickname. This event is being
        emitted when the registration is completed, but the user modes have not
        yet been set.
        av[0]  The nickname of the newly registered user.

    EVENT_NICK_SUSPENDED
        A user's nick has just been suspended.
        av[0]  The nickname that has just been suspended.

    EVENT_NICK_UNSUSPEND
        A user's nick has just been unsuspended.
        av[0]  The nickname that has just been unsuspended.

    EVENT_PART_CHANNEL
        A user parts a channel.
        av[0]  EVENT_START or EVENT_STOP. EVENT_START when the user is about
               to be removed from the channel internally, EVENT_STOP when
               this has been done.
        av[1]  The nickname of the user parting the channel.
        av[2]  The name of the channel the user has parted.
        av[3]  The reason the user parted the channel, this is not always sent
               so check the count to make sure it was passed. (ac == 4)

    EVENT_RELOAD
        This event is emitted after the configuration file has been reloaded.
        av[0]  Always EVENT_START.

    EVENT_RESTART
        This event is emitted before the services are being restarted.
        av[0]  Always EVENT_START.

    EVENT_SERVER_CONNECT
        A new server has just connected to the network.
        av[0]  The name of the new server.

    EVENT_SERVER_SQUIT
        A server has sent an SQUIT and is about to be removed from the
        network. This event is being sent before the server is actually
        removed from the network.
        av[0]  The name of the server that is being removed.

    EVENT_SHUTDOWN
        This event is emitted when Anope is being shut down.
        av[0]  EVENT_START or EVENT_STOP, to indicate where in the process of
               restarting the core is. With EVENT_START, services are still
               fully online and operating. With EVENT_STOP, every internal
               clean up has been done already, and the SQUIT has been sent;
               the only thing done after emitting the event is closing the
               socket to the uplink hub.

    EVENT_SIGNAL
        This event is emitted when Anope is quitting because of a signal it
        received.
        av[0]  The quit message that will be sent with the SQUIT for this
               shutdown.

    EVENT_TOPIC_UPDATED
        A channel topic has been succesfully updated. Note that this event is
        only emitted if the new topic has been fully accepted and set by the
        Anope core.
        av[0]  The name of the channel involved.
        av[1]  The new topic set on the channel.

    EVENT_USER_LOGOFF
        A user has left the network. This event is emitted before the internal
        removal is performed, so the user still exists internally.
        av[0]  The nickname of the user leaving the network.

    EVENT_MODLOAD
        A module has been loaded. This event is emitted after the loading
        sequence has been finished: AnopeInit() has been called and the
        module has already been added to the modules table.
        av[0] Name of the loaded module.

    EVENT_MODUNLOAD
        A module has been unloaded. This event is emitted when the unloading
        sequence is almost complete: AnopeFini() has been called and all
        commands, hooks and callbacks have been removed. The module itself
        is still in memory however.
        av[0] Name of the unloaded module.

    EVENT_ADDCOMMAND
        A command hook has been added to anopes command table.
        Note that the command may have previously existed and merely a new hook
        was added before or after an existing command hook.
        av[0] Name of the module adding the command.
        av[1] Name of the command hook that was added.

    EVENT_DELCOMMAND
        A command hook has been removed from anopes command table.
        Note that the command may still exist in anopes command table if other
        modules have hooks for the same command.
        av[0] Name of the module deleting the command.
        av[1] Name of the command hook that was removed.