]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/fmode.cpp
...because every now and again, i have to do a massive commit.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / fmode.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 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 void TreeSocket::ForceMode(User* who, parameterlist &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;
32         }
33
34         std::string sourceserv = who->server;
35
36         std::vector<std::string> modelist;
37         time_t TS = 0;
38         for (unsigned int q = 0; (q < params.size()) && (q < 64); q++)
39         {
40                 if (q == 1)
41                 {
42                         /* The timestamp is in this position.
43                          * We don't want to pass that up to the
44                          * server->client protocol!
45                          */
46                         TS = atoi(params[q].c_str());
47                 }
48                 else
49                 {
50                         /* Everything else is fine to append to the modelist */
51                         modelist.push_back(params[q]);
52                 }
53
54         }
55         /* Extract the TS value of the object, either User or Channel */
56         User* dst = ServerInstance->FindNick(params[0]);
57         Channel* chan = NULL;
58         time_t ourTS = 0;
59
60         if (dst)
61         {
62                 ourTS = dst->age;
63         }
64         else
65         {
66                 chan = ServerInstance->FindChan(params[0]);
67                 if (chan)
68                 {
69                         ourTS = chan->age;
70                 }
71                 else
72                         /* Oops, channel doesnt exist! */
73                         return;
74         }
75
76         if (!TS)
77         {
78                 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.");
79                 ServerInstance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending FMODE with a TS of zero. Total craq. Mode was dropped.", sourceserv.c_str());
80                 return;
81         }
82
83         /* TS is equal or less: Merge the mode changes into ours and pass on.
84          */
85         if (TS <= ourTS)
86         {
87                 ServerInstance->Modes->Process(modelist, who, IS_SERVER(who));
88
89                 /* HOT POTATO! PASS IT ON! */
90                 Utils->DoOneToAllButSender(sourceserv,"FMODE",params,sourceserv);
91         }
92         /* If the TS is greater than ours, we drop the mode and dont pass it anywhere.
93          */
94 }
95
96