]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/fmode.cpp
-Woverloaded-virtual fixes
[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         /* Are we dealing with an FMODE from a user, or from a server? */
37         User* who = this->Instance->FindNick(source);
38         if (who)
39         {
40                 /* FMODE from a user, set sourceserv to the users server name */
41                 sourceserv = who->server;
42         }
43         else
44         {
45                 /* FMODE from a server, use a fake user to receive mode feedback */
46                 who = this->Instance->FakeClient;
47                 smode = true;      /* Setting this flag tells us we should free the User later */
48                 sourceserv = source;    /* Set sourceserv to the actual source string */
49         }
50         const char* modelist[64];
51         time_t TS = 0;
52         int n = 0;
53         memset(&modelist,0,sizeof(modelist));
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].c_str();
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         if (dst)
76         {
77                 ourTS = dst->age;
78         }
79         else
80         {
81                 chan = this->Instance->FindChan(params[0]);
82                 if (chan)
83                 {
84                         ourTS = chan->age;
85                 }
86                 else
87                         /* Oops, channel doesnt exist! */
88                         return true;
89         }
90
91         if (!TS)
92         {
93                 Instance->Log(DEFAULT,"*** BUG? *** TS of 0 sent to FMODE. Are some services authors smoking craq, or is it 1970 again?. Dropped.");
94                 Instance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending FMODE with a TS of zero. Total craq. Mode was dropped.", sourceserv.c_str());
95                 return true;
96         }
97
98         /* TS is equal or less: Merge the mode changes into ours and pass on.
99          */
100         if (TS <= ourTS)
101         {
102                 if ((TS < ourTS) && (!dst))
103                         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);
104
105                 if (smode)
106                 {
107                         this->Instance->SendMode(modelist, n, who);
108                 }
109                 else
110                 {
111                         this->Instance->CallCommandHandler("MODE", modelist, n, who);
112                 }
113                 /* HOT POTATO! PASS IT ON! */
114                 Utils->DoOneToAllButSender(source,"FMODE",params,sourceserv);
115         }
116         /* If the TS is greater than ours, we drop the mode and dont pass it anywhere.
117          */
118         return true;
119 }
120
121