-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathsqlChannel.cc
More file actions
659 lines (599 loc) · 23.5 KB
/
sqlChannel.cc
File metadata and controls
659 lines (599 loc) · 23.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
/**
* sqlChannel.cc
*
* Storage class for accessing user information either from the backend
* or internal storage.
*
* 20/12/2000: Greg Sikorski <gte@atomicrevs.demon.co.uk>
* Initial Version.
* 30/12/2000: Moved static SQL data to constants.h --Gte
* Set loadData up to take data from rows other than 0.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*
* $Id: sqlChannel.cc,v 1.43 2007/08/28 16:10:12 dan_karrels Exp $
*/
#include <sstream>
#include <string>
#include <iostream>
#include <cstring>
#include "ELog.h"
#include "misc.h"
#include "sqlChannel.h"
#include "constants.h"
#include "cservice.h"
#include "cservice_config.h"
#include "dbHandle.h"
namespace gnuworld {
using std::endl;
using std::ends;
using std::string;
using std::stringstream;
chanFloodType::chanFloodType() : last_time((time_t)(0)), msgCount(0), noticeCount(0), ctcpCount(0) {
repCount = 1;
}
chanFloodType::~chanFloodType() {}
const sqlChannel::flagType sqlChannel::F_NOPURGE = 0x00000001;
const sqlChannel::flagType sqlChannel::F_SPECIAL = 0x00000002;
const sqlChannel::flagType sqlChannel::F_NOREG = 0x00000004;
const sqlChannel::flagType sqlChannel::F_NEVREG = 0x00000008;
const sqlChannel::flagType sqlChannel::F_SUSPEND = 0x00000010;
const sqlChannel::flagType sqlChannel::F_TEMP = 0x00000020;
const sqlChannel::flagType sqlChannel::F_CAUTION = 0x00000040;
const sqlChannel::flagType sqlChannel::F_VACATION = 0x00000080;
const sqlChannel::flagType sqlChannel::F_LOCKED = 0x00000100;
const sqlChannel::flagType sqlChannel::F_FLOATLIM = 0x00000200;
const sqlChannel::flagType sqlChannel::F_MIA = 0x00000400;
const sqlChannel::flagType sqlChannel::F_JOINLIM = 0x00000800;
const sqlChannel::flagType sqlChannel::F_ALWAYSOP = 0x00010000;
const sqlChannel::flagType sqlChannel::F_STRICTOP = 0x00020000;
const sqlChannel::flagType sqlChannel::F_NOOP = 0x00040000;
const sqlChannel::flagType sqlChannel::F_AUTOTOPIC = 0x00080000;
const sqlChannel::flagType sqlChannel::F_OPONLY = 0x00100000; // Deprecated
const sqlChannel::flagType sqlChannel::F_AUTOJOIN = 0x00200000;
const sqlChannel::flagType sqlChannel::F_NOFORCE = 0x00400000; // Reserved for use by Planetarion.
const sqlChannel::flagType sqlChannel::F_NOVOICE = 0x00800000;
const sqlChannel::flagType sqlChannel::F_NOTAKE = 0x01000000;
const sqlChannel::flagType sqlChannel::F_FLOODPRO = 0x02000000;
const sqlChannel::flagType sqlChannel::F_FLOODPROGLINE = 0x04000000;
const sqlChannel::flagType sqlChannel::F_OPLOG = 0x08000000;
const int sqlChannel::EV_MISC = 1;
const int sqlChannel::EV_JOIN = 2;
const int sqlChannel::EV_PART = 3;
const int sqlChannel::EV_OPERJOIN = 4;
const int sqlChannel::EV_OPERPART = 5;
const int sqlChannel::EV_FORCE = 6;
const int sqlChannel::EV_REGISTER = 7;
const int sqlChannel::EV_PURGE = 8;
/* Manually added Comment */
const int sqlChannel::EV_COMMENT = 9;
const int sqlChannel::EV_REMOVEALL = 10;
const int sqlChannel::EV_IDLE = 11;
/* other events */
const int sqlChannel::EV_MGRCHANGE = 12;
const int sqlChannel::EV_ADMREJECT = 13;
const int sqlChannel::EV_WITHDRAW = 14;
const int sqlChannel::EV_NEWAPP = 15;
const int sqlChannel::EV_NONSUPPORT = 16;
const int sqlChannel::EV_ADMREVIEW = 17;
const int sqlChannel::EV_CLRREVIEW = 18;
const int sqlChannel::EV_SUSPEND = 19;
const int sqlChannel::EV_UNSUSPEND = 20;
sqlChannel::sqlChannel(cservice* _bot)
: id(0), name(), canon_name(), flags(0), mass_deop_pro(3), flood_pro(0), msg_period(0), notice_period(0),
ctcp_period(0), flood_period(0), repeat_count(0), floodlevel(FLOODPRO_KICK),
man_floodlevel(FLOODPRO_KICK), url(), description(), comment(), keywords(), welcome(),
registered_ts(0), channel_ts(0), channel_mode(), userflags(0), last_topic(0), inChan(false),
last_used(0), limit_offset(3), limit_period(20), last_limit_check(0), last_flood(0),
limit_grace(2), limit_max(0), limit_joinmax(0), limit_joinsecs(0), limit_joinmode(),
limit_joinperiod(0), limit_jointimerID(0), max_bans(0), no_take(0),
#ifdef THERETURN_ENABLED
hasw(false), w_ts(0),
#endif
logger(_bot->getLogger()), SQLDb(_bot->SQLDb) {
}
bool sqlChannel::loadData(const string& channelName) {
/*
* With the open database handle 'SQLDb', retrieve information about
* 'channelName' and fill our member variables.
*/
LOG(TRACE, "Attempting to load data for channel-name: {}", channelName);
stringstream queryString;
queryString << "SELECT " << sql::channel_fields;
#ifdef THERETURN_ENABLED
queryString << ",cw.status,cw.timestamp";
#endif
queryString << " FROM channels ";
#ifdef THERETURN_ENABLED
queryString << "LEFT JOIN channels_w cw on channels.id = cw.channel_id ";
#endif
queryString << "WHERE lower(channels.canon_name) = '" << escapeSQLChars(rfc1459_tolower(channelName))
<< "'";
if (SQLDb->Exec(queryString, true))
// if( PGRES_TUPLES_OK == status )
{
/*
* If the channel doesn't exist, we won't get any rows back.
*/
if (SQLDb->Tuples() < 1) {
return (false);
}
setAllMembers(0);
return (true);
}
return (false);
}
bool sqlChannel::loadData(int channelID) {
/*
* With the open database handle 'SQLDb', retrieve information about
* 'channelID' and fill our member variables.
*/
LOG_MSG(TRACE, "Attempting to load data for channel-id: {}", channelID);
stringstream queryString;
queryString << "SELECT " << sql::channel_fields;
#ifdef THERETURN_ENABLED
queryString << ",cw.status,cw.timestamp";
#endif
queryString << " FROM channels ";
#ifdef THERETURN_ENABLED
queryString << "LEFT JOIN channels_w cw on channels.id = cw.channel_id";
#endif
queryString << "WHERE channels.id = " << channelID;
if (SQLDb->Exec(queryString, true))
// if( PGRES_TUPLES_OK == status )
{
/*
* If the channel doesn't exist, we won't get any rows back.
*/
if (SQLDb->Tuples() < 1) {
return (false);
}
setAllMembers(0);
return (true);
}
return (false);
}
void sqlChannel::setAllMembers(int row) {
/*
* Support function for both loadData's.
* Assumes SQLDb contains a valid results set for all channel information.
*/
id = atoi(SQLDb->GetValue(row, 0).c_str());
name = SQLDb->GetValue(row, 1);
canon_name = SQLDb->GetValue(row, 2);
flags = atoi(SQLDb->GetValue(row, 3).c_str());
mass_deop_pro = atoi(SQLDb->GetValue(row, 4).c_str());
flood_pro = atoi(SQLDb->GetValue(row, 5).c_str());
url = SQLDb->GetValue(row, 6);
description = SQLDb->GetValue(row, 7);
comment = SQLDb->GetValue(row, 8);
keywords = SQLDb->GetValue(row, 9);
registered_ts = atoi(SQLDb->GetValue(row, 10).c_str());
channel_ts = atoi(SQLDb->GetValue(row, 11).c_str());
channel_mode = SQLDb->GetValue(row, 12);
userflags = atoi(SQLDb->GetValue(row, 13));
last_updated = atoi(SQLDb->GetValue(row, 14));
limit_offset = atoi(SQLDb->GetValue(row, 15));
limit_period = atoi(SQLDb->GetValue(row, 16));
limit_grace = atoi(SQLDb->GetValue(row, 17));
limit_max = atoi(SQLDb->GetValue(row, 18));
max_bans = atoi(SQLDb->GetValue(row, 19));
no_take = atoi(SQLDb->GetValue(row, 20));
welcome = SQLDb->GetValue(row, 21);
limit_joinmax = atoi(SQLDb->GetValue(row, 22));
limit_joinsecs = atoi(SQLDb->GetValue(row, 23));
limit_joinperiod = atoi(SQLDb->GetValue(row, 24));
limit_joinmode = SQLDb->GetValue(row, 25);
#ifdef THERETURN_ENABLED
hasw = atoi(SQLDb->GetValue(row, 26)); // This must always be the last column.
w_ts = atoi(SQLDb->GetValue(row, 27));
#endif
setAllFlood();
}
#ifdef THERETURN_ENABLED
bool sqlChannel::setW(const bool status) {
hasw = status;
stringstream queryString;
queryString << "INSERT INTO channels_w (channel_id,status,timestamp) VALUES (" << id << ","
<< status << ",date_part('epoch', CURRENT_TIMESTAMP)::int) "
<< "ON CONFLICT (channel_id) DO UPDATE SET status = " << status
<< ",timestamp=date_part('epoch', CURRENT_TIMESTAMP)::int "
<< "RETURNING timestamp";
if (!SQLDb->Exec(queryString)) {
LOGSQL_ERROR(SQLDb);
return false;
}
w_ts = atoi(SQLDb->GetValue(0, 0));
return true;
}
#endif // THERETURN_ENABLED
bool sqlChannel::commit() {
/*
* Build an SQL statement to commit the transient data in this storage class
* back into the database.
*/
static const char* queryHeader = "UPDATE channels ";
static const char* queryCondition = "WHERE id = ";
stringstream queryString;
queryString << queryHeader << "SET "
<< "canon_name = '" << escapeSQLChars(canon_name) << "', "
<< "flags = " << flags << ", "
<< "mass_deop_pro = " << mass_deop_pro << ", "
<< "flood_pro = " << flood_pro << ", "
<< "url = '" << escapeSQLChars(url) << "', "
<< "keywords = '" << escapeSQLChars(keywords) << "', "
<< "welcome = '" << escapeSQLChars(welcome) << "', "
<< "registered_ts = " << registered_ts << ", "
<< "channel_ts = " << channel_ts << ", "
<< "channel_mode = '" << escapeSQLChars(channel_mode) << "', "
<< "userflags = " << userflags << ", "
<< "last_updated = date_part('epoch', CURRENT_TIMESTAMP)::int, "
<< "limit_offset = " << limit_offset << ", "
<< "limit_period = " << limit_period << ", "
<< "limit_grace = " << limit_grace << ", "
<< "limit_max = " << limit_max << ", "
<< "max_bans = " << max_bans << ", "
<< "description = '" << escapeSQLChars(description) << "', "
<< "comment = '" << escapeSQLChars(comment) << "', "
<< "no_take = " << no_take << ", "
<< "limit_joinmax = " << limit_joinmax << ", "
<< "limit_joinsecs = " << limit_joinsecs << ", "
<< "limit_joinperiod = " << limit_joinperiod << ", "
<< "limit_joinmode = '" << escapeSQLChars(limit_joinmode) << "' " << queryCondition
<< id << ends;
if (!SQLDb->Exec(queryString)) {
LOGSQL_ERROR(SQLDb);
return false;
}
return true;
}
bool sqlChannel::insertRecord() {
static const char* queryHeader = "INSERT INTO channels (name, canon_name, flags, registered_ts, "
"channel_ts, channel_mode, last_updated, no_take) VALUES (";
stringstream queryString;
queryString << queryHeader << "'" << escapeSQLChars(name) << "', '" << escapeSQLChars(canon_name) << "', " << flags << ", "
<< registered_ts << ", " << channel_ts << ", '" << escapeSQLChars(channel_mode)
<< "', "
<< "date_part('epoch', CURRENT_TIMESTAMP)::int," << no_take << ")" << ends;
if (!SQLDb->Exec(queryString)) {
LOGSQL_ERROR(SQLDb);
return false;
}
return true;
}
void sqlChannel::setAllFlood() {
if (flood_pro == 0)
return;
unsigned int tmp = flood_pro;
div_t divresult;
divresult = div(tmp, 0x100);
msg_period = divresult.rem;
tmp = divresult.quot;
divresult = div(tmp, 0x10);
notice_period = divresult.rem;
tmp = divresult.quot;
divresult = div(tmp, 0x10);
ctcp_period = divresult.rem;
tmp = divresult.quot;
divresult = div(tmp, 0x10);
flood_period = divresult.rem;
tmp = divresult.quot;
divresult = div(tmp, 0x10);
repeat_count = divresult.rem;
}
void sqlChannel::setFloodMsg(const unsigned short& _floodMsg) {
msg_period = _floodMsg;
div_t divresult;
divresult = div(flood_pro, 0x100);
flood_pro = flood_pro - divresult.rem + _floodMsg;
}
void sqlChannel::setFloodNotice(const unsigned short& _floodNotice) {
notice_period = _floodNotice;
div_t div1, div2;
div1 = div(flood_pro, 0x100);
int tmp = div1.quot;
div2 = div(tmp, 0x10);
tmp = tmp - div2.rem + _floodNotice;
flood_pro = tmp * 0x100 + div1.rem;
}
void sqlChannel::setFloodCTCP(const unsigned short& _floodCTCP) {
ctcp_period = _floodCTCP;
div_t div1, div2;
div1 = div(flood_pro, 0x1000);
int tmp = div1.quot;
div2 = div(tmp, 0x10);
tmp = tmp - div2.rem + _floodCTCP;
flood_pro = tmp * 0x1000 + div1.rem;
}
void sqlChannel::setFloodPeriod(const unsigned short& _floodPrd) {
flood_period = _floodPrd;
div_t div1, div2;
div1 = div(flood_pro, 0x10000);
int tmp = div1.quot;
div2 = div(tmp, 0x10);
tmp = tmp - div2.rem + _floodPrd;
flood_pro = tmp * 0x10000 + div1.rem;
}
void sqlChannel::setRepeatCount(const unsigned short& _repCount) {
repeat_count = _repCount;
div_t div1, div2;
div1 = div(flood_pro, 0x100000);
int tmp = div1.quot;
div2 = div(tmp, 0x10);
tmp = tmp - div2.rem + _repCount;
flood_pro = tmp * 0x100000 + div1.rem;
}
void sqlChannel::setDefaultFloodproValues() {
setFloodMsg(15);
setFloodNotice(5);
setFloodCTCP(5);
setFloodPeriod(15);
setRepeatCount(5);
setFloodproLevel(sqlChannel::FLOODPRO_KICK);
setManualFloodproLevel(sqlChannel::FLOODPRO_KICK);
}
unsigned int sqlChannel::getTotalMessageCount(const string& Mask) {
chanFloodMapType::iterator itr = chanFloodMap.find(Mask);
chanFloodType* theChFlood = itr->second;
if (itr != chanFloodMap.end())
return theChFlood->getTotalMessageCount();
return 0;
}
unsigned int sqlChannel::getTotalNoticeCount(const string& Mask) {
chanFloodMapType::iterator itr = chanFloodMap.find(Mask);
chanFloodType* theChFlood = itr->second;
if (itr != chanFloodMap.end())
return theChFlood->getTotalNoticeCount();
return 0;
}
unsigned int sqlChannel::getTotalCTCPCount(const string& Mask) {
chanFloodMapType::iterator itr = chanFloodMap.find(Mask);
chanFloodType* theChFlood = itr->second;
if (itr != chanFloodMap.end())
return theChFlood->getTotalCTCPCount();
return 0;
}
string sqlChannel::getFloodLevelName(const FloodProLevel& floodLevel) {
if (floodLevel == FLOODPRO_NONE)
return "NONE";
if (floodLevel == FLOODPRO_KICK)
return "KICK";
if (floodLevel == FLOODPRO_BAN)
return "BAN";
if (floodLevel == FLOODPRO_GLINE)
return "GLINE";
return "NONE";
}
sqlChannel::repeatMaskMapType sqlChannel::getRepeatMessageCount(const string& Message,
string Mask) {
unsigned int sum = 0;
repeatMaskMapType res;
std::list<string> MaskList;
chanFloodMapType::iterator ptr = chanFloodMap.begin();
while (ptr != chanFloodMap.end()) {
bool incMask = false;
chanFloodType* currChanFloodMap = ptr->second;
// If a Mask is specified, means we want to count repetition referring to a single Mask
if ((!Mask.empty()) && (Mask != ptr->first)) {
ptr++;
continue;
}
if (currChanFloodMap->getLastMessage() == Message) {
sum += currChanFloodMap->repCount;
incMask = true;
}
if (incMask)
MaskList.push_back(ptr->first);
ptr++;
}
// if (MaskList.size() > 1) incFloodPro();
res = std::make_pair(sum, MaskList);
return res;
}
time_t sqlChannel::getMaskLastTime(const string& Mask) {
if (chanFloodMap.find(Mask) != chanFloodMap.end())
return chanFloodMap[Mask]->getLastTime();
return (time_t)(0);
}
// void sqlChannel::setMaskLastTime(const string& Mask)
//{
// if (chanFloodMap.find(Mask) != chanFloodMap.end())
// chanFloodMap[Mask]->setLastTime(now);
// }
void sqlChannel::RemoveFlooderMask(const string& Mask) {
if (chanFloodMap.find(Mask) != chanFloodMap.end()) {
// elog << "sqlChannel::RemoveFlooderMask> chanFloodMap.find(" << Mask << ") !=
// chanFloodMap.end() ERASING" << endl;
delete chanFloodMap[Mask];
chanFloodMap.erase(Mask);
}
}
void sqlChannel::handleNewMessage(const FloodType& floodtype, const string& Mask,
const string& Message) {
chanFloodType* chanFlooder;
chanFloodMapType::iterator itr = chanFloodMap.find(Mask);
if (itr == chanFloodMap.end()) {
chanFlooder = new (std::nothrow) chanFloodType();
assert(chanFlooder != 0);
chanFlooder->setLastTime(now);
chanFlooder->setLastMessage(Message);
chanFlooder->repCount = 1;
if (floodtype == FLOOD_MSG) {
chanFlooder->messageFloodMap[Message].first = now;
chanFlooder->messageFloodMap[Message].second = 1;
}
if (floodtype == FLOOD_NOTICE) {
chanFlooder->noticeFloodMap[Message].first = now;
chanFlooder->noticeFloodMap[Message].second = 1;
}
if (floodtype == FLOOD_CTCP) {
chanFlooder->ctcpFloodMap[Message].first = now;
chanFlooder->ctcpFloodMap[Message].second = 1;
}
chanFloodMap.insert(std::make_pair(Mask, chanFlooder));
} else {
// If expired ...
chanFlooder = itr->second;
if ((now - chanFlooder->getLastTime()) > (time_t)flood_period) {
chanFlooder->messageFloodMap.clear();
chanFlooder->noticeFloodMap.clear();
chanFlooder->ctcpFloodMap.clear();
chanFlooder->messageFloodMap[Message].second = 0;
chanFlooder->noticeFloodMap[Message].second = 0;
chanFlooder->ctcpFloodMap[Message].second = 0;
chanFlooder->repCount = 0;
}
floodMessageType currMessageMap;
if (floodtype == FLOOD_MSG) {
currMessageMap = chanFlooder->messageFloodMap;
if (currMessageMap.find(Message) != currMessageMap.end()) {
chanFlooder->messageFloodMap[Message].second++;
if (chanFlooder->getLastMessage() == Message)
chanFlooder->repCount++;
else
chanFlooder->repCount = 1;
} else {
chanFlooder->messageFloodMap[Message].second = 1;
chanFlooder->repCount = 1;
}
chanFlooder->messageFloodMap[Message].first = now;
}
if (floodtype == FLOOD_NOTICE) {
currMessageMap = chanFlooder->noticeFloodMap;
if (currMessageMap.find(Message) != currMessageMap.end()) {
chanFlooder->noticeFloodMap[Message].second++;
if (chanFlooder->getLastMessage() == Message)
chanFlooder->repCount++;
else
chanFlooder->repCount = 1;
} else {
chanFlooder->noticeFloodMap[Message].second = 1;
chanFlooder->repCount = 1;
}
chanFlooder->noticeFloodMap[Message].first = now;
}
if (floodtype == FLOOD_CTCP) {
currMessageMap = chanFlooder->ctcpFloodMap;
if (currMessageMap.find(Message) != currMessageMap.end()) {
chanFlooder->ctcpFloodMap[Message].second++;
if (chanFlooder->getLastMessage() == Message)
chanFlooder->repCount++;
else
chanFlooder->repCount = 1;
} else {
chanFlooder->ctcpFloodMap[Message].second = 1;
chanFlooder->repCount = 1;
}
chanFlooder->ctcpFloodMap[Message].first = now;
}
chanFlooder->setLastTime(now);
chanFlooder->setLastMessage(Message);
}
if (floodtype == FLOOD_MSG)
calcTotalMessageCount(Mask);
if (floodtype == FLOOD_NOTICE)
calcTotalNoticeCount(Mask);
if (floodtype == FLOOD_CTCP)
calcTotalCTCPCount(Mask);
}
void sqlChannel::calcTotalMessageCount(const string& Mask) {
sqlChannel::chanFloodMapType::iterator ptr = chanFloodMap.find(Mask);
if (ptr != chanFloodMap.end()) {
unsigned int sum = 0;
chanFloodType* currChanFloodMap = ptr->second;
if ((now - currChanFloodMap->getLastTime()) > (time_t)flood_period) {
RemoveFlooderMask(Mask);
return;
}
floodMessageType currMessageMap = currChanFloodMap->messageFloodMap;
floodMessageType::iterator ptr2 = currMessageMap.begin();
while (ptr2 != currMessageMap.end()) {
if ((now - ptr2->second.first) > (time_t)flood_period)
currMessageMap.erase(ptr2++);
else {
sum += ptr2->second.second;
ptr2++;
}
}
currChanFloodMap->setTotalMessageCount(sum);
}
}
void sqlChannel::calcTotalNoticeCount(const string& Mask) {
sqlChannel::chanFloodMapType::iterator ptr = chanFloodMap.find(Mask);
if (ptr != chanFloodMap.end()) {
unsigned int sum = 0;
chanFloodType* currChanFloodMap = ptr->second;
if ((now - currChanFloodMap->getLastTime()) > (time_t)flood_period) {
RemoveFlooderMask(Mask);
return;
}
floodMessageType currMessageMap = currChanFloodMap->noticeFloodMap;
floodMessageType::iterator ptr2 = currMessageMap.begin();
while (ptr2 != currMessageMap.end()) {
if ((now - ptr2->second.first) > (time_t)flood_period)
currMessageMap.erase(ptr2++);
else {
sum += ptr2->second.second;
ptr2++;
}
}
currChanFloodMap->setTotalNoticeCount(sum);
}
}
void sqlChannel::calcTotalCTCPCount(const string& Mask) {
sqlChannel::chanFloodMapType::iterator ptr = chanFloodMap.find(Mask);
if (ptr != chanFloodMap.end()) {
unsigned int sum = 0;
chanFloodType* currChanFloodMap = ptr->second;
if ((now - currChanFloodMap->getLastTime()) > (time_t)flood_period) {
RemoveFlooderMask(Mask);
return;
}
floodMessageType currMessageMap = currChanFloodMap->ctcpFloodMap;
floodMessageType::iterator ptr2 = currMessageMap.begin();
while (ptr2 != currMessageMap.end()) {
if ((now - ptr2->second.first) > (time_t)flood_period)
currMessageMap.erase(ptr2++);
else {
sum += ptr2->second.second;
ptr2++;
}
}
currChanFloodMap->setTotalCTCPCount(sum);
}
}
void sqlChannel::ExpireMessagesForChannel(sqlChannel* theChan) {
sqlChannel::chanFloodMapType::iterator itr = theChan->chanFloodMap.begin();
while (itr != theChan->chanFloodMap.end()) {
time_t iplasttime = theChan->getMaskLastTime(itr->first);
if (!iplasttime) {
++itr;
continue;
}
// theChan->ExpireMessagesForMask(itr->first, currentTime());
time_t lastTime = now - iplasttime;
if ((lastTime) > (time_t)theChan->getFloodPeriod()) {
theChan->RemoveFlooderMask(itr++->first);
} else
++itr;
}
return;
}
sqlChannel::~sqlChannel() {
/* TODO: Clean up bans */
chanFloodMap.clear();
}
} // Namespace gnuworld