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