]>
Commit | Line | Data |
---|---|---|
e40ccdcc C |
1 | /** |
2 | * OPLISTCommand.cc | |
3 | * | |
9afcd235 | 4 | * 07/21/2005 - Jimmy Lipham <music0m@alltel.net> |
e40ccdcc C |
5 | * Initial Version |
6 | * | |
9afcd235 | 7 | * Shows a list of accounts plus their score of the top ops of this channel |
e40ccdcc C |
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 | ||
e40ccdcc C |
27 | #include "gnuworld_config.h" |
28 | #include "Network.h" | |
29 | ||
30 | #include "chanfix.h" | |
91cad274 | 31 | #include "responses.h" |
e40ccdcc C |
32 | #include "StringTokenizer.h" |
33 | #include "sqlChannel.h" | |
34 | #include "sqlChanOp.h" | |
35 | ||
36 | RCSTAG("$Id$"); | |
37 | ||
38 | namespace gnuworld | |
39 | { | |
1d54d2a1 | 40 | namespace cf |
41 | { | |
e40ccdcc | 42 | |
13a50edb | 43 | void OPLISTCommand::Exec(iClient* theClient, sqlcfUser* theUser, const std::string& Message) |
e40ccdcc C |
44 | { |
45 | StringTokenizer st(Message); | |
e40ccdcc | 46 | |
20c3e550 | 47 | bool all = false; |
3d7c4fa0 | 48 | bool days = false; |
1d8ad9a6 | 49 | |
50 | unsigned int pos = 2; | |
3d7c4fa0 | 51 | while (pos < st.size()) { |
1d8ad9a6 | 52 | if (!strcasecmp(st[pos],"-all")) |
53 | all = true; | |
54 | ||
55 | if (!strcasecmp(st[pos],"all")) | |
20c3e550 | 56 | all = true; |
1d8ad9a6 | 57 | |
58 | if (!strcasecmp(st[pos],"!")) | |
59 | all = true; | |
60 | ||
3d7c4fa0 | 61 | if (!strcasecmp(st[pos],"-days")) |
62 | days = true; | |
1d8ad9a6 | 63 | |
64 | pos++; | |
20c3e550 | 65 | } |
66 | ||
7b4033d3 | 67 | chanfix::chanOpsType myOps = bot->getMyOps(st[1]); |
e40ccdcc | 68 | if (myOps.empty()) { |
91cad274 | 69 | bot->SendTo(theClient, |
70 | bot->getResponse(theUser, | |
71 | language::no_scores_for_chan, | |
72 | std::string("There are no scores in the database for %s.")).c_str(), | |
7b4033d3 | 73 | st[1].c_str()); |
3d7e9543 | 74 | |
75 | sqlChannel* theChan = bot->getChannelRecord(st[1]); | |
76 | if (theChan) { | |
23cb8771 | 77 | bot->SendTo(theClient, "Notes: %d", theChan->countNotes(bot->getLocalDBHandle(),0)); |
3d7e9543 | 78 | |
79 | if (bot->isTempBlocked(theChan->getChannel())) | |
80 | bot->SendTo(theClient, | |
81 | bot->getResponse(theUser, | |
82 | language::info_chan_temp_blocked, | |
83 | std::string("%s is TEMPBLOCKED.")).c_str(), | |
84 | theChan->getChannel().c_str()); | |
85 | else if (theChan->getFlag(sqlChannel::F_BLOCKED)) | |
86 | bot->SendTo(theClient, | |
87 | bot->getResponse(theUser, | |
88 | language::info_chan_blocked, | |
89 | std::string("%s is BLOCKED.")).c_str(), | |
90 | theChan->getChannel().c_str()); | |
91 | else if (theChan->getFlag(sqlChannel::F_ALERT)) | |
92 | bot->SendTo(theClient, | |
93 | bot->getResponse(theUser, | |
94 | language::info_chan_alerted, | |
95 | std::string("%s is ALERTED.")).c_str(), | |
96 | theChan->getChannel().c_str()); | |
97 | } | |
e40ccdcc C |
98 | return; |
99 | } | |
100 | ||
20c3e550 | 101 | unsigned int oCnt = myOps.size(); |
e40ccdcc | 102 | |
20c3e550 | 103 | /** |
104 | * Technically, if there are all 0 scores, it will get to this point. | |
105 | * We don't want a notice saying 0 accounts. | |
106 | */ | |
e40ccdcc | 107 | if (oCnt == 0) { |
91cad274 | 108 | bot->SendTo(theClient, |
109 | bot->getResponse(theUser, | |
110 | language::no_scores_for_chan, | |
111 | std::string("There are no scores in the database for %s.")).c_str(), | |
7b4033d3 | 112 | st[1].c_str()); |
3d7e9543 | 113 | |
114 | sqlChannel* theChan = bot->getChannelRecord(st[1]); | |
115 | if (theChan) { | |
23cb8771 | 116 | bot->SendTo(theClient, "Notes: %d", theChan->countNotes(bot->getLocalDBHandle(),0)); |
3d7e9543 | 117 | |
118 | if (bot->isTempBlocked(theChan->getChannel())) | |
119 | bot->SendTo(theClient, | |
120 | bot->getResponse(theUser, | |
121 | language::info_chan_temp_blocked, | |
122 | std::string("%s is TEMPBLOCKED.")).c_str(), | |
123 | theChan->getChannel().c_str()); | |
124 | else if (theChan->getFlag(sqlChannel::F_BLOCKED)) | |
125 | bot->SendTo(theClient, | |
126 | bot->getResponse(theUser, | |
127 | language::info_chan_blocked, | |
128 | std::string("%s is BLOCKED.")).c_str(), | |
129 | theChan->getChannel().c_str()); | |
130 | else if (theChan->getFlag(sqlChannel::F_ALERT)) | |
131 | bot->SendTo(theClient, | |
132 | bot->getResponse(theUser, | |
133 | language::info_chan_alerted, | |
134 | std::string("%s is ALERTED.")).c_str(), | |
135 | theChan->getChannel().c_str()); | |
136 | } | |
e40ccdcc C |
137 | return; |
138 | } | |
139 | ||
20c3e550 | 140 | if (oCnt > OPCOUNT && !all) |
91cad274 | 141 | bot->SendTo(theClient, |
142 | bot->getResponse(theUser, | |
143 | language::top_unique_op_accounts, | |
144 | std::string("Top %d unique op accounts in channel %s:")).c_str(), | |
7b4033d3 | 145 | OPCOUNT, st[1].c_str()); |
9afcd235 | 146 | else |
91cad274 | 147 | bot->SendTo(theClient, |
148 | bot->getResponse(theUser, | |
149 | language::found_unique_op_accounts, | |
150 | std::string("Found %d unique op accounts in channel %s:")).c_str(), | |
7b4033d3 | 151 | oCnt, st[1].c_str()); |
91cad274 | 152 | |
153 | bot->SendTo(theClient, | |
154 | bot->getResponse(theUser, | |
155 | language::rank_score_acc_header, | |
1d8ad9a6 | 156 | std::string("Rank Score Account -- Time first opped / Time last opped / Nick")).c_str()); |
92b0a9b9 | 157 | |
3d7c4fa0 | 158 | sqlChanOp* curOp = 0; |
e40ccdcc | 159 | unsigned int opCount = 0; |
3d7c4fa0 | 160 | unsigned int percent = 0; |
161 | int cScore; | |
7a601551 | 162 | bool inChan = false; |
92b0a9b9 | 163 | std::string firstop; |
164 | std::string lastop; | |
3d7c4fa0 | 165 | std::string nickName; |
166 | std::stringstream dayString; | |
9afcd235 | 167 | for (chanfix::chanOpsType::iterator opPtr = myOps.begin(); |
20c3e550 | 168 | opPtr != myOps.end() && (all || opCount < OPCOUNT); opPtr++) { |
e40ccdcc | 169 | curOp = *opPtr; |
20c3e550 | 170 | opCount++; |
171 | firstop = bot->tsToDateTime(curOp->getTimeFirstOpped(), false); | |
172 | lastop = bot->tsToDateTime(curOp->getTimeLastOpped(), true); | |
7a601551 | 173 | inChan = bot->accountIsOnChan(st[1], curOp->getAccount()); |
fec4bf6d | 174 | if (inChan) |
1dd02282 | 175 | nickName = bot->getChanNickName(st[1], curOp->getAccount()); |
1d8ad9a6 | 176 | |
3d7c4fa0 | 177 | if (days) { |
178 | dayString.str(""); | |
179 | ||
180 | for (int i = 1; i <= DAYSAMPLES; i++) { | |
181 | cScore = curOp->getDay((currentDay + i) % DAYSAMPLES); | |
182 | percent = static_cast<unsigned int>(((static_cast<float>(cScore) / static_cast<float>(86400 / POINTS_UPDATE_TIME)) * 100) + 0.5); | |
183 | ||
184 | if (!cScore) | |
185 | dayString << "."; // no score (.) | |
186 | else if (percent <= 10) | |
187 | dayString << "0"; // 0%-10% (0) | |
188 | else if ((percent >= 11) && (percent <= 20)) | |
189 | dayString << "1"; // 11%-20% (1) | |
190 | else if ((percent >= 21) && (percent <= 30)) | |
191 | dayString << "2"; // 21%-30% (2) | |
192 | else if ((percent >= 31) && (percent <= 40)) | |
193 | dayString << "3"; // 31%-40% (3) | |
194 | else if ((percent >= 41) && (percent <= 50)) | |
195 | dayString << "4"; // 41%-50% (4) | |
196 | else if ((percent >= 51) && (percent <= 60)) | |
197 | dayString << "5"; // 51%-60% (5) | |
198 | else if ((percent >= 61) && (percent <= 70)) | |
199 | dayString << "6"; // 61%-70% (6) | |
200 | else if ((percent >= 71) && (percent <= 80)) | |
201 | dayString << "7"; // 71%-80% (7) | |
202 | else if ((percent >= 81) && (percent <= 90)) | |
203 | dayString << "8"; // 81%-90% (8) | |
204 | else if ((percent >= 91)) | |
205 | dayString << "9"; // 91%-100% (9) | |
1d8ad9a6 | 206 | } |
3d7c4fa0 | 207 | dayString << std::ends; |
1d8ad9a6 | 208 | } |
209 | ||
3d7c4fa0 | 210 | bot->SendTo(theClient, "%3d. %4d %s -- %s / %s%s%s%s%s%s", |
211 | opCount, curOp->getPoints(), | |
7a601551 | 212 | curOp->getAccount().c_str(), firstop.c_str(), |
87fb1731 | 213 | lastop.c_str(), inChan ? " / " : "", |
3d7c4fa0 | 214 | inChan ? nickName.c_str() : "", |
215 | (days) ? " [" : "", | |
216 | (days) ? dayString.str().c_str() : "", | |
217 | (days) ? "]" : ""); | |
e40ccdcc C |
218 | } |
219 | ||
7c7edab6 | 220 | sqlChannel* theChan = bot->getChannelRecord(st[1]); |
221 | if (theChan) { | |
23cb8771 | 222 | bot->SendTo(theClient, "Notes: %d", theChan->countNotes(bot->getLocalDBHandle(), 0)); |
f5b9e7e0 | 223 | |
224 | if (bot->isTempBlocked(theChan->getChannel())) | |
225 | bot->SendTo(theClient, | |
226 | bot->getResponse(theUser, | |
227 | language::info_chan_temp_blocked, | |
228 | std::string("%s is TEMPBLOCKED.")).c_str(), | |
229 | theChan->getChannel().c_str()); | |
230 | else if (theChan->getFlag(sqlChannel::F_BLOCKED)) | |
7c7edab6 | 231 | bot->SendTo(theClient, |
232 | bot->getResponse(theUser, | |
233 | language::info_chan_blocked, | |
234 | std::string("%s is BLOCKED.")).c_str(), | |
235 | theChan->getChannel().c_str()); | |
236 | else if (theChan->getFlag(sqlChannel::F_ALERT)) | |
237 | bot->SendTo(theClient, | |
238 | bot->getResponse(theUser, | |
239 | language::info_chan_alerted, | |
240 | std::string("%s is ALERTED.")).c_str(), | |
241 | theChan->getChannel().c_str()); | |
242 | } | |
243 | ||
972e228a | 244 | bot->SendTo(theClient, |
245 | bot->getResponse(theUser, | |
246 | language::end_of_oplist, | |
247 | std::string("End of OPLIST for %s")).c_str(), | |
248 | st[1].c_str()); | |
249 | ||
8de4dcba | 250 | bot->logAdminMessage("%s (%s) OPLIST %s %s", |
87fb1731 | 251 | theUser ? theUser->getUserName().c_str() : "!NOT-LOGGED-IN!", |
252 | theClient->getRealNickUserHost().c_str(), | |
3d7c4fa0 | 253 | st[1].c_str(), |
254 | (st.size() > 2) ? st.assemble(2).c_str() : ""); | |
8de4dcba | 255 | |
25f00d30 | 256 | bot->logLastComMessage(theClient, Message); |
257 | ||
e40ccdcc C |
258 | return; |
259 | } | |
260 | ||
1d54d2a1 | 261 | } //namespace cf |
1d54d2a1 | 262 | } //namespace gnuworld |