]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sajoin.cpp
Merge pull request #217 from Shawn-Smith/insp20+antiredirect
[user/henk/code/inspircd.git] / src / modules / m_sajoin.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
6  *   Copyright (C) 2004-2005, 2007 Craig Edwards <craigedwards@brainbox.cc>
7  *
8  * This file is part of InspIRCd.  InspIRCd is free software: you can
9  * redistribute it and/or modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation, version 2.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21
22 #include "inspircd.h"
23
24 /* $ModDesc: Provides command SAJOIN to allow opers to force-join users to channels */
25
26 /** Handle /SAJOIN
27  */
28 class CommandSajoin : public Command
29 {
30  public:
31         CommandSajoin(Module* Creator) : Command(Creator,"SAJOIN", 2)
32         {
33                 flags_needed = 'o'; Penalty = 0; syntax = "<nick> <channel>";
34                 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
35         }
36
37         CmdResult Handle (const std::vector<std::string>& parameters, User *user)
38         {
39                 User* dest = ServerInstance->FindNick(parameters[0]);
40                 if (dest)
41                 {
42                         if (ServerInstance->ULine(dest->server))
43                         {
44                                 user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Cannot use an SA command on a u-lined client",user->nick.c_str());
45                                 return CMD_FAILURE;
46                         }
47                         if (IS_LOCAL(user) && !ServerInstance->IsChannel(parameters[1].c_str(), ServerInstance->Config->Limits.ChanMax))
48                         {
49                                 /* we didn't need to check this for each character ;) */
50                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name or name too long");
51                                 return CMD_FAILURE;
52                         }
53
54                         /* For local users, we send the JoinUser which may create a channel and set its TS.
55                          * For non-local users, we just return CMD_SUCCESS, knowing this will propagate it where it needs to be
56                          * and then that server will generate the users JOIN or FJOIN instead.
57                          */
58                         if (IS_LOCAL(dest))
59                         {
60                                 Channel::JoinUser(dest, parameters[1].c_str(), true, "", false, ServerInstance->Time());
61                                 /* Fix for dotslasher and w00t - if the join didnt succeed, return CMD_FAILURE so that it doesnt propagate */
62                                 Channel* n = ServerInstance->FindChan(parameters[1]);
63                                 if (n)
64                                 {
65                                         if (n->HasUser(dest))
66                                         {
67                                                 ServerInstance->SNO->WriteToSnoMask('a', std::string(user->nick)+" used SAJOIN to make "+std::string(dest->nick)+" join "+parameters[1]);
68                                                 return CMD_SUCCESS;
69                                         }
70                                         else
71                                         {
72                                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Could not join "+std::string(dest->nick)+" to "+parameters[1]+" (User is probably banned, or blocking modes)");
73                                                 return CMD_FAILURE;
74                                         }
75                                 }
76                                 else
77                                 {
78                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Could not join "+std::string(dest->nick)+" to "+parameters[1]);
79                                         return CMD_FAILURE;
80                                 }
81                         }
82                         else
83                         {
84                                 ServerInstance->SNO->WriteToSnoMask('a', std::string(user->nick)+" sent remote SAJOIN to make "+std::string(dest->nick)+" join "+parameters[1]);
85                                 return CMD_SUCCESS;
86                         }
87                 }
88                 else
89                 {
90                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** No such nickname "+parameters[0]);
91                         return CMD_FAILURE;
92                 }
93         }
94
95         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
96         {
97                 User* dest = ServerInstance->FindNick(parameters[0]);
98                 if (dest)
99                         return ROUTE_OPT_UCAST(dest->server);
100                 return ROUTE_LOCALONLY;
101         }
102 };
103
104 class ModuleSajoin : public Module
105 {
106         CommandSajoin cmd;
107  public:
108         ModuleSajoin()
109                 : cmd(this)
110         {
111                 ServerInstance->AddCommand(&cmd);
112         }
113
114         virtual ~ModuleSajoin()
115         {
116         }
117
118         virtual Version GetVersion()
119         {
120                 return Version("Provides command SAJOIN to allow opers to force-join users to channels", VF_OPTCOMMON | VF_VENDOR);
121         }
122
123 };
124
125 MODULE_INIT(ModuleSajoin)