Epiphanic Networks' Wikka : AthemeEvents

Home :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

Atheme Event System


This file is also available on Atheme's Wiki

NOTE: examples are from my memoserv system
ACHTUNG: I also have written far more C# than Java, so my documentation may use terms that are not from the C world, sorry
 


Certain functions in Atheme will fire "events" to the rest of the system upon their completion. For example, identify calls
hook_call_event("user_identify", mu); //char* and myuser_t*

on a successful identification. I wanted to consume this hook because I wanted my MemoServ to notice you of new memos on login. Using this hook as I did below is a far nicer solution than putting code in both userserv and nickserv, because potentially any service for ID that gets built will fire that event.

Type sig of event consumers:
static void on_user_identify(void *vptr); //ah yes... void pointer hack, kinda like passing Object in java

All hooks pass a myuser_t (as you can see from the second param in hook_call_event above)

In your _modinit:
hook_add_event("user_identify"); //we want user_identify to know we consume it
hook_add_hook("user_identify", on_user_identify); //we want to consume it with on_user_identify


Function:
static void on_user_identify(void *vptr)
{
    myuser_t *mu = vptr;
    if (mu->memoct_new > 0)
    {
        myuser_notice(memosvs.nick, mu, "You have %d new memo%s.",
            mu->memoct_new, (mu->memoct_new > 1) ? "" : "s");
    }
}


myuser_notice was just added by jilles and will take care of the fact that myuser_t and user_t are not mutually exclusive


CategoryAtheme

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.3
Page was generated in 0.0704 seconds