~ubuntu-branches/ubuntu/quantal/znc/quantal-backports

« back to all changes in this revision

Viewing changes to modules/extra/fakeonline.cpp

  • Committer: Package Import Robot
  • Author(s): Micah Gersten
  • Date: 2013-01-01 19:39:47 UTC
  • mfrom: (21.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130101193947-zlqyse3v2mjxnhvw
Tags: 1.0-2~ubuntu12.10.1
No-change backport to quantal (LP: #1085731)

Show diffs side-by-side

added added

removed removed

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