]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/fmode.cpp
fix some unitialised vectors and tidy up a bit.
[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         for (unsigned int q = 0; (q < params.size()) && (q < 64); q++)
54         {
55                 if (q == 1)
56                 {
57                         /* The timestamp is in this position.
58                          * We don't want to pass that up to the
59                          * server->client protocol!
60                          */
61                         TS = atoi(params[q].c_str());
62                 }
63                 else
64                 {
65                         /* Everything else is fine to append to the modelist */
66                         modelist.push_back(params[q]);
67                 }
68
69         }
70         /* Extract the TS value of the object, either User or Channel */
71         User* dst = this->Instance->FindNick(params[0]);
72         Channel* chan = NULL;
73         time_t ourTS = 0;
74
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->Logs->Log("m_spanningtree",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 (smode)
103                 {
104                         this->Instance->SendMode(modelist, who);
105                 }
106                 else
107                 {
108                         this->Instance->CallCommandHandler("MODE", modelist, who);
109                 }
110                 /* HOT POTATO! PASS IT ON! */
111                 Utils->DoOneToAllButSender(source,"FMODE",params,sourceserv);
112         }
113         /* If the TS is greater than ours, we drop the mode and dont pass it anywhere.
114          */
115         return true;
116 }
117
118