]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_cycle.cpp
Fix potential for duplicate SID if the SID is auto generated.
[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 cmd_cycle : public command_t
21 {
22  public:
23         cmd_cycle (InspIRCd* Instance) : command_t(Instance,"CYCLE", 0, 1)
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, userrec *user)
31         {
32                 chanrec* 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                         /*
44                          * technically, this is only ever sent locally, but pays to be safe ;p
45                          */
46                         if (IS_LOCAL(user))
47                         {
48                                 if (channel->GetStatus(user) < STATUS_VOICE && channel->IsBanned(user))
49                                 {
50                                         /* banned, boned. drop the message. */
51                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** You may not cycle, as you are banned on channel " + channel->name);
52                                         return CMD_FAILURE;
53                                 }
54                                 
55                                 /* XXX in the future, this may move to a static chanrec method (the delete.) -- w00t */
56                                 if (!channel->PartUser(user, reason.c_str()))
57                                         delete channel;
58                                 
59                                 chanrec::JoinUser(ServerInstance, user, parameters[0], true, "", ServerInstance->Time(true));
60                         }
61
62                         return CMD_LOCALONLY;
63                 }
64                 else
65                 {
66                         user->WriteServ("NOTICE %s :*** You are not on this channel", user->nick);
67                 }
68
69                 return CMD_FAILURE;
70         }
71 };
72
73
74 class ModuleCycle : public Module
75 {
76         cmd_cycle*      mycommand;
77  public:
78         ModuleCycle(InspIRCd* Me)
79                 : Module(Me)
80         {
81                 
82                 mycommand = new cmd_cycle(ServerInstance);
83                 ServerInstance->AddCommand(mycommand);
84         }
85         
86         virtual ~ModuleCycle()
87         {
88         }
89         
90         virtual Version GetVersion()
91         {
92                 return Version(1, 1, 0, 1, VF_COMMON | VF_VENDOR, API_VERSION);
93         }
94         
95 };
96
97 MODULE_INIT(ModuleCycle)