]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_topic.cpp
Added comment
[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 using namespace std;
18
19 #include "inspircd_config.h"
20 #include "inspircd.h"
21 #include "inspircd_io.h"
22 #include <time.h>
23 #include <string>
24 #ifdef GCC3
25 #include <ext/hash_map>
26 #else
27 #include <hash_map>
28 #endif
29 #include <map>
30 #include <sstream>
31 #include <vector>
32 #include <deque>
33 #include "users.h"
34 #include "ctables.h"
35 #include "globals.h"
36 #include "modules.h"
37 #include "dynamic.h"
38 #include "wildcard.h"
39 #include "message.h"
40 #include "commands.h"
41 #include "mode.h"
42 #include "xline.h"
43 #include "inspstring.h"
44 #include "dnsqueue.h"
45 #include "helperfuncs.h"
46 #include "hashcomp.h"
47 #include "socketengine.h"
48 #include "typedefs.h"
49 #include "command_parse.h"
50 #include "cmd_topic.h"
51
52 extern ServerConfig* Config;
53 extern InspIRCd* ServerInstance;
54 extern int MODCOUNT;
55 extern std::vector<Module*> modules;
56 extern std::vector<ircd_module*> factory;
57 extern time_t TIME;
58 extern user_hash clientlist;
59 extern chan_hash chanlist;
60 extern whowas_hash whowas;
61 extern std::vector<userrec*> all_opers;
62 extern std::vector<userrec*> local_users;
63 extern userrec* fd_ref_table[MAX_DESCRIPTORS];
64
65 void cmd_topic::Handle (char **parameters, int pcnt, userrec *user)
66 {
67         chanrec* Ptr;
68
69         if (pcnt == 1)
70         {
71                 if (strlen(parameters[0]) <= CHANMAX)
72                 {
73                         Ptr = FindChan(parameters[0]);
74                         if (Ptr)
75                         {
76                                 if (((Ptr) && (!has_channel(user,Ptr))) && (Ptr->binarymodes & CM_SECRET))
77                                 {
78                                         WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, Ptr->name);
79                                         return;
80                                 }
81                                 if (Ptr->topicset)
82                                 {
83                                         WriteServ(user->fd,"332 %s %s :%s", user->nick, Ptr->name, Ptr->topic);
84                                         WriteServ(user->fd,"333 %s %s %s %d", user->nick, Ptr->name, Ptr->setby, Ptr->topicset);
85                                 }
86                                 else
87                                 {
88                                         WriteServ(user->fd,"331 %s %s :No topic is set.", user->nick, Ptr->name);
89                                 }
90                         }
91                         else
92                         {
93                                 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
94                         }
95                 }
96                 return;
97         }
98         else if (pcnt>1)
99         {
100                 if (strlen(parameters[0]) <= CHANMAX)
101                 {
102                         Ptr = FindChan(parameters[0]);
103                         if (Ptr)
104                         {
105                                 if (IS_LOCAL(user))
106                                 {
107                                         if ((Ptr) && (!has_channel(user,Ptr)))
108                                         {
109                                                 WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, Ptr->name);
110                                                 return;
111                                         }
112                                         if ((Ptr->binarymodes & CM_TOPICLOCK) && (cstatus(user,Ptr)<STATUS_HOP))
113                                         {
114                                                 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel", user->nick, Ptr->name);
115                                                 return;
116                                         }
117                                 }
118
119                                 char topic[MAXBUF];
120                                 strlcpy(topic,parameters[1],MAXBUF);
121                                 if (strlen(topic)>MAXTOPIC)
122                                 {
123                                         topic[MAXTOPIC] = '\0';
124                                 }
125
126                                 if (IS_LOCAL(user))
127                                 {
128                                         int MOD_RESULT = 0;
129                                         FOREACH_RESULT(I_OnLocalTopicChange,OnLocalTopicChange(user,Ptr,topic));
130                                         if (MOD_RESULT)
131                                                 return;
132                                 }
133
134                                 strlcpy(Ptr->topic,topic,MAXTOPIC);
135                                 strlcpy(Ptr->setby,user->nick,NICKMAX-1);
136                                 Ptr->topicset = TIME;
137                                 WriteChannel(Ptr,user,"TOPIC %s :%s",Ptr->name, Ptr->topic);
138                                 if (IS_LOCAL(user))
139                                 {
140                                         FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(user,Ptr,topic));
141                                 }
142                         }
143                         else
144                         {
145                                 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
146                         }
147                 }
148         }
149 }
150
151