]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sajoin.cpp
Add Module* creator to Command and ModeHandler
[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 (InspIRCd* Instance, Module* Creator) : Command(Instance, Creator,"SAJOIN", "o", 2, false, 0)
24         {
25                 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(ServerInstance, 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
88 class ModuleSajoin : public Module
89 {
90         CommandSajoin cmd;
91  public:
92         ModuleSajoin(InspIRCd* Me)
93                 : Module(Me), cmd(Me, this)
94         {
95                 ServerInstance->AddCommand(&cmd);
96         }
97
98         virtual ~ModuleSajoin()
99         {
100         }
101
102         virtual Version GetVersion()
103         {
104                 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
105         }
106
107 };
108
109 MODULE_INIT(ModuleSajoin)