]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chancmds/giveowner.c
Merge pull request #1 from meeb/meeb
[irc/quakenet/newserv.git] / chanserv / chancmds / giveowner.c
1 /*
2 * CMDNAME: giveowner
3 * CMDLEVEL: QCMD_AUTHED
4 * CMDARGS: 3
5 * CMDDESC: Gives total control over a channel to another user.
6 * CMDFUNC: csc_dogiveowner
7 * CMDPROTO: int csc_dogiveowner(void *source, int cargc, char **cargv);
8 * CMDHELP: Usage: GIVEOWNER <channel> <user> [<code>]
9 * CMDHELP: Gives complete control (+n flag) to the named user on the channel. The new owner
10 * CMDHELP: will have full control over the channel, including the ability to remove the
11 * CMDHELP: existing owner(s). As a precaution the named user must already have master (+m)
12 * CMDHELP: access on the channel. Use this command with extreme caution. Where:
13 * CMDHELP: channel - channel to use
14 * CMDHELP: user - user to give owner to, either a nickname on the network or #accountname.
15 * CMDHELP: code - a unique code used to authorize the operation. If the code is not
16 * CMDHELP: supplied, the appropriate code will be provided together with a
17 * CMDHELP: warning about the dangers of this command. If the wrong code is
18 * CMDHELP: entered owner access will not be granted.
19 * CMDHELP: GIVEOWNER requires owner (+n) 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_dogiveowner(void *source, int cargc, char **cargv) {
34 nick *sender=source;
35 chanindex *cip;
36 regchan *rcp;
37 regchanuser *rcup;
38 reguser *rup=getreguserfromnick(sender), *target;
39 char flagbuf[30];
40 flag_t oldflags;
41 unsigned int thehash;
42 char hashstr[100];
43 void *args[3];
44
45 if (cargc<2) {
46 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "giveowner");
47 return CMD_ERROR;
48 }
49
50 /* You need to either be +n or have the relevant override... */
51 if (!(cip=cs_checkaccess(sender, cargv[0], CA_OWNERPRIV,
52 NULL, "giveowner", QPRIV_CHANGECHANLEV, 0)))
53 return CMD_ERROR;
54
55 rcp=cip->exts[chanservext];
56
57 if (!(target=findreguser(sender, cargv[1])))
58 return CMD_ERROR; /* If there was an error, findreguser will have sent a message saying why.. */
59
60 rcup=findreguseronchannel(rcp, target);
61
62 /* Can't promote if already owner */
63 if (rcup && (rcup->flags & QCUFLAG_OWNER)) {
64 chanservstdmessage(sender,QM_GIVEOWNERALREADYOWNER,target->username,cip->name->content);
65 return CMD_ERROR;
66 }
67
68 /* You can only promote a master */
69 if (!rcup || !(rcup->flags & QCUFLAG_MASTER)) {
70 chanservstdmessage(sender,QM_GIVEOWNERNOTMASTER,target->username,cip->name->content);
71 return CMD_ERROR;
72 }
73
74 /* Compute ze hash */
75 sprintf(hashstr,"%u.%u.%u",rcp->ID,target->ID,rup->ID);
76 thehash=irc_crc32(hashstr);
77
78 sprintf(hashstr,"%x",thehash);
79
80 if (cargc<3) {
81 chanservstdmessage(sender,QM_GIVEOWNERNEEDHASH,cip->name->content,target->username,
82 cip->name->content,target->username,hashstr);
83 return CMD_OK;
84 }
85
86 if (ircd_strcmp(cargv[2], hashstr)) {
87 chanservstdmessage(sender,QM_GIVEOWNERWRONGHASH,target->username,
88 cip->name->content);
89 return CMD_ERROR;
90 }
91
92 /* OK, hash matches, do it. */
93 oldflags = rcup->flags;
94 rcup->flags |= QCUFLAG_OWNER;
95 rcup->changetime=time(NULL);
96
97 args[0]=sender;
98 args[1]=rcup;
99 args[2]=(void *)oldflags;
100
101 triggerhook(HOOK_CHANSERV_CHANLEVMOD, args);
102
103 chanservstdmessage(sender,QM_DONE);
104
105 strcpy(flagbuf,printflags(oldflags,rcuflags));
106 cs_log(sender,"GIVEOWNER %s #%s (%s -> %s)",cip->name->content,rcup->user->username,
107 flagbuf,printflags(rcup->flags,rcuflags));
108
109 csdb_chanlevhistory_insert(rcp, sender, rcup->user, oldflags, rcup->flags);
110 csdb_updatechanuser(rcup);
111
112 return CMD_OK;
113 }