]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sajoin.cpp
Added ability to send and receive a challenge, dont do anything with it yet
[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                         chanrec::JoinUser(ServerInstance, dest, parameters[1], true, "");
53
54                         /* Fix for dotslasher and w00t - if the join didnt succeed, return CMD_FAILURE so that it doesnt propogate */
55                         chanrec* n = ServerInstance->FindChan(parameters[1]);
56                         if (n)
57                         {
58                                 if (n->HasUser(dest))
59                                 {
60                                         ServerInstance->WriteOpers(std::string(user->nick)+" used SAJOIN to make "+std::string(dest->nick)+" join "+parameters[1]);
61                                         return CMD_SUCCESS;
62                                 }
63                                 else
64                                 {
65                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Could not join "+std::string(dest->nick)+" to "+parameters[1]+" (User is probably banned, or blocking modes)");
66                                         return CMD_FAILURE;
67                                 }
68                         }
69                         else
70                         {
71                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Could not join "+std::string(dest->nick)+" to "+parameters[1]);
72                                 return CMD_FAILURE;
73                         }
74                 }
75                 else
76                 {
77                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** No such nickname "+parameters[0]);
78                         return CMD_FAILURE;
79                 }
80         }
81 };
82
83 class ModuleSajoin : public Module
84 {
85         cmd_sajoin*     mycommand;
86  public:
87         ModuleSajoin(InspIRCd* Me)
88                 : Module::Module(Me)
89         {
90                 
91                 mycommand = new cmd_sajoin(ServerInstance);
92                 ServerInstance->AddCommand(mycommand);
93         }
94         
95         virtual ~ModuleSajoin()
96         {
97         }
98         
99         virtual Version GetVersion()
100         {
101                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
102         }
103         
104 };
105
106 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
107
108 class ModuleSajoinFactory : public ModuleFactory
109 {
110  public:
111         ModuleSajoinFactory()
112         {
113         }
114         
115         ~ModuleSajoinFactory()
116         {
117         }
118         
119         virtual Module * CreateModule(InspIRCd* Me)
120         {
121                 return new ModuleSajoin(Me);
122         }
123         
124 };
125
126
127 extern "C" void * init_module( void )
128 {
129         return new ModuleSajoinFactory;
130 }
131