]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/fmode.cpp
Fix for bug #513
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / fmode.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 /** FMODE command - server mode with timestamp checks */
25 bool TreeSocket::ForceMode(const std::string &source, std::deque<std::string> &params)
26 {
27         /* Chances are this is a 1.0 FMODE without TS */
28         if (params.size() < 3)
29         {
30                 /* No modes were in the command, probably a channel with no modes set on it */
31                 return true;
32         }
33
34         bool smode = false;
35         std::string sourceserv;
36
37         /* Are we dealing with an FMODE from a user, or from a server? */
38         User* who = this->Instance->FindNick(source);
39         if (who)
40         {
41                 /* FMODE from a user, set sourceserv to the users server name */
42                 sourceserv = who->server;
43         }
44         else
45         {
46                 /* FMODE from a server, use a fake user to receive mode feedback */
47                 who = this->Instance->FakeClient;
48                 smode = true;                   /* Setting this flag tells us it is a server mode*/
49                 sourceserv = source;    /* Set sourceserv to the actual source string */
50         }
51         const char* modelist[64];
52         time_t TS = 0;
53         int n = 0;
54         memset(&modelist,0,sizeof(modelist));
55         for (unsigned int q = 0; (q < params.size()) && (q < 64); q++)
56         {
57                 if (q == 1)
58                 {
59                         /* The timestamp is in this position.
60                          * We don't want to pass that up to the
61                          * server->client protocol!
62                          */
63                         TS = atoi(params[q].c_str());
64                 }
65                 else
66                 {
67                         /* Everything else is fine to append to the modelist */
68                         modelist[n++] = params[q].c_str();
69                 }
70
71         }
72         /* Extract the TS value of the object, either User or Channel */
73         User* dst = this->Instance->FindNick(params[0]);
74         Channel* chan = NULL;
75         time_t ourTS = 0;
76
77         if (dst)
78         {
79                 ourTS = dst->age;
80         }
81         else
82         {
83                 chan = this->Instance->FindChan(params[0]);
84                 if (chan)
85                 {
86                         ourTS = chan->age;
87                 }
88                 else
89                         /* Oops, channel doesnt exist! */
90                         return true;
91         }
92
93         if (!TS)
94         {
95                 Instance->Logs->Log("m_spanningtree",DEFAULT,"*** BUG? *** TS of 0 sent to FMODE. Are some services authors smoking craq, or is it 1970 again?. Dropped.");
96                 Instance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending FMODE with a TS of zero. Total craq. Mode was dropped.", sourceserv.c_str());
97                 return true;
98         }
99
100         /* TS is equal or less: Merge the mode changes into ours and pass on.
101          */
102         if (TS <= ourTS)
103         {
104                 if (smode)
105                 {
106                         this->Instance->SendMode(modelist, n, who);
107                 }
108                 else
109                 {
110                         this->Instance->CallCommandHandler("MODE", modelist, n, who);
111                 }
112                 /* HOT POTATO! PASS IT ON! */
113                 Utils->DoOneToAllButSender(source,"FMODE",params,sourceserv);
114         }
115         /* If the TS is greater than ours, we drop the mode and dont pass it anywhere.
116          */
117         return true;
118 }
119
120