]>
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
];
24 releasechanindex(cip
);
27 static void wwc_hook_joincreate(int hooknum
, void *arg
) {
29 channel
*cp
= args
[0];
31 chanindex
**wchans
= np
->exts
[wwcnext
];
34 wchans
= calloc(sizeof(chanindex
*), WW_MAXCHANNELS
);
35 np
->exts
[wwcnext
] = wchans
;
38 wwc_refchannel(cp
->index
);
40 memmove(&wchans
[1], &wchans
[0], sizeof(chanindex
*) * (WW_MAXCHANNELS
- 1));
41 wchans
[0] = cp
->index
;
44 static void wwc_hook_lostnick(int hooknum
, void *arg
) {
46 chanindex
**wchans
= np
->exts
[wwcnext
];
52 for (i
= 0; i
< WW_MAXCHANNELS
; i
++) {
56 wwc_derefchannel(wchans
[i
]);
60 np
->exts
[wwcnext
] = NULL
;
63 static void wwc_hook_newrecord(int hooknum
, void *arg
) {
67 chanindex
**wchans
= np
->exts
[wwcnext
];
70 memset(ww
->channels
, 0, sizeof(ww
->channels
));
75 for (i
= 0; i
< WW_MAXCHANNELS
; i
++) {
79 wwc_refchannel(wchans
[i
]);
80 ww
->channels
[i
] = wchans
[i
];
84 static void wwc_hook_lostrecord(int hooknum
, void *arg
) {
88 for (i
= 0; i
< WW_MAXCHANNELS
; i
++) {
92 wwc_derefchannel(ww
->channels
[i
]);
97 wwcnext
= registernickext("whowas_channels");
98 wwccext
= registerchanext("whowas_channels");
100 registerhook(HOOK_CHANNEL_JOIN
, &wwc_hook_joincreate
);
101 registerhook(HOOK_CHANNEL_CREATE
, &wwc_hook_joincreate
);
102 registerhook(HOOK_NICK_LOSTNICK
, &wwc_hook_lostnick
);
103 registerhook(HOOK_WHOWAS_NEWRECORD
, &wwc_hook_newrecord
);
104 registerhook(HOOK_WHOWAS_LOSTRECORD
, &wwc_hook_lostrecord
);
108 releasenickext(wwcnext
);
109 releasechanext(wwccext
);
111 deregisterhook(HOOK_CHANNEL_JOIN
, &wwc_hook_joincreate
);
112 deregisterhook(HOOK_CHANNEL_CREATE
, &wwc_hook_joincreate
);
113 deregisterhook(HOOK_NICK_LOSTNICK
, &wwc_hook_lostnick
);
114 deregisterhook(HOOK_WHOWAS_NEWRECORD
, &wwc_hook_newrecord
);
115 deregisterhook(HOOK_WHOWAS_LOSTRECORD
, &wwc_hook_lostrecord
);