1 |
douglas |
1450 |
/* |
2 |
|
|
* Copyright (C) 2008-2012 See the AUTHORS file for details. |
3 |
|
|
* |
4 |
|
|
* This program is free software; you can redistribute it and/or modify it |
5 |
|
|
* under the terms of the GNU General Public License version 2 as published |
6 |
|
|
* by the Free Software Foundation. |
7 |
|
|
*/ |
8 |
|
|
|
9 |
|
|
#include <znc/User.h> |
10 |
|
|
#include <znc/IRCNetwork.h> |
11 |
|
|
#include <znc/znc.h> |
12 |
|
|
|
13 |
|
|
class CFOModule : public CModule { |
14 |
|
|
public: |
15 |
|
|
MODCONSTRUCTOR(CFOModule) {} |
16 |
|
|
virtual ~CFOModule() {} |
17 |
|
|
|
18 |
|
|
bool IsOnlineModNick(const CString& sNick) { |
19 |
|
|
const CString& sPrefix = m_pUser->GetStatusPrefix(); |
20 |
|
|
if (!sNick.Equals(sPrefix, false, sPrefix.length())) |
21 |
|
|
return false; |
22 |
|
|
|
23 |
|
|
CString sModNick = sNick.substr(sPrefix.length()); |
24 |
|
|
if (!sModNick.Equals("status") && |
25 |
|
|
!m_pUser->GetModules().FindModule(sModNick) && |
26 |
|
|
!CZNC::Get().GetModules().FindModule(sModNick)) |
27 |
|
|
return false; |
28 |
|
|
return true; |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
virtual EModRet OnUserRaw(CString& sLine) { |
32 |
|
|
//Handle ISON |
33 |
|
|
if (sLine.Token(0).Equals("ison")) { |
34 |
|
|
VCString vsNicks; |
35 |
|
|
VCString::const_iterator it; |
36 |
|
|
|
37 |
|
|
// Get the list of nicks which are being asked for |
38 |
|
|
sLine.Token(1, true).TrimLeft_n(":").Split(" ", vsNicks, false); |
39 |
|
|
|
40 |
|
|
CString sBNCNicks; |
41 |
|
|
for (it = vsNicks.begin(); it != vsNicks.end(); ++it) { |
42 |
|
|
if (IsOnlineModNick(*it)) { |
43 |
|
|
sBNCNicks += " " + *it; |
44 |
|
|
} |
45 |
|
|
} |
46 |
|
|
// Remove the leading space |
47 |
|
|
sBNCNicks.LeftChomp(); |
48 |
|
|
|
49 |
|
|
if (!m_pNetwork->GetIRCSock()) { |
50 |
|
|
// if we are not connected to any IRC server, send |
51 |
|
|
// an empty or module-nick filled response. |
52 |
|
|
PutUser(":irc.znc.in 303 " + m_pClient->GetNick() + " :" + sBNCNicks); |
53 |
|
|
} else { |
54 |
|
|
// We let the server handle this request and then act on |
55 |
|
|
// the 303 response from the IRC server. |
56 |
|
|
m_ISONRequests.push_back(sBNCNicks); |
57 |
|
|
} |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
//Handle WHOIS |
61 |
|
|
if (sLine.Token(0).Equals("whois")) { |
62 |
|
|
CString sNick = sLine.Token(1); |
63 |
|
|
|
64 |
|
|
if (IsOnlineModNick(sNick)) { |
65 |
|
|
PutUser(":znc.in 311 " + m_pNetwork->GetCurNick() + " " + sNick + " " + sNick + " znc.in * :" + sNick); |
66 |
|
|
PutUser(":znc.in 312 " + m_pNetwork->GetCurNick() + " " + sNick + " *.znc.in :Bouncer"); |
67 |
|
|
PutUser(":znc.in 318 " + m_pNetwork->GetCurNick() + " " + sNick + " :End of /WHOIS list."); |
68 |
|
|
|
69 |
|
|
return HALT; |
70 |
|
|
} |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
return CONTINUE; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
virtual EModRet OnRaw(CString& sLine) { |
77 |
|
|
//Handle 303 reply if m_Requests is not empty |
78 |
|
|
if (sLine.Token(1) == "303" && !m_ISONRequests.empty()) { |
79 |
|
|
VCString::iterator it = m_ISONRequests.begin(); |
80 |
|
|
|
81 |
|
|
sLine.Trim(); |
82 |
|
|
|
83 |
|
|
// Only append a space if this isn't an empty reply |
84 |
|
|
if (sLine.Right(1) != ":") { |
85 |
|
|
sLine += " "; |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
//add BNC nicks to the reply |
89 |
|
|
sLine += *it; |
90 |
|
|
m_ISONRequests.erase(it); |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
return CONTINUE; |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
private: |
97 |
|
|
VCString m_ISONRequests; |
98 |
|
|
}; |
99 |
|
|
|
100 |
|
|
NETWORKMODULEDEFS(CFOModule, "Fakes online status of ZNC *-users.") |
101 |
|
|
|
102 |
|
|
// vim: noexpandtab tabstop=4 |