]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/compat.cpp
Change SWHOIS to OPTCOMMON, remove m_operinvex
[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 };
30
31 static std::string wide_newline("\r\n");
32
33 void TreeSocket::CompatAddModules(std::vector<std::string>& modlist)
34 {
35         if (proto_version < 1202)
36         {
37                 // you MUST have chgident loaded in order to be able to translate FIDENT
38                 modlist.push_back("m_chgident.so");
39                 for(int i=0; i * sizeof(char*) < sizeof(forge_common_1201); i++)
40                 {
41                         if (ServerInstance->Modules->Find(forge_common_1201[i]))
42                                 modlist.push_back(forge_common_1201[i]);
43                 }
44                 // module was merged
45                 if (ServerInstance->Modules->Find("m_operchans.so"))
46                         modlist.push_back("m_operinvex.so");
47         }
48 }
49
50 void TreeSocket::WriteLine(std::string line)
51 {
52         if (LinkState == CONNECTED)
53         {
54                 if (line[0] != ':')
55                 {
56                         ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Sending line without server prefix!");
57                         line = ":" + ServerInstance->Config->GetSID() + " " + line;
58                 }
59                 if (proto_version != ProtocolVersion)
60                 {
61                         std::string::size_type a = line.find(' ');
62                         std::string::size_type b = line.find(' ', a + 1);
63                         std::string command = line.substr(a + 1, b-a-1);
64                         // now try to find a translation entry
65                         // TODO a more efficient lookup method will be needed later
66                         if (proto_version < 1202 && command == "FIDENT")
67                         {
68                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting FIDENT for 1201-protocol server");
69                                 line = ":" + ServerInstance->Config->GetSID() + " CHGIDENT " +  line.substr(1,a-1) + line.substr(b);
70                         }
71                         else if (proto_version < 1202 && command == "SAVE")
72                         {
73                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting SAVE for 1201-protocol server");
74                                 std::string::size_type c = line.find(' ', b + 1);
75                                 std::string uid = line.substr(b, c - b);
76                                 line = ":" + ServerInstance->Config->GetSID() + " SVSNICK " + uid + line.substr(b);
77                         }
78                         else if (proto_version < 1202 && command == "AWAY")
79                         {
80                                 if (b != std::string::npos)
81                                 {
82                                         ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Stripping AWAY timestamp for 1201-protocol server");
83                                         std::string::size_type c = line.find(' ', b + 1);
84                                         line.erase(b,c-b);
85                                 }
86                         }
87                         else if (proto_version < 1202 && command == "ENCAP")
88                         {
89                                 // :src ENCAP target command [args...]
90                                 //     A     B      C       D
91                                 // Therefore B and C cannot be npos in a valid command
92                                 if (b == std::string::npos)
93                                         return;
94                                 std::string::size_type c = line.find(' ', b + 1);
95                                 if (c == std::string::npos)
96                                         return;
97                                 std::string::size_type d = line.find(' ', c + 1);
98                                 std::string subcmd = line.substr(c, d - c);
99                                 Command* thiscmd = ServerInstance->Parser->GetHandler(subcmd);
100                                 if (thiscmd)
101                                 {
102                                         Version ver = thiscmd->creator->GetVersion();
103                                         if (ver.Flags & VF_OPTCOMMON)
104                                         {
105                                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Removing ENCAP on '%s' for 1201-protocol server",
106                                                         subcmd.c_str());
107                                                 line.erase(a, c-a);
108                                         }
109                                 }
110                         }
111                 }
112         }
113
114         ServerInstance->Logs->Log("m_spanningtree",DEBUG, "S[%d] O %s", this->GetFd(), line.c_str());
115         this->WriteData(line);
116         this->WriteData(wide_newline);
117 }