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