]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_topic.cpp
913b80dd3fe377635847bb19ce907fd2007e4449
[user/henk/code/inspircd.git] / src / cmd_topic.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                        E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include "inspircd_config.h"
18 #include "configreader.h"
19 #include "users.h"
20 #include "modules.h"
21 #include "message.h"
22 #include "commands.h"
23 #include "commands/cmd_topic.h"
24 #include "helperfuncs.h"
25
26 extern InspIRCd* ServerInstance;
27 extern int MODCOUNT;
28 extern time_t TIME;
29 extern ModuleList modules;
30 extern FactoryList factory;
31
32 void cmd_topic::Handle (const char** parameters, int pcnt, userrec *user)
33 {
34         chanrec* Ptr;
35
36         if (pcnt == 1)
37         {
38                 Ptr = FindChan(parameters[0]);
39                 if (Ptr)
40                 {
41                         if ((Ptr->modes[CM_SECRET]) && (!Ptr->HasUser(user)))
42                         {
43                                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, Ptr->name);
44                                 return;
45                         }
46                         if (Ptr->topicset)
47                         {
48                                 user->WriteServ("332 %s %s :%s", user->nick, Ptr->name, Ptr->topic);
49                                 user->WriteServ("333 %s %s %s %d", user->nick, Ptr->name, Ptr->setby, Ptr->topicset);
50                         }
51                         else
52                         {
53                                 user->WriteServ("331 %s %s :No topic is set.", user->nick, Ptr->name);
54                         }
55                 }
56                 else
57                 {
58                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
59                 }
60                 return;
61         }
62         else if (pcnt>1)
63         {
64                 Ptr = FindChan(parameters[0]);
65                 if (Ptr)
66                 {
67                         if (IS_LOCAL(user))
68                         {
69                                 if (!Ptr->HasUser(user))
70                                 {
71                                         user->WriteServ("442 %s %s :You're not on that channel!",user->nick, Ptr->name);
72                                         return;
73                                 }
74                                 if ((Ptr->modes[CM_TOPICLOCK]) && (cstatus(user,Ptr)<STATUS_HOP))
75                                 {
76                                         user->WriteServ("482 %s %s :You must be at least a half-operator to change modes on this channel", user->nick, Ptr->name);
77                                         return;
78                                 }
79                         }
80                         char topic[MAXTOPIC];
81                         strlcpy(topic,parameters[1],MAXTOPIC-1);
82
83                         if (IS_LOCAL(user))
84                         {
85                                 int MOD_RESULT = 0;
86                                 FOREACH_RESULT(I_OnLocalTopicChange,OnLocalTopicChange(user,Ptr,topic));
87                                 if (MOD_RESULT)
88                                         return;
89                         }
90
91                         strlcpy(Ptr->topic,topic,MAXTOPIC-1);
92                         strlcpy(Ptr->setby,user->nick,NICKMAX-1);
93                         Ptr->topicset = TIME;
94                         Ptr->WriteChannel(user, "TOPIC %s :%s", Ptr->name, Ptr->topic);
95                         if (IS_LOCAL(user))
96                         {
97                                 FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(user,Ptr,topic));
98                         }
99                 }
100                 else
101                 {
102                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
103                 }
104         }
105 }
106