-
Notifications
You must be signed in to change notification settings - Fork 0
/
os_redirect.c
138 lines (122 loc) · 4.58 KB
/
os_redirect.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
* -----------------------------------------------------------------------------
* Name : os_redirect
* Author : VisioN <vision@myirc.net>
* Date: 24/1/2012 Last Updated: 15/1/2012
* Version : 1.0
* -----------------------------------------------------------------------------
* Limitations : Any IRCd which supports SVSPART and SVSJOIN
* Requires : Anope 1.8.7
* Tested : Anope 1.8.7 + UnrealIRCd 3.2.8 & UnrealIRCD 3.2.9
* -----------------------------------------------------------------------------
* This module creates the /os redirect command.
* The command syntax is /os redirect user #from_channel #to_channel
* This command makes the user part the #from_channel and join the #to_channel.
*
* -----------------------------------------------------------------------------
* Changelog:
*
* 1.0 - Initial Module Release
*
*
*
* -----------------------------------------------------------------------------
**/
#include "module.h"
#define AUTHOR "VisioN"
#define VERSION "1.0"
int do_redirect (User *u);
int AnopeInit(int argc, char **argv) {
/* We create the command we're going to use */
int req_access = 1;
char *usermsg =
Directive conf[]=
{
{"RedirectAccess",{ { PARAM_INT, PARAM_RELOAD, &req_access } } }
};
moduleGetConfigDirective(conf);
Command *c;
if ((req_access!=0) && (req_access!=1) && (req_access!=2)) req_access=1;
if (req_access==0)
{
c = createCommand("redirect", do_redirect,NULL, -1, -1, -1, -1, -1);
alog("Loading os_redirect with restriction to noone");
}
else if (req_access==1)
{
c = createCommand("redirect", do_redirect,is_services_oper, -1, -1, -1, -1, -1);
alog("Loading os_redirect with restriction to services operators");
}
else if (req_access==2)
{
c = createCommand("redirect", do_redirect,is_services_admin, -1, -1, -1, -1, -1);
alog("Loading os_redirect with restriction to services administrators");
}
/* We add the command to HelpServ and log it */
alog("os_redirect: Add command 'redirect' status: %d", moduleAddCommand(OPERSERV, c, MOD_HEAD));
/* We tell Anope who we are and what version this module is */
moduleAddAuthor(AUTHOR);
moduleAddVersion(VERSION);
/* Loading succeeded */
return MOD_CONT;
}
void AnopeFini(void) {
/* Nothing to clean up */
}
int do_redirect (User *u) {
char *buf = moduleGetLastBuffer();
User *target= NULL;
Channel *c;
ChannelInfo *ci;
char *nick = myStrGetToken (buf,' ', 0);
char *chan1 = myStrGetToken (buf,' ', 1);
char *chan2 = myStrGetToken (buf,' ', 2);
if (!u ||!chan1||!nick||!chan2)
{
if (nick) free(nick);
if (chan1) free(chan1);
if (chan2) free(chan2);
return MOD_STOP;
}
if (!(target = finduser(nick)))
{
notice (s_OperServ, u->nick,"No such user to redirect");
if (nick) free(nick);
if (chan1) free(chan1);
if (chan2) free(chan2);
return MOD_STOP;
}
if (!(ci = cs_findchan(chan1)))
{
if (nick) free(nick);
if (chan1) free(chan1);
if (chan2) free(chan2);
return MOD_STOP;
}
if (!(c = findchan(ci->name)))
{
notice (s_OperServ, u->nick,"No such channel to be redirected from.");
if (nick) free(nick);
if (chan1) free(chan1);
if (chan2) free(chan2);
return MOD_STOP;
}
if (!(is_on_chan(c,target)))
{
notice (s_OperServ, u->nick,"User %s is not in this channel", target->nick);
if (nick) free(nick);
if (chan1) free(chan1);
if (chan2) free(chan2);
return MOD_STOP;
}
notice (s_OperServ, u->nick,"Redirecting user %s from channel %s to channel %s",target->nick,chan1,chan2);
wallops(c->ci->bi->nick, "%s redirected %s from channel %s to channel %s .", u->nick, nick, c->name , chan2);
anope_cmd_svspart(c->ci->bi->nick, nick, c->name);
anope_cmd_svsjoin(s_OperServ, target->nick, chan2, NULL);
notice (s_OperServ, target->nick,"You have been redirected from channel %s to channel %s by operator %s", chan1,chan2,u->nick);
if (nick) free(nick);
if (chan1) free(chan1);
if (chan2) free(chan2);
/* Halt processing */
return MOD_STOP;
}