]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chancmds/adduser.c
556b32ac93739ddbebbbaacb63cbec1e88411594
[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 void *args[3];
45
46 if (cargc<2) {
47 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "adduser");
48 return CMD_ERROR;
49 }
50
51 if (!(cip=cs_checkaccess(sender, cargv[0], CA_MASTERPRIV, NULL, "adduser", QPRIV_CHANGECHANLEV, 0)))
52 return CMD_ERROR;
53
54 rcp=cip->exts[chanservext];
55
56 /* See if there are flags defined */
57 if (*cargv[1] == '+') {
58 foundflags=1;
59
60 /* If there are we now need at least 3 parameters */
61 if (cargc<3) {
62 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "adduser");
63 return CMD_ERROR;
64 }
65 addflags=0;
66
67 /* Set the flags. We allow everything except personal flags and +mn. */
68 setflags(&addflags, QCUFLAG_ALL & ~(QCUFLAGS_PERSONAL | QCUFLAG_MASTER | QCUFLAG_OWNER), cargv[1], rcuflags, 0);
69
70 /* Remove impossible combinations */
71 addflags=cs_sanitisechanlev(addflags);
72
73 /* It helps a lot if they have actually set something */
74 if (!addflags) {
75 chanservstdmessage(sender, QM_NOFLAGSPECIFIED);
76 return CMD_ERROR;
77 }
78 } else {
79 addflags=QCUFLAG_OP | QCUFLAG_AUTOOP | QCUFLAG_TOPIC;
80 }
81
82 flagbuf=printflags(addflags, rcuflags);
83
84 /* ugh */
85 for (count=i=0;i<REGCHANUSERHASHSIZE;i++)
86 for (rcuplist=rcp->regusers[i];rcuplist;rcuplist=rcuplist->nextbychan)
87 count++;
88
89 /* If we found flags don't try to add them as a user as well.. */
90 for (i=1+foundflags;i<cargc;i++) {
91 if (!(rup=findreguser(sender, cargv[i])))
92 continue;
93
94 if ((rcup=findreguseronchannel(rcp, rup))) {
95 chanservstdmessage(sender, QM_ALREADYKNOWNONCHAN, cargv[i], cip->name->content);
96 continue;
97 }
98
99 if(count++ >= MAXCHANLEVS) {
100 chanservstdmessage(sender, QM_TOOMANYCHANLEVS);
101 chanservstdmessage(sender, QM_DONE);
102 return CMD_OK;
103 }
104
105 rcup=getregchanuser();
106 rcup->chan=rcp;
107 rcup->user=rup;
108 rcup->flags = addflags;
109 rcup->changetime=time(NULL);
110 rcup->usetime=0;
111 rcup->info=NULL;
112
113 args[0]=sender;
114 args[1]=rcup;
115 args[2]=(void *)0;
116
117 triggerhook(HOOK_CHANSERV_CHANLEVMOD, args);
118
119 cs_log(sender,"CHANLEV %s #%s %s (+ -> %s)",cip->name->content,rup->username, flagbuf, flagbuf);
120 addregusertochannel(rcup);
121 csdb_createchanuser(rcup);
122 csdb_chanlevhistory_insert(rcp, sender, rcup->user, 0, rcup->flags);
123 added++;
124 }
125
126 rcp->status |= QCSTAT_OPCHECK;
127 cs_timerfunc(cip);
128
129 if (added)
130 chanservstdmessage(sender, QM_DONE);
131
132 return CMD_OK;
133 }