]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sajoin.cpp
Report invalid command name when invalid command is given in negotiation phase
[user/henk/code/inspircd.git] / src / modules / m_sajoin.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                     E-mail:
7  *              <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *          the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 #include <stdio.h>
20 #include <string>
21 #include "users.h"
22 #include "channels.h"
23 #include "modules.h"
24
25 #include "inspircd.h"
26
27 /* $ModDesc: Provides support for unreal-style SAJOIN command */
28
29
30
31
32 class cmd_sajoin : public command_t
33 {
34  public:
35  cmd_sajoin (InspIRCd* Instance) : command_t(Instance,"SAJOIN", 'o', 2)
36         {
37                 this->source = "m_sajoin.so";
38                 syntax = "<nick> <channel>";
39         }
40
41         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
42         {
43                 userrec* dest = ServerInstance->FindNick(parameters[0]);
44                 if (dest)
45                 {
46                         if (ServerInstance->ULine(dest->server))
47                         {
48                                 user->WriteServ("990 %s :Cannot use an SA command on a u-lined client",user->nick);
49                                 return CMD_FAILURE;
50                         }
51                         if (!ServerInstance->IsChannel(parameters[1]))
52                         {
53                                 /* we didn't need to check this for each character ;) */
54                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name");
55                                 return CMD_FAILURE;
56                         }
57
58                         chanrec::JoinUser(ServerInstance, dest, parameters[1], true);
59
60                         /* Fix for dotslasher and w00t - if the join didnt succeed, return CMD_FAILURE so that it doesnt propogate */
61                         chanrec* n = ServerInstance->FindChan(parameters[1]);
62                         if (n)
63                         {
64                                 if (n->HasUser(dest))
65                                 {
66                                         ServerInstance->WriteOpers(std::string(user->nick)+" used SAJOIN to make "+std::string(dest->nick)+" join "+parameters[1]);
67                                         return CMD_SUCCESS;
68                                 }
69                                 else
70                                 {
71                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Could not join "+std::string(dest->nick)+" to "+parameters[1]+" (User is probably banned, or blocking modes)");
72                                         return CMD_FAILURE;
73                                 }
74                         }
75                         else
76                         {
77                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Could not join "+std::string(dest->nick)+" to "+parameters[1]);
78                                 return CMD_FAILURE;
79                         }
80                 }
81
82                 return CMD_SUCCESS;
83         }
84 };
85
86 class ModuleSajoin : public Module
87 {
88         cmd_sajoin*     mycommand;
89  public:
90         ModuleSajoin(InspIRCd* Me)
91                 : Module::Module(Me)
92         {
93                 
94                 mycommand = new cmd_sajoin(ServerInstance);
95                 ServerInstance->AddCommand(mycommand);
96         }
97         
98         virtual ~ModuleSajoin()
99         {
100         }
101         
102         virtual Version GetVersion()
103         {
104                 return Version(1,0,0,1,VF_VENDOR,API_VERSION);
105         }
106         
107 };
108
109 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
110
111 class ModuleSajoinFactory : public ModuleFactory
112 {
113  public:
114         ModuleSajoinFactory()
115         {
116         }
117         
118         ~ModuleSajoinFactory()
119         {
120         }
121         
122         virtual Module * CreateModule(InspIRCd* Me)
123         {
124                 return new ModuleSajoin(Me);
125         }
126         
127 };
128
129
130 extern "C" void * init_module( void )
131 {
132         return new ModuleSajoinFactory;
133 }
134