]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/compat.cpp
a11db82155e66e216e763261e7dea9e3f3e79fa7
[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_silence.so",
66         "m_sslmodes.so",
67         "m_stripcolor.so",
68         "m_swhois.so",
69         "m_watch.so"
70 };
71
72 static std::string wide_newline("\r\n");
73 static std::string newline("\n");
74
75 void TreeSocket::CompatAddModules(std::vector<std::string>& modlist)
76 {
77         if (proto_version < 1202)
78         {
79                 // you MUST have chgident loaded in order to be able to translate FIDENT
80                 modlist.push_back("m_chgident.so");
81                 for(int i=0; i * sizeof(char*) < sizeof(forge_common_1201); i++)
82                 {
83                         if (ServerInstance->Modules->Find(forge_common_1201[i]))
84                                 modlist.push_back(forge_common_1201[i]);
85                 }
86                 // module was merged
87                 if (ServerInstance->Modules->Find("m_operchans.so"))
88                 {
89                         modlist.push_back("m_operchans.so");
90                         modlist.push_back("m_operinvex.so");
91                 }
92         }
93 }
94
95 void TreeSocket::WriteLine(std::string line)
96 {
97         if (LinkState == CONNECTED)
98         {
99                 if (line[0] != ':')
100                 {
101                         ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Sending line without server prefix!");
102                         line = ":" + ServerInstance->Config->GetSID() + " " + line;
103                 }
104                 if (proto_version != ProtocolVersion)
105                 {
106                         std::string::size_type a = line.find(' ');
107                         std::string::size_type b = line.find(' ', a + 1);
108                         std::string command = line.substr(a + 1, b-a-1);
109                         // now try to find a translation entry
110                         // TODO a more efficient lookup method will be needed later
111                         if (proto_version < 1202 && command == "FIDENT")
112                         {
113                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting FIDENT for 1201-protocol server");
114                                 line = ":" + ServerInstance->Config->GetSID() + " CHGIDENT " +  line.substr(1,a-1) + line.substr(b);
115                         }
116                         else if (proto_version < 1202 && command == "SAVE")
117                         {
118                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting SAVE for 1201-protocol server");
119                                 std::string::size_type c = line.find(' ', b + 1);
120                                 std::string uid = line.substr(b, c - b);
121                                 line = ":" + ServerInstance->Config->GetSID() + " SVSNICK" + uid + line.substr(b);
122                         }
123                         else if (proto_version < 1202 && command == "AWAY")
124                         {
125                                 if (b != std::string::npos)
126                                 {
127                                         ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Stripping AWAY timestamp for 1201-protocol server");
128                                         std::string::size_type c = line.find(' ', b + 1);
129                                         line.erase(b,c-b);
130                                 }
131                         }
132                         else if (proto_version < 1202 && command == "ENCAP")
133                         {
134                                 // :src ENCAP target command [args...]
135                                 //     A     B      C       D
136                                 // Therefore B and C cannot be npos in a valid command
137                                 if (b == std::string::npos)
138                                         return;
139                                 std::string::size_type c = line.find(' ', b + 1);
140                                 if (c == std::string::npos)
141                                         return;
142                                 std::string::size_type d = line.find(' ', c + 1);
143                                 std::string subcmd = line.substr(c, d - c);
144                                 Command* thiscmd = ServerInstance->Parser->GetHandler(subcmd);
145                                 if (thiscmd)
146                                 {
147                                         Version ver = thiscmd->creator->GetVersion();
148                                         if (ver.Flags & VF_OPTCOMMON)
149                                         {
150                                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Removing ENCAP on '%s' for 1201-protocol server",
151                                                         subcmd.c_str());
152                                                 line.erase(a, c-a);
153                                         }
154                                 }
155                         }
156                 }
157         }
158
159         ServerInstance->Logs->Log("m_spanningtree",DEBUG, "S[%d] O %s", this->GetFd(), line.c_str());
160         this->WriteData(line);
161         if (proto_version < 1202)
162                 this->WriteData(wide_newline);
163         else
164                 this->WriteData(newline);
165 }