]> 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: 4
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>]]]
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 */
18
19 #include "../chanserv.h"
20 #include "../../nick/nick.h"
21 #include "../../lib/flags.h"
22 #include "../../lib/irc_string.h"
23 #include "../../channel/channel.h"
24 #include "../../parser/parser.h"
25 #include "../../irc/irc.h"
26 #include "../../localuser/localuserchannel.h"
27 #include <string.h>
28 #include <stdio.h>
29
30 int csc_doaddchan(void *source, int cargc, char **cargv) {
31 nick *sender=source;
32 reguser *rup=getreguserfromnick(sender);
33 chanindex *cip;
34 regchan *rcp;
35 regchanuser *rcup;
36 reguser *founder;
37 flag_t flags;
38 short type=0;
39 unsigned int i;
40
41 if (!rup)
42 return CMD_ERROR;
43
44 if (cargc<1) {
45 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "addchan");
46 return CMD_ERROR;
47 }
48
49 if (*cargv[0] != '#') {
50 chanservstdmessage(sender, QM_INVALIDCHANNAME, cargv[0]);
51 return CMD_ERROR;
52 }
53
54 if (cargc>1) {
55 if (!(founder=findreguser(sender, cargv[1])))
56 return CMD_ERROR;
57 } else {
58 founder=rup;
59 }
60
61 if (cargc>2) {
62 flags=0;
63 setflags(&flags, QCFLAG_ALL, cargv[2], rcflags, REJECT_NONE);
64 } else {
65 flags = (QCFLAG_JOINED);
66 }
67
68 /* Pick up the chantype */
69 if (cargc>3) {
70 for (type=CHANTYPES-1;type;type--) {
71 if (!ircd_strcmp(chantypes[type]->content, cargv[3]))
72 break;
73 }
74 if (!type) {
75 chanservstdmessage(sender, QM_UNKNOWNCHANTYPE, cargv[3]);
76 return CMD_ERROR;
77 }
78 }
79
80 if (!(cip=findorcreatechanindex(cargv[0]))) {
81 chanservstdmessage(sender, QM_INVALIDCHANNAME, cargv[0]);
82 return CMD_ERROR;
83 }
84
85 if (cip->exts[chanservext]) {
86 chanservstdmessage(sender, QM_ALREADYREGISTERED, cip->name->content);
87 return CMD_ERROR;
88 }
89
90 /* Initialise the channel */
91 rcp=getregchan();
92
93 /* ID, index */
94 rcp->ID=++lastchannelID;
95 rcp->index=cip;
96 cip->exts[chanservext]=rcp;
97
98 rcp->chantype=type;
99 rcp->flags=flags;
100 rcp->status=0;
101 rcp->bans=NULL;
102 rcp->lastcountersync=0;
103
104 rcp->limit=0;
105 rcp->forcemodes=CHANMODE_NOEXTMSG | CHANMODE_TOPICLIMIT;
106 rcp->denymodes=0;
107
108 if (CIsAutoLimit(rcp)) {
109 rcp->forcemodes |= CHANMODE_LIMIT;
110 }
111
112 rcp->autolimit=5;
113 rcp->banstyle=0;
114
115 rcp->created=rcp->lastactive=rcp->statsreset=rcp->ostatsreset=time(NULL);
116 rcp->banduration=0;
117 rcp->autoupdate=0;
118 rcp->lastbancheck=0;
119
120 /* Added by */
121 rcp->addedby=rup->ID;
122
123 /* Founder */
124 rcp->founder=founder->ID;
125
126 /* Suspend by */
127 rcp->suspendby=0;
128 rcp->suspendtime=0;
129
130 rcp->totaljoins=rcp->tripjoins=rcp->otripjoins=rcp->maxusers=rcp->tripusers=rcp->otripusers=0;
131 rcp->welcome=rcp->topic=rcp->key=rcp->suspendreason=rcp->comment=NULL;
132
133 /* Users */
134 memset(rcp->regusers,0,REGCHANUSERHASHSIZE*sizeof(reguser *));
135
136 rcp->checksched=NULL;
137 rcp->ltimestamp=0;
138 for (i=0;i<CHANOPHISTORY;i++) {
139 rcp->chanopnicks[i][0]='\0';
140 rcp->chanopaccts[i]=0;
141 }
142 rcp->chanoppos=0;
143
144 /* Add new channel to db.. */
145 csdb_createchannel(rcp);
146
147 /* Add the founder as +ano */
148 rcup=getregchanuser();
149 rcup->chan=rcp;
150 rcup->user=founder;
151 rcup->flags=(QCUFLAG_OWNER | QCUFLAG_OP | QCUFLAG_AUTOOP);
152 rcup->usetime=0;
153 rcup->info=NULL;
154 rcup->changetime=time(NULL);
155
156 addregusertochannel(rcup);
157 csdb_createchanuser(rcup);
158 csdb_chanlevhistory_insert(rcp, sender, rcup->user, 0, rcup->flags);
159
160 /* If the channel exists, get the ball rolling */
161 if (cip->channel) {
162 chanservjoinchan(cip->channel);
163 rcp->status |= QCSTAT_MODECHECK | QCSTAT_OPCHECK | QCSTAT_BANCHECK;
164 cs_timerfunc(cip);
165 }
166
167 cs_log(sender, "ADDCHAN %s #%s %s %s",cip->name->content,founder->username,printflags(rcp->flags,rcflags), chantypes[type]->content);
168 chanservstdmessage(sender, QM_DONE);
169 return CMD_OK;
170 }