]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sajoin.cpp
Windows support. Tested and working to compile on freebsd and linux. Next step is...
[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 <stdio.h>
15 #include <string>
16 #include "users.h"
17 #include "channels.h"
18 #include "modules.h"
19
20 #include "inspircd.h"
21
22 /* $ModDesc: Provides support for unreal-style SAJOIN command */
23
24 /** Handle /SAJOIN
25  */
26 class cmd_sajoin : public command_t
27 {
28  public:
29  cmd_sajoin (InspIRCd* Instance) : command_t(Instance,"SAJOIN", 'o', 2)
30         {
31                 this->source = "m_sajoin.so";
32                 syntax = "<nick> <channel>";
33         }
34
35         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
36         {
37                 userrec* dest = ServerInstance->FindNick(parameters[0]);
38                 if (dest)
39                 {
40                         if (ServerInstance->ULine(dest->server))
41                         {
42                                 user->WriteServ("990 %s :Cannot use an SA command on a u-lined client",user->nick);
43                                 return CMD_FAILURE;
44                         }
45                         if (!ServerInstance->IsChannel(parameters[1]))
46                         {
47                                 /* we didn't need to check this for each character ;) */
48                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name");
49                                 return CMD_FAILURE;
50                         }
51
52                         /* For local users, we send the JoinUser which may create a channel and set its TS.
53                          * For non-local users, we just return CMD_SUCCESS, knowing this will propogate it where it needs to be
54                          * and then that server will generate the users JOIN or FJOIN instead.
55                          */
56                         if (IS_LOCAL(dest))
57                         {
58                                 chanrec::JoinUser(ServerInstance, dest, parameters[1], true, "", ServerInstance->Time(true));
59                                 /* Fix for dotslasher and w00t - if the join didnt succeed, return CMD_FAILURE so that it doesnt propogate */
60                                 chanrec* n = ServerInstance->FindChan(parameters[1]);
61                                 if (n)
62                                 {
63                                         if (n->HasUser(dest))
64                                         {
65                                                 ServerInstance->WriteOpers("*** "+std::string(user->nick)+" used SAJOIN to make "+std::string(dest->nick)+" join "+parameters[1]);
66                                                 return CMD_SUCCESS;
67                                         }
68                                         else
69                                         {
70                                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Could not join "+std::string(dest->nick)+" to "+parameters[1]+" (User is probably banned, or blocking modes)");
71                                                 return CMD_FAILURE;
72                                         }
73                                 }
74                                 else
75                                 {
76                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Could not join "+std::string(dest->nick)+" to "+parameters[1]);
77                                         return CMD_FAILURE;
78                                 }
79                         }
80                         else
81                         {
82                                 ServerInstance->WriteOpers("*** "+std::string(user->nick)+" sent remote SAJOIN to make "+std::string(dest->nick)+" join "+parameters[1]);
83                                 return CMD_SUCCESS;
84                         }
85                 }
86                 else
87                 {
88                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** No such nickname "+parameters[0]);
89                         return CMD_FAILURE;
90                 }
91         }
92 };
93
94 class ModuleSajoin : public Module
95 {
96         cmd_sajoin*     mycommand;
97  public:
98         ModuleSajoin(InspIRCd* Me)
99                 : Module(Me)
100         {
101                 
102                 mycommand = new cmd_sajoin(ServerInstance);
103                 ServerInstance->AddCommand(mycommand);
104         }
105         
106         virtual ~ModuleSajoin()
107         {
108         }
109         
110         virtual Version GetVersion()
111         {
112                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
113         }
114         
115 };
116
117 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
118
119 class ModuleSajoinFactory : public ModuleFactory
120 {
121  public:
122         ModuleSajoinFactory()
123         {
124         }
125         
126         ~ModuleSajoinFactory()
127         {
128         }
129         
130         virtual Module * CreateModule(InspIRCd* Me)
131         {
132                 return new ModuleSajoin(Me);
133         }
134         
135 };
136
137
138 extern "C" DllExport void * init_module( void )
139 {
140         return new ModuleSajoinFactory;
141 }
142