-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiplist.cpp
110 lines (96 loc) · 1.75 KB
/
iplist.cpp
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
#include "iplist.h"
#include <iostream>
#include <fstream>
#include <cstdlib>
#define TRY_LIMIT 3
iplist::iplist()
{
//ctor
}
void iplist::read()
{
clear();
int pos;
string line, name;
time_t mytime;
ifstream handle;
handle.open(".badguys", ios::in);
while (handle.good())
{
getline (handle,line);
pos=line.find(":",0);
name=line.substr(0,pos);
line =line.substr(pos+1);
mytime=atoi(line.c_str());
}
}
void iplist::clear()
{
badguys.clear();
}
void iplist::add(string arg)
{
badguys.push_back(badguy(arg));
}
void iplist::debug_msg()
{
list<badguy>::iterator it;
it=badguys.begin();
while(it!=badguys.end())
{
cout<<"Element name: "<<(*it).get_name()<<endl;
cout <<"Element time "<<(*it).get_time()<<endl;
it++;
}
}
void iplist::refresh()
{
time_t mytime;
time(&mytime);
while(badguys.front().get_time()<mytime && badguys.begin()!=badguys.end())badguys.pop_front();
}
int iplist::check(string arg)
{
//if(badguys.empty()==0)return 0;
string h;
int count=0;
time_t mytime;
time(&mytime);
list<badguy>::iterator it;
it=badguys.begin();
while((*it).get_time()<mytime && it!=badguys.end())
{
it++;
}
while(it!=badguys.end())
{
if(!arg.compare((*it).get_name()))
{
count++;
if(count==TRY_LIMIT)
{
return 1;
}
}
it++;
}
return 0;
}
void clear();
void iplist::save()
{
ofstream handle;
list<badguy>::iterator it;
handle.open(".badguys",ios::out);
it=badguys.begin();
while(it!=badguys.end())
{
handle<<(*it).get_name()<<":"<<(*it).get_time()<<endl;
it++;
}
handle.close();
}
iplist::~iplist()
{
//dtor
}