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 const char* const forge_common_1201[] = {
51 "m_inviteexception.so",
79 "m_services_account.so",
91 static std::string wide_newline("\r\n");
92 static std::string newline("\n");
94 void TreeSocket::CompatAddModules(std::vector<std::string>& modlist)
96 if (proto_version < 1202)
98 // you MUST have chgident loaded in order to be able to translate FIDENT
99 modlist.push_back("m_chgident.so");
100 for(int i=0; i * sizeof(char*) < sizeof(forge_common_1201); i++)
102 if (ServerInstance->Modules->Find(forge_common_1201[i]))
103 modlist.push_back(forge_common_1201[i]);
106 if (ServerInstance->Modules->Find("m_operchans.so"))
108 modlist.push_back("m_operchans.so");
109 modlist.push_back("m_operinvex.so");
114 void TreeSocket::WriteLine(std::string line)
116 if (LinkState == CONNECTED)
120 ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Sending line without server prefix!");
121 line = ":" + ServerInstance->Config->GetSID() + " " + line;
123 if (proto_version != ProtocolVersion)
125 std::string::size_type a = line.find(' ');
126 std::string::size_type b = line.find(' ', a + 1);
127 std::string command = line.substr(a + 1, b-a-1);
128 // now try to find a translation entry
129 // TODO a more efficient lookup method will be needed later
130 if (proto_version < 1202 && command == "FIDENT")
132 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting FIDENT for 1201-protocol server");
133 line = ":" + ServerInstance->Config->GetSID() + " CHGIDENT " + line.substr(1,a-1) + line.substr(b);
135 else if (proto_version < 1202 && command == "SAVE")
137 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting SAVE for 1201-protocol server");
138 std::string::size_type c = line.find(' ', b + 1);
139 std::string uid = line.substr(b, c - b);
140 line = ":" + ServerInstance->Config->GetSID() + " SVSNICK" + uid + line.substr(b);
142 else if (proto_version < 1202 && command == "AWAY")
144 if (b != std::string::npos)
146 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Stripping AWAY timestamp for 1201-protocol server");
147 std::string::size_type c = line.find(' ', b + 1);
151 else if (proto_version < 1202 && command == "ENCAP")
153 // :src ENCAP target command [args...]
155 // Therefore B and C cannot be npos in a valid command
156 if (b == std::string::npos)
158 std::string::size_type c = line.find(' ', b + 1);
159 if (c == std::string::npos)
161 std::string::size_type d = line.find(' ', c + 1);
162 std::string subcmd = line.substr(c + 1, d - c - 1);
164 if (subcmd == "CHGIDENT" && d != std::string::npos)
166 std::string::size_type e = line.find(' ', d + 1);
167 if (e == std::string::npos)
169 std::string target = line.substr(d + 1, e - d - 1);
171 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Forging acceptance of CHGIDENT from 1201-protocol server");
172 recvq.insert(0, ":" + target + " FIDENT " + line.substr(e) + "\n");
175 Command* thiscmd = ServerInstance->Parser->GetHandler(subcmd);
176 if (thiscmd && subcmd != "WHOISNOTICE")
178 Version ver = thiscmd->creator->GetVersion();
179 if (ver.Flags & VF_OPTCOMMON)
181 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Removing ENCAP on '%s' for 1201-protocol server",
190 ServerInstance->Logs->Log("m_spanningtree", RAWIO, "S[%d] O %s", this->GetFd(), line.c_str());
191 this->WriteData(line);
192 if (proto_version < 1202)
193 this->WriteData(wide_newline);
195 this->WriteData(newline);