]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_cycle.cpp
Remove InspIRCd* parameters and fields
[user/henk/code/inspircd.git] / src / modules / m_cycle.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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(Module* Creator) : Command(Creator,"CYCLE", 1)
24         {
25                 Penalty = 3; syntax = "<channel> :[reason]";
26                 TRANSLATE3(TR_TEXT, TR_TEXT, TR_END);
27         }
28
29         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
30         {
31                 Channel* channel = ServerInstance->FindChan(parameters[0]);
32                 std::string reason = ConvToStr("Cycling");
33
34                 if (parameters.size() > 1)
35                 {
36                         /* reason provided, use it */
37                         reason = reason + ": " + parameters[1];
38                 }
39
40                 if (!channel)
41                 {
42                         user->WriteNumeric(403, "%s %s :No such channel", user->nick.c_str(), parameters[0].c_str());
43                         return CMD_FAILURE;
44                 }
45
46                 if (channel->HasUser(user))
47                 {
48                         /*
49                          * technically, this is only ever sent locally, but pays to be safe ;p
50                          */
51                         if (IS_LOCAL(user))
52                         {
53                                 if (channel->GetPrefixValue(user) < VOICE_VALUE && channel->IsBanned(user))
54                                 {
55                                         /* banned, boned. drop the message. */
56                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** You may not cycle, as you are banned on channel " + channel->name);
57                                         return CMD_FAILURE;
58                                 }
59
60                                 /* XXX in the future, this may move to a static Channel method (the delete.) -- w00t */
61                                 if (!channel->PartUser(user, reason))
62                                         delete channel;
63
64                                 Channel::JoinUser(user, parameters[0].c_str(), true, "", false, ServerInstance->Time());
65                         }
66
67                         return CMD_SUCCESS;
68                 }
69                 else
70                 {
71                         user->WriteNumeric(442, "%s %s :You're not on that channel", user->nick.c_str(), channel->name.c_str());
72                 }
73
74                 return CMD_FAILURE;
75         }
76 };
77
78
79 class ModuleCycle : public Module
80 {
81         CommandCycle cmd;
82  public:
83         ModuleCycle()
84                 : cmd(this)
85         {
86                 ServerInstance->AddCommand(&cmd);
87         }
88
89         virtual ~ModuleCycle()
90         {
91         }
92
93         virtual Version GetVersion()
94         {
95                 return Version("Provides support for unreal-style CYCLE command.", VF_VENDOR, API_VERSION);
96         }
97
98 };
99
100 MODULE_INIT(ModuleCycle)