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

« back to all changes in this revision

Viewing changes to modules/autoop.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
1
/*
2
 
 * Copyright (C) 2004-2011  See the AUTHORS file for details.
 
2
 * Copyright (C) 2004-2012  See the AUTHORS file for details.
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify it
5
5
 * under the terms of the GNU General Public License version 2 as published
6
6
 * by the Free Software Foundation.
7
7
 */
8
8
 
9
 
#include "Chan.h"
10
 
#include "User.h"
 
9
#include <znc/IRCNetwork.h>
 
10
#include <znc/Chan.h>
 
11
 
 
12
using std::map;
 
13
using std::set;
 
14
using std::vector;
11
15
 
12
16
class CAutoOpMod;
13
17
 
160
164
        virtual void OnJoin(const CNick& Nick, CChan& Channel) {
161
165
                // If we have ops in this chan
162
166
                if (Channel.HasPerm(CChan::Op)) {
163
 
                        for (map<CString, CAutoOpUser*>::iterator it = m_msUsers.begin(); it != m_msUsers.end(); ++it) {
164
 
                                // and the nick who joined is a valid user
165
 
                                if (it->second->HostMatches(Nick.GetHostMask()) && it->second->ChannelMatches(Channel.GetName())) {
166
 
                                        if (it->second->GetUserKey().Equals("__NOKEY__")) {
167
 
                                                PutIRC("MODE " + Channel.GetName() + " +o " + Nick.GetNick());
168
 
                                        } else {
169
 
                                                // then insert this nick into the queue, the timer does the rest
170
 
                                                CString sNick = Nick.GetNick().AsLower();
171
 
                                                if (m_msQueue.find(sNick) == m_msQueue.end()) {
172
 
                                                        m_msQueue[sNick] = "";
173
 
                                                }
174
 
                                        }
175
 
 
176
 
                                        break;
177
 
                                }
178
 
                        }
 
167
                        CheckAutoOp(Nick, Channel);
179
168
                }
180
169
        }
181
170
 
213
202
                return HALTCORE;
214
203
        }
215
204
 
 
205
        virtual void OnOp(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange) {
 
206
                if (Nick.GetNick() == m_pNetwork->GetIRCNick().GetNick()) {
 
207
                        const map<CString,CNick>& msNicks = Channel.GetNicks();
 
208
 
 
209
                        for (map<CString,CNick>::const_iterator it = msNicks.begin(); it != msNicks.end(); ++it) {
 
210
                                if (!it->second.HasPerm(CChan::Op)) {
 
211
                                        CheckAutoOp(it->second, Channel);
 
212
                                }
 
213
                        }
 
214
                }
 
215
        }
 
216
 
216
217
        virtual void OnModCommand(const CString& sLine) {
217
218
                CString sCommand = sLine.Token(0).AsUpper();
218
219
 
309
310
                return NULL;
310
311
        }
311
312
 
 
313
        bool CheckAutoOp(const CNick& Nick, CChan& Channel) {
 
314
                CAutoOpUser *pUser = FindUserByHost(Nick.GetHostMask(), Channel.GetName());
 
315
 
 
316
                if (pUser) {
 
317
                        if (pUser->GetUserKey().Equals("__NOKEY__")) {
 
318
                                PutIRC("MODE " + Channel.GetName() + " +o " + Nick.GetNick());
 
319
                        } else {
 
320
                                // then insert this nick into the queue, the timer does the rest
 
321
                                CString sNick = Nick.GetNick().AsLower();
 
322
                                if (m_msQueue.find(sNick) == m_msQueue.end()) {
 
323
                                        m_msQueue[sNick] = "";
 
324
                                }
 
325
                        }
 
326
                }
 
327
 
 
328
                return pUser;
 
329
        }
 
330
 
312
331
        void DelUser(const CString& sUser) {
313
332
                map<CString, CAutoOpUser*>::iterator it = m_msUsers.find(sUser.AsLower());
314
333
 
345
364
 
346
365
                        // First verify that the guy who challenged us matches a user's host
347
366
                        if (pUser->HostMatches(Nick.GetHostMask())) {
348
 
                                const vector<CChan*>& Chans = m_pUser->GetChans();
 
367
                                const vector<CChan*>& Chans = m_pNetwork->GetChans();
349
368
                                bMatchedHost = true;
350
369
 
351
370
                                // Also verify that they are opped in at least one of the user's chans
440
459
        }
441
460
 
442
461
        void OpUser(const CNick& Nick, const CAutoOpUser& User) {
443
 
                const vector<CChan*>& Chans = m_pUser->GetChans();
 
462
                const vector<CChan*>& Chans = m_pNetwork->GetChans();
444
463
 
445
464
                for (size_t a = 0; a < Chans.size(); a++) {
446
465
                        const CChan& Chan = *Chans[a];
467
486
        Info.SetWikiPage("autoop");
468
487
}
469
488
 
470
 
MODULEDEFS(CAutoOpMod, "Auto op the good guys")
 
489
NETWORKMODULEDEFS(CAutoOpMod, "Auto op the good guys")