]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/compat.cpp
fe262134fe40d1ea86f18e1b477719a260d174d2
[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_allowinvite.so",
20         "m_auditorium.so",
21         "m_banexception.so",
22         "m_blockcaps.so",
23         "m_blockcolor.so",
24         "m_botmode.so",
25         "m_censor.so",
26         "m_chanfilter.so",
27         "m_chanhistory.so",
28         "m_chanprotect.so",
29         "m_chghost.so",
30         "m_chgname.so",
31         "m_commonchans.so",
32         "m_deaf.so",
33         "m_delayjoin.so",
34         "m_delaymsg.so",
35         "m_exemptchanops.so",
36         "m_helpop.so",
37         "m_hidechans.so",
38         "m_hideoper.so",
39         "m_invisible.so",
40         "m_inviteexception.so",
41         "m_joinflood.so",
42         "m_kicknorejoin.so",
43         "m_messageflood.so",
44         "m_nickflood.so",
45         "m_noctcp.so",
46         "m_nokicks.so",
47         "m_nonicks.so",
48         "m_nonotice.so",
49         "m_ojoin.so",
50         "m_operprefix.so",
51         "m_permchannels.so",
52         "m_redirect.so",
53         "m_regex_glob.so",
54         "m_regex_pcre.so",
55         "m_regex_posix.so",
56         "m_regex_tre.so",
57         "m_remove.so",
58         "m_sajoin.so",
59         "m_sakick.so",
60         "m_sanick.so",
61         "m_sapart.so",
62         "m_saquit.so",
63         "m_servprotect.so",
64         "m_setident.so",
65         "m_sslmodes.so",
66         "m_stripcolor.so",
67         "m_swhois.so",
68 };
69
70 static std::string wide_newline("\r\n");
71 static std::string newline("\n");
72
73 void TreeSocket::CompatAddModules(std::vector<std::string>& modlist)
74 {
75         if (proto_version < 1202)
76         {
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++)
80                 {
81                         if (ServerInstance->Modules->Find(forge_common_1201[i]))
82                                 modlist.push_back(forge_common_1201[i]);
83                 }
84                 // module was merged
85                 if (ServerInstance->Modules->Find("m_operchans.so"))
86                 {
87                         modlist.push_back("m_operchans.so");
88                         modlist.push_back("m_operinvex.so");
89                 }
90         }
91 }
92
93 void TreeSocket::WriteLine(std::string line)
94 {
95         if (LinkState == CONNECTED)
96         {
97                 if (line[0] != ':')
98                 {
99                         ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Sending line without server prefix!");
100                         line = ":" + ServerInstance->Config->GetSID() + " " + line;
101                 }
102                 if (proto_version != ProtocolVersion)
103                 {
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")
110                         {
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);
113                         }
114                         else if (proto_version < 1202 && command == "SAVE")
115                         {
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);
120                         }
121                         else if (proto_version < 1202 && command == "AWAY")
122                         {
123                                 if (b != std::string::npos)
124                                 {
125                                         ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Stripping AWAY timestamp for 1201-protocol server");
126                                         std::string::size_type c = line.find(' ', b + 1);
127                                         line.erase(b,c-b);
128                                 }
129                         }
130                         else if (proto_version < 1202 && command == "ENCAP")
131                         {
132                                 // :src ENCAP target command [args...]
133                                 //     A     B      C       D
134                                 // Therefore B and C cannot be npos in a valid command
135                                 if (b == std::string::npos)
136                                         return;
137                                 std::string::size_type c = line.find(' ', b + 1);
138                                 if (c == std::string::npos)
139                                         return;
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);
143                                 if (thiscmd)
144                                 {
145                                         Version ver = thiscmd->creator->GetVersion();
146                                         if (ver.Flags & VF_OPTCOMMON)
147                                         {
148                                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Removing ENCAP on '%s' for 1201-protocol server",
149                                                         subcmd.c_str());
150                                                 line.erase(a, c-a);
151                                         }
152                                 }
153                         }
154                 }
155         }
156
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);
161         else
162                 this->WriteData(newline);
163 }