]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/fmode.cpp
Merge pull request #53 from SaberUK/clang-analyze
[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 "commands.h"
16
17 #include "treesocket.h"
18 #include "treeserver.h"
19 #include "utils.h"
20
21 /** FMODE command - server mode with timestamp checks */
22 CmdResult CommandFMode::Handle(const std::vector<std::string>& params, User *who)
23 {
24         std::string sourceserv = who->server;
25
26         std::vector<std::string> modelist;
27         time_t TS = 0;
28         for (unsigned int q = 0; (q < params.size()) && (q < 64); q++)
29         {
30                 if (q == 1)
31                 {
32                         /* The timestamp is in this position.
33                          * We don't want to pass that up to the
34                          * server->client protocol!
35                          */
36                         TS = atoi(params[q].c_str());
37                 }
38                 else
39                 {
40                         /* Everything else is fine to append to the modelist */
41                         modelist.push_back(params[q]);
42                 }
43
44         }
45         /* Extract the TS value of the object, either User or Channel */
46         User* dst = ServerInstance->FindNick(params[0]);
47         Channel* chan = NULL;
48         time_t ourTS = 0;
49
50         if (dst)
51         {
52                 ourTS = dst->age;
53         }
54         else
55         {
56                 chan = ServerInstance->FindChan(params[0]);
57                 if (chan)
58                 {
59                         ourTS = chan->age;
60                 }
61                 else
62                         /* Oops, channel doesnt exist! */
63                         return CMD_FAILURE;
64         }
65
66         if (!TS)
67         {
68                 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.");
69                 ServerInstance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending FMODE with a TS of zero. Total craq. Mode was dropped.", sourceserv.c_str());
70                 return CMD_INVALID;
71         }
72
73         /* TS is equal or less: Merge the mode changes into ours and pass on.
74          */
75         if (TS <= ourTS)
76         {
77                 bool merge = (TS == ourTS) && IS_SERVER(who);
78                 ServerInstance->Modes->Process(modelist, who, merge);
79                 return CMD_SUCCESS;
80         }
81         /* If the TS is greater than ours, we drop the mode and dont pass it anywhere.
82          */
83         return CMD_FAILURE;
84 }
85
86