]> jfr.im git - irc/quakenet/newserv.git/blame - chanserv/chancmds/adduser.c
Fixed summary for ADDUSER.
[irc/quakenet/newserv.git] / chanserv / chancmds / adduser.c
CommitLineData
1dd6d55d 1/* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: adduser
5 * CMDLEVEL: QCMD_AUTHED
6 * CMDARGS: 20
b9aed926 7 * CMDDESC: Adds one or more users to a channel.
1dd6d55d 8 * CMDFUNC: csc_doadduser
9 * CMDPROTO: int csc_doadduser(void *source, int cargc, char **cargv);
95332d7b 10 * CMDHELP: Usage: ADDUSER <channel> [<flags>] <user1> [<user2> [<user3> [...]]]
11 * CMDHELP: Adds the named user(s) to the channel, where:
cabd7271 12 * CMDHELP: channel - the channel to use
95332d7b 13 * CMDHELP: flags - the list of flags to add for each user, introduced by + (for example
14 * CMDHELP: +gv). See CHANLEV for valid flags. If no flags are specified,
15 * CMDHELP: +aot is used. This command cannot be used to add masters (+m) or
16 * CMDHELP: owners (+n).
cabd7271 17 * CMDHELP: user<n> - either a user's current nickname on the network or #accountname. Up to
18 * CMDHELP: 18 users can be specified.
19 * CMDHELP: ADDUSER requires master (+m) access on the named channel.
1dd6d55d 20 */
21
22#include "../chanserv.h"
23#include "../../nick/nick.h"
24#include "../../lib/flags.h"
25#include "../../lib/irc_string.h"
26#include "../../channel/channel.h"
27#include "../../parser/parser.h"
28#include "../../irc/irc.h"
29#include "../../localuser/localuserchannel.h"
30#include <string.h>
31#include <stdio.h>
32
33int csc_doadduser(void *source, int cargc, char **cargv) {
34 nick *sender=source;
35 chanindex *cip;
705542fa 36 regchanuser *rcup, *rcuplist;
1dd6d55d 37 regchan *rcp;
38 reguser *rup;
95332d7b 39 flag_t addflags;
40 char *flagbuf;
c269075e 41 unsigned int count=0;
42 int added=0;
3a20635f 43 int i, foundflags=0;
1dd6d55d 44
45 if (cargc<2) {
46 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "adduser");
47 return CMD_ERROR;
48 }
49
50 if (!(cip=cs_checkaccess(sender, cargv[0], CA_MASTERPRIV, NULL, "adduser", QPRIV_CHANGECHANLEV, 0)))
51 return CMD_ERROR;
52
53 rcp=cip->exts[chanservext];
54
95332d7b 55 /* See if there are flags defined */
56 if (*cargv[1] == '+') {
3a20635f 57 foundflags=1;
58
95332d7b 59 /* If there are we now need at least 3 parameters */
60 if (cargc<3) {
61 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "adduser");
62 return CMD_ERROR;
63 }
64 addflags=0;
65
66 /* Set the flags. We allow everything except personal flags and +mn. */
67 setflags(&addflags, QCUFLAG_ALL & ~(QCUFLAGS_PERSONAL | QCUFLAG_MASTER | QCUFLAG_OWNER), cargv[1], rcuflags, 0);
68
69 /* Remove impossible combinations */
70 addflags=cs_sanitisechanlev(addflags);
71
72 /* It helps a lot if they have actually set something */
73 if (!addflags) {
74 chanservstdmessage(sender, QM_NOFLAGSPECIFIED);
75 return CMD_ERROR;
76 }
95332d7b 77 } else {
78 addflags=QCUFLAG_OP | QCUFLAG_AUTOOP | QCUFLAG_TOPIC;
79 }
80
81 flagbuf=printflags(addflags, rcuflags);
82
705542fa
CP
83 /* ugh */
84 for (count=i=0;i<REGCHANUSERHASHSIZE;i++)
85 for (rcuplist=rcp->regusers[i];rcuplist;rcuplist=rcuplist->nextbychan)
86 count++;
87
3a20635f 88 /* If we found flags don't try to add them as a user as well.. */
89 for (i=1+foundflags;i<cargc;i++) {
1dd6d55d 90 if (!(rup=findreguser(sender, cargv[i])))
91 continue;
92
93 if ((rcup=findreguseronchannel(rcp, rup))) {
94 chanservstdmessage(sender, QM_ALREADYKNOWNONCHAN, cargv[i], cip->name->content);
95 continue;
96 }
97
705542fa
CP
98 if(count++ >= MAXCHANLEVS) {
99 chanservstdmessage(sender, QM_TOOMANYCHANLEVS);
100 chanservstdmessage(sender, QM_DONE);
101 return CMD_OK;
102 }
103
1dd6d55d 104 rcup=getregchanuser();
105 rcup->chan=rcp;
106 rcup->user=rup;
95332d7b 107 rcup->flags = addflags;
1dd6d55d 108 rcup->changetime=time(NULL);
109 rcup->usetime=0;
110 rcup->info=NULL;
111
95332d7b 112 cs_log(sender,"CHANLEV %s #%s %s (+ -> %s)",cip->name->content,rup->username, flagbuf, flagbuf);
1dd6d55d 113 addregusertochannel(rcup);
114 csdb_createchanuser(rcup);
183b8e2f 115 csdb_chanlevhistory_insert(rcp, sender, rcup->user, 0, rcup->flags);
c269075e 116 added++;
1dd6d55d 117 }
118
119 rcp->status |= QCSTAT_OPCHECK;
120 cs_timerfunc(cip);
121
c269075e 122 if (added)
123 chanservstdmessage(sender, QM_DONE);
1dd6d55d 124
125 return CMD_OK;
126}