]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chancmds/addchan.c
Merge.
[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;
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
50 if (*cargv[0] != '#') {
51 chanservstdmessage(sender, QM_INVALIDCHANNAME, cargv[0]);
52 return CMD_ERROR;
53 }
54
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
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;
69 setflags(&flags, QCFLAG_ALL, cargv[2], rcflags, REJECT_NONE);
70 /* Apply relevant policy */
71 if (!UIsDev(rup)) {
72 flags &= QCFLAG_USERCONTROL;
73 flags |= QCFLAG_JOINED;
74 }
75 } else {
76 flags = (QCFLAG_JOINED);
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]);
93 if (notify)
94 chanservstdmessage(notify, QM_INVALIDCHANNAME, cargv[0]);
95 return CMD_ERROR;
96 }
97
98 if (cip->exts[chanservext]) {
99 chanservstdmessage(sender, QM_ALREADYREGISTERED, cip->name->content);
100 if (notify)
101 chanservstdmessage(notify, QM_ALREADYREGISTERED, cip->name->content);
102 return CMD_ERROR;
103 }
104
105 /* Initialise the channel */
106 rcp=getregchan();
107
108 /* ID, index */
109 rcp->ID=++lastchannelID;
110 rcp->index=cip;
111 cip->exts[chanservext]=rcp;
112
113 rcp->chantype=type;
114 rcp->flags=flags;
115 rcp->status=0;
116 rcp->bans=NULL;
117 rcp->lastcountersync=0;
118
119 rcp->limit=0;
120 rcp->forcemodes=CHANMODE_NOEXTMSG | CHANMODE_TOPICLIMIT;
121 rcp->denymodes=0;
122
123 if (CIsAutoLimit(rcp)) {
124 rcp->forcemodes |= CHANMODE_LIMIT;
125 }
126
127 rcp->autolimit=5;
128 rcp->banstyle=0;
129
130 rcp->created=rcp->lastactive=rcp->statsreset=rcp->ostatsreset=time(NULL);
131 rcp->banduration=0;
132 rcp->autoupdate=0;
133 rcp->lastbancheck=0;
134
135 /* Added by */
136 rcp->addedby=rup->ID;
137
138 /* Founder */
139 rcp->founder=founder->ID;
140
141 /* Suspend by */
142 rcp->suspendby=0;
143 rcp->suspendtime=0;
144
145 rcp->totaljoins=rcp->tripjoins=rcp->otripjoins=rcp->maxusers=rcp->tripusers=rcp->otripusers=0;
146 rcp->welcome=rcp->topic=rcp->key=rcp->suspendreason=rcp->comment=NULL;
147
148 /* Users */
149 memset(rcp->regusers,0,REGCHANUSERHASHSIZE*sizeof(reguser *));
150
151 rcp->checksched=NULL;
152 rcp->ltimestamp=0;
153 for (i=0;i<CHANOPHISTORY;i++) {
154 rcp->chanopnicks[i][0]='\0';
155 rcp->chanopaccts[i]=0;
156 }
157 rcp->chanoppos=0;
158
159 /* Add new channel to db.. */
160 csdb_createchannel(rcp);
161
162 /* Add the founder as +ano */
163 rcup=getregchanuser();
164 rcup->chan=rcp;
165 rcup->user=founder;
166 rcup->flags=(QCUFLAG_OWNER | QCUFLAG_OP | QCUFLAG_AUTOOP);
167 rcup->usetime=0;
168 rcup->info=NULL;
169 rcup->changetime=time(NULL);
170
171 addregusertochannel(rcup);
172 csdb_createchanuser(rcup);
173 csdb_chanlevhistory_insert(rcp, sender, rcup->user, 0, rcup->flags);
174
175 /* If the channel exists, get the ball rolling */
176 if (cip->channel) {
177 chanservjoinchan(cip->channel);
178 rcp->status |= QCSTAT_MODECHECK | QCSTAT_OPCHECK | QCSTAT_BANCHECK;
179 cs_timerfunc(cip);
180 }
181
182 cs_log(sender, "ADDCHAN %s #%s %s %s",cip->name->content,founder->username,printflags(rcp->flags,rcflags), chantypes[type]->content);
183 chanservstdmessage(sender, QM_DONE);
184 if (notify)
185 chanservstdmessage(notify, QM_DONE);
186 return CMD_OK;
187 }