]>
jfr.im git - irc/quakenet/newserv.git/blob - patrol/patrol_commands.c
1 #include "../core/schedule.h"
2 #include "../control/control.h"
3 #include "../localuser/localuserchannel.h"
4 #include "../lib/version.h"
5 #include "../lib/irc_string.h"
10 typedef struct patrolchannel
{
14 struct patrolchannel
*next
;
17 static patrolchannel
*patrolchannels
;
19 static void patroluserhandler(nick
*np
, int event
, void **args
) {
22 if (event
== LU_KILLED
) {
23 for (pc
= patrolchannels
; pc
; pc
= pc
->next
) {
32 static void pc_check(void) {
36 for (pc
= patrolchannels
; pc
; pc
= pc
->next
) {
37 if (pc
->nick
&& pc
->nick
->timestamp
> getnettime() - 900)
41 deregisterlocaluser(pc
->nick
, NULL
);
43 cp
= findchannel(pc
->channel
->content
);
50 pc
->nick
= patrol_generateclone(0, patroluserhandler
);
51 localjoinchannel(pc
->nick
, cp
);
55 static void pc_sched_check(void *arg
) {
59 static int pc_join(char *name
) {
60 patrolchannel
*pc
= NULL
;
63 for (pc
= patrolchannels
; pc
; pc
= pc
->next
)
64 if (ircd_strcmp(pc
->channel
->content
, name
) == 0)
67 cp
= findchannel(name
);
72 pc
= malloc(sizeof(patrolchannel
));
74 pc
->channel
= getsstring(name
, 512);
77 pc
->next
= patrolchannels
;
85 static int pc_part(char *name
) {
86 patrolchannel
**pnext
, *pc
;
88 for (pnext
= &patrolchannels
; *pnext
; pnext
= &((*pnext
)->next
)) {
91 if (ircd_strcmp(pc
->channel
->content
, name
) == 0) {
92 freesstring(pc
->channel
);
95 deregisterlocaluser(pc
->nick
, NULL
);
107 static int pc_cmd_patroljoin(void *source
, int cargc
, char **cargv
) {
108 nick
*sender
= source
;
113 if (pc_join(cargv
[0]) < 0) {
114 controlreply(sender
, "Could not join channel.");
119 controlreply(sender
, "Done.");
124 static int pc_cmd_patrolpart(void *source
, int cargc
, char **cargv
) {
125 nick
*sender
= source
;
130 if (pc_part(cargv
[0]) < 0) {
131 controlreply(sender
, "Could not join channel.");
136 controlreply(sender
, "Done.");
141 static int pc_cmd_patrollist(void *source
, int cargc
, char **cargv
) {
142 nick
*sender
= source
;
145 for (pc
= patrolchannels
; pc
; pc
= pc
->next
)
146 controlreply(sender
, "%s - %s", pc
->channel
->content
, pc
->nick
? controlid(pc
->nick
) : "Not currently joined.");
148 controlreply(sender
, "End of list.");
154 registercontrolhelpcmd("patroljoin", NO_OPER
, 1, &pc_cmd_patroljoin
, "Usage: patroljoin <channel>\nJoins a patrol client to a channel.");
155 registercontrolhelpcmd("patrolpart", NO_OPER
, 1, &pc_cmd_patrolpart
, "Usage: patrolpart <#id>\nRemoves a patrol client from a channel.");
156 registercontrolhelpcmd("patrollist", NO_OPER
, 0, &pc_cmd_patrollist
, "Usage: patrollist\nLists patrol channels.");
158 schedulerecurring(time(NULL
) + 5, 0, 10, &pc_sched_check
, NULL
);
162 patrolchannel
*pc
, *next
;
164 deregistercontrolcmd("patroljoin", &pc_cmd_patroljoin
);
165 deregistercontrolcmd("patrolpart", &pc_cmd_patrolpart
);
166 deregistercontrolcmd("patrollist", &pc_cmd_patrollist
);
168 deleteallschedules(&pc_sched_check
);
170 for (pc
= patrolchannels
; pc
; pc
= next
) {
173 freesstring(pc
->channel
);
176 deregisterlocaluser(pc
->nick
, NULL
);