]>
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
) {
20 /* Nothing to do here. */
23 static void pc_check(void) {
27 for (pc
= patrolchannels
; pc
; pc
= pc
->next
) {
28 if (pc
->nick
&& pc
->nick
->timestamp
> getnettime() - 900)
32 deregisterlocaluser(pc
->nick
, NULL
);
34 cp
= findchannel(pc
->channel
->content
);
41 pc
->nick
= patrol_generateclone(0, patroluserhandler
);
42 localjoinchannel(pc
->nick
, cp
);
46 static void pc_sched_check(void *arg
) {
50 static int pc_join(char *name
) {
51 patrolchannel
*pc
= NULL
;
54 for (pc
= patrolchannels
; pc
; pc
= pc
->next
)
55 if (ircd_strcmp(pc
->channel
->content
, name
) == 0)
58 cp
= findchannel(name
);
63 pc
= malloc(sizeof(patrolchannel
));
65 pc
->channel
= getsstring(name
, 512);
68 pc
->next
= patrolchannels
;
76 static int pc_part(char *name
) {
77 patrolchannel
**pnext
, *pc
;
79 for (pnext
= &patrolchannels
; *pnext
; pnext
= &((*pnext
)->next
)) {
82 if (ircd_strcmp(pc
->channel
->content
, name
) == 0) {
83 freesstring(pc
->channel
);
84 deregisterlocaluser(pc
->nick
, NULL
);
96 static int pc_cmd_patroljoin(void *source
, int cargc
, char **cargv
) {
97 nick
*sender
= source
;
102 if (pc_join(cargv
[0]) < 0) {
103 controlreply(sender
, "Could not join channel.");
108 controlreply(sender
, "Done.");
113 static int pc_cmd_patrolpart(void *source
, int cargc
, char **cargv
) {
114 nick
*sender
= source
;
119 if (pc_part(cargv
[0]) < 0) {
120 controlreply(sender
, "Could not join channel.");
125 controlreply(sender
, "Done.");
130 static int pc_cmd_patrollist(void *source
, int cargc
, char **cargv
) {
131 nick
*sender
= source
;
134 for (pc
= patrolchannels
; pc
; pc
= pc
->next
)
135 controlreply(sender
, "%s - %s", pc
->channel
->content
, pc
->nick
? controlid(pc
->nick
) : "Not currently joined.");
137 controlreply(sender
, "End of list.");
143 registercontrolhelpcmd("patroljoin", NO_OPER
, 1, &pc_cmd_patroljoin
, "Usage: patroljoin <channel>\nJoins a patrol client to a channel.");
144 registercontrolhelpcmd("patrolpart", NO_OPER
, 1, &pc_cmd_patrolpart
, "Usage: patrolpart <#id>\nRemoves a patrol client from a channel.");
145 registercontrolhelpcmd("patrollist", NO_OPER
, 0, &pc_cmd_patrollist
, "Usage: patrollist\nLists patrol channels.");
147 schedulerecurring(time(NULL
) + 5, 0, 10, &pc_sched_check
, NULL
);
151 patrolchannel
*pc
, *next
;
153 deregistercontrolcmd("patroljoin", &pc_cmd_patroljoin
);
154 deregistercontrolcmd("patrolpart", &pc_cmd_patrolpart
);
155 deregistercontrolcmd("patrollist", &pc_cmd_patrollist
);
157 deleteallschedules(&pc_sched_check
);
159 for (pc
= patrolchannels
; pc
; pc
= next
) {
162 freesstring(pc
->channel
);
165 deregisterlocaluser(pc
->nick
, NULL
);