~ubuntu-branches/ubuntu/trusty/znc/trusty

« back to all changes in this revision

Viewing changes to modules/route_replies.cpp

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2013-05-06 09:18:27 UTC
  • mfrom: (21.1.5 experimental)
  • Revision ID: package-import@ubuntu.com-20130506091827-08sixjiyy3hjfx6b
Tags: 1.0-4
* Change section from znc-tcl to interpreters.
* Uploading to unstable.

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 "znc.h"
10
 
#include "User.h"
11
 
#include "IRCSock.h"
 
9
#include <znc/znc.h>
 
10
#include <znc/IRCNetwork.h>
 
11
#include <znc/IRCSock.h>
12
12
 
13
13
struct reply {
14
14
        const char *szReply;
18
18
// TODO this list is far from complete, no errors are handled
19
19
static const struct {
20
20
        const char *szRequest;
21
 
        struct reply vReplies[10];
 
21
        struct reply vReplies[16];
22
22
} vRouteReplies[] = {
23
23
        {"WHO", {
24
 
                {"352", false},
 
24
                {"402", true},  /* rfc1459 ERR_NOSUCHSERVER */
 
25
                {"352", false},  /* rfc1459 RPL_WHOREPLY */
 
26
                {"315", true},  /* rfc1459 RPL_ENDOFWHO */
25
27
                {"354", false}, // e.g. Quaknet uses this for WHO #chan %n
26
28
                {"403", true}, // No such chan
27
 
                {"315", true},
28
29
                {NULL, true}
29
30
        }},
30
31
        {"LIST", {
31
 
                {"321", false},
32
 
                {"322", false},
33
 
                {"323", true},
 
32
                {"402", true},  /* rfc1459 ERR_NOSUCHSERVER */
 
33
                {"321", false},  /* rfc1459 RPL_LISTSTART */
 
34
                {"322", false},  /* rfc1459 RPL_LIST */
 
35
                {"323", true},  /* rfc1459 RPL_LISTEND */
34
36
                {NULL, true}
35
37
        }},
36
38
        {"NAMES", {
37
 
                {"353", false},
38
 
                {"366", true},
 
39
                {"353", false},  /* rfc1459 RPL_NAMREPLY */
 
40
                {"366", true},  /* rfc1459 RPL_ENDOFNAMES */
39
41
                // No such nick/channel
40
42
                {"401", true},
41
43
                {NULL, true},
42
44
        }},
43
45
        {"LUSERS", {
44
 
                {"251", false},
45
 
                {"252", false},
46
 
                {"253", false},
47
 
                {"254", false},
48
 
                {"255", false},
 
46
                {"251", false},  /* rfc1459 RPL_LUSERCLIENT */
 
47
                {"252", false},  /* rfc1459 RPL_LUSEROP */
 
48
                {"253", false},  /* rfc1459 RPL_LUSERUNKNOWN */
 
49
                {"254", false},  /* rfc1459 RPL_LUSERCHANNELS */
 
50
                {"255", false},  /* rfc1459 RPL_LUSERME */
49
51
                {"265", false},
50
52
                {"266", true},
51
53
                // We don't handle 250 here since some IRCds don't sent it
53
55
                {NULL, true}
54
56
        }},
55
57
        {"WHOIS", {
56
 
                {"311", false},
57
 
                {"319", false},
58
 
                {"312", false},
 
58
                {"311", false},  /* rfc1459 RPL_WHOISUSER */
 
59
                {"312", false},  /* rfc1459 RPL_WHOISSERVER */
 
60
                {"313", false},  /* rfc1459 RPL_WHOISOPERATOR */
 
61
                {"317", false},  /* rfc1459 RPL_WHOISIDLE */
 
62
                {"319", false},  /* rfc1459 RPL_WHOISCHANNELS */
59
63
                // "<ip> :actually using host"
60
64
                {"338", false},
61
 
                {"318", true},
62
 
                // No such nick/channel
63
 
                {"401", true},
64
 
                // No such server
65
 
                {"402", true},
 
65
                {"301", false},  /* rfc1459 RPL_AWAY */
 
66
                {"318", true},  /* rfc1459 RPL_ENDOFWHOIS */
 
67
                {"401", true},  /* rfc1459 ERR_NOSUCHNICK */
 
68
                {"402", true},  /* rfc1459 ERR_NOSUCHSERVER */
 
69
                {"431", true},  /* rfc1459 ERR_NONICKNAMEGIVEN */
66
70
                {NULL, true}
67
71
        }},
68
72
        {"PING", {
69
73
                {"PONG", true},
 
74
                {"402", true},  /* rfc1459 ERR_NOSUCHSERVER */
 
75
                {"409", true},  /* rfc1459 ERR_NOORIGIN */
70
76
                {NULL, true}
71
77
        }},
72
78
        {"USERHOST", {
73
79
                {"302", true},
 
80
                {"461", true},  /* rfc1459 ERR_NEEDMOREPARAMS */
74
81
                {NULL, true}
75
82
        }},
76
83
        {"TIME", {
77
 
                {"391", true},
 
84
                {"391", true},  /* rfc1459 RPL_TIME */
 
85
                {"402", true},  /* rfc1459 ERR_NOSUCHSERVER */
78
86
                {NULL, true}
79
87
        }},
80
88
        {"WHOWAS", {
81
 
                {"312", false},
82
 
                {"314", false},
83
 
                {"369", true},
 
89
                {"406", false},  /* rfc1459 ERR_WASNOSUCHNICK */
 
90
                {"312", false},  /* rfc1459 RPL_WHOISSERVER */
 
91
                {"314", false},  /* rfc1459 RPL_WHOWASUSER */
 
92
                {"369", true},  /* rfc1459 RPL_ENDOFWHOWAS */
 
93
                {"431", true},  /* rfc1459 ERR_NONICKNAMEGIVEN */
84
94
                {NULL, true}
85
95
        }},
86
96
        {"ISON", {
87
 
                {"303", true},
 
97
                {"303", true},  /* rfc1459 RPL_ISON */
 
98
                {"461", true},  /* rfc1459 ERR_NEEDMOREPARAMS */
88
99
                {NULL, true}
89
100
        }},
90
101
        {"LINKS", {
91
 
                {"364", false},
92
 
                {"365", true},
 
102
                {"364", false},  /* rfc1459 RPL_LINKS */
 
103
                {"365", true},  /* rfc1459 RPL_ENDOFLINKS */
 
104
                {"402", true},  /* rfc1459 ERR_NOSUCHSERVER */
93
105
                {NULL, true}
94
106
        }},
95
107
        {"MAP", {
100
112
                {"015", false},
101
113
                {"017", true},
102
114
                {"007", true},
 
115
                {"481", true},  /* rfc1459 ERR_NOPRIVILEGES */
103
116
                {NULL, true}
104
117
        }},
105
118
        {"TRACE", {
106
 
                {"200", false},
107
 
                {"205", false},
 
119
                {"200", false},  /* rfc1459 RPL_TRACELINK */
 
120
                {"201", false},  /* rfc1459 RPL_TRACECONNECTING */
 
121
                {"202", false},  /* rfc1459 RPL_TRACEHANDSHAKE */
 
122
                {"203", false},  /* rfc1459 RPL_TRACEUNKNOWN */
 
123
                {"204", false},  /* rfc1459 RPL_TRACEOPERATOR */
 
124
                {"205", false},  /* rfc1459 RPL_TRACEUSER */
 
125
                {"206", false},  /* rfc1459 RPL_TRACESERVER */
 
126
                {"208", false},  /* rfc1459 RPL_TRACENEWTYPE */
 
127
                {"261", false},  /* rfc1459 RPL_TRACELOG */
108
128
                {"262", true},
 
129
                {"402", true},  /* rfc1459 ERR_NOSUCHSERVER */
109
130
                {NULL, true}
110
131
        }},
111
132
        {"USERS", {
112
133
                {"265", false},
113
134
                {"266", true},
 
135
                {"392", false},  /* rfc1459 RPL_USERSSTART */
 
136
                {"393", false},  /* rfc1459 RPL_USERS */
 
137
                {"394", true},  /* rfc1459 RPL_ENDOFUSERS */
 
138
                {"395", false},  /* rfc1459 RPL_NOUSERS */
 
139
                {"402", true},  /* rfc1459 ERR_NOSUCHSERVER */
 
140
                {"424", true},  /* rfc1459 ERR_FILEERROR */
 
141
                {"446", true},  /* rfc1459 ERR_USERSDISABLED */
114
142
                {NULL, true},
115
143
        }},
116
144
        // This is just a list of all possible /mode replies stuffed together.
128
156
                // MODE e
129
157
                {"348", false},
130
158
                {"349", true},
 
159
                {"467", true},  /* rfc1459 ERR_KEYSET */
 
160
                {"472", true},  /* rfc1459 ERR_UNKNOWNMODE */
 
161
                {"501", true},  /* rfc1459 ERR_UMODEUNKNOWNFLAG */
 
162
                {"502", true},  /* rfc1459 ERR_USERSDONTMATCH */
131
163
                {NULL, true},
132
164
         }},
133
165
        // END (last item!)
159
191
        {
160
192
                m_pDoing = NULL;
161
193
                m_pReplies = NULL;
 
194
 
 
195
                AddHelpCommand();
 
196
                AddCommand("Silent", static_cast<CModCommand::ModCmdFunc>(&CRouteRepliesMod::SilentCommand),
 
197
                        "[yes|no]");
162
198
        }
163
199
 
164
200
        virtual ~CRouteRepliesMod() {
251
287
        {
252
288
                CString sCmd = sLine.Token(0).AsUpper();
253
289
 
254
 
                if (!m_pUser->GetIRCSock())
 
290
                if (!m_pNetwork->GetIRCSock())
255
291
                        return CONTINUE;
256
292
 
257
293
                if (sCmd.Equals("MODE")) {
308
344
        {
309
345
                // The timer will be deleted after this by the event loop
310
346
 
311
 
                if (GetNV("silent_timeouts") != "yes") {
 
347
                if (!GetNV("silent_timeouts").ToBool()) {
312
348
                        PutModule("This module hit a timeout which is possibly a bug.");
313
349
                        PutModule("To disable this message, do \"/msg " + GetModNick()
314
350
                                        + " silent yes\"");
337
373
 
338
374
                // 353 needs special treatment due to NAMESX and UHNAMES
339
375
                if (bIsRaw353)
340
 
                        GetUser()->GetIRCSock()->ForwardRaw353(sLine, m_pDoing);
 
376
                        m_pNetwork->GetIRCSock()->ForwardRaw353(sLine, m_pDoing);
341
377
                else
342
378
                        m_pDoing->PutClient(sLine);
343
379
 
389
425
                it->second.erase(it->second.begin());
390
426
        }
391
427
 
392
 
        virtual void OnModCommand(const CString& sCommand) {
393
 
                const CString sCmd = sCommand.Token(0);
394
 
                const CString sArgs = sCommand.Token(1, true);
 
428
        void SilentCommand(const CString& sLine) {
 
429
                const CString sValue = sLine.Token(1);
395
430
 
396
 
                if (sCmd.Equals("silent")) {
397
 
                        if (sArgs.Equals("yes")) {
398
 
                                SetNV("silent_timeouts", "yes");
399
 
                                PutModule("Disabled timeout messages");
400
 
                        } else if (sArgs.Equals("no")) {
401
 
                                DelNV("silent_timeouts");
402
 
                                PutModule("Enabled timeout messages");
403
 
                        } else if (sArgs.empty()) {
404
 
                                if (GetNV("silent_timeouts") == "yes")
405
 
                                        PutModule("Timeout messages are disabled");
406
 
                                else
407
 
                                        PutModule("Timeout message are enabled");
408
 
                        } else
409
 
                                PutModule("Invalid argument");
410
 
                } else {
411
 
                        PutModule("Available commands: silent [yes/no], silent");
 
431
                if (!sValue.empty()) {
 
432
                        SetNV("silent_timeouts", sValue);
412
433
                }
 
434
 
 
435
                CString sPrefix = GetNV("silent_timeouts").ToBool() ? "dis" : "en";
 
436
                PutModule("Timeout messages are " + sPrefix + "abled.");
413
437
        }
414
438
 
415
439
        CClient            *m_pDoing;
429
453
        Info.SetWikiPage("route_replies");
430
454
}
431
455
 
432
 
MODULEDEFS(CRouteRepliesMod, "Send replies (e.g. to /who) to the right client only")
 
456
NETWORKMODULEDEFS(CRouteRepliesMod, "Send replies (e.g. to /who) to the right client only")