]>
Commit | Line | Data |
---|---|---|
1dd6d55d | 1 | /* Automatically generated by refactor.pl. |
2 | * | |
3 | * | |
4 | * CMDNAME: renchan | |
5 | * CMDLEVEL: QCMD_OPER | |
9864c77d | 6 | * CMDARGS: 3 |
1dd6d55d | 7 | * CMDDESC: Renames a channel on the bot. |
8 | * CMDFUNC: csc_dorenchan | |
9 | * CMDPROTO: int csc_dorenchan(void *source, int cargc, char **cargv); | |
94e4d2f4 CP |
10 | * CMDHELP: Usage: renchan <old channel> <new channel> |
11 | * CMDHELP: Moves the bot from one channel to another, preserving flags. | |
1dd6d55d | 12 | */ |
13 | ||
14 | #include "../chanserv.h" | |
15 | #include "../../nick/nick.h" | |
16 | #include "../../lib/flags.h" | |
17 | #include "../../lib/irc_string.h" | |
18 | #include "../../channel/channel.h" | |
19 | #include "../../parser/parser.h" | |
20 | #include "../../irc/irc.h" | |
21 | #include "../../localuser/localuserchannel.h" | |
22 | #include <string.h> | |
23 | #include <stdio.h> | |
24 | ||
25 | int csc_dorenchan(void *source, int cargc, char **cargv) { | |
26 | nick *sender=source; | |
27 | reguser *rup=getreguserfromnick(sender); | |
28 | chanindex *cip1,*cip2; | |
29 | regchan *rcp; | |
30 | ||
31 | if (!rup) | |
32 | return CMD_ERROR; | |
33 | ||
34 | if (cargc<2) { | |
35 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "renchan"); | |
36 | return CMD_ERROR; | |
37 | } | |
38 | ||
39 | if (!(cip1=findchanindex(cargv[0])) || !(rcp=cip1->exts[chanservext])) { | |
40 | chanservstdmessage(sender, QM_UNKNOWNCHAN, cargv[0]); | |
41 | return CMD_ERROR; | |
42 | } | |
43 | ||
44 | if (*cargv[1] != '#') { | |
45 | chanservstdmessage(sender, QM_INVALIDCHANNAME, cargv[0]); | |
46 | return CMD_ERROR; | |
47 | } | |
48 | ||
49 | if (!(cip2=findorcreatechanindex(cargv[1])) || cip2->exts[chanservext]) { | |
50 | chanservstdmessage(sender, QM_ALREADYREGISTERED, cip2->name->content); | |
51 | return CMD_ERROR; | |
52 | } | |
53 | ||
54 | cs_log(sender,"RENCHAN %s -> %s",cip1->name->content,cip2->name->content); | |
55 | ||
56 | /* Remove from the channel. Don't bother if the channel doesn't exist. */ | |
57 | if (!CIsSuspended(rcp) && cip1->channel) { | |
58 | CSetSuspended(rcp); | |
59 | chanservjoinchan(cip1->channel); | |
60 | CClearSuspended(rcp); | |
61 | } | |
62 | ||
63 | cip1->exts[chanservext]=NULL; | |
64 | releasechanindex(cip1); | |
65 | ||
66 | cip2->exts[chanservext]=rcp; | |
67 | rcp->index=cip2; | |
68 | if (cip2->channel) { | |
69 | chanservjoinchan(cip2->channel); | |
70 | } | |
71 | ||
72 | csdb_updatechannel(rcp); | |
73 | chanservstdmessage(sender, QM_DONE); | |
74 | ||
75 | return CMD_OK; | |
76 | } |