]>
Commit | Line | Data |
---|---|---|
1dd6d55d | 1 | /* Automatically generated by refactor.pl. |
2 | * | |
3 | * | |
4 | * CMDNAME: addchan | |
5 | * CMDLEVEL: QCMD_OPER | |
2acffe5d | 6 | * CMDARGS: 5 |
1dd6d55d | 7 | * CMDDESC: Adds a new channel to the bot. |
8 | * CMDFUNC: csc_doaddchan | |
9 | * CMDPROTO: int csc_doaddchan(void *source, int cargc, char **cargv); | |
2acffe5d | 10 | * CMDHELP: Usage: addchan <channel> [<owner> [<flags> [<type> [<msguser>]]]] |
cabd7271 | 11 | * CMDHELP: Adds the given channel to the bot, where: |
2acffe5d | 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) | |
1dd6d55d | 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) { | |
2acffe5d | 32 | nick *sender=source, *notify=NULL; |
1dd6d55d | 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; | |
1482fb78 | 40 | unsigned int i; |
1dd6d55d | 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 | ||
2acffe5d | 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 | ||
1dd6d55d | 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 | } else { | |
cabd7271 | 71 | flags = (QCFLAG_JOINED); |
1dd6d55d | 72 | } |
73 | ||
74 | /* Pick up the chantype */ | |
75 | if (cargc>3) { | |
76 | for (type=CHANTYPES-1;type;type--) { | |
77 | if (!ircd_strcmp(chantypes[type]->content, cargv[3])) | |
78 | break; | |
79 | } | |
80 | if (!type) { | |
81 | chanservstdmessage(sender, QM_UNKNOWNCHANTYPE, cargv[3]); | |
82 | return CMD_ERROR; | |
83 | } | |
84 | } | |
85 | ||
86 | if (!(cip=findorcreatechanindex(cargv[0]))) { | |
87 | chanservstdmessage(sender, QM_INVALIDCHANNAME, cargv[0]); | |
2acffe5d | 88 | if (notify) |
89 | chanservstdmessage(notify, QM_INVALIDCHANNAME, cargv[0]); | |
1dd6d55d | 90 | return CMD_ERROR; |
91 | } | |
92 | ||
93 | if (cip->exts[chanservext]) { | |
94 | chanservstdmessage(sender, QM_ALREADYREGISTERED, cip->name->content); | |
2acffe5d | 95 | if (notify) |
96 | chanservstdmessage(notify, QM_ALREADYREGISTERED, cip->name->content); | |
1dd6d55d | 97 | return CMD_ERROR; |
98 | } | |
99 | ||
100 | /* Initialise the channel */ | |
101 | rcp=getregchan(); | |
102 | ||
103 | /* ID, index */ | |
104 | rcp->ID=++lastchannelID; | |
105 | rcp->index=cip; | |
106 | cip->exts[chanservext]=rcp; | |
107 | ||
108 | rcp->chantype=type; | |
109 | rcp->flags=flags; | |
110 | rcp->status=0; | |
111 | rcp->bans=NULL; | |
112 | rcp->lastcountersync=0; | |
113 | ||
114 | rcp->limit=0; | |
115 | rcp->forcemodes=CHANMODE_NOEXTMSG | CHANMODE_TOPICLIMIT; | |
116 | rcp->denymodes=0; | |
117 | ||
118 | if (CIsAutoLimit(rcp)) { | |
119 | rcp->forcemodes |= CHANMODE_LIMIT; | |
120 | } | |
121 | ||
122 | rcp->autolimit=5; | |
123 | rcp->banstyle=0; | |
124 | ||
125 | rcp->created=rcp->lastactive=rcp->statsreset=rcp->ostatsreset=time(NULL); | |
cabd7271 | 126 | rcp->banduration=0; |
1dd6d55d | 127 | rcp->autoupdate=0; |
128 | rcp->lastbancheck=0; | |
129 | ||
130 | /* Added by */ | |
131 | rcp->addedby=rup->ID; | |
132 | ||
133 | /* Founder */ | |
134 | rcp->founder=founder->ID; | |
135 | ||
136 | /* Suspend by */ | |
137 | rcp->suspendby=0; | |
88d191e3 | 138 | rcp->suspendtime=0; |
1dd6d55d | 139 | |
140 | rcp->totaljoins=rcp->tripjoins=rcp->otripjoins=rcp->maxusers=rcp->tripusers=rcp->otripusers=0; | |
141 | rcp->welcome=rcp->topic=rcp->key=rcp->suspendreason=rcp->comment=NULL; | |
142 | ||
143 | /* Users */ | |
144 | memset(rcp->regusers,0,REGCHANUSERHASHSIZE*sizeof(reguser *)); | |
145 | ||
146 | rcp->checksched=NULL; | |
147 | rcp->ltimestamp=0; | |
1482fb78 | 148 | for (i=0;i<CHANOPHISTORY;i++) { |
149 | rcp->chanopnicks[i][0]='\0'; | |
150 | rcp->chanopaccts[i]=0; | |
151 | } | |
152 | rcp->chanoppos=0; | |
1dd6d55d | 153 | |
154 | /* Add new channel to db.. */ | |
155 | csdb_createchannel(rcp); | |
156 | ||
157 | /* Add the founder as +ano */ | |
158 | rcup=getregchanuser(); | |
159 | rcup->chan=rcp; | |
160 | rcup->user=founder; | |
161 | rcup->flags=(QCUFLAG_OWNER | QCUFLAG_OP | QCUFLAG_AUTOOP); | |
162 | rcup->usetime=0; | |
163 | rcup->info=NULL; | |
164 | rcup->changetime=time(NULL); | |
165 | ||
166 | addregusertochannel(rcup); | |
167 | csdb_createchanuser(rcup); | |
183b8e2f | 168 | csdb_chanlevhistory_insert(rcp, sender, rcup->user, 0, rcup->flags); |
1dd6d55d | 169 | |
170 | /* If the channel exists, get the ball rolling */ | |
171 | if (cip->channel) { | |
172 | chanservjoinchan(cip->channel); | |
173 | rcp->status |= QCSTAT_MODECHECK | QCSTAT_OPCHECK | QCSTAT_BANCHECK; | |
174 | cs_timerfunc(cip); | |
175 | } | |
176 | ||
177 | cs_log(sender, "ADDCHAN %s #%s %s %s",cip->name->content,founder->username,printflags(rcp->flags,rcflags), chantypes[type]->content); | |
178 | chanservstdmessage(sender, QM_DONE); | |
2acffe5d | 179 | if (notify) |
180 | chanservstdmessage(notify, QM_DONE); | |
1dd6d55d | 181 | return CMD_OK; |
182 | } |