]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_topic.cpp
Update copyrights for 2009.
[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://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 "commands/cmd_topic.h"
16
17
18 extern "C" DllExport Command* init_command(InspIRCd* Instance)
19 {
20         return new CommandTopic(Instance);
21 }
22
23 CmdResult CommandTopic::Handle (const std::vector<std::string>& parameters, User *user)
24 {
25         Channel* c;
26
27         c = ServerInstance->FindChan(parameters[0]);
28         if (!c)
29         {
30                 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
31                 return CMD_FAILURE;
32         }
33
34         if (parameters.size() == 1)
35         {
36                 if (c)
37                 {
38                         if ((c->IsModeSet('s')) && (!c->HasUser(user)))
39                         {
40                                 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), c->name.c_str());
41                                 return CMD_FAILURE;
42                         }
43
44                         if (c->topic.length())
45                         {
46                                 user->WriteNumeric(332, "%s %s :%s", user->nick.c_str(), c->name.c_str(), c->topic.c_str());
47                                 user->WriteNumeric(333, "%s %s %s %lu", user->nick.c_str(), c->name.c_str(), c->setby.c_str(), (unsigned long)c->topicset);
48                         }
49                         else
50                         {
51                                 user->WriteNumeric(331, "%s %s :No topic is set.", user->nick.c_str(), c->name.c_str());
52                         }
53                 }
54                 return CMD_SUCCESS;
55         }
56         else if (parameters.size()>1)
57         {
58                 std::string t = parameters[1]; // needed, in case a module wants to change it
59                 c->SetTopic(user, t);
60         }
61
62         return CMD_SUCCESS;
63 }
64