]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/fmode.cpp
e7209a85268e387d31130f62e16e3c7371ab8255
[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         std::vector<std::string> modelist;
52         time_t TS = 0;
53         int n = 0;
54         for (unsigned int q = 0; (q < params.size()) && (q < 64); q++)
55         {
56                 if (q == 1)
57                 {
58                         /* The timestamp is in this position.
59                          * We don't want to pass that up to the
60                          * server->client protocol!
61                          */
62                         TS = atoi(params[q].c_str());
63                 }
64                 else
65                 {
66                         /* Everything else is fine to append to the modelist */
67                         modelist[n++] = params[q];
68                 }
69
70         }
71         /* Extract the TS value of the object, either User or Channel */
72         User* dst = this->Instance->FindNick(params[0]);
73         Channel* chan = NULL;
74         time_t ourTS = 0;
75
76         if (dst)
77         {
78                 ourTS = dst->age;
79         }
80         else
81         {
82                 chan = this->Instance->FindChan(params[0]);
83                 if (chan)
84                 {
85                         ourTS = chan->age;
86                 }
87                 else
88                         /* Oops, channel doesnt exist! */
89                         return true;
90         }
91
92         if (!TS)
93         {
94                 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.");
95                 Instance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending FMODE with a TS of zero. Total craq. Mode was dropped.", sourceserv.c_str());
96                 return true;
97         }
98
99         /* TS is equal or less: Merge the mode changes into ours and pass on.
100          */
101         if (TS <= ourTS)
102         {
103                 if (smode)
104                 {
105                         this->Instance->SendMode(modelist, who);
106                 }
107                 else
108                 {
109                         this->Instance->CallCommandHandler("MODE", modelist, who);
110                 }
111                 /* HOT POTATO! PASS IT ON! */
112                 Utils->DoOneToAllButSender(source,"FMODE",params,sourceserv);
113         }
114         /* If the TS is greater than ours, we drop the mode and dont pass it anywhere.
115          */
116         return true;
117 }
118
119