~ubuntu-branches/ubuntu/natty/znc/natty-backports

« back to all changes in this revision

Viewing changes to modules/partyline.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Matthäi
  • Date: 2009-05-23 16:17:47 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090523161747-dtgbsub23o1sl7ss
Tags: 0.070-1
* New upstream release.
  - Add new pkgconfig files to znc-dev.
* Fix typo in get-orig-source target.
* Merge 0.058-2~bpo40+1 and 0.058-2~bpo40+2 changelog.
* Add recommends on the new source package znc-extra.
* Add my own copyright for the Debian packaging.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
#include "User.h"
10
10
#include "znc.h"
11
11
 
 
12
// If you change these and it breaks, you get to keep the pieces
 
13
#define CHAN_PREFIX_1   "~"
 
14
#define CHAN_PREFIX_1C  '~'
 
15
#define CHAN_PREFIX     CHAN_PREFIX_1 "#"
 
16
 
12
17
class CPartylineChannel {
13
18
public:
14
19
        CPartylineChannel(const CString& sName) { m_sName = sName.AsLower(); }
60
65
                for (map<CString, CUser*>::const_iterator it = msUsers.begin(); it != msUsers.end(); it++) {
61
66
                        CUser* pUser = it->second;
62
67
                        if (pUser->GetIRCSock()) {
63
 
                                if (pUser->GetChanPrefixes().find("~") == CString::npos) {
64
 
                                        pUser->PutUser(":" + GetIRCServer(pUser) + " 005 " + pUser->GetIRCNick().GetNick() + " CHANTYPES=" + pUser->GetChanPrefixes() + "~ :are supported by this server.");
 
68
                                if (pUser->GetChanPrefixes().find(CHAN_PREFIX_1) == CString::npos) {
 
69
                                        pUser->PutUser(":" + GetIRCServer(pUser) + " 005 " + pUser->GetIRCNick().GetNick() + " CHANTYPES=" + pUser->GetChanPrefixes() + CHAN_PREFIX_1 " :are supported by this server.");
65
70
                                }
66
71
                        }
67
72
                }
69
74
                CString sChan;
70
75
                unsigned int a = 0;
71
76
                while (!(sChan = sArgs.Token(a++)).empty()) {
72
 
                        if (sChan.Left(2) == "~#") {
 
77
                        if (sChan.Left(2) == CHAN_PREFIX) {
73
78
                                sChan = sChan.Left(32);
74
79
                                m_ssDefaultChans.insert(sChan);
75
80
                        }
124
129
        virtual EModRet OnDeleteUser(CUser& User) {
125
130
                // Loop through each chan
126
131
                for (set<CPartylineChannel*>::iterator it = m_ssChannels.begin(); it != m_ssChannels.end(); it++) {
127
 
                        RemoveUser(&User, *it, "KICK", true, "User deleted");
 
132
                        RemoveUser(&User, *it, "KICK", true, "User deleted", true);
128
133
                }
129
134
 
130
135
                return CONTINUE;
136
141
                        if (uPos != CString::npos) {
137
142
                                uPos = sLine.find(" ", uPos);
138
143
 
139
 
                                sLine.insert(uPos, "~");
 
144
                                sLine.insert(uPos, CHAN_PREFIX_1);
140
145
                                m_spInjectedPrefixes.insert(m_pUser);
141
146
                        }
142
147
                }
150
155
 
151
156
        virtual void OnClientLogin() {
152
157
                if (m_spInjectedPrefixes.find(m_pUser) == m_spInjectedPrefixes.end()) {
153
 
                        m_pClient->PutClient(":" + GetIRCServer(m_pUser) + " 005 " + m_pUser->GetIRCNick().GetNick() + " CHANTYPES=" + m_pUser->GetChanPrefixes() + "~ :are supported by this server.");
 
158
                        m_pClient->PutClient(":" + GetIRCServer(m_pUser) + " 005 " + m_pUser->GetIRCNick().GetNick() + " CHANTYPES=" + m_pUser->GetChanPrefixes() + CHAN_PREFIX_1 " :are supported by this server.");
154
159
                }
155
160
 
156
161
                // Make sure this user is in the default channels
206
211
        }
207
212
 
208
213
        virtual EModRet OnUserRaw(CString& sLine) {
209
 
                if (sLine.Equals("WHO ~", false, 5)) {
210
 
                        return HALT;
211
 
                } else if (sLine.Equals("MODE ~", false, 6)) {
212
 
                        return HALT;
213
 
                } else if (sLine.Equals("TOPIC ~#", false, 8)) {
 
214
                if (sLine.Equals("WHO " CHAN_PREFIX_1, false, 5)) {
 
215
                        return HALT;
 
216
                } else if (sLine.Equals("MODE " CHAN_PREFIX_1, false, 6)) {
 
217
                        return HALT;
 
218
                } else if (sLine.Equals("TOPIC " CHAN_PREFIX, false, 8)) {
214
219
                        CString sChannel = sLine.Token(1);
215
220
                        CString sTopic = sLine.Token(2, true);
216
221
 
246
251
        }
247
252
 
248
253
        virtual EModRet OnUserPart(CString& sChannel, CString& sMessage) {
249
 
                if (sChannel.Left(1) != "~") {
 
254
                if (sChannel.Left(1) != CHAN_PREFIX_1) {
250
255
                        return CONTINUE;
251
256
                }
252
257
 
253
 
                if (sChannel.Left(2) != "~#") {
 
258
                if (sChannel.Left(2) != CHAN_PREFIX) {
254
259
                        m_pClient->PutClient(":" + GetIRCServer(m_pUser) + " 403 " + m_pUser->GetIRCNick().GetNick() + " " + sChannel + " :No such channel");
255
260
                        return HALT;
256
261
                }
268
273
        }
269
274
 
270
275
        void RemoveUser(CUser* pUser, CPartylineChannel* pChannel, const CString& sCommand,
271
 
                        bool bForce = false, const CString& sMessage = "") {
 
276
                        bool bForce = false, const CString& sMessage = "", bool bNickAsTarget = false) {
272
277
                if (!pChannel || !pChannel->IsInChannel(pUser->GetUserName())) {
273
278
                        return;
274
279
                }
289
294
                                sHost = pUser->GetIRCNick().GetHost();
290
295
                        }
291
296
 
292
 
                        pUser->PutUser(":" + pUser->GetIRCNick().GetNickMask() + sCmd
293
 
                                        + pChannel->GetName() + sMsg);
294
 
                        PutChan(ssNicks, ":?" + pUser->GetUserName() + "!" + pUser->GetIdent() + "@" + sHost
295
 
                                        + sCmd + pChannel->GetName() + sMsg, false);
 
297
                        if (bNickAsTarget) {
 
298
                                pUser->PutUser(":" + pUser->GetIRCNick().GetNickMask() + sCmd
 
299
                                                + pChannel->GetName() + " " + pUser->GetIRCNick().GetNick() + sMsg);
 
300
                                PutChan(ssNicks, ":?" + pUser->GetUserName() + "!" + pUser->GetIdent() + "@" + sHost
 
301
                                                + sCmd + pChannel->GetName() + " ?" + pUser->GetUserName() + sMsg, false);
 
302
                        } else {
 
303
                                pUser->PutUser(":" + pUser->GetIRCNick().GetNickMask() + sCmd
 
304
                                                + pChannel->GetName() + sMsg);
 
305
                                PutChan(ssNicks, ":?" + pUser->GetUserName() + "!" + pUser->GetIdent() + "@" + sHost
 
306
                                                + sCmd + pChannel->GetName() + sMsg, false);
 
307
                        }
296
308
 
297
309
                        if (ssNicks.empty()) {
298
310
                                delete pChannel;
305
317
        }
306
318
 
307
319
        virtual EModRet OnUserJoin(CString& sChannel, CString& sKey) {
308
 
                if (sChannel.Left(1) != "~") {
 
320
                if (sChannel.Left(1) != CHAN_PREFIX_1) {
309
321
                        return CONTINUE;
310
322
                }
311
323
 
312
 
                if (sChannel.Left(2) != "~#") {
313
 
                        m_pClient->PutClient(":" + GetIRCServer(m_pUser) + " 403 " + m_pUser->GetIRCNick().GetNick() + " " + sChannel + " :Channels look like ~#znc");
 
324
                if (sChannel.Left(2) != CHAN_PREFIX) {
 
325
                        m_pClient->PutClient(":" + GetIRCServer(m_pUser) + " 403 " + m_pUser->GetIRCNick().GetNick() + " " + sChannel + " :Channels look like " CHAN_PREFIX "znc");
314
326
                        return HALT;
315
327
                }
316
328
 
343
355
                        SendNickList(pUser, ssNicks, pChannel->GetName());
344
356
 
345
357
                        if (pUser->IsAdmin()) {
346
 
                                PutChan(ssNicks, ":*" + GetModName() + "!znc@znc.in MODE " + pChannel->GetName() + " +o ?" + pUser->GetUserName(), (pUser == m_pUser) ? false : true, pUser);
 
358
                                PutChan(ssNicks, ":*" + GetModName() + "!znc@znc.in MODE " + pChannel->GetName() + " +o ?" + pUser->GetUserName(), false);
347
359
                        }
348
360
                }
349
361
        }
355
367
 
356
368
                char cPrefix = sTarget[0];
357
369
 
358
 
                if (cPrefix != '~' && cPrefix != '?') {
 
370
                if (cPrefix != CHAN_PREFIX_1C && cPrefix != '?') {
359
371
                        return CONTINUE;
360
372
                }
361
373
 
365
377
                        sHost = m_pUser->GetIRCNick().GetHost();
366
378
                }
367
379
 
368
 
                if (cPrefix == '~') {
 
380
                if (cPrefix == CHAN_PREFIX_1C) {
369
381
                        if (FindChannel(sTarget) == NULL) {
370
382
                                m_pClient->PutClient(":" + GetIRCServer(m_pUser) + " 403 " + m_pUser->GetIRCNick().GetNick() + " " + sTarget + " :No such channel");
371
383
                                return HALT;
455
467
                        CUser* pUser = CZNC::Get().FindUser(sUser);
456
468
                        CPartylineChannel* pChan;
457
469
 
458
 
                        if (sChan.Left(2) != "~#") {
 
470
                        if (sChan.Left(2) != CHAN_PREFIX) {
459
471
                                PutModule("Invalid channel name");
460
472
                                return;
461
473
                        }
596
608
        void SendNickList(CUser* pUser, const set<CString>& ssNicks, const CString& sChan) {
597
609
                CString sNickList;
598
610
 
599
 
                for (set<CString>::iterator it = ssNicks.begin(); it != ssNicks.end(); it++) {
 
611
                for (set<CString>::const_iterator it = ssNicks.begin(); it != ssNicks.end(); it++) {
600
612
                        CUser* pChanUser = CZNC::Get().FindUser(*it);
601
613
 
602
614
                        if (pChanUser && pChanUser->IsUserAttached()) {