1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 #include "treesocket.h"
18 static const char* const forge_common_1201[] = {
45 "m_inviteexception.so",
73 "m_services_account.so",
85 static std::string wide_newline("\r\n");
86 static std::string newline("\n");
88 void TreeSocket::CompatAddModules(std::vector<std::string>& modlist)
90 if (proto_version < 1202)
92 // you MUST have chgident loaded in order to be able to translate FIDENT
93 modlist.push_back("m_chgident.so");
94 for(int i=0; i * sizeof(char*) < sizeof(forge_common_1201); i++)
96 if (ServerInstance->Modules->Find(forge_common_1201[i]))
97 modlist.push_back(forge_common_1201[i]);
100 if (ServerInstance->Modules->Find("m_operchans.so"))
102 modlist.push_back("m_operchans.so");
103 modlist.push_back("m_operinvex.so");
108 void TreeSocket::WriteLine(std::string line)
110 if (LinkState == CONNECTED)
114 ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Sending line without server prefix!");
115 line = ":" + ServerInstance->Config->GetSID() + " " + line;
117 if (proto_version != ProtocolVersion)
119 std::string::size_type a = line.find(' ');
120 std::string::size_type b = line.find(' ', a + 1);
121 std::string command = line.substr(a + 1, b-a-1);
122 // now try to find a translation entry
123 // TODO a more efficient lookup method will be needed later
124 if (proto_version < 1202 && command == "FIDENT")
126 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting FIDENT for 1201-protocol server");
127 line = ":" + ServerInstance->Config->GetSID() + " CHGIDENT " + line.substr(1,a-1) + line.substr(b);
129 else if (proto_version < 1202 && command == "SAVE")
131 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting SAVE for 1201-protocol server");
132 std::string::size_type c = line.find(' ', b + 1);
133 std::string uid = line.substr(b, c - b);
134 line = ":" + ServerInstance->Config->GetSID() + " SVSNICK" + uid + line.substr(b);
136 else if (proto_version < 1202 && command == "AWAY")
138 if (b != std::string::npos)
140 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Stripping AWAY timestamp for 1201-protocol server");
141 std::string::size_type c = line.find(' ', b + 1);
145 else if (proto_version < 1202 && command == "ENCAP")
147 // :src ENCAP target command [args...]
149 // Therefore B and C cannot be npos in a valid command
150 if (b == std::string::npos)
152 std::string::size_type c = line.find(' ', b + 1);
153 if (c == std::string::npos)
155 std::string::size_type d = line.find(' ', c + 1);
156 std::string subcmd = line.substr(c + 1, d - c - 1);
158 if (subcmd == "CHGIDENT" && d != std::string::npos)
160 std::string::size_type e = line.find(' ', d + 1);
161 if (e == std::string::npos)
163 std::string target = line.substr(d + 1, e - d - 1);
165 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Forging acceptance of CHGIDENT from 1201-protocol server");
166 recvq.insert(0, ":" + target + " FIDENT " + line.substr(e) + "\n");
169 Command* thiscmd = ServerInstance->Parser->GetHandler(subcmd);
170 if (thiscmd && subcmd != "WHOISNOTICE")
172 Version ver = thiscmd->creator->GetVersion();
173 if (ver.Flags & VF_OPTCOMMON)
175 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Removing ENCAP on '%s' for 1201-protocol server",
184 ServerInstance->Logs->Log("m_spanningtree", RAWIO, "S[%d] O %s", this->GetFd(), line.c_str());
185 this->WriteData(line);
186 if (proto_version < 1202)
187 this->WriteData(wide_newline);
189 this->WriteData(newline);