]>
jfr.im git - irc/quakenet/newserv.git/blob - whowas/whowas_channels.c
3 #include "../lib/version.h"
4 #include "../nick/nick.h"
5 #include "../chanindex/chanindex.h"
6 #include "../channel/channel.h"
7 #include "../core/hooks.h"
12 static int wwcnext
, wwccext
;
14 static void wwc_refchannel(chanindex
*cip
) {
15 uintptr_t *refcount
= (uintptr_t *)&cip
->exts
[wwccext
];
19 static void wwc_derefchannel(chanindex
*cip
) {
20 uintptr_t *refcount
= (uintptr_t *)&cip
->exts
[wwccext
];
23 assert(*refcount
>= 0);
26 releasechanindex(cip
);
29 static void wwc_hook_joincreate(int hooknum
, void *arg
) {
31 channel
*cp
= args
[0];
33 chanindex
**wchans
= np
->exts
[wwcnext
];
36 wchans
= calloc(sizeof(chanindex
*), WW_MAXCHANNELS
);
37 np
->exts
[wwcnext
] = wchans
;
40 wwc_refchannel(cp
->index
);
42 memmove(&wchans
[1], &wchans
[0], sizeof(chanindex
*) * (WW_MAXCHANNELS
- 1));
43 wchans
[0] = cp
->index
;
46 static void wwc_hook_lostnick(int hooknum
, void *arg
) {
48 chanindex
**wchans
= np
->exts
[wwcnext
];
54 for (i
= 0; i
< WW_MAXCHANNELS
; i
++) {
58 wwc_derefchannel(wchans
[i
]);
64 static void wwc_hook_newrecord(int hooknum
, void *arg
) {
68 chanindex
**wchans
= np
->exts
[wwcnext
];
71 memset(ww
->channels
, 0, sizeof(ww
->channels
));
76 for (i
= 0; i
< WW_MAXCHANNELS
; i
++) {
80 wwc_refchannel(wchans
[i
]);
81 ww
->channels
[i
] = wchans
[i
];
85 static void wwc_hook_lostrecord(int hooknum
, void *arg
) {
89 for (i
= 0; i
< WW_MAXCHANNELS
; i
++) {
93 wwc_derefchannel(ww
->channels
[i
]);
98 wwcnext
= registernickext("whowas_channels");
99 wwccext
= registerchanext("whowas_channels");
101 registerhook(HOOK_CHANNEL_JOIN
, &wwc_hook_joincreate
);
102 registerhook(HOOK_CHANNEL_CREATE
, &wwc_hook_joincreate
);
103 registerhook(HOOK_NICK_LOSTNICK
, &wwc_hook_lostnick
);
104 registerhook(HOOK_WHOWAS_NEWRECORD
, &wwc_hook_newrecord
);
105 registerhook(HOOK_WHOWAS_LOSTRECORD
, &wwc_hook_lostrecord
);
109 releasenickext(wwcnext
);
110 releasechanext(wwccext
);
112 deregisterhook(HOOK_CHANNEL_JOIN
, &wwc_hook_joincreate
);
113 deregisterhook(HOOK_CHANNEL_CREATE
, &wwc_hook_joincreate
);
114 deregisterhook(HOOK_NICK_LOSTNICK
, &wwc_hook_lostnick
);
115 deregisterhook(HOOK_WHOWAS_NEWRECORD
, &wwc_hook_newrecord
);
116 deregisterhook(HOOK_WHOWAS_LOSTRECORD
, &wwc_hook_lostrecord
);