]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chancmds/addchan.c
a77e2258505883a801a529a55f30737dbeb102ba
[irc/quakenet/newserv.git] / chanserv / chancmds / addchan.c
1 /* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: addchan
5 * CMDLEVEL: QCMD_OPER
6 * CMDARGS: 5
7 * CMDDESC: Adds a new channel to the bot.
8 * CMDFUNC: csc_doaddchan
9 * CMDPROTO: int csc_doaddchan(void *source, int cargc, char **cargv);
10 * CMDHELP: Usage: addchan <channel> [<owner> [<flags> [<type> [<msguser>]]]]
11 * CMDHELP: Adds the given channel to the bot, where:
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)
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
31 int csc_doaddchan(void *source, int cargc, char **cargv) {
32 nick *sender=source, *notify=NULL;
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;
40 unsigned int i, count;
41 void *args[3];
42
43 if (!rup)
44 return CMD_ERROR;
45
46 if (cargc<1) {
47 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "addchan");
48 return CMD_ERROR;
49 }
50
51 if (*cargv[0] != '#' || strlen(cargv[0]) > CHANNELLEN) {
52 chanservstdmessage(sender, QM_INVALIDCHANNAME, cargv[0]);
53 return CMD_ERROR;
54 }
55
56 /* If a 5th argument is supplied, it's a nick to send the reply messages to. */
57 if (cargc>4) {
58 notify=getnickbynick(cargv[4]);
59 }
60
61 if (cargc>1) {
62 if (!(founder=findreguser(sender, cargv[1])))
63 return CMD_ERROR;
64 } else {
65 founder=rup;
66 }
67
68 if (cargc>2) {
69 flags=0;
70 setflags(&flags, QCFLAG_ALL, cargv[2], rcflags, REJECT_NONE);
71 /* Apply relevant policy */
72 if (!UIsDev(rup)) {
73 flags &= QCFLAG_USERCONTROL;
74 flags |= QCFLAG_JOINED;
75 }
76 } else {
77 flags = (QCFLAG_JOINED);
78 }
79
80 /* Pick up the chantype */
81 if (cargc>3) {
82 for (type=CHANTYPES-1;type;type--) {
83 if (!ircd_strcmp(chantypes[type]->content, cargv[3]))
84 break;
85 }
86 if (!type) {
87 chanservstdmessage(sender, QM_UNKNOWNCHANTYPE, cargv[3]);
88 return CMD_ERROR;
89 }
90 }
91
92 if (!(cip=findorcreatechanindex(cargv[0]))) {
93 chanservstdmessage(sender, QM_INVALIDCHANNAME, cargv[0]);
94 if (notify)
95 chanservstdmessage(notify, QM_INVALIDCHANNAME, cargv[0]);
96 return CMD_ERROR;
97 }
98
99 if (cip->exts[chanservext]) {
100 chanservstdmessage(sender, QM_ALREADYREGISTERED, cip->name->content);
101 if (notify)
102 chanservstdmessage(notify, QM_ALREADYREGISTERED, cip->name->content);
103 return CMD_ERROR;
104 }
105
106 count = 0;
107
108 for (rcup=founder->knownon;rcup;rcup=rcup->nextbyuser)
109 count++;
110
111 if (count > MAXCHANNELS) {
112 chanservstdmessage(sender, QM_TOOMANYCHANNELS, cip->name->content);
113 if (notify)
114 chanservstdmessage(sender, QM_TOOMANYCHANNELS, cip->name->content);
115 return CMD_ERROR;
116 }
117
118 /* Initialise the channel */
119 rcp=getregchan();
120
121 /* ID, index */
122 rcp->ID=++lastchannelID;
123 rcp->index=cip;
124 cip->exts[chanservext]=rcp;
125
126 rcp->chantype=type;
127 rcp->flags=flags;
128 rcp->status=0;
129 rcp->bans=NULL;
130 rcp->lastcountersync=0;
131
132 rcp->limit=0;
133 rcp->forcemodes=CHANMODE_DEFAULT;
134 rcp->denymodes=0;
135
136 if (CIsAutoLimit(rcp)) {
137 rcp->forcemodes |= CHANMODE_LIMIT;
138 }
139
140 rcp->autolimit=5;
141 rcp->banstyle=0;
142
143 rcp->created=rcp->lastactive=rcp->statsreset=rcp->ostatsreset=time(NULL);
144 rcp->banduration=0;
145 rcp->autoupdate=0;
146 rcp->lastbancheck=0;
147
148 /* Added by */
149 rcp->addedby=rup->ID;
150
151 /* Founder */
152 rcp->founder=founder->ID;
153
154 /* Suspend by */
155 rcp->suspendby=0;
156 rcp->suspendtime=0;
157
158 rcp->totaljoins=rcp->tripjoins=rcp->otripjoins=rcp->maxusers=rcp->tripusers=rcp->otripusers=0;
159 rcp->welcome=rcp->topic=rcp->key=rcp->suspendreason=rcp->comment=NULL;
160
161 /* Users */
162 memset(rcp->regusers,0,REGCHANUSERHASHSIZE*sizeof(reguser *));
163
164 rcp->checksched=NULL;
165 rcp->ltimestamp=0;
166 for (i=0;i<CHANOPHISTORY;i++) {
167 rcp->chanopnicks[i][0]='\0';
168 rcp->chanopaccts[i]=0;
169 }
170 rcp->chanoppos=0;
171
172 /* Add new channel to db.. */
173 csdb_createchannel(rcp);
174
175 /* Add the founder as +ano */
176 rcup=getregchanuser();
177 rcup->chan=rcp;
178 rcup->user=founder;
179 rcup->flags=(QCUFLAG_OWNER | QCUFLAG_OP | QCUFLAG_AUTOOP);
180 rcup->usetime=0;
181 rcup->info=NULL;
182 rcup->changetime=time(NULL);
183
184 addregusertochannel(rcup);
185 csdb_createchanuser(rcup);
186 csdb_chanlevhistory_insert(rcp, sender, rcup->user, 0, rcup->flags);
187
188 args[0]=sender;
189 args[1]=rcup;
190 args[2]=(void *)0;
191
192 triggerhook(HOOK_CHANSERV_CHANLEVMOD, args);
193
194 /* If the channel exists, get the ball rolling */
195 if (cip->channel) {
196 chanservjoinchan(cip->channel);
197 rcp->status |= QCSTAT_MODECHECK | QCSTAT_OPCHECK | QCSTAT_BANCHECK;
198 cs_timerfunc(cip);
199 }
200
201 cs_log(sender, "ADDCHAN %s #%s %s %s",cip->name->content,founder->username,printflags(rcp->flags,rcflags), chantypes[type]->content);
202 chanservstdmessage(sender, QM_DONE);
203 if (notify)
204 chanservstdmessage(notify, QM_DONE);
205 return CMD_OK;
206 }