]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chancmds/addchan.c
1 /* Automatically generated by refactor.pl.
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)
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"
31 int csc_doaddchan(void *source
, int cargc
, char **cargv
) {
32 nick
*sender
=source
, *notify
=NULL
;
33 reguser
*rup
=getreguserfromnick(sender
);
47 chanservstdmessage(sender
, QM_NOTENOUGHPARAMS
, "addchan");
51 if (*cargv
[0] != '#' || strlen(cargv
[0]) > CHANNELLEN
) {
52 chanservstdmessage(sender
, QM_INVALIDCHANNAME
, cargv
[0]);
56 /* If a 5th argument is supplied, it's a nick to send the reply messages to. */
58 notify
=getnickbynick(cargv
[4]);
62 if (!(founder
=findreguser(sender
, cargv
[1])))
70 setflags(&flags
, QCFLAG_ALL
, cargv
[2], rcflags
, REJECT_NONE
);
71 /* Apply relevant policy */
73 flags
&= QCFLAG_USERCONTROL
;
74 flags
|= QCFLAG_JOINED
;
77 flags
= (QCFLAG_JOINED
);
80 /* Pick up the chantype */
82 for (type
=CHANTYPES
-1;type
;type
--) {
83 if (!ircd_strcmp(chantypes
[type
]->content
, cargv
[3]))
87 chanservstdmessage(sender
, QM_UNKNOWNCHANTYPE
, cargv
[3]);
92 if (!(cip
=findorcreatechanindex(cargv
[0]))) {
93 chanservstdmessage(sender
, QM_INVALIDCHANNAME
, cargv
[0]);
95 chanservstdmessage(notify
, QM_INVALIDCHANNAME
, cargv
[0]);
99 if (cip
->exts
[chanservext
]) {
100 chanservstdmessage(sender
, QM_ALREADYREGISTERED
, cip
->name
->content
);
102 chanservstdmessage(notify
, QM_ALREADYREGISTERED
, cip
->name
->content
);
106 /* Initialise the channel */
110 rcp
->ID
=++lastchannelID
;
112 cip
->exts
[chanservext
]=rcp
;
118 rcp
->lastcountersync
=0;
121 rcp
->forcemodes
=CHANMODE_DEFAULT
;
124 if (CIsAutoLimit(rcp
)) {
125 rcp
->forcemodes
|= CHANMODE_LIMIT
;
131 rcp
->created
=rcp
->lastactive
=rcp
->statsreset
=rcp
->ostatsreset
=time(NULL
);
137 rcp
->addedby
=rup
->ID
;
140 rcp
->founder
=founder
->ID
;
146 rcp
->totaljoins
=rcp
->tripjoins
=rcp
->otripjoins
=rcp
->maxusers
=rcp
->tripusers
=rcp
->otripusers
=0;
147 rcp
->welcome
=rcp
->topic
=rcp
->key
=rcp
->suspendreason
=rcp
->comment
=NULL
;
150 memset(rcp
->regusers
,0,REGCHANUSERHASHSIZE
*sizeof(reguser
*));
152 rcp
->checksched
=NULL
;
154 for (i
=0;i
<CHANOPHISTORY
;i
++) {
155 rcp
->chanopnicks
[i
][0]='\0';
156 rcp
->chanopaccts
[i
]=0;
160 /* Add new channel to db.. */
161 csdb_createchannel(rcp
);
163 /* Add the founder as +ano */
164 rcup
=getregchanuser();
167 rcup
->flags
=(QCUFLAG_OWNER
| QCUFLAG_OP
| QCUFLAG_AUTOOP
);
170 rcup
->changetime
=time(NULL
);
172 addregusertochannel(rcup
);
173 csdb_createchanuser(rcup
);
174 csdb_chanlevhistory_insert(rcp
, sender
, rcup
->user
, 0, rcup
->flags
);
180 triggerhook(HOOK_CHANSERV_CHANLEVMOD
, args
);
182 /* If the channel exists, get the ball rolling */
184 chanservjoinchan(cip
->channel
);
185 rcp
->status
|= QCSTAT_MODECHECK
| QCSTAT_OPCHECK
| QCSTAT_BANCHECK
;
189 cs_log(sender
, "ADDCHAN %s #%s %s %s",cip
->name
->content
,founder
->username
,printflags(rcp
->flags
,rcflags
), chantypes
[type
]->content
);
190 chanservstdmessage(sender
, QM_DONE
);
192 chanservstdmessage(notify
, QM_DONE
);