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[] = {
40 "m_inviteexception.so",
70 static std::string wide_newline("\r\n");
71 static std::string newline("\n");
73 void TreeSocket::CompatAddModules(std::vector<std::string>& modlist)
75 if (proto_version < 1202)
77 // you MUST have chgident loaded in order to be able to translate FIDENT
78 modlist.push_back("m_chgident.so");
79 for(int i=0; i * sizeof(char*) < sizeof(forge_common_1201); i++)
81 if (ServerInstance->Modules->Find(forge_common_1201[i]))
82 modlist.push_back(forge_common_1201[i]);
85 if (ServerInstance->Modules->Find("m_operchans.so"))
87 modlist.push_back("m_operchans.so");
88 modlist.push_back("m_operinvex.so");
93 void TreeSocket::WriteLine(std::string line)
95 if (LinkState == CONNECTED)
99 ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Sending line without server prefix!");
100 line = ":" + ServerInstance->Config->GetSID() + " " + line;
102 if (proto_version != ProtocolVersion)
104 std::string::size_type a = line.find(' ');
105 std::string::size_type b = line.find(' ', a + 1);
106 std::string command = line.substr(a + 1, b-a-1);
107 // now try to find a translation entry
108 // TODO a more efficient lookup method will be needed later
109 if (proto_version < 1202 && command == "FIDENT")
111 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting FIDENT for 1201-protocol server");
112 line = ":" + ServerInstance->Config->GetSID() + " CHGIDENT " + line.substr(1,a-1) + line.substr(b);
114 else if (proto_version < 1202 && command == "SAVE")
116 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting SAVE for 1201-protocol server");
117 std::string::size_type c = line.find(' ', b + 1);
118 std::string uid = line.substr(b, c - b);
119 line = ":" + ServerInstance->Config->GetSID() + " SVSNICK" + uid + line.substr(b);
121 else if (proto_version < 1202 && command == "AWAY")
123 if (b != std::string::npos)
125 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Stripping AWAY timestamp for 1201-protocol server");
126 std::string::size_type c = line.find(' ', b + 1);
130 else if (proto_version < 1202 && command == "ENCAP")
132 // :src ENCAP target command [args...]
134 // Therefore B and C cannot be npos in a valid command
135 if (b == std::string::npos)
137 std::string::size_type c = line.find(' ', b + 1);
138 if (c == std::string::npos)
140 std::string::size_type d = line.find(' ', c + 1);
141 std::string subcmd = line.substr(c, d - c);
142 Command* thiscmd = ServerInstance->Parser->GetHandler(subcmd);
145 Version ver = thiscmd->creator->GetVersion();
146 if (ver.Flags & VF_OPTCOMMON)
148 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Removing ENCAP on '%s' for 1201-protocol server",
157 ServerInstance->Logs->Log("m_spanningtree",DEBUG, "S[%d] O %s", this->GetFd(), line.c_str());
158 this->WriteData(line);
159 if (proto_version < 1202)
160 this->WriteData(wide_newline);
162 this->WriteData(newline);