ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_topic.c
(Generate patch)

Comparing:
ircd-hybrid-7.2/modules/m_topic.c (file contents), Revision 895 by michael, Fri Nov 2 11:15:22 2007 UTC vs.
ircd-hybrid/trunk/modules/m_topic.c (file contents), Revision 5347 by michael, Sun Jan 11 12:42:20 2015 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  m_topic.c: Sets a channel topic.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2015 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 16 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file m_topic.c
23 > * \brief Includes required functions for processing the TOPIC command.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28 < #include "tools.h"
27 < #include "handlers.h"
28 > #include "list.h"
29   #include "channel.h"
30   #include "channel_mode.h"
31   #include "client.h"
32   #include "hash.h"
33   #include "irc_string.h"
33 #include "sprintf_irc.h"
34   #include "ircd.h"
35   #include "numeric.h"
36   #include "send.h"
37 #include "s_conf.h"
38 #include "s_serv.h"
39 #include "msg.h"
37   #include "parse.h"
38   #include "modules.h"
39   #include "packet.h"
43 #include "common.h"
44
45 static void m_topic(struct Client *, struct Client *, int, char *[]);
40  
47 struct Message topic_msgtab = {
48  "TOPIC", 0, 0, 2, 0, MFLG_SLOW, 0,
49  {m_unregistered, m_topic, m_topic, m_ignore, m_topic, m_ignore}
50 };
41  
42 < #ifndef STATIC_MODULES
43 < void
44 < _modinit(void)
45 < {
46 <  mod_add_cmd(&topic_msgtab);
47 < }
48 <
49 < void
50 < _moddeinit(void)
51 < {
52 <  mod_del_cmd(&topic_msgtab);
63 < }
64 <
65 < const char *_version = "$Revision$";
66 < #endif
67 <
68 < /* m_topic()
69 < *  parv[0] = sender prefix
70 < *  parv[1] = channel name
71 < *  parv[2] = new topic, if setting topic
42 > /*! \brief TOPIC command handler
43 > *
44 > * \param source_p Pointer to allocated Client struct from which the message
45 > *                 originally comes from.  This can be a local or remote client.
46 > * \param parc     Integer holding the number of supplied arguments.
47 > * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
48 > *                 pointers.
49 > * \note Valid arguments for this command are:
50 > *      - parv[0] = command
51 > *      - parv[1] = channel name
52 > *      - parv[2] = topic text, if setting topic
53   */
54 < static void
55 < m_topic(struct Client *client_p, struct Client *source_p,
75 <        int parc, char *parv[])
54 > static int
55 > m_topic(struct Client *source_p, int parc, char *parv[])
56   {
57    struct Channel *chptr = NULL;
78  const char *from, *to;
79
80  if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
81  {
82    from = me.id;
83    to = source_p->id;
84  }
85  else
86  {
87    from = me.name;
88    to = source_p->name;
89  }
58  
59    if (EmptyString(parv[1]))
60    {
61 <    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
62 <               from, to, "TOPIC");
95 <    return;
61 >    sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "TOPIC");
62 >    return 0;
63    }
64  
65 <  if (MyClient(source_p) && !IsFloodDone(source_p))
65 >  if (!IsFloodDone(source_p))
66      flood_endgrace(source_p);
67  
68    if ((chptr = hash_find_channel(parv[1])) == NULL)
69    {
70 <    sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
71 <               from, to, parv[1]);
105 <    return;
70 >    sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]);
71 >    return 0;
72    }
73  
74    /* setting topic */
75    if (parc > 2)
76    {
77 <    struct Membership *ms;
77 >    const struct Membership *member = NULL;
78  
79 <    if ((ms = find_channel_link(source_p, chptr)) == NULL)
79 >    if ((member = find_channel_link(source_p, chptr)) == NULL)
80      {
81 <      sendto_one(source_p, form_str(ERR_NOTONCHANNEL), from,
82 <                 to, parv[1]);
117 <      return;
81 >      sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->name);
82 >      return 0;
83      }
84  
85      if (!(chptr->mode.mode & MODE_TOPICLIMIT) ||
86 <        has_member_flags(ms, CHFL_CHANOP|CHFL_HALFOP))
86 >        has_member_flags(member, CHFL_CHANOP|CHFL_HALFOP))
87      {
88 <      char topic_info[USERHOST_REPLYLEN];
88 >      char topic_info[USERHOST_REPLYLEN];
89  
90 <      ircsprintf(topic_info, "%s!%s@%s", source_p->name,
91 <                 source_p->username, source_p->host);
92 <      set_channel_topic(chptr, parv[2], topic_info, CurrentTime);
93 <
94 <      sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
95 <                    ":%s TOPIC %s :%s",
96 <                    ID(source_p), chptr->chname,
97 <                    chptr->topic == NULL ? "" : chptr->topic);
133 <      sendto_server(client_p, chptr, NOCAPS, CAP_TS6,
134 <                    ":%s TOPIC %s :%s",
135 <                    source_p->name, chptr->chname,
136 <                    chptr->topic == NULL ? "" : chptr->topic);
137 <      sendto_channel_local(ALL_MEMBERS, NO,
138 <                           chptr, ":%s!%s@%s TOPIC %s :%s",
90 >      snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name,
91 >               source_p->username, source_p->host);
92 >      channel_set_topic(chptr, parv[2], topic_info, CurrentTime, 1);
93 >
94 >      sendto_server(source_p, 0, 0, ":%s TOPIC %s :%s",
95 >                    source_p->id, chptr->name,
96 >                    chptr->topic);
97 >      sendto_channel_local(0, chptr, ":%s!%s@%s TOPIC %s :%s",
98                             source_p->name,
99                             source_p->username,
100                             source_p->host,
101 <                           chptr->chname, chptr->topic == NULL ?
143 <                           "" : chptr->topic);
101 >                           chptr->name, chptr->topic);
102      }
103      else
104 <      sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
147 <                 from, to, chptr->chname);
104 >      sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, chptr->name);
105    }
106    else /* only asking for topic */
107    {
108      if (!SecretChannel(chptr) || IsMember(source_p, chptr))
109      {
110 <      if (chptr->topic == NULL)
111 <        sendto_one(source_p, form_str(RPL_NOTOPIC),
155 <                   from, to, chptr->chname);
110 >      if (chptr->topic[0] == '\0')
111 >        sendto_one_numeric(source_p, &me, RPL_NOTOPIC, chptr->name);
112        else
113        {
114 <        sendto_one(source_p, form_str(RPL_TOPIC),
115 <                   from, to,
116 <                   chptr->chname, chptr->topic);
117 <        sendto_one(source_p, form_str(RPL_TOPICWHOTIME),
118 <                   from, to, chptr->chname,
163 <                   chptr->topic_info,
164 <                   chptr->topic_time);
114 >        sendto_one_numeric(source_p, &me, RPL_TOPIC,
115 >                           chptr->name, chptr->topic);
116 >        sendto_one_numeric(source_p, &me, RPL_TOPICWHOTIME, chptr->name,
117 >                           chptr->topic_info,
118 >                           chptr->topic_time);
119        }
120      }
121      else
122 <      sendto_one(source_p, form_str(ERR_NOTONCHANNEL),
169 <                 from, to, chptr->chname);
122 >      sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->name);
123    }
124 +
125 +  return 0;
126   }
127 +
128 +
129 + /*! \brief TOPIC command handler
130 + *
131 + * \param source_p Pointer to allocated Client struct from which the message
132 + *                 originally comes from.  This can be a local or remote client.
133 + * \param parc     Integer holding the number of supplied arguments.
134 + * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
135 + *                 pointers.
136 + * \note Valid arguments for this command are:
137 + *      - parv[0] = command
138 + *      - parv[1] = channel name
139 + *      - parv[2] = topic text
140 + */
141 + static int
142 + ms_topic(struct Client *source_p, int parc, char *parv[])
143 + {
144 +  struct Channel *chptr = NULL;
145 +  char topic_info[USERHOST_REPLYLEN];
146 +
147 +  if (EmptyString(parv[1]))
148 +  {
149 +    sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "TOPIC");
150 +    return 0;
151 +  }
152 +
153 +  if ((chptr = hash_find_channel(parv[1])) == NULL)
154 +  {
155 +    sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]);
156 +    return 0;
157 +  }
158 +
159 +  if (!IsClient(source_p))
160 +    strlcpy(topic_info, source_p->name, sizeof(topic_info));
161 +  else
162 +    snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name,
163 +             source_p->username, source_p->host);
164 +  channel_set_topic(chptr, parv[2], topic_info, CurrentTime, 0);
165 +
166 +  sendto_server(source_p, 0, 0, ":%s TOPIC %s :%s",
167 +                source_p->id, chptr->name,
168 +                chptr->topic);
169 +
170 +  if (!IsClient(source_p))
171 +    sendto_channel_local(0, chptr, ":%s TOPIC %s :%s",
172 +                         source_p->name,
173 +                         chptr->name, chptr->topic);
174 +
175 +  else
176 +    sendto_channel_local(0, chptr, ":%s!%s@%s TOPIC %s :%s",
177 +                         source_p->name,
178 +                         source_p->username,
179 +                         source_p->host,
180 +                         chptr->name, chptr->topic);
181 +  return 0;
182 + }
183 +
184 +
185 + static struct Message topic_msgtab =
186 + {
187 +  "TOPIC", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
188 +  { m_unregistered, m_topic, ms_topic, m_ignore, m_topic, m_ignore }
189 + };
190 +
191 + static void
192 + module_init(void)
193 + {
194 +  mod_add_cmd(&topic_msgtab);
195 + }
196 +
197 + static void
198 + module_exit(void)
199 + {
200 +  mod_del_cmd(&topic_msgtab);
201 + }
202 +
203 + struct module module_entry =
204 + {
205 +  .node    = { NULL, NULL, NULL },
206 +  .name    = NULL,
207 +  .version = "$Revision$",
208 +  .handle  = NULL,
209 +  .modinit = module_init,
210 +  .modexit = module_exit,
211 +  .flags   = 0
212 + };

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)