]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/fmode.cpp
880f250860a2d120f4524764bfe98f3c99571db5
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / fmode.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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 "treesocket.h"
18 #include "treeserver.h"
19 #include "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         std::string sourceserv;
35
36         /* Are we dealing with an FMODE from a user, or from a server? */
37         User* who = this->ServerInstance->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 = Utils->ServerUser;
47                 sourceserv = source;    /* Set sourceserv to the actual source string */
48         }
49         std::vector<std::string> modelist;
50         time_t TS = 0;
51         for (unsigned int q = 0; (q < params.size()) && (q < 64); q++)
52         {
53                 if (q == 1)
54                 {
55                         /* The timestamp is in this position.
56                          * We don't want to pass that up to the
57                          * server->client protocol!
58                          */
59                         TS = atoi(params[q].c_str());
60                 }
61                 else
62                 {
63                         /* Everything else is fine to append to the modelist */
64                         modelist.push_back(params[q]);
65                 }
66
67         }
68         /* Extract the TS value of the object, either User or Channel */
69         User* dst = this->ServerInstance->FindNick(params[0]);
70         Channel* chan = NULL;
71         time_t ourTS = 0;
72
73         if (dst)
74         {
75                 ourTS = dst->age;
76         }
77         else
78         {
79                 chan = this->ServerInstance->FindChan(params[0]);
80                 if (chan)
81                 {
82                         ourTS = chan->age;
83                 }
84                 else
85                         /* Oops, channel doesnt exist! */
86                         return true;
87         }
88
89         if (!TS)
90         {
91                 ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"*** BUG? *** TS of 0 sent to FMODE. Are some services authors smoking craq, or is it 1970 again?. Dropped.");
92                 ServerInstance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending FMODE with a TS of zero. Total craq. Mode was dropped.", sourceserv.c_str());
93                 return true;
94         }
95
96         /* TS is equal or less: Merge the mode changes into ours and pass on.
97          */
98         if (TS <= ourTS)
99         {
100                 ServerInstance->Modes->Process(modelist, who, (who == Utils->ServerUser));
101
102                 /* HOT POTATO! PASS IT ON! */
103                 Utils->DoOneToAllButSender(source,"FMODE",params,sourceserv);
104         }
105         /* If the TS is greater than ours, we drop the mode and dont pass it anywhere.
106          */
107         return true;
108 }
109
110