]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chancmds/adduser.c
Fixed summary for ADDUSER.
[irc/quakenet/newserv.git] / chanserv / chancmds / adduser.c
1 /* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: adduser
5 * CMDLEVEL: QCMD_AUTHED
6 * CMDARGS: 20
7 * CMDDESC: Adds one or more users to a channel.
8 * CMDFUNC: csc_doadduser
9 * CMDPROTO: int csc_doadduser(void *source, int cargc, char **cargv);
10 * CMDHELP: Usage: ADDUSER <channel> [<flags>] <user1> [<user2> [<user3> [...]]]
11 * CMDHELP: Adds the named user(s) to the channel, where:
12 * CMDHELP: channel - the channel to use
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).
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.
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
33 int csc_doadduser(void *source, int cargc, char **cargv) {
34 nick *sender=source;
35 chanindex *cip;
36 regchanuser *rcup, *rcuplist;
37 regchan *rcp;
38 reguser *rup;
39 flag_t addflags;
40 char *flagbuf;
41 unsigned int count=0;
42 int added=0;
43 int i, foundflags=0;
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
55 /* See if there are flags defined */
56 if (*cargv[1] == '+') {
57 foundflags=1;
58
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 }
77 } else {
78 addflags=QCUFLAG_OP | QCUFLAG_AUTOOP | QCUFLAG_TOPIC;
79 }
80
81 flagbuf=printflags(addflags, rcuflags);
82
83 /* ugh */
84 for (count=i=0;i<REGCHANUSERHASHSIZE;i++)
85 for (rcuplist=rcp->regusers[i];rcuplist;rcuplist=rcuplist->nextbychan)
86 count++;
87
88 /* If we found flags don't try to add them as a user as well.. */
89 for (i=1+foundflags;i<cargc;i++) {
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
98 if(count++ >= MAXCHANLEVS) {
99 chanservstdmessage(sender, QM_TOOMANYCHANLEVS);
100 chanservstdmessage(sender, QM_DONE);
101 return CMD_OK;
102 }
103
104 rcup=getregchanuser();
105 rcup->chan=rcp;
106 rcup->user=rup;
107 rcup->flags = addflags;
108 rcup->changetime=time(NULL);
109 rcup->usetime=0;
110 rcup->info=NULL;
111
112 cs_log(sender,"CHANLEV %s #%s %s (+ -> %s)",cip->name->content,rup->username, flagbuf, flagbuf);
113 addregusertochannel(rcup);
114 csdb_createchanuser(rcup);
115 csdb_chanlevhistory_insert(rcp, sender, rcup->user, 0, rcup->flags);
116 added++;
117 }
118
119 rcp->status |= QCSTAT_OPCHECK;
120 cs_timerfunc(cip);
121
122 if (added)
123 chanservstdmessage(sender, QM_DONE);
124
125 return CMD_OK;
126 }