]> jfr.im git - irc/rqf/shadowircd.git/blob - modules/m_tb.c
Change over some dlink functions.
[irc/rqf/shadowircd.git] / modules / m_tb.c
1 /* modules/m_tb.c
2 *
3 * Copyright (C) 2003 Lee Hardy <lee@leeh.co.uk>
4 * Copyright (C) 2003-2005 ircd-ratbox development team
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * 1.Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * 2.Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3.The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 *
30 * $Id: m_tb.c 1349 2006-05-17 17:37:46Z jilles $
31 */
32
33 #include "stdinc.h"
34 #include "tools.h"
35 #include "send.h"
36 #include "channel.h"
37 #include "client.h"
38 #include "common.h"
39 #include "config.h"
40 #include "ircd.h"
41 #include "irc_string.h"
42 #include "s_conf.h"
43 #include "msg.h"
44 #include "modules.h"
45 #include "hash.h"
46 #include "s_serv.h"
47
48 static int ms_tb(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
49
50 struct Message tb_msgtab = {
51 "TB", 0, 0, 0, MFLG_SLOW,
52 {mg_unreg, mg_ignore, mg_ignore, {ms_tb, 4}, mg_ignore, mg_ignore}
53 };
54
55 mapi_clist_av1 tb_clist[] = { &tb_msgtab, NULL };
56 DECLARE_MODULE_AV1(tb, NULL, NULL, tb_clist, NULL, NULL, "$Revision: 1349 $");
57
58 /* m_tb()
59 *
60 * parv[1] - channel
61 * parv[2] - topic ts
62 * parv[3] - optional topicwho/topic
63 * parv[4] - topic
64 */
65 static int
66 ms_tb(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
67 {
68 struct Channel *chptr;
69 const char *newtopic;
70 const char *newtopicwho;
71 time_t newtopicts;
72 struct Client *fakesource_p;
73
74 chptr = find_channel(parv[1]);
75
76 if(chptr == NULL)
77 return 0;
78
79 newtopicts = atol(parv[2]);
80
81 /* Hide connecting server on netburst -- jilles */
82 if (ConfigServerHide.flatten_links && !HasSentEob(source_p))
83 fakesource_p = &me;
84 else
85 fakesource_p = source_p;
86
87 if(parc == 5)
88 {
89 newtopic = parv[4];
90 newtopicwho = parv[3];
91 }
92 else
93 {
94 newtopic = parv[3];
95 newtopicwho = fakesource_p->name;
96 }
97
98 if (EmptyString(newtopic))
99 return 0;
100
101 if(chptr->topic == NULL || chptr->topic_time > newtopicts)
102 {
103 /* its possible the topicts is a few seconds out on some
104 * servers, due to lag when propagating it, so if theyre the
105 * same topic just drop the message --fl
106 */
107 if(chptr->topic != NULL && strcmp(chptr->topic, newtopic) == 0)
108 return 0;
109
110 set_channel_topic(chptr, newtopic, newtopicwho, newtopicts);
111 sendto_channel_local(ALL_MEMBERS, chptr, ":%s TOPIC %s :%s",
112 fakesource_p->name, chptr->chname, newtopic);
113 sendto_server(client_p, chptr, CAP_TB|CAP_TS6, NOCAPS,
114 ":%s TB %s %ld %s%s:%s",
115 use_id(source_p), chptr->chname, (long) chptr->topic_time,
116 ConfigChannel.burst_topicwho ? chptr->topic_info : "",
117 ConfigChannel.burst_topicwho ? " " : "", chptr->topic);
118 sendto_server(client_p, chptr, CAP_TB, CAP_TS6,
119 ":%s TB %s %ld %s%s:%s",
120 source_p->name, chptr->chname, (long) chptr->topic_time,
121 ConfigChannel.burst_topicwho ? chptr->topic_info : "",
122 ConfigChannel.burst_topicwho ? " " : "", chptr->topic);
123 }
124
125 return 0;
126 }