]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_topic.cpp
Convert more modules
[user/henk/code/inspircd.git] / src / 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 "configreader.h"
16 #include "users.h"
17 #include "modules.h"
18 #include "commands/cmd_topic.h"
19
20
21 extern "C" DllExport command_t* init_command(InspIRCd* Instance)
22 {
23         return new cmd_topic(Instance);
24 }
25
26 CmdResult cmd_topic::Handle (const char** parameters, int pcnt, userrec *user)
27 {
28         chanrec* Ptr;
29
30         if (pcnt == 1)
31         {
32                 Ptr = ServerInstance->FindChan(parameters[0]);
33                 if (Ptr)
34                 {
35                         if ((Ptr->modes[CM_SECRET]) && (!Ptr->HasUser(user)))
36                         {
37                                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, Ptr->name);
38                                 return CMD_FAILURE;
39                         }
40                         if (Ptr->topicset)
41                         {
42                                 user->WriteServ("332 %s %s :%s", user->nick, Ptr->name, Ptr->topic);
43                                 user->WriteServ("333 %s %s %s %d", user->nick, Ptr->name, Ptr->setby, Ptr->topicset);
44                         }
45                         else
46                         {
47                                 user->WriteServ("331 %s %s :No topic is set.", user->nick, Ptr->name);
48                         }
49                 }
50                 else
51                 {
52                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
53                         return CMD_FAILURE;
54                 }
55                 return CMD_SUCCESS;
56         }
57         else if (pcnt>1)
58         {
59                 Ptr = ServerInstance->FindChan(parameters[0]);
60                 if (Ptr)
61                 {
62                         if (IS_LOCAL(user))
63                         {
64                                 if (!Ptr->HasUser(user))
65                                 {
66                                         user->WriteServ("442 %s %s :You're not on that channel!",user->nick, Ptr->name);
67                                         return CMD_FAILURE;
68                                 }
69                                 if ((Ptr->modes[CM_TOPICLOCK]) && (Ptr->GetStatus(user) < STATUS_HOP))
70                                 {
71                                         user->WriteServ("482 %s %s :You must be at least a half-operator to change the topic on this channel", user->nick, Ptr->name);
72                                         return CMD_FAILURE;
73                                 }
74                         }
75
76                         char topic[MAXTOPIC];
77
78                         if (IS_LOCAL(user))
79                         {
80                                 /* XXX: we need two string copies for a local topic, because we cant
81                                  * let a module see the topic as longer than it actually is
82                                  */
83                                 int MOD_RESULT = 0;
84
85                                 strlcpy(topic,parameters[1],MAXTOPIC-1);
86                                 FOREACH_RESULT(I_OnLocalTopicChange,OnLocalTopicChange(user,Ptr,topic));
87                                 if (MOD_RESULT)
88                                         return CMD_FAILURE;
89
90                                 strlcpy(Ptr->topic,topic,MAXTOPIC-1);
91                         }
92                         else
93                         {
94                                 /* Sneaky shortcut, one string copy for a remote topic */
95                                 strlcpy(Ptr->topic, parameters[1], MAXTOPIC-1);
96                         }
97
98                         if (ServerInstance->Config->FullHostInTopic)
99                                 strlcpy(Ptr->setby,user->GetFullHost(),127);
100                         else
101                                 strlcpy(Ptr->setby,user->nick,127);
102
103                         Ptr->topicset = ServerInstance->Time();
104                         Ptr->WriteChannel(user, "TOPIC %s :%s", Ptr->name, Ptr->topic);
105
106                         if (IS_LOCAL(user))
107                                 /* We know 'topic' will contain valid data here */
108                                 FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(user, Ptr, topic));
109                 }
110                 else
111                 {
112                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
113                         return CMD_FAILURE;
114                 }
115         }
116         return CMD_SUCCESS;
117 }
118