mirror of
https://github.com/anope/anope.git
synced 2026-06-26 15:16:38 +02:00
03573ab139
git-svn-id: svn://svn.anope.org/anope/trunk@588 31f1291d-b8d6-0310-a050-a5561fc1590b git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@438 5417fbe8-f217-4b02-8779-1006273d7864
168 lines
7.2 KiB
Plaintext
168 lines
7.2 KiB
Plaintext
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(char *message);
|
|
|
|
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(char *source)
|
|
{
|
|
if (!stricmp(source, 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.
|
|
|
|
Note that all events are emitted AFTER the action has taken place, so
|
|
any deleted nick/channel/etc won't exist anymore when your function is
|
|
being run.
|
|
|
|
|------------------------|-------------------------------------------|
|
|
| Event Hook | Event Argument |
|
|
|------------------------|-------------------------------------------|
|
|
| EVENT_DB_SAVING | EVENT_START, EVENT_STOP |
|
|
| EVENT_NEWNICK | Nick that just connected to the network |
|
|
| EVENT_BOT_UNASSIGN | Channel name the bot is on |
|
|
| EVENT_BOT_JOIN | Channel name the bot is on |
|
|
| EVENT_BOT_CREATE | Nick of the bot involved |
|
|
| EVENT_BOT_CHANGE | Nick of the bot involved |
|
|
| EVENT_BOT_DEL | Nick of the bot involved |
|
|
| EVENT_BOT_ASSIGN | Nick of the bot involved |
|
|
| EVENT_TOPIC_UPDATED | Channel name of the channel involved |
|
|
| EVENT_CHAN_EXPIRE | Channel name of the channel involved |
|
|
| EVENT_CHAN_REGISTERED | Channel name of the channel involved |
|
|
| EVENT_CHAN_DROP | Channel name of the channel involved |
|
|
| EVENT_CHAN_FORBIDDEN | Channel name of the channel involved |
|
|
| EVENT_CHAN_SUSPENDED | Channel name of the channel involved |
|
|
| EVENT_CONNECT | EVENT_START, EVENT_STOP |
|
|
| EVENT_DB_EXPIRE | EVENT_START, EVENT_STOP |
|
|
| EVENT_RESTART | EVENT_START |
|
|
| EVENT_SHUTDOWN | EVENT_START, EVENT_STOP |
|
|
| EVENT_SIGNAL | Quit message sent |
|
|
| EVENT_NICK_REGISTERED | Nick of the account involved |
|
|
| EVENT_NICK_DROPPED | Nick of the account involved |
|
|
| EVENT_NICK_FORBIDDEN | Nick of the account involved |
|
|
| EVENT_NICK_EXPIRE | Nick of the account involved |
|
|
| EVENT_CHANGE_NICK | Nick of the user involved |
|
|
| EVENT_USER_LOGOFF | Nick of the user involved |
|
|
| EVENT_GROUP | Nick of the user involved |
|
|
| EVENT_NICK_IDENTIFY | Nick of the user involved |
|
|
| EVENT_SERVER_SQUIT | Name of the server involved |
|
|
| EVENT_SERVER_CONNECT | Name of the server involved |
|
|
|------------------------|-------------------------------------------|
|