]> jfr.im git - irc/evilnet/mod.chanfix.git/blob - LISTBLOCKEDCommand.cc
Fixed missing include, corebug fix was already applied here.
[irc/evilnet/mod.chanfix.git] / LISTBLOCKEDCommand.cc
1 /**
2 * LISTBLOCKEDCommand.cc
3 *
4 * 03/25/2006 - Jimmy Lipham <music0m@alltel.net>
5 * Initial Version
6 *
7 * Lists all blocked chans that chanfix has stored
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 * USA.
23 *
24 * $Id$
25 */
26
27 #include "gnuworld_config.h"
28 #include "Network.h"
29
30 #include "chanfix.h"
31 #include "responses.h"
32 #include "StringTokenizer.h"
33 #include "sqlChannel.h"
34 #include "sqlcfUser.h"
35
36 RCSTAG("$Id$");
37
38 namespace gnuworld
39 {
40 namespace cf
41 {
42 void LISTBLOCKEDCommand::Exec(iClient* theClient, sqlcfUser* theUser, const std::string& Message)
43 {
44
45 /* Check if channel blocking has been disabled in the config. */
46 if (!bot->doChanBlocking()) {
47 bot->SendTo(theClient,
48 bot->getResponse(theUser,
49 language::channel_blocking_disabled,
50 std::string("Channel blocking is disabled.")).c_str());
51 return;
52 }
53
54 /* List blocks */
55 dbHandle* cacheCon = bot->getLocalDBHandle();
56
57 std::stringstream theQuery;
58 theQuery << "SELECT channel FROM channels WHERE (flags & "
59 << sqlChannel::F_BLOCKED
60 << ") = "
61 << sqlChannel::F_BLOCKED
62 << " ORDER BY channel ASC";
63
64 if (!cacheCon->Exec(theQuery.str(),true)) {
65 elog << "chanfix::LISTBLOCKEDCommand> SQL Error: "
66 << cacheCon->ErrorMessage()
67 << std::endl;
68 return;
69 }
70
71 // SQL query returned no errors
72 unsigned int numBlocks = 0;
73 std::string strBlocks;
74 bot->SendTo(theClient,
75 bot->getResponse(theUser,
76 language::listblocks_blocked_chans,
77 std::string("List of all blocked channels:")).c_str());
78
79 for (unsigned int i = 0 ; i < cacheCon->Tuples(); i++) {
80 strBlocks += cacheCon->GetValue(i, 0);
81 strBlocks += " ";
82 if (strBlocks.size() >= 410) {
83 bot->SendTo(theClient, strBlocks.c_str());
84 strBlocks = "";
85 }
86 numBlocks++;
87 }
88
89 /* Dispose of our connection instance */
90 //bot->theManager->removeConnection(cacheCon);
91
92 if (strBlocks.size())
93 bot->SendTo(theClient, strBlocks.c_str());
94
95 bot->SendTo(theClient,
96 bot->getResponse(theUser,
97 language::listblocked_total_blocked,
98 std::string("%d channels blocked.")).c_str(),
99 numBlocks);
100
101 bot->logAdminMessage("%s (%s) LISTBLOCKED",
102 theUser->getUserName().c_str(),
103 theClient->getRealNickUserHost().c_str());
104
105 bot->logLastComMessage(theClient, Message);
106
107 return;
108 }
109 } // namespace cf
110 } // namespace gnuworld