]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sajoin.cpp
75e01704409a2a16e9063e72b771ad857194f23f
[user/henk/code/inspircd.git] / src / modules / m_sajoin.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18
19 /* $ModDesc: Provides support for unreal-style SAJOIN command */
20
21 /** Handle /SAJOIN
22  */
23 class cmd_sajoin : public command_t
24 {
25  public:
26  cmd_sajoin (InspIRCd* Instance) : command_t(Instance,"SAJOIN", 'o', 2)
27         {
28                 this->source = "m_sajoin.so";
29                 syntax = "<nick> <channel>";
30         }
31
32         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
33         {
34                 userrec* dest = ServerInstance->FindNick(parameters[0]);
35                 if (dest)
36                 {
37                         if (ServerInstance->ULine(dest->server))
38                         {
39                                 user->WriteServ("990 %s :Cannot use an SA command on a u-lined client",user->nick);
40                                 return CMD_FAILURE;
41                         }
42                         if (!ServerInstance->IsChannel(parameters[1]))
43                         {
44                                 /* we didn't need to check this for each character ;) */
45                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name");
46                                 return CMD_FAILURE;
47                         }
48
49                         /* For local users, we send the JoinUser which may create a channel and set its TS.
50                          * For non-local users, we just return CMD_SUCCESS, knowing this will propogate it where it needs to be
51                          * and then that server will generate the users JOIN or FJOIN instead.
52                          */
53                         if (IS_LOCAL(dest))
54                         {
55                                 chanrec::JoinUser(ServerInstance, dest, parameters[1], true, "", ServerInstance->Time(true));
56                                 /* Fix for dotslasher and w00t - if the join didnt succeed, return CMD_FAILURE so that it doesnt propogate */
57                                 chanrec* n = ServerInstance->FindChan(parameters[1]);
58                                 if (n)
59                                 {
60                                         if (n->HasUser(dest))
61                                         {
62                                                 ServerInstance->WriteOpers("*** "+std::string(user->nick)+" used SAJOIN to make "+std::string(dest->nick)+" join "+parameters[1]);
63                                                 return CMD_SUCCESS;
64                                         }
65                                         else
66                                         {
67                                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Could not join "+std::string(dest->nick)+" to "+parameters[1]+" (User is probably banned, or blocking modes)");
68                                                 return CMD_FAILURE;
69                                         }
70                                 }
71                                 else
72                                 {
73                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Could not join "+std::string(dest->nick)+" to "+parameters[1]);
74                                         return CMD_FAILURE;
75                                 }
76                         }
77                         else
78                         {
79                                 ServerInstance->WriteOpers("*** "+std::string(user->nick)+" sent remote SAJOIN to make "+std::string(dest->nick)+" join "+parameters[1]);
80                                 return CMD_SUCCESS;
81                         }
82                 }
83                 else
84                 {
85                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** No such nickname "+parameters[0]);
86                         return CMD_FAILURE;
87                 }
88         }
89 };
90
91 class ModuleSajoin : public Module
92 {
93         cmd_sajoin*     mycommand;
94  public:
95         ModuleSajoin(InspIRCd* Me)
96                 : Module(Me)
97         {
98                 
99                 mycommand = new cmd_sajoin(ServerInstance);
100                 ServerInstance->AddCommand(mycommand);
101         }
102         
103         virtual ~ModuleSajoin()
104         {
105         }
106         
107         virtual Version GetVersion()
108         {
109                 return Version(1, 1, 0, 1, VF_COMMON | VF_VENDOR, API_VERSION);
110         }
111         
112 };
113
114 MODULE_INIT(ModuleSajoin)