1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 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 cmd_topic(Instance);
23 CmdResult cmd_topic::Handle (const char** parameters, int pcnt, User *user)
29 Ptr = ServerInstance->FindChan(parameters[0]);
32 if ((Ptr->IsModeSet('s')) && (!Ptr->HasUser(user)))
34 user->WriteServ("401 %s %s :No such nick/channel",user->nick, Ptr->name);
39 user->WriteServ("332 %s %s :%s", user->nick, Ptr->name, Ptr->topic);
40 user->WriteServ("333 %s %s %s %d", user->nick, Ptr->name, Ptr->setby, Ptr->topicset);
44 user->WriteServ("331 %s %s :No topic is set.", user->nick, Ptr->name);
49 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
56 Ptr = ServerInstance->FindChan(parameters[0]);
61 if (!Ptr->HasUser(user))
63 user->WriteServ("442 %s %s :You're not on that channel!",user->nick, Ptr->name);
66 if ((Ptr->IsModeSet('t')) && (Ptr->GetStatus(user) < STATUS_HOP))
68 user->WriteServ("482 %s %s :You must be at least a half-operator to change the topic on this channel", user->nick, Ptr->name);
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 strlcpy(topic,parameters[1],MAXTOPIC-1);
83 FOREACH_RESULT(I_OnLocalTopicChange,OnLocalTopicChange(user,Ptr,topic));
87 strlcpy(Ptr->topic,topic,MAXTOPIC-1);
91 /* Sneaky shortcut, one string copy for a remote topic */
92 strlcpy(Ptr->topic, parameters[1], MAXTOPIC-1);
95 if (ServerInstance->Config->FullHostInTopic)
96 strlcpy(Ptr->setby,user->GetFullHost(),127);
98 strlcpy(Ptr->setby,user->nick,127);
100 Ptr->topicset = ServerInstance->Time();
101 Ptr->WriteChannel(user, "TOPIC %s :%s", Ptr->name, Ptr->topic);
104 /* We know 'topic' will contain valid data here */
105 FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(user, Ptr, topic));
109 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);