]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sajoin.cpp
32d136d6bdcdd0fcb2dd9395707aa555b6efbe73
[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
16 /* $ModDesc: Provides support for unreal-style SAJOIN command */
17
18 /** Handle /SAJOIN
19  */
20 class cmd_sajoin : public command_t
21 {
22  public:
23  cmd_sajoin (InspIRCd* Instance) : command_t(Instance,"SAJOIN", 'o', 2)
24         {
25                 this->source = "m_sajoin.so";
26                 syntax = "<nick> <channel>";
27         }
28
29         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
30         {
31                 userrec* dest = ServerInstance->FindNick(parameters[0]);
32                 if (dest)
33                 {
34                         if (ServerInstance->ULine(dest->server))
35                         {
36                                 user->WriteServ("990 %s :Cannot use an SA command on a u-lined client",user->nick);
37                                 return CMD_FAILURE;
38                         }
39                         if (!ServerInstance->IsChannel(parameters[1]))
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");
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 propogate 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                                 chanrec::JoinUser(ServerInstance, dest, parameters[1], true, "", ServerInstance->Time(true));
53                                 /* Fix for dotslasher and w00t - if the join didnt succeed, return CMD_FAILURE so that it doesnt propogate */
54                                 chanrec* n = ServerInstance->FindChan(parameters[1]);
55                                 if (n)
56                                 {
57                                         if (n->HasUser(dest))
58                                         {
59                                                 ServerInstance->WriteOpers("*** "+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->WriteOpers("*** "+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         cmd_sajoin*     mycommand;
91  public:
92         ModuleSajoin(InspIRCd* Me)
93                 : Module(Me)
94         {
95                 
96                 mycommand = new cmd_sajoin(ServerInstance);
97                 ServerInstance->AddCommand(mycommand);
98         }
99         
100         virtual ~ModuleSajoin()
101         {
102         }
103         
104         virtual Version GetVersion()
105         {
106                 return Version(1, 1, 0, 1, VF_COMMON | VF_VENDOR, API_VERSION);
107         }
108         
109 };
110
111 MODULE_INIT(ModuleSajoin)