2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "treesocket.h"
24 static std::string newline("\n");
26 void TreeSocket::WriteLine(std::string line)
28 if (LinkState == CONNECTED)
32 ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Sending line without server prefix!");
33 line = ":" + ServerInstance->Config->GetSID() + " " + line;
35 if (proto_version != ProtocolVersion)
37 std::string::size_type a = line.find(' ');
38 std::string::size_type b = line.find(' ', a + 1);
39 std::string command = line.substr(a + 1, b-a-1);
40 // now try to find a translation entry
41 // TODO a more efficient lookup method will be needed later
42 if (proto_version < 1205)
44 if (command == "IJOIN")
47 // :<uid> IJOIN <chan> [<ts> [<flags>]]
49 // :<sid> FJOIN <chan> <ts> + [<flags>],<uuid>
50 std::string::size_type c = line.find(' ', b + 1);
51 if (c == std::string::npos)
53 // No TS or modes in the command
54 // :22DAAAAAB IJOIN #chan
55 const std::string channame = line.substr(b+1, c-b-1);
56 Channel* chan = ServerInstance->FindChan(channame);
61 line.append(ConvToStr(chan->age));
66 std::string::size_type d = line.find(' ', c + 1);
67 if (d == std::string::npos)
69 // TS present, no modes
70 // :22DAAAAAC IJOIN #chan 12345
75 // Both TS and modes are present
76 // :22DAAAAAC IJOIN #chan 12345 ov
77 std::string::size_type e = line.find(' ', d + 1);
78 if (e != std::string::npos)
86 // Move the uuid to the end and replace the I with an F
87 line.append(line.substr(1, 9));
91 else if (command == "RESYNC")
93 else if (command == "METADATA")
95 // Drop TS for channel METADATA
96 // :sid METADATA #target TS extname ...
98 if (b == std::string::npos)
101 std::string::size_type c = line.find(' ', b + 1);
102 if (c == std::string::npos)
105 if (line[b + 1] == '#')
107 // We're sending channel metadata
108 std::string::size_type d = line.find(' ', c + 1);
109 if (d == std::string::npos)
115 else if (command == "FTOPIC")
117 // Drop channel TS for FTOPIC
118 // :sid FTOPIC #target TS TopicTS ...
120 if (b == std::string::npos)
123 std::string::size_type c = line.find(' ', b + 1);
124 if (c == std::string::npos)
127 std::string::size_type d = line.find(' ', c + 1);
128 if (d == std::string::npos)
137 ServerInstance->Logs->Log("m_spanningtree", LOG_RAWIO, "S[%d] O %s", this->GetFd(), line.c_str());
138 this->WriteData(line);
139 this->WriteData(newline);
144 bool InsertCurrentChannelTS(std::vector<std::string>& params)
146 Channel* chan = ServerInstance->FindChan(params[0]);
150 // Insert the current TS of the channel between the first and the second parameters
151 params.insert(params.begin()+1, ConvToStr(chan->age));
156 bool TreeSocket::PreProcessOldProtocolMessage(User*& who, std::string& cmd, std::vector<std::string>& params)
158 if ((cmd == "METADATA") && (params.size() >= 3))
160 // :20D METADATA #channel extname :extdata
161 return InsertCurrentChannelTS(params);
163 else if ((cmd == "FTOPIC") && (params.size() >= 4))
165 // :20D FTOPIC #channel 100 Attila :topic text
166 return InsertCurrentChannelTS(params);
169 return true; // Passthru