]>
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
) {
29 patrol_nickchange(pc
->nick
);
31 if (pc
->nick
&& pc
->nick
->channels
&& pc
->nick
->channels
->cursi
> 0)
35 deregisterlocaluser(pc
->nick
, NULL
);
37 cp
= findchannel(pc
->channel
->content
);
44 pc
->nick
= patrol_generateclone(0, patroluserhandler
);
45 localjoinchannel(pc
->nick
, cp
);
49 static void pc_sched_check(void *arg
) {
53 static int pc_join(char *name
) {
54 patrolchannel
*pc
= NULL
;
57 for (pc
= patrolchannels
; pc
; pc
= pc
->next
)
58 if (ircd_strcmp(pc
->channel
->content
, name
) == 0)
61 cp
= findchannel(name
);
66 pc
= malloc(sizeof(patrolchannel
));
68 pc
->channel
= getsstring(name
, 512);
71 pc
->next
= patrolchannels
;
79 static int pc_part(char *name
) {
80 patrolchannel
**pnext
, *pc
;
82 for (pnext
= &patrolchannels
; *pnext
; pnext
= &((*pnext
)->next
)) {
85 if (ircd_strcmp(pc
->channel
->content
, name
) == 0) {
86 freesstring(pc
->channel
);
87 deregisterlocaluser(pc
->nick
, NULL
);
99 static int pc_cmd_patroljoin(void *source
, int cargc
, char **cargv
) {
100 nick
*sender
= source
;
105 if (pc_join(cargv
[0]) < 0) {
106 controlreply(sender
, "Could not join channel.");
111 controlreply(sender
, "Done.");
116 static int pc_cmd_patrolpart(void *source
, int cargc
, char **cargv
) {
117 nick
*sender
= source
;
122 if (pc_part(cargv
[0]) < 0) {
123 controlreply(sender
, "Could not join channel.");
128 controlreply(sender
, "Done.");
133 static int pc_cmd_patrollist(void *source
, int cargc
, char **cargv
) {
134 nick
*sender
= source
;
137 for (pc
= patrolchannels
; pc
; pc
= pc
->next
)
138 controlreply(sender
, "%s - %s", pc
->channel
->content
, pc
->nick
? controlid(pc
->nick
) : "Not currently joined.");
140 controlreply(sender
, "End of list.");
146 registercontrolhelpcmd("patroljoin", NO_OPER
, 1, &pc_cmd_patroljoin
, "Usage: patroljoin <channel>\nJoins a patrol client to a channel.");
147 registercontrolhelpcmd("patrolpart", NO_OPER
, 1, &pc_cmd_patrolpart
, "Usage: patrolpart <#id>\nRemoves a patrol client from a channel.");
148 registercontrolhelpcmd("patrollist", NO_OPER
, 0, &pc_cmd_patrollist
, "Usage: patrollist\nLists patrol channels.");
150 schedulerecurring(time(NULL
) + 5, 0, 300, &pc_sched_check
, NULL
);
154 patrolchannel
*pc
, *next
;
156 deregistercontrolcmd("patroljoin", &pc_cmd_patroljoin
);
157 deregistercontrolcmd("patrolpart", &pc_cmd_patrolpart
);
158 deregistercontrolcmd("patrollist", &pc_cmd_patrollist
);
160 deleteallschedules(&pc_sched_check
);
162 for (pc
= patrolchannels
; pc
; pc
= next
) {
165 freesstring(pc
->channel
);
168 deregisterlocaluser(pc
->nick
, NULL
);