]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_topic.cpp
e12fd64f9ef6becf26db735955246c7279e05cac
[user/henk/code/inspircd.git] / src / commands / cmd_topic.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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 char** parameters, int pcnt, User *user)
24 {
25         Channel* Ptr;
26
27         if (pcnt == 1)
28         {
29                 Ptr = ServerInstance->FindChan(parameters[0]);
30                 if (Ptr)
31                 {
32                         if ((Ptr->IsModeSet('s')) && (!Ptr->HasUser(user)))
33                         {
34                                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, Ptr->name);
35                                 return CMD_FAILURE;
36                         }
37                         if (Ptr->topicset)
38                         {
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);
41                         }
42                         else
43                         {
44                                 user->WriteServ("331 %s %s :No topic is set.", user->nick, Ptr->name);
45                         }
46                 }
47                 else
48                 {
49                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
50                         return CMD_FAILURE;
51                 }
52                 return CMD_SUCCESS;
53         }
54         else if (pcnt>1)
55         {
56                 Ptr = ServerInstance->FindChan(parameters[0]);
57                 if (Ptr)
58                 {
59                         if (IS_LOCAL(user))
60                         {
61                                 if (!Ptr->HasUser(user))
62                                 {
63                                         user->WriteServ("442 %s %s :You're not on that channel!",user->nick, Ptr->name);
64                                         return CMD_FAILURE;
65                                 }
66                                 if ((Ptr->IsModeSet('t')) && (Ptr->GetStatus(user) < STATUS_HOP))
67                                 {
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);
69                                         return CMD_FAILURE;
70                                 }
71                         }
72
73                         char topic[MAXTOPIC];
74
75                         if (IS_LOCAL(user))
76                         {
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
79                                  */
80                                 int MOD_RESULT = 0;
81
82                                 strlcpy(topic,parameters[1],MAXTOPIC-1);
83                                 FOREACH_RESULT(I_OnLocalTopicChange,OnLocalTopicChange(user,Ptr,topic));
84                                 if (MOD_RESULT)
85                                         return CMD_FAILURE;
86
87                                 strlcpy(Ptr->topic,topic,MAXTOPIC-1);
88                         }
89                         else
90                         {
91                                 /* Sneaky shortcut, one string copy for a remote topic */
92                                 strlcpy(Ptr->topic, parameters[1], MAXTOPIC-1);
93                         }
94
95                         if (ServerInstance->Config->FullHostInTopic)
96                                 strlcpy(Ptr->setby,user->GetFullHost(),127);
97                         else
98                                 strlcpy(Ptr->setby,user->nick,127);
99
100                         Ptr->topicset = ServerInstance->Time();
101                         Ptr->WriteChannel(user, "TOPIC %s :%s", Ptr->name, Ptr->topic);
102
103                         if (IS_LOCAL(user))
104                                 /* We know 'topic' will contain valid data here */
105                                 FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(user, Ptr, topic));
106                 }
107                 else
108                 {
109                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
110                         return CMD_FAILURE;
111                 }
112         }
113         return CMD_SUCCESS;
114 }
115