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