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[] = {
32 static std::string wide_newline("\r\n");
34 void TreeSocket::CompatAddModules(std::vector<std::string>& modlist)
36 if (proto_version < 1202)
38 for(std::vector<std::string>::iterator i = modlist.begin(); i != modlist.end(); ++i)
40 if (*i == "m_halfop.so")
46 // you MUST have chgident loaded in order to be able to translate FIDENT
47 modlist.push_back("m_chgident.so");
48 for(int i=0; i * sizeof(char*) < sizeof(forge_common_1201); i++)
50 if (ServerInstance->Modules->Find(forge_common_1201[i]))
51 modlist.push_back(forge_common_1201[i]);
54 if (ServerInstance->Modules->Find("m_operchans.so"))
55 modlist.push_back("m_operinvex.so");
59 void TreeSocket::WriteLine(std::string line)
61 if (LinkState == CONNECTED)
65 ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Sending line without server prefix!");
66 line = ":" + ServerInstance->Config->GetSID() + " " + line;
68 if (proto_version != ProtocolVersion)
70 std::string::size_type a = line.find(' ');
71 std::string::size_type b = line.find(' ', a + 1);
72 std::string command = line.substr(a + 1, b-a-1);
73 // now try to find a translation entry
74 // TODO a more efficient lookup method will be needed later
75 if (proto_version < 1202 && command == "FIDENT")
77 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting FIDENT for 1201-protocol server");
78 line = ":" + ServerInstance->Config->GetSID() + " CHGIDENT " + line.substr(1,a-1) + line.substr(b);
80 else if (proto_version < 1202 && command == "SAVE")
82 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting SAVE for 1201-protocol server");
83 std::string::size_type c = line.find(' ', b + 1);
84 std::string uid = line.substr(b, c - b);
85 line = ":" + ServerInstance->Config->GetSID() + " SVSNICK" + uid + line.substr(b);
87 else if (proto_version < 1202 && command == "AWAY")
89 if (b != std::string::npos)
91 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Stripping AWAY timestamp for 1201-protocol server");
92 std::string::size_type c = line.find(' ', b + 1);
96 else if (proto_version < 1202 && command == "ENCAP")
98 // :src ENCAP target command [args...]
100 // Therefore B and C cannot be npos in a valid command
101 if (b == std::string::npos)
103 std::string::size_type c = line.find(' ', b + 1);
104 if (c == std::string::npos)
106 std::string::size_type d = line.find(' ', c + 1);
107 std::string subcmd = line.substr(c, d - c);
108 Command* thiscmd = ServerInstance->Parser->GetHandler(subcmd);
111 Version ver = thiscmd->creator->GetVersion();
112 if (ver.Flags & VF_OPTCOMMON)
114 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Removing ENCAP on '%s' for 1201-protocol server",
123 ServerInstance->Logs->Log("m_spanningtree",DEBUG, "S[%d] O %s", this->GetFd(), line.c_str());
124 this->WriteData(line);
125 this->WriteData(wide_newline);