]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/compat.cpp
Verify cloak keys match during CAPAB negotiation
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / compat.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "main.h"
16 #include "treesocket.h"
17
18 static const char* const forge_common_1201[] = {
19         "m_chghost.so",
20         "m_chgname.so",
21         "m_remove.so",
22         "m_sajoin.so",
23         "m_sakick.so",
24         "m_sanick.so",
25         "m_sapart.so",
26         "m_saquit.so",
27         "m_setident.so",
28         "m_swhois.so",
29         "m_regex_pcre.so"
30 };
31
32 static std::string wide_newline("\r\n");
33 static std::string newline("\n");
34
35 void TreeSocket::CompatAddModules(std::vector<std::string>& modlist)
36 {
37         if (proto_version < 1202)
38         {
39                 for(std::vector<std::string>::iterator i = modlist.begin(); i != modlist.end(); ++i)
40                 {
41                         if (*i == "m_halfop.so")
42                         {
43                                 modlist.erase(i);
44                                 break;
45                         }
46                 }
47                 // you MUST have chgident loaded in order to be able to translate FIDENT
48                 modlist.push_back("m_chgident.so");
49                 for(int i=0; i * sizeof(char*) < sizeof(forge_common_1201); i++)
50                 {
51                         if (ServerInstance->Modules->Find(forge_common_1201[i]))
52                                 modlist.push_back(forge_common_1201[i]);
53                 }
54                 // module was merged
55                 if (ServerInstance->Modules->Find("m_operchans.so"))
56                         modlist.push_back("m_operinvex.so");
57         }
58 }
59
60 void TreeSocket::WriteLine(std::string line)
61 {
62         if (LinkState == CONNECTED)
63         {
64                 if (line[0] != ':')
65                 {
66                         ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Sending line without server prefix!");
67                         line = ":" + ServerInstance->Config->GetSID() + " " + line;
68                 }
69                 if (proto_version != ProtocolVersion)
70                 {
71                         std::string::size_type a = line.find(' ');
72                         std::string::size_type b = line.find(' ', a + 1);
73                         std::string command = line.substr(a + 1, b-a-1);
74                         // now try to find a translation entry
75                         // TODO a more efficient lookup method will be needed later
76                         if (proto_version < 1202 && command == "FIDENT")
77                         {
78                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting FIDENT for 1201-protocol server");
79                                 line = ":" + ServerInstance->Config->GetSID() + " CHGIDENT " +  line.substr(1,a-1) + line.substr(b);
80                         }
81                         else if (proto_version < 1202 && command == "SAVE")
82                         {
83                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting SAVE for 1201-protocol server");
84                                 std::string::size_type c = line.find(' ', b + 1);
85                                 std::string uid = line.substr(b, c - b);
86                                 line = ":" + ServerInstance->Config->GetSID() + " SVSNICK" + uid + line.substr(b);
87                         }
88                         else if (proto_version < 1202 && command == "AWAY")
89                         {
90                                 if (b != std::string::npos)
91                                 {
92                                         ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Stripping AWAY timestamp for 1201-protocol server");
93                                         std::string::size_type c = line.find(' ', b + 1);
94                                         line.erase(b,c-b);
95                                 }
96                         }
97                         else if (proto_version < 1202 && command == "ENCAP")
98                         {
99                                 // :src ENCAP target command [args...]
100                                 //     A     B      C       D
101                                 // Therefore B and C cannot be npos in a valid command
102                                 if (b == std::string::npos)
103                                         return;
104                                 std::string::size_type c = line.find(' ', b + 1);
105                                 if (c == std::string::npos)
106                                         return;
107                                 std::string::size_type d = line.find(' ', c + 1);
108                                 std::string subcmd = line.substr(c, d - c);
109                                 Command* thiscmd = ServerInstance->Parser->GetHandler(subcmd);
110                                 if (thiscmd)
111                                 {
112                                         Version ver = thiscmd->creator->GetVersion();
113                                         if (ver.Flags & VF_OPTCOMMON)
114                                         {
115                                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Removing ENCAP on '%s' for 1201-protocol server",
116                                                         subcmd.c_str());
117                                                 line.erase(a, c-a);
118                                         }
119                                 }
120                         }
121                 }
122         }
123
124         ServerInstance->Logs->Log("m_spanningtree",DEBUG, "S[%d] O %s", this->GetFd(), line.c_str());
125         this->WriteData(line);
126         if (proto_version < 1202)
127                 this->WriteData(wide_newline);
128         else
129                 this->WriteData(newline);
130 }