]>
Commit | Line | Data |
---|---|---|
91ccda4f EK |
1 | #include <stdinc.h> |
2 | #include <modules.h> | |
3 | #include <msgbuf.h> | |
4 | #include <client.h> | |
5 | #include <hash.h> | |
6 | #include <send.h> | |
7 | #include <s_serv.h> | |
8 | ||
9 | static const char inv_notify_desc[] = "Notifies channel on /invite and provides the invite-notify client capability"; | |
10 | ||
11 | static void hook_invite(void *); | |
12 | static void m_invited(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
13 | static unsigned int CAP_INVITE_NOTIFY; | |
14 | ||
15 | mapi_hfn_list_av1 inv_notify_hfnlist[] = { | |
c500b0bd | 16 | { "invite", hook_invite, HOOK_MONITOR }, |
91ccda4f EK |
17 | { NULL, NULL } |
18 | }; | |
19 | ||
20 | struct Message invited_msgtab = { | |
21 | "INVITED", 0, 0, 0, 0, | |
22 | {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {m_invited, 4}, mg_ignore} | |
23 | }; | |
24 | ||
25 | mapi_cap_list_av2 inv_notify_caplist[] = { | |
26 | { MAPI_CAP_CLIENT, "invite-notify", NULL, &CAP_INVITE_NOTIFY }, | |
27 | { 0, NULL, NULL, NULL } | |
28 | }; | |
29 | ||
30 | mapi_clist_av1 inv_notify_clist[] = { &invited_msgtab, NULL }; | |
31 | ||
32 | static void | |
33 | invite_notify(struct Client *source, struct Client *target, struct Channel *channel) | |
34 | { | |
35 | sendto_channel_local_with_capability(source, CHFL_CHANOP, 0, CAP_INVITE_NOTIFY, channel, | |
36 | ":%s NOTICE %s :%s is inviting %s to %s.", | |
37 | me.name, channel->chname, source->name, target->name, channel->chname); | |
38 | sendto_channel_local_with_capability(source, CHFL_CHANOP, CAP_INVITE_NOTIFY, 0, channel, | |
39 | ":%s!%s@%s INVITE %s %s", source->name, source->username, | |
40 | source->host, target->name, channel->chname); | |
41 | } | |
42 | ||
43 | static void | |
44 | hook_invite(void *data_) | |
45 | { | |
46 | hook_data_channel_approval *data = data_; | |
47 | ||
48 | if (data->approved) | |
49 | /* Don't notify if another hook is rejecting the invite. | |
50 | * This won't work if the other hook is after us... but really, it's | |
51 | * the thought that counts. | |
52 | */ | |
53 | return; | |
54 | ||
55 | sendto_server(NULL, NULL, CAP_TS6 | CAP_ENCAP, 0, "ENCAP * INVITED %s %s %s", | |
56 | use_id(data->client), use_id(data->target), | |
57 | data->chptr->chname); | |
58 | invite_notify(data->client, data->target, data->chptr); | |
59 | } | |
60 | ||
61 | static void | |
62 | m_invited(struct MsgBuf *msgbuf, struct Client *client_p, struct Client *source_p, int parc, const char **parv) | |
63 | { | |
64 | struct Client *inviter = find_person(parv[1]); | |
65 | struct Client *target = find_person(parv[2]); | |
66 | struct Channel *chptr = find_channel(parv[3]); | |
67 | ||
68 | if (inviter == NULL || target == NULL || chptr == NULL) | |
69 | return; | |
70 | ||
71 | invite_notify(inviter, target, chptr); | |
72 | } | |
73 | ||
74 | DECLARE_MODULE_AV2("invite_notify", NULL, NULL, inv_notify_clist, NULL, inv_notify_hfnlist, inv_notify_caplist, NULL, inv_notify_desc); |