]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_cycle.cpp
...because every now and again, i have to do a massive commit.
[user/henk/code/inspircd.git] / src / modules / m_cycle.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 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                                 channel->PartUser(user, reason);
61
62                                 Channel::JoinUser(user, parameters[0].c_str(), true, "", false, ServerInstance->Time());
63                         }
64
65                         return CMD_SUCCESS;
66                 }
67                 else
68                 {
69                         user->WriteNumeric(442, "%s %s :You're not on that channel", user->nick.c_str(), channel->name.c_str());
70                 }
71
72                 return CMD_FAILURE;
73         }
74 };
75
76
77 class ModuleCycle : public Module
78 {
79         CommandCycle cmd;
80  public:
81         ModuleCycle()
82                 : cmd(this)
83         {
84                 ServerInstance->AddCommand(&cmd);
85         }
86
87         virtual ~ModuleCycle()
88         {
89         }
90
91         virtual Version GetVersion()
92         {
93                 return Version("Provides support for unreal-style CYCLE command.", VF_VENDOR);
94         }
95
96 };
97
98 MODULE_INIT(ModuleCycle)