]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/compat.cpp
Run configure -update on all svn/git changes
[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 };
29
30 static std::string wide_newline("\r\n");
31
32 void TreeSocket::CompatAddModules(std::vector<std::string>& modlist)
33 {
34         if (proto_version < 1202)
35         {
36                 // you MUST have chgident loaded in order to be able to translate FIDENT
37                 modlist.push_back("m_chgident.so");
38                 for(int i=0; i * sizeof(char*) < sizeof(forge_common_1201); i++)
39                 {
40                         if (ServerInstance->Modules->Find(forge_common_1201[i]))
41                                 modlist.push_back(forge_common_1201[i]);
42                 }
43         }
44 }
45
46 void TreeSocket::WriteLine(std::string line)
47 {
48         if (LinkState == CONNECTED)
49         {
50                 if (line[0] != ':')
51                 {
52                         ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Sending line without server prefix!");
53                         line = ":" + ServerInstance->Config->GetSID() + " " + line;
54                 }
55                 if (proto_version != ProtocolVersion)
56                 {
57                         std::string::size_type a = line.find(' ') + 1;
58                         std::string::size_type b = line.find(' ', a);
59                         std::string command = line.substr(a, b-a);
60                         // now try to find a translation entry
61                         // TODO a more efficient lookup method will be needed later
62                         if (proto_version < 1202 && command == "FIDENT")
63                         {
64                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting FIDENT for 1201-protocol server");
65                                 line = ":" + ServerInstance->Config->GetSID() + " CHGIDENT " +  line.substr(1,a-2) + line.substr(b);
66                         }
67                         else if (proto_version < 1202 && command == "SAVE")
68                         {
69                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting SAVE for 1201-protocol server");
70                                 std::string::size_type c = line.find(' ', b + 1);
71                                 std::string uid = line.substr(b, c - b);
72                                 line = ":" + ServerInstance->Config->GetSID() + " SVSNICK " + uid + line.substr(b);
73                         }
74                         else if (proto_version < 1202 && command == "AWAY")
75                         {
76                                 if (b != std::string::npos)
77                                 {
78                                         std::string::size_type c = line.find(' ', b + 1);
79                                         line.erase(b,c-b);
80                                 }
81                         }
82                 }
83         }
84
85         ServerInstance->Logs->Log("m_spanningtree",DEBUG, "S[%d] O %s", this->GetFd(), line.c_str());
86         this->WriteData(line);
87         this->WriteData(wide_newline);
88 }
89
90
91