-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlacklist.cpp
139 lines (119 loc) · 3.47 KB
/
Blacklist.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
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
#include "main.h"
BOOL Blacklist::AddToList(char *name, BOOL output)
{
char *blockReport, *insert;
DWORD edx = 0;
if(!name)
{
return FALSE;
}
if(WaitForSingleObject(blacklistMutex, INFINITE) != WAIT_OBJECT_0)
{
return FALSE;
}
if(!list.empty())
{
for(vector<string>::iterator i = list.begin(); i!= list.end(); ++i)
{
if(i->compare(name) == 0)
{
asm("movl %0, %%edx;" : :"r"(edx):"edx");
blockReport = new char[(strlen(name) + 40)];
sprintf(blockReport, "%s's messages are already blocked", name);
CTListBoxAppendText((EmptyClass*)InfoBoxPtr, edx, blockReport, 0xFFFF0000, (char)1);
delete[] blockReport;
ReleaseMutex(blacklistMutex);
return FALSE;
}
}
}
list.push_back(name);
insert = new char[(strlen(name) + 40)];
sprintf(insert, "INSERT INTO Blacklist VALUES('%s')", name);
sqlite3_exec(database, insert, 0,0,0);
delete[] insert;
if(output)
{
asm("movl %0, %%edx;" : :"r"(edx):"edx");
blockReport = new char[(strlen(name) + 35)];
sprintf(blockReport, "%s's messages have been blocked", name);
CTListBoxAppendText((EmptyClass*)InfoBoxPtr, edx, blockReport, 0xFFFF0000, (char)1);
delete[] blockReport;
}
ReleaseMutex(blacklistMutex);
return TRUE;
}
BOOL Blacklist::CheckList(char *name)
{
if(WaitForSingleObject(blacklistMutex, INFINITE) != WAIT_OBJECT_0)
{
return FALSE;
}
if(name && (list.empty() == FALSE))
{
for(vector<string>::iterator i = list.begin(); i!= list.end(); ++i)
{
if(i->compare(name) == 0)
{
ReleaseMutex(blacklistMutex);
return TRUE;
}
}
}
ReleaseMutex(blacklistMutex);
return FALSE;
}
BOOL Blacklist::RemoveFromList(char *name)
{
char *blockReport;
DWORD edx = 0;
if(WaitForSingleObject(blacklistMutex, INFINITE) != WAIT_OBJECT_0)
{
return FALSE;
}
if(list.empty())
{
ReleaseMutex(blacklistMutex);
return FALSE;
}
for(vector<string>::iterator i = list.begin(); i!= list.end(); ++i)
{
if(i->compare(name) == 0)
{
list.erase(i);
asm("movl %0, %%edx;" : :"r"(edx):"edx");
blockReport = new char[(strlen(name) + 35)];
sprintf(blockReport, "%s's messages are no longer blocked", name);
CTListBoxAppendText((EmptyClass*)InfoBoxPtr, edx, blockReport, 0xFFFF0000, (char)1);
delete[] blockReport;
ReleaseMutex(blacklistMutex);
return TRUE;
}
}
ReleaseMutex(blacklistMutex);
return FALSE;
}
void Blacklist::OutputList()
{
char *blockedMsg;
DWORD edx = 0;
if(WaitForSingleObject(blacklistMutex, INFINITE) != WAIT_OBJECT_0)
{
return ;
}
if(list.empty())
{
ReleaseMutex(blacklistMutex);
return;
}
for(vector<string>::iterator i = list.begin(); i!= list.end(); ++i)
{
asm("movl %0, %%edx;" : :"r"(edx):"edx");
blockedMsg = new char[i->size() + 30];
sprintf(blockedMsg, "%s's messages have been blocked", (char*)i->c_str());
CTListBoxAppendText((EmptyClass*)InfoBoxPtr, edx, blockedMsg, 0xFFFF0000, (char)1);
delete[] blockedMsg;
}
ReleaseMutex(blacklistMutex);
return;
}