]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sajoin.cpp
Fix double dot in half-cloaked resolved hosts
[user/henk/code/inspircd.git] / src / modules / m_sajoin.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Provides support for unreal-style SAJOIN command */
17
18 /** Handle /SAJOIN
19  */
20 class CommandSajoin : public Command
21 {
22  public:
23         CommandSajoin(Module* Creator) : Command(Creator,"SAJOIN", 2)
24         {
25                 flags_needed = 'o'; Penalty = 0; syntax = "<nick> <channel>";
26                 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
27         }
28
29         CmdResult Handle (const std::vector<std::string>& parameters, User *user)
30         {
31                 User* dest = ServerInstance->FindNick(parameters[0]);
32                 if (dest)
33                 {
34                         if (ServerInstance->ULine(dest->server))
35                         {
36                                 user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Cannot use an SA command on a u-lined client",user->nick.c_str());
37                                 return CMD_FAILURE;
38                         }
39                         if (IS_LOCAL(user) && !ServerInstance->IsChannel(parameters[1].c_str(), ServerInstance->Config->Limits.ChanMax))
40                         {
41                                 /* we didn't need to check this for each character ;) */
42                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name or name too long");
43                                 return CMD_FAILURE;
44                         }
45
46                         /* For local users, we send the JoinUser which may create a channel and set its TS.
47                          * For non-local users, we just return CMD_SUCCESS, knowing this will propagate it where it needs to be
48                          * and then that server will generate the users JOIN or FJOIN instead.
49                          */
50                         if (IS_LOCAL(dest))
51                         {
52                                 Channel::JoinUser(dest, parameters[1].c_str(), true, "", false, ServerInstance->Time());
53                                 /* Fix for dotslasher and w00t - if the join didnt succeed, return CMD_FAILURE so that it doesnt propagate */
54                                 Channel* n = ServerInstance->FindChan(parameters[1]);
55                                 if (n)
56                                 {
57                                         if (n->HasUser(dest))
58                                         {
59                                                 ServerInstance->SNO->WriteToSnoMask('a', std::string(user->nick)+" used SAJOIN to make "+std::string(dest->nick)+" join "+parameters[1]);
60                                                 return CMD_SUCCESS;
61                                         }
62                                         else
63                                         {
64                                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Could not join "+std::string(dest->nick)+" to "+parameters[1]+" (User is probably banned, or blocking modes)");
65                                                 return CMD_FAILURE;
66                                         }
67                                 }
68                                 else
69                                 {
70                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Could not join "+std::string(dest->nick)+" to "+parameters[1]);
71                                         return CMD_FAILURE;
72                                 }
73                         }
74                         else
75                         {
76                                 ServerInstance->SNO->WriteToSnoMask('a', std::string(user->nick)+" sent remote SAJOIN to make "+std::string(dest->nick)+" join "+parameters[1]);
77                                 return CMD_SUCCESS;
78                         }
79                 }
80                 else
81                 {
82                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** No such nickname "+parameters[0]);
83                         return CMD_FAILURE;
84                 }
85         }
86
87         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
88         {
89                 User* dest = ServerInstance->FindNick(parameters[0]);
90                 if (dest)
91                         return ROUTE_OPT_UCAST(dest->server);
92                 return ROUTE_LOCALONLY;
93         }
94 };
95
96 class ModuleSajoin : public Module
97 {
98         CommandSajoin cmd;
99  public:
100         ModuleSajoin()
101                 : cmd(this)
102         {
103                 ServerInstance->AddCommand(&cmd);
104         }
105
106         virtual ~ModuleSajoin()
107         {
108         }
109
110         virtual Version GetVersion()
111         {
112                 return Version("Provides support for unreal-style SAJOIN command", VF_OPTCOMMON | VF_VENDOR, API_VERSION);
113         }
114
115 };
116
117 MODULE_INIT(ModuleSajoin)