1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 #include "m_spanningtree/treesocket.h"
18 #include "m_spanningtree/treeserver.h"
19 #include "m_spanningtree/utils.h"
21 /* $ModDep: m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
24 /** FMODE command - server mode with timestamp checks */
25 bool TreeSocket::ForceMode(const std::string &source, std::deque<std::string> ¶ms)
27 /* Chances are this is a 1.0 FMODE without TS */
28 if (params.size() < 3)
30 /* No modes were in the command, probably a channel with no modes set on it */
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);
40 /* FMODE from a user, set sourceserv to the users server name */
41 sourceserv = who->server;
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 */
50 const char* modelist[64];
53 memset(&modelist,0,sizeof(modelist));
54 for (unsigned int q = 0; (q < params.size()) && (q < 64); q++)
58 /* The timestamp is in this position.
59 * We don't want to pass that up to the
60 * server->client protocol!
62 TS = atoi(params[q].c_str());
66 /* Everything else is fine to append to the modelist */
67 modelist[n++] = params[q].c_str();
71 /* Extract the TS value of the object, either User or Channel */
72 User* dst = this->Instance->FindNick(params[0]);
81 chan = this->Instance->FindChan(params[0]);
87 /* Oops, channel doesnt exist! */
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());
98 /* TS is equal or less: Merge the mode changes into ours and pass on.
102 if ((TS < ourTS) && (!dst))
103 Instance->Logs->Log("m_spanningtree",DEFAULT,"*** BUG *** Channel TS sent in FMODE to %s is %lu which is not equal to %lu!", params[0].c_str(), (unsigned long) TS, (unsigned long) ourTS);
107 this->Instance->SendMode(modelist, n, who);
111 this->Instance->CallCommandHandler("MODE", modelist, n, who);
113 /* HOT POTATO! PASS IT ON! */
114 Utils->DoOneToAllButSender(source,"FMODE",params,sourceserv);
116 /* If the TS is greater than ours, we drop the mode and dont pass it anywhere.