]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_cycle.cpp
045ea3ad9470de0eb773abf7e39a957e6cec6f0f
[user/henk/code/inspircd.git] / src / modules / m_cycle.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 CYCLE command. */
17
18 /** Handle /CYCLE
19  */
20 class CommandCycle : public Command
21 {
22  public:
23         CommandCycle (InspIRCd* Instance) : Command(Instance,"CYCLE", 0, 1, false, 3)
24         {
25                 this->source = "m_cycle.so";
26                 syntax = "<channel> :[reason]";
27                 TRANSLATE3(TR_TEXT, TR_TEXT, TR_END);
28         }
29
30         CmdResult Handle (const char** parameters, int pcnt, User *user)
31         {
32                 Channel* channel = ServerInstance->FindChan(parameters[0]);
33                 std::string reason = ConvToStr("Cycling");
34                         
35                 if (pcnt > 1)
36                 {
37                         /* reason provided, use it */
38                         reason = reason + ": " + parameters[1];
39                 }
40                 
41                 if (!channel)
42                 {
43                         user->WriteServ("403 %s %s :No such channel", user->nick, parameters[0]);
44                         return CMD_FAILURE;
45                 }
46                 
47                 if (channel->HasUser(user))
48                 {
49                         /*
50                          * technically, this is only ever sent locally, but pays to be safe ;p
51                          */
52                         if (IS_LOCAL(user))
53                         {
54                                 if (channel->GetStatus(user) < STATUS_VOICE && channel->IsBanned(user))
55                                 {
56                                         /* banned, boned. drop the message. */
57                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** You may not cycle, as you are banned on channel " + channel->name);
58                                         return CMD_FAILURE;
59                                 }
60                                 
61                                 /* XXX in the future, this may move to a static Channel method (the delete.) -- w00t */
62                                 if (!channel->PartUser(user, reason.c_str()))
63                                         delete channel;
64                                 
65                                 Channel::JoinUser(ServerInstance, user, parameters[0], true, "", false, ServerInstance->Time(true));
66                         }
67
68                         return CMD_LOCALONLY;
69                 }
70                 else
71                 {
72                         user->WriteServ("442 %s %s :You're not on that channel", user->nick, channel->name);
73                 }
74
75                 return CMD_FAILURE;
76         }
77 };
78
79
80 class ModuleCycle : public Module
81 {
82         CommandCycle*   mycommand;
83  public:
84         ModuleCycle(InspIRCd* Me)
85                 : Module(Me)
86         {
87                 
88                 mycommand = new CommandCycle(ServerInstance);
89                 ServerInstance->AddCommand(mycommand);
90
91         }
92         
93         virtual ~ModuleCycle()
94         {
95         }
96         
97         virtual Version GetVersion()
98         {
99                 return Version(1, 1, 0, 1, VF_COMMON | VF_VENDOR, API_VERSION);
100         }
101         
102 };
103
104 MODULE_INIT(ModuleCycle)