1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
17 #include "configreader.h"
20 #include "commands/cmd_topic.h"
24 extern "C" command_t* init_command(InspIRCd* Instance)
26 return new cmd_topic(Instance);
29 CmdResult cmd_topic::Handle (const char** parameters, int pcnt, userrec *user)
35 Ptr = ServerInstance->FindChan(parameters[0]);
38 if ((Ptr->modes[CM_SECRET]) && (!Ptr->HasUser(user)))
40 user->WriteServ("401 %s %s :No such nick/channel",user->nick, Ptr->name);
45 user->WriteServ("332 %s %s :%s", user->nick, Ptr->name, Ptr->topic);
46 user->WriteServ("333 %s %s %s %d", user->nick, Ptr->name, Ptr->setby, Ptr->topicset);
50 user->WriteServ("331 %s %s :No topic is set.", user->nick, Ptr->name);
55 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
62 Ptr = ServerInstance->FindChan(parameters[0]);
67 if (!Ptr->HasUser(user))
69 user->WriteServ("442 %s %s :You're not on that channel!",user->nick, Ptr->name);
72 if ((Ptr->modes[CM_TOPICLOCK]) && (Ptr->GetStatus(user) < STATUS_HOP))
74 user->WriteServ("482 %s %s :You must be at least a half-operator to change modes on this channel", user->nick, Ptr->name);
83 /* XXX: we need two string copies for a local topic, because we cant
84 * let a module see the topic as longer than it actually is
88 strlcpy(topic,parameters[1],MAXTOPIC-1);
89 FOREACH_RESULT(I_OnLocalTopicChange,OnLocalTopicChange(user,Ptr,topic));
93 strlcpy(Ptr->topic,topic,MAXTOPIC-1);
97 /* Sneaky shortcut, one string copy for a remote topic */
98 strlcpy(Ptr->topic, parameters[1], MAXTOPIC-1);
101 strlcpy(Ptr->setby,user->nick,NICKMAX-1);
102 Ptr->topicset = ServerInstance->Time();
103 Ptr->WriteChannel(user, "TOPIC %s :%s", Ptr->name, Ptr->topic);
106 /* We know 'topic' will contain valid data here */
107 FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(user, Ptr, topic));
111 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);