1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "commands/cmd_topic.h"
18 extern "C" DllExport Command* init_command(InspIRCd* Instance)
20 return new CommandTopic(Instance);
23 CmdResult CommandTopic::Handle (const std::vector<std::string>& parameters, User *user)
27 if (parameters.size() == 1)
29 Ptr = ServerInstance->FindChan(parameters[0]);
32 if ((Ptr->IsModeSet('s')) && (!Ptr->HasUser(user)))
34 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), Ptr->name.c_str());
39 user->WriteNumeric(332, "%s %s :%s", user->nick.c_str(), Ptr->name.c_str(), Ptr->topic.c_str());
40 user->WriteNumeric(333, "%s %s %s %lu", user->nick.c_str(), Ptr->name.c_str(), Ptr->setby.c_str(), (unsigned long)Ptr->topicset);
44 user->WriteNumeric(331, "%s %s :No topic is set.", user->nick.c_str(), Ptr->name.c_str());
49 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
54 else if (parameters.size()>1)
56 Ptr = ServerInstance->FindChan(parameters[0]);
61 if (!Ptr->HasUser(user))
63 user->WriteNumeric(442, "%s %s :You're not on that channel!",user->nick.c_str(), Ptr->name.c_str());
66 if ((Ptr->IsModeSet('t')) && (Ptr->GetStatus(user) < STATUS_HOP))
68 user->WriteNumeric(482, "%s %s :You must be at least a half-operator to change the topic on this channel", user->nick.c_str(), Ptr->name.c_str());
77 /* XXX: we need two string copies for a local topic, because we cant
78 * let a module see the topic as longer than it actually is
82 topic.assign(parameters[1], 0, ServerInstance->Config->Limits.MaxTopic);
83 FOREACH_RESULT(I_OnLocalTopicChange,OnLocalTopicChange(user,Ptr,topic));
87 Ptr->topic.assign(topic, 0, ServerInstance->Config->Limits.MaxTopic);
91 /* Sneaky shortcut, one string copy for a remote topic */
92 Ptr->topic.assign(parameters[1], 0, ServerInstance->Config->Limits.MaxTopic);
95 Ptr->setby.assign(ServerInstance->Config->FullHostInTopic ?
96 user->GetFullHost() : user->nick,
99 Ptr->topicset = ServerInstance->Time();
100 Ptr->WriteChannel(user, "TOPIC %s :%s", Ptr->name.c_str(), Ptr->topic.c_str());
103 /* We know 'topic' will contain valid data here */
104 FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(user, Ptr, topic));
108 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());