1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 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[] = {
31 static std::string wide_newline("\r\n");
33 void TreeSocket::CompatAddModules(std::vector<std::string>& modlist)
35 if (proto_version < 1202)
37 // you MUST have chgident loaded in order to be able to translate FIDENT
38 modlist.push_back("m_chgident.so");
39 for(int i=0; i * sizeof(char*) < sizeof(forge_common_1201); i++)
41 if (ServerInstance->Modules->Find(forge_common_1201[i]))
42 modlist.push_back(forge_common_1201[i]);
45 if (ServerInstance->Modules->Find("m_operchans.so"))
46 modlist.push_back("m_operinvex.so");
50 void TreeSocket::WriteLine(std::string line)
52 if (LinkState == CONNECTED)
56 ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Sending line without server prefix!");
57 line = ":" + ServerInstance->Config->GetSID() + " " + line;
59 if (proto_version != ProtocolVersion)
61 std::string::size_type a = line.find(' ');
62 std::string::size_type b = line.find(' ', a + 1);
63 std::string command = line.substr(a + 1, b-a-1);
64 // now try to find a translation entry
65 // TODO a more efficient lookup method will be needed later
66 if (proto_version < 1202 && command == "FIDENT")
68 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting FIDENT for 1201-protocol server");
69 line = ":" + ServerInstance->Config->GetSID() + " CHGIDENT " + line.substr(1,a-1) + line.substr(b);
71 else if (proto_version < 1202 && command == "SAVE")
73 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting SAVE for 1201-protocol server");
74 std::string::size_type c = line.find(' ', b + 1);
75 std::string uid = line.substr(b, c - b);
76 line = ":" + ServerInstance->Config->GetSID() + " SVSNICK" + uid + line.substr(b);
78 else if (proto_version < 1202 && command == "AWAY")
80 if (b != std::string::npos)
82 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Stripping AWAY timestamp for 1201-protocol server");
83 std::string::size_type c = line.find(' ', b + 1);
87 else if (proto_version < 1202 && command == "ENCAP")
89 // :src ENCAP target command [args...]
91 // Therefore B and C cannot be npos in a valid command
92 if (b == std::string::npos)
94 std::string::size_type c = line.find(' ', b + 1);
95 if (c == std::string::npos)
97 std::string::size_type d = line.find(' ', c + 1);
98 std::string subcmd = line.substr(c, d - c);
99 Command* thiscmd = ServerInstance->Parser->GetHandler(subcmd);
102 Version ver = thiscmd->creator->GetVersion();
103 if (ver.Flags & VF_OPTCOMMON)
105 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Removing ENCAP on '%s' for 1201-protocol server",
114 ServerInstance->Logs->Log("m_spanningtree",DEBUG, "S[%d] O %s", this->GetFd(), line.c_str());
115 this->WriteData(line);
116 this->WriteData(wide_newline);