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 for(std::vector<std::string>::iterator i = modlist.begin(); i != modlist.end(); ++i)
39 if (*i == "m_halfop.so")
45 // you MUST have chgident loaded in order to be able to translate FIDENT
46 modlist.push_back("m_chgident.so");
47 for(int i=0; i * sizeof(char*) < sizeof(forge_common_1201); i++)
49 if (ServerInstance->Modules->Find(forge_common_1201[i]))
50 modlist.push_back(forge_common_1201[i]);
53 if (ServerInstance->Modules->Find("m_operchans.so"))
54 modlist.push_back("m_operinvex.so");
58 void TreeSocket::WriteLine(std::string line)
60 if (LinkState == CONNECTED)
64 ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Sending line without server prefix!");
65 line = ":" + ServerInstance->Config->GetSID() + " " + line;
67 if (proto_version != ProtocolVersion)
69 std::string::size_type a = line.find(' ');
70 std::string::size_type b = line.find(' ', a + 1);
71 std::string command = line.substr(a + 1, b-a-1);
72 // now try to find a translation entry
73 // TODO a more efficient lookup method will be needed later
74 if (proto_version < 1202 && command == "FIDENT")
76 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting FIDENT for 1201-protocol server");
77 line = ":" + ServerInstance->Config->GetSID() + " CHGIDENT " + line.substr(1,a-1) + line.substr(b);
79 else if (proto_version < 1202 && command == "SAVE")
81 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting SAVE for 1201-protocol server");
82 std::string::size_type c = line.find(' ', b + 1);
83 std::string uid = line.substr(b, c - b);
84 line = ":" + ServerInstance->Config->GetSID() + " SVSNICK" + uid + line.substr(b);
86 else if (proto_version < 1202 && command == "AWAY")
88 if (b != std::string::npos)
90 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Stripping AWAY timestamp for 1201-protocol server");
91 std::string::size_type c = line.find(' ', b + 1);
95 else if (proto_version < 1202 && command == "ENCAP")
97 // :src ENCAP target command [args...]
99 // Therefore B and C cannot be npos in a valid command
100 if (b == std::string::npos)
102 std::string::size_type c = line.find(' ', b + 1);
103 if (c == std::string::npos)
105 std::string::size_type d = line.find(' ', c + 1);
106 std::string subcmd = line.substr(c, d - c);
107 Command* thiscmd = ServerInstance->Parser->GetHandler(subcmd);
110 Version ver = thiscmd->creator->GetVersion();
111 if (ver.Flags & VF_OPTCOMMON)
113 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Removing ENCAP on '%s' for 1201-protocol server",
122 ServerInstance->Logs->Log("m_spanningtree",DEBUG, "S[%d] O %s", this->GetFd(), line.c_str());
123 this->WriteData(line);
124 this->WriteData(wide_newline);