]>
jfr.im git - irc/quakenet/newserv.git/blob - nickwatch/nickwatch.c
0015d0209d9aae9fd98da3e5bf29ea61c5f4ef61
4 #include "../core/schedule.h"
5 #include "../control/control.h"
6 #include "../newsearch/newsearch.h"
7 #include "../newsearch/parser.h"
9 typedef struct nickwatch
{
17 struct nickwatch
*next
;
20 typedef struct nickwatchevent
{
21 char description
[128];
25 static nickwatch
*nickwatches
;
26 static int nextnickwatch
= 1;
28 static void nw_dummyreply(nick
*np
, char *format
, ...) { }
30 static void nw_dummywall(int level
, char *format
, ...) { }
32 static nickwatch
*nw_currentwatch
;
33 static nickwatchevent
*nw_currentevent
;
35 static void nw_printnick(searchCtx
*ctx
, nick
*sender
, nick
*np
) {
36 char hostbuf
[HOSTLEN
+NICKLEN
+USERLEN
+4];
38 nw_currentwatch
->hits
++;
40 controlwall(NO_OPER
, NL_HITS
, "nickwatch(#%d, %s): %s [%s] (%s) (%s)", nw_currentwatch
->id
, nw_currentevent
->description
, visiblehostmask(np
,hostbuf
),
41 IPtostr(np
->ipaddress
), printflags(np
->umodes
, umodeflags
), np
->realname
->name
->content
);
44 static nickwatchevent
*nwe_new(nick
*np
, const char *format
, ...) {
48 nwe
= malloc(sizeof(nickwatchevent
));
49 nwe
->numeric
= np
->numeric
;
52 vsnprintf(nwe
->description
, sizeof(nwe
->description
), format
, va
);
58 static void nwe_free(nickwatchevent
*nwe
) {
62 static void nw_sched_processevent(void *arg
) {
63 nickwatchevent
*nwe
= arg
;
67 np
= getnickbynumeric(nwe
->numeric
);
73 nw_currentevent
= nwe
;
75 for (nw
= nickwatches
; nw
; nw
= nw
->next
) {
77 ast_nicksearch(nw
->tree
->root
, &nw_dummyreply
, mynick
, &nw_dummywall
, &nw_printnick
, NULL
, NULL
, 10, np
);
83 static void nw_hook_newnick(int hooknum
, void *arg
) {
85 nickwatchevent
*nwe
= nwe_new(np
, "new user");
86 scheduleoneshot(0, nw_sched_processevent
, nwe
);
89 static void nw_hook_rename(int hooknum
, void *arg
) {
92 char *oldnick
= args
[1];
93 nickwatchevent
*nwe
= nwe_new(np
, "renamed from %s", oldnick
);
94 scheduleoneshot(0, nw_sched_processevent
, nwe
);
97 static void nw_hook_joinchannel(int hooknum
, void *arg
) {
99 channel
*cp
= args
[0];
101 nickwatchevent
*nwe
= nwe_new(np
, "join channel %s", cp
->index
->name
->content
);
102 scheduleoneshot(0, nw_sched_processevent
, nwe
);
105 static int nw_cmd_nickwatch(void *source
, int cargc
, char **cargv
) {
106 nick
*sender
= source
;
113 tree
= parse_string(reg_nicksearch
, cargv
[0]);
115 displaystrerror(controlreply
, sender
, cargv
[0]);
119 nw
= malloc(sizeof(nickwatch
));
120 nw
->id
= nextnickwatch
++;
121 snprintf(nw
->createdby
, sizeof(nw
->createdby
), "#%s", sender
->authname
);
123 strncpy(nw
->term
, cargv
[0], sizeof(nw
->term
));
124 nw
->tree
= parse_string(reg_nicksearch
, cargv
[0]);
125 nw
->next
= nickwatches
;
128 controlreply(sender
, "Done.");
133 static int nw_cmd_nickunwatch(void *source
, int cargc
, char **cargv
) {
134 nick
*sender
= source
;
135 nickwatch
**pnext
, *nw
;
143 for (pnext
= &nickwatches
; *pnext
; pnext
= &((*pnext
)->next
)) {
147 parse_free(nw
->tree
);
151 controlreply(sender
, "Done.");
156 controlreply(sender
, "Nickwatch #%d not found.", id
);
161 static int nw_cmd_nickwatches(void *source
, int cargc
, char **cargv
) {
162 nick
*sender
= source
;
165 controlreply(sender
, "ID Created By Hits Term");
167 for (nw
= nickwatches
; nw
; nw
= nw
->next
)
168 controlreply(sender
, "%-5d %-15s %-7d %s", nw
->id
, nw
->createdby
, nw
->hits
, nw
->term
);
170 controlreply(sender
, "--- End of nickwatches.");
176 registercontrolhelpcmd("nickwatch", NO_OPER
, 1, &nw_cmd_nickwatch
, "Usage: nickwatch <nicksearch term>\nAdds a nickwatch entry.");
177 registercontrolhelpcmd("nickunwatch", NO_OPER
, 1, &nw_cmd_nickunwatch
, "Usage: nickunwatch <#id>\nRemoves a nickwatch entry.");
178 registercontrolhelpcmd("nickwatches", NO_OPER
, 0, &nw_cmd_nickwatches
, "Usage: nickwatches\nLists nickwatches.");
180 registerhook(HOOK_NICK_NEWNICK
, &nw_hook_newnick
);
181 registerhook(HOOK_NICK_RENAME
, &nw_hook_rename
);
182 registerhook(HOOK_CHANNEL_CREATE
, &nw_hook_joinchannel
);
183 registerhook(HOOK_CHANNEL_JOIN
, &nw_hook_joinchannel
);
187 nickwatch
*nw
, *next
;
189 deregistercontrolcmd("nickwatch", &nw_cmd_nickwatch
);
190 deregistercontrolcmd("nickunwatch", &nw_cmd_nickunwatch
);
191 deregistercontrolcmd("nickwatches", &nw_cmd_nickwatches
);
193 deregisterhook(HOOK_NICK_NEWNICK
, &nw_hook_newnick
);
194 deregisterhook(HOOK_NICK_RENAME
, &nw_hook_rename
);
195 deregisterhook(HOOK_CHANNEL_CREATE
, &nw_hook_joinchannel
);
196 deregisterhook(HOOK_CHANNEL_JOIN
, &nw_hook_joinchannel
);
198 for (nw
= nickwatches
; nw
; nw
= next
) {
201 parse_free(nw
->tree
);