]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_topic.cpp
97321460e470f4dabbb07b6b1907108339972a54
[user/henk/code/inspircd.git] / src / commands / cmd_topic.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 #ifndef __CMD_TOPIC_H__
17 #define __CMD_TOPIC_H__
18
19 // include the common header files
20
21 #include "users.h"
22 #include "channels.h"
23
24 /** Handle /TOPIC. These command handlers can be reloaded by the core,
25  * and handle basic RFC1459 commands. Commands within modules work
26  * the same way, however, they can be fully unloaded, where these
27  * may not.
28  */
29 class CommandTopic : public Command
30 {
31  public:
32         /** Constructor for topic.
33          */
34         CommandTopic (InspIRCd* Instance, Module* parent) : Command(Instance,parent,"TOPIC",0,1,false,2) { syntax = "<channel> [<topic>]"; }
35         /** Handle command.
36          * @param parameters The parameters to the comamnd
37          * @param pcnt The number of parameters passed to teh command
38          * @param user The user issuing the command
39          * @return A value from CmdResult to indicate command success or failure.
40          */
41         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
42 };
43
44 #endif
45
46
47
48 CmdResult CommandTopic::Handle (const std::vector<std::string>& parameters, User *user)
49 {
50         Channel* c;
51
52         c = ServerInstance->FindChan(parameters[0]);
53         if (!c)
54         {
55                 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
56                 return CMD_FAILURE;
57         }
58
59         if (parameters.size() == 1)
60         {
61                 if (c)
62                 {
63                         if ((c->IsModeSet('s')) && (!c->HasUser(user)))
64                         {
65                                 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), c->name.c_str());
66                                 return CMD_FAILURE;
67                         }
68
69                         if (c->topic.length())
70                         {
71                                 user->WriteNumeric(332, "%s %s :%s", user->nick.c_str(), c->name.c_str(), c->topic.c_str());
72                                 user->WriteNumeric(333, "%s %s %s %lu", user->nick.c_str(), c->name.c_str(), c->setby.c_str(), (unsigned long)c->topicset);
73                         }
74                         else
75                         {
76                                 user->WriteNumeric(RPL_NOTOPICSET, "%s %s :No topic is set.", user->nick.c_str(), c->name.c_str());
77                         }
78                 }
79                 return CMD_SUCCESS;
80         }
81         else if (parameters.size()>1)
82         {
83                 std::string t = parameters[1]; // needed, in case a module wants to change it
84                 c->SetTopic(user, t);
85         }
86
87         return CMD_SUCCESS;
88 }
89
90
91 COMMAND_INIT(CommandTopic)