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