]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_topic.cpp
Move all_opers into class InspIRCd
[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 "commands.h"
22 #include "commands/cmd_topic.h"
23 #include "helperfuncs.h"
24
25 extern InspIRCd* ServerInstance;
26 extern time_t TIME;
27
28 void cmd_topic::Handle (const char** parameters, int pcnt, userrec *user)
29 {
30         chanrec* Ptr;
31
32         if (pcnt == 1)
33         {
34                 Ptr = ServerInstance->FindChan(parameters[0]);
35                 if (Ptr)
36                 {
37                         if ((Ptr->modes[CM_SECRET]) && (!Ptr->HasUser(user)))
38                         {
39                                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, Ptr->name);
40                                 return;
41                         }
42                         if (Ptr->topicset)
43                         {
44                                 user->WriteServ("332 %s %s :%s", user->nick, Ptr->name, Ptr->topic);
45                                 user->WriteServ("333 %s %s %s %d", user->nick, Ptr->name, Ptr->setby, Ptr->topicset);
46                         }
47                         else
48                         {
49                                 user->WriteServ("331 %s %s :No topic is set.", user->nick, Ptr->name);
50                         }
51                 }
52                 else
53                 {
54                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
55                 }
56                 return;
57         }
58         else if (pcnt>1)
59         {
60                 Ptr = ServerInstance->FindChan(parameters[0]);
61                 if (Ptr)
62                 {
63                         if (IS_LOCAL(user))
64                         {
65                                 if (!Ptr->HasUser(user))
66                                 {
67                                         user->WriteServ("442 %s %s :You're not on that channel!",user->nick, Ptr->name);
68                                         return;
69                                 }
70                                 if ((Ptr->modes[CM_TOPICLOCK]) && (Ptr->GetStatus(user) < STATUS_HOP))
71                                 {
72                                         user->WriteServ("482 %s %s :You must be at least a half-operator to change modes on this channel", user->nick, Ptr->name);
73                                         return;
74                                 }
75                         }
76                         char topic[MAXTOPIC];
77                         strlcpy(topic,parameters[1],MAXTOPIC-1);
78
79                         if (IS_LOCAL(user))
80                         {
81                                 int MOD_RESULT = 0;
82                                 FOREACH_RESULT(I_OnLocalTopicChange,OnLocalTopicChange(user,Ptr,topic));
83                                 if (MOD_RESULT)
84                                         return;
85                         }
86
87                         strlcpy(Ptr->topic,topic,MAXTOPIC-1);
88                         strlcpy(Ptr->setby,user->nick,NICKMAX-1);
89                         Ptr->topicset = TIME;
90                         Ptr->WriteChannel(user, "TOPIC %s :%s", Ptr->name, Ptr->topic);
91                         if (IS_LOCAL(user))
92                         {
93                                 FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(user,Ptr,topic));
94                         }
95                 }
96                 else
97                 {
98                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
99                 }
100         }
101 }
102