]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/compat.cpp
dd577fca7c2a1b7fe9a0f82205b8c2c74fe1c2f9
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / compat.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 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
34 void TreeSocket::CompatAddModules(std::vector<std::string>& modlist)
35 {
36         if (proto_version < 1202)
37         {
38                 for(std::vector<std::string>::iterator i = modlist.begin(); i != modlist.end(); ++i)
39                 {
40                         if (*i == "m_halfop.so")
41                         {
42                                 modlist.erase(i);
43                                 break;
44                         }
45                 }
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++)
49                 {
50                         if (ServerInstance->Modules->Find(forge_common_1201[i]))
51                                 modlist.push_back(forge_common_1201[i]);
52                 }
53                 // module was merged
54                 if (ServerInstance->Modules->Find("m_operchans.so"))
55                         modlist.push_back("m_operinvex.so");
56         }
57 }
58
59 void TreeSocket::WriteLine(std::string line)
60 {
61         if (LinkState == CONNECTED)
62         {
63                 if (line[0] != ':')
64                 {
65                         ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Sending line without server prefix!");
66                         line = ":" + ServerInstance->Config->GetSID() + " " + line;
67                 }
68                 if (proto_version != ProtocolVersion)
69                 {
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")
76                         {
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);
79                         }
80                         else if (proto_version < 1202 && command == "SAVE")
81                         {
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);
86                         }
87                         else if (proto_version < 1202 && command == "AWAY")
88                         {
89                                 if (b != std::string::npos)
90                                 {
91                                         ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Stripping AWAY timestamp for 1201-protocol server");
92                                         std::string::size_type c = line.find(' ', b + 1);
93                                         line.erase(b,c-b);
94                                 }
95                         }
96                         else if (proto_version < 1202 && command == "ENCAP")
97                         {
98                                 // :src ENCAP target command [args...]
99                                 //     A     B      C       D
100                                 // Therefore B and C cannot be npos in a valid command
101                                 if (b == std::string::npos)
102                                         return;
103                                 std::string::size_type c = line.find(' ', b + 1);
104                                 if (c == std::string::npos)
105                                         return;
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);
109                                 if (thiscmd)
110                                 {
111                                         Version ver = thiscmd->creator->GetVersion();
112                                         if (ver.Flags & VF_OPTCOMMON)
113                                         {
114                                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Removing ENCAP on '%s' for 1201-protocol server",
115                                                         subcmd.c_str());
116                                                 line.erase(a, c-a);
117                                         }
118                                 }
119                         }
120                 }
121         }
122
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);
126 }