]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/compat.cpp
b5b31cf4d962ad2f7e0d4b4cf20e03989001bbf7
[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_alltime.so",
21         "m_auditorium.so",
22         "m_banexception.so",
23         "m_blockcaps.so",
24         "m_blockcolor.so",
25         "m_botmode.so",
26         "m_censor.so",
27         "m_chanfilter.so",
28         "m_chanhistory.so",
29         "m_channelban.so",
30         "m_chanprotect.so",
31         "m_chghost.so",
32         "m_chgname.so",
33         "m_commonchans.so",
34         "m_customtitle.so",
35         "m_deaf.so",
36         "m_delayjoin.so",
37         "m_delaymsg.so",
38         "m_exemptchanops.so",
39         "m_gecosban.so",
40         "m_globops.so",
41         "m_helpop.so",
42         "m_hidechans.so",
43         "m_hideoper.so",
44         "m_invisible.so",
45         "m_inviteexception.so",
46         "m_joinflood.so",
47         "m_kicknorejoin.so",
48         "m_knock.so",
49         "m_messageflood.so",
50         "m_muteban.so",
51         "m_nickflood.so",
52         "m_nicklock.so",
53         "m_noctcp.so",
54         "m_nokicks.so",
55         "m_nonicks.so",
56         "m_nonotice.so",
57         "m_nopartmsg.so",
58         "m_ojoin.so",
59         "m_operprefix.so",
60         "m_permchannels.so",
61         "m_redirect.so",
62         "m_regex_glob.so",
63         "m_regex_pcre.so",
64         "m_regex_posix.so",
65         "m_regex_tre.so",
66         "m_remove.so",
67         "m_sajoin.so",
68         "m_sakick.so",
69         "m_sanick.so",
70         "m_sapart.so",
71         "m_saquit.so",
72         "m_serverban.so",
73         "m_services_account.so",
74         "m_servprotect.so",
75         "m_setident.so",
76         "m_showwhois.so",
77         "m_silence.so",
78         "m_sslmodes.so",
79         "m_stripcolor.so",
80         "m_swhois.so",
81         "m_uninvite.so",
82         "m_watch.so"
83 };
84
85 static std::string wide_newline("\r\n");
86 static std::string newline("\n");
87
88 void TreeSocket::CompatAddModules(std::vector<std::string>& modlist)
89 {
90         if (proto_version < 1202)
91         {
92                 // you MUST have chgident loaded in order to be able to translate FIDENT
93                 modlist.push_back("m_chgident.so");
94                 for(int i=0; i * sizeof(char*) < sizeof(forge_common_1201); i++)
95                 {
96                         if (ServerInstance->Modules->Find(forge_common_1201[i]))
97                                 modlist.push_back(forge_common_1201[i]);
98                 }
99                 // module was merged
100                 if (ServerInstance->Modules->Find("m_operchans.so"))
101                 {
102                         modlist.push_back("m_operchans.so");
103                         modlist.push_back("m_operinvex.so");
104                 }
105         }
106 }
107
108 void TreeSocket::WriteLine(std::string line)
109 {
110         if (LinkState == CONNECTED)
111         {
112                 if (line[0] != ':')
113                 {
114                         ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Sending line without server prefix!");
115                         line = ":" + ServerInstance->Config->GetSID() + " " + line;
116                 }
117                 if (proto_version != ProtocolVersion)
118                 {
119                         std::string::size_type a = line.find(' ');
120                         std::string::size_type b = line.find(' ', a + 1);
121                         std::string command = line.substr(a + 1, b-a-1);
122                         // now try to find a translation entry
123                         // TODO a more efficient lookup method will be needed later
124                         if (proto_version < 1202 && command == "FIDENT")
125                         {
126                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting FIDENT for 1201-protocol server");
127                                 line = ":" + ServerInstance->Config->GetSID() + " CHGIDENT " +  line.substr(1,a-1) + line.substr(b);
128                         }
129                         else if (proto_version < 1202 && command == "SAVE")
130                         {
131                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting SAVE for 1201-protocol server");
132                                 std::string::size_type c = line.find(' ', b + 1);
133                                 std::string uid = line.substr(b, c - b);
134                                 line = ":" + ServerInstance->Config->GetSID() + " SVSNICK" + uid + line.substr(b);
135                         }
136                         else if (proto_version < 1202 && command == "AWAY")
137                         {
138                                 if (b != std::string::npos)
139                                 {
140                                         ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Stripping AWAY timestamp for 1201-protocol server");
141                                         std::string::size_type c = line.find(' ', b + 1);
142                                         line.erase(b,c-b);
143                                 }
144                         }
145                         else if (proto_version < 1202 && command == "ENCAP")
146                         {
147                                 // :src ENCAP target command [args...]
148                                 //     A     B      C       D
149                                 // Therefore B and C cannot be npos in a valid command
150                                 if (b == std::string::npos)
151                                         return;
152                                 std::string::size_type c = line.find(' ', b + 1);
153                                 if (c == std::string::npos)
154                                         return;
155                                 std::string::size_type d = line.find(' ', c + 1);
156                                 std::string subcmd = line.substr(c + 1, d - c - 1);
157
158                                 if (subcmd == "CHGIDENT" && d != std::string::npos)
159                                 {
160                                         std::string::size_type e = line.find(' ', d + 1);
161                                         if (e == std::string::npos)
162                                                 return; // not valid
163                                         std::string target = line.substr(d + 1, e - d - 1);
164
165                                         ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Forging acceptance of CHGIDENT from 1201-protocol server");
166                                         recvq.insert(0, ":" + target + " FIDENT " + line.substr(e) + "\n");
167                                 }
168
169                                 Command* thiscmd = ServerInstance->Parser->GetHandler(subcmd);
170                                 if (thiscmd && subcmd != "WHOISNOTICE")
171                                 {
172                                         Version ver = thiscmd->creator->GetVersion();
173                                         if (ver.Flags & VF_OPTCOMMON)
174                                         {
175                                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Removing ENCAP on '%s' for 1201-protocol server",
176                                                         subcmd.c_str());
177                                                 line.erase(a, c-a);
178                                         }
179                                 }
180                         }
181                 }
182         }
183
184         ServerInstance->Logs->Log("m_spanningtree", RAWIO, "S[%d] O %s", this->GetFd(), line.c_str());
185         this->WriteData(line);
186         if (proto_version < 1202)
187                 this->WriteData(wide_newline);
188         else
189                 this->WriteData(newline);
190 }