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