]> jfr.im git - irc/quakenet/newserv.git/blame - chanserv/chancmds/addchan.c
CHANSERV: add ADDCHAN relay command.
[irc/quakenet/newserv.git] / chanserv / chancmds / addchan.c
CommitLineData
1dd6d55d 1/* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: addchan
5 * CMDLEVEL: QCMD_OPER
2acffe5d 6 * CMDARGS: 5
1dd6d55d 7 * CMDDESC: Adds a new channel to the bot.
8 * CMDFUNC: csc_doaddchan
9 * CMDPROTO: int csc_doaddchan(void *source, int cargc, char **cargv);
2acffe5d 10 * CMDHELP: Usage: addchan <channel> [<owner> [<flags> [<type> [<msguser>]]]]
cabd7271 11 * CMDHELP: Adds the given channel to the bot, where:
2acffe5d 12 * CMDHELP: owner - can be either nickname on the network or #authname. If not supplied,
13 * CMDHELP: the channel will belong to the user issuing the ADDCHAN command.
14 * CMDHELP: flags - can be any valid chanflags (see CHANFLAGS). If not specified this
15 * CMDHELP: defaults to +j.
16 * CMDHELP: type - is a channel type as per old Q and is now obsolete.
17 * CMDHELP: msguser - send a notification to this user (for service use)
1dd6d55d 18 */
19
20#include "../chanserv.h"
21#include "../../nick/nick.h"
22#include "../../lib/flags.h"
23#include "../../lib/irc_string.h"
24#include "../../channel/channel.h"
25#include "../../parser/parser.h"
26#include "../../irc/irc.h"
27#include "../../localuser/localuserchannel.h"
28#include <string.h>
29#include <stdio.h>
30
31int csc_doaddchan(void *source, int cargc, char **cargv) {
2acffe5d 32 nick *sender=source, *notify=NULL;
1dd6d55d 33 reguser *rup=getreguserfromnick(sender);
34 chanindex *cip;
35 regchan *rcp;
36 regchanuser *rcup;
37 reguser *founder;
38 flag_t flags;
39 short type=0;
bdeb548f 40 unsigned int count;
1dd6d55d 41
42 if (!rup)
43 return CMD_ERROR;
44
45 if (cargc<1) {
46 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "addchan");
47 return CMD_ERROR;
48 }
49
351c489c 50 if (*cargv[0] != '#' || strlen(cargv[0]) > CHANNELLEN) {
1dd6d55d 51 chanservstdmessage(sender, QM_INVALIDCHANNAME, cargv[0]);
52 return CMD_ERROR;
53 }
54
2acffe5d 55 /* If a 5th argument is supplied, it's a nick to send the reply messages to. */
56 if (cargc>4) {
57 notify=getnickbynick(cargv[4]);
58 }
59
1dd6d55d 60 if (cargc>1) {
61 if (!(founder=findreguser(sender, cargv[1])))
62 return CMD_ERROR;
63 } else {
64 founder=rup;
65 }
66
67 if (cargc>2) {
68 flags=0;
7d21b16f 69 setflags(&flags, QCFLAG_ALL, cargv[2], rcflags, REJECT_NONE);
8f164e6d 70 /* Apply relevant policy */
71 if (!UIsDev(rup)) {
72 flags &= QCFLAG_USERCONTROL;
7d21b16f 73 flags |= QCFLAG_JOINED;
8f164e6d 74 }
1dd6d55d 75 } else {
cabd7271 76 flags = (QCFLAG_JOINED);
1dd6d55d 77 }
78
79 /* Pick up the chantype */
80 if (cargc>3) {
81 for (type=CHANTYPES-1;type;type--) {
82 if (!ircd_strcmp(chantypes[type]->content, cargv[3]))
83 break;
84 }
85 if (!type) {
86 chanservstdmessage(sender, QM_UNKNOWNCHANTYPE, cargv[3]);
87 return CMD_ERROR;
88 }
89 }
90
91 if (!(cip=findorcreatechanindex(cargv[0]))) {
92 chanservstdmessage(sender, QM_INVALIDCHANNAME, cargv[0]);
2acffe5d 93 if (notify)
94 chanservstdmessage(notify, QM_INVALIDCHANNAME, cargv[0]);
1dd6d55d 95 return CMD_ERROR;
96 }
97
3c6cc37d
GB
98 count = 0;
99
100 for (rcup=founder->knownon;rcup;rcup=rcup->nextbyuser)
101 count++;
102
103 if (count > MAXCHANNELS) {
104 chanservstdmessage(sender, QM_TOOMANYCHANNELS, cip->name->content);
105 if (notify)
106 chanservstdmessage(sender, QM_TOOMANYCHANNELS, cip->name->content);
107 return CMD_ERROR;
108 }
109
bdeb548f
CP
110 rcp=cs_addchan(cip, sender, rup, founder, flags, type);
111 if(rcp == NULL) {
112 chanservstdmessage(sender, QM_ALREADYREGISTERED, cip->name->content);
113 if (notify)
114 chanservstdmessage(notify, QM_ALREADYREGISTERED, cip->name->content);
115 return CMD_ERROR;
1dd6d55d 116 }
117
118 cs_log(sender, "ADDCHAN %s #%s %s %s",cip->name->content,founder->username,printflags(rcp->flags,rcflags), chantypes[type]->content);
119 chanservstdmessage(sender, QM_DONE);
2acffe5d 120 if (notify)
121 chanservstdmessage(notify, QM_DONE);
1dd6d55d 122 return CMD_OK;
123}