]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/ftopic.cpp
Forward-port r10098 and r10099, fixing anope+inspircd=ftopic ddos. Thanks to Namegduf...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / ftopic.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "xline.h"
16
17 #include "m_spanningtree/treesocket.h"
18 #include "m_spanningtree/treeserver.h"
19 #include "m_spanningtree/utils.h"
20
21 /* $ModDep: m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
22
23
24 /** FTOPIC command */
25 bool TreeSocket::ForceTopic(const std::string &source, std::deque<std::string> &params)
26 {
27         if (params.size() != 4)
28                 return true;
29         time_t ts = atoi(params[1].c_str());
30         std::string nsource = source;
31         Channel* c = this->Instance->FindChan(params[0]);
32         if (c)
33         {
34                 if ((ts >= c->topicset) || (c->topic.empty()))
35                 {
36                         User* user = this->Instance->FindNick(source);
37
38                         if (c->topic != params[3])
39                         {
40                                 // Update topic only when it differs from current topic
41                                 c->topic.assign(params[3], 0, Instance->Config->Limits.MaxTopic);
42                                 if (!user)
43                                 {
44                                         c->WriteChannelWithServ(Instance->Config->ServerName, "TOPIC %s :%s", c->name.c_str(), c->topic.c_str());
45                                 }
46                                 else
47                                 {
48                                         c->WriteChannel(user, "TOPIC %s :%s", c->name.c_str(), c->topic.c_str());
49                                 }
50                         }
51
52                         // Always update setter and settime.
53                         c->setby.assign(params[2], 0, 127);
54                         c->topicset = ts;
55
56                         /*
57                          * Take careful note of what happens here;
58                          * Above, we display the topic change to the server IF the topic incoming is different to the topic already set.
59                          * HERE, we find the server the user that sent this topic is on, so we *do not* send topics back to the link they just
60                          * came from. This *cannot* be easily merged with the above check!
61                          *
62                          * Thanks to Anope and Namegduf for finally helping me isolate this
63                          *                      -- w00t (5th/aug/2008)
64                          */
65                         if (user)
66                         {
67                                 nsource = user->server;
68                         }
69
70                         /* all done, send it on its way */
71                         params[3] = ":" + params[3];
72                         User* u = Instance->FindNick(nsource);
73                         if (u)
74                                 Utils->DoOneToAllButSender(u->uuid,"FTOPIC",params,u->server);
75                         else
76                                 Utils->DoOneToAllButSender(source,"FTOPIC",params,nsource);
77                 }
78
79         }
80         return true;
81 }
82