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