]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sajoin.cpp
Record compression ratio stats for a /stats char (this isnt finished yet)
[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 /** Handle /SAJOIN
30  */
31 class cmd_sajoin : public command_t
32 {
33  public:
34  cmd_sajoin (InspIRCd* Instance) : command_t(Instance,"SAJOIN", 'o', 2)
35         {
36                 this->source = "m_sajoin.so";
37                 syntax = "<nick> <channel>";
38         }
39
40         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
41         {
42                 userrec* dest = ServerInstance->FindNick(parameters[0]);
43                 if (dest)
44                 {
45                         if (ServerInstance->ULine(dest->server))
46                         {
47                                 user->WriteServ("990 %s :Cannot use an SA command on a u-lined client",user->nick);
48                                 return CMD_FAILURE;
49                         }
50                         if (!ServerInstance->IsChannel(parameters[1]))
51                         {
52                                 /* we didn't need to check this for each character ;) */
53                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name");
54                                 return CMD_FAILURE;
55                         }
56
57                         chanrec::JoinUser(ServerInstance, dest, parameters[1], true);
58
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                         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::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_VENDOR,API_VERSION);
107         }
108         
109 };
110
111 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
112
113 class ModuleSajoinFactory : public ModuleFactory
114 {
115  public:
116         ModuleSajoinFactory()
117         {
118         }
119         
120         ~ModuleSajoinFactory()
121         {
122         }
123         
124         virtual Module * CreateModule(InspIRCd* Me)
125         {
126                 return new ModuleSajoin(Me);
127         }
128         
129 };
130
131
132 extern "C" void * init_module( void )
133 {
134         return new ModuleSajoinFactory;
135 }
136