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
|
#include "module.h"
struct NickAliasFlagInfo
{
std::string Name;
NickNameFlag Flag;
};
NickAliasFlagInfo NickAliasFlags[] = {
{"FORBIDDEN", NS_FORBIDDEN},
{"NOEXPIRE", NS_NO_EXPIRE},
{"", static_cast<NickNameFlag>(-1)}
};
struct NickCoreFlagInfo
{
std::string Name;
NickCoreFlag Flag;
};
NickCoreFlagInfo NickCoreFlags[] = {
{"KILLPROTECT", NI_KILLPROTECT},
{"SECURE", NI_SECURE},
{"MSG", NI_MSG},
{"MEMO_HARDMAX", NI_MEMO_HARDMAX},
{"MEMO_SIGNON", NI_MEMO_SIGNON},
{"MEMO_RECEIVE", NI_MEMO_RECEIVE},
{"PRIVATE", NI_PRIVATE},
{"HIDE_EMAIL", NI_HIDE_EMAIL},
{"HIDE_MASK", NI_HIDE_MASK},
{"HIDE_QUIT", NI_HIDE_QUIT},
{"KILL_QUICK", NI_KILL_QUICK},
{"KILL_IMMED", NI_KILL_IMMED},
{"MEMO_MAIL", NI_MEMO_MAIL},
{"HIDE_STATUS", NI_HIDE_STATUS},
{"SUSPENDED", NI_SUSPENDED},
{"AUTOOP", NI_AUTOOP},
{"FORBIDDEN", NI_FORBIDDEN},
{"", static_cast<NickCoreFlag>(-1)}
};
struct BotFlagInfo
{
std::string Name;
BotServFlag Flag;
};
BotFlagInfo BotFlags[] = {
{"DONTKICKOPS", BS_DONTKICKOPS},
{"DONTKICKVOICES", BS_DONTKICKVOICES},
{"FANTASY", BS_FANTASY},
{"SYMBIOSIS", BS_SYMBIOSIS},
{"GREET", BS_GREET},
{"NOBOT", BS_NOBOT},
{"KICK_BOLDS", BS_KICK_BOLDS},
{"KICK_COLORS", BS_KICK_COLORS},
{"KICK_REVERSES", BS_KICK_REVERSES},
{"KICK_UNDERLINES", BS_KICK_UNDERLINES},
{"KICK_BADWORDS", BS_KICK_BADWORDS},
{"KICK_CAPS", BS_KICK_CAPS},
{"KICK_FLOOD", BS_KICK_FLOOD},
{"KICK_REPEAT", BS_KICK_REPEAT},
{"", static_cast<BotServFlag>(-1)}
};
struct ChannelFlagInfo
{
std::string Name;
ChannelInfoFlag Flag;
};
ChannelFlagInfo ChannelFlags[] = {
{"KEEPTOPIC", CI_KEEPTOPIC},
{"SECUREOPS", CI_SECUREOPS},
{"PRIVATE", CI_PRIVATE},
{"TOPICLOCK", CI_TOPICLOCK},
{"RESTRICTED", CI_RESTRICTED},
{"PEACE", CI_PEACE},
{"SECURE", CI_SECURE},
{"FORBIDDEN", CI_FORBIDDEN},
{"NO_EXPIRE", CI_NO_EXPIRE},
{"MEMO_HARDMAX", CI_MEMO_HARDMAX},
{"OPNOTICE", CI_OPNOTICE},
{"SECUREFOUNDER", CI_SECUREFOUNDER},
{"SIGNKICK", CI_SIGNKICK},
{"SIGNKICK_LEVEL", CI_SIGNKICK_LEVEL},
{"XOP", CI_XOP},
{"SUSPENDED", CI_SUSPENDED},
{"PERSIST", CI_PERSIST},
{"", static_cast<ChannelInfoFlag>(-1)}
};
struct BotServFlagInfo
{
std::string Name;
BotFlag Flag;
};
BotServFlagInfo BotServFlags[] = {
{"PRIVATE", BI_PRIVATE},
{"", static_cast<BotFlag>(-1)}
};
struct MemoFlagInfo
{
std::string Name;
MemoFlag Flag;
};
MemoFlagInfo MemoFlags[] = {
{"UNREAD", MF_UNREAD},
{"RECEIPT", MF_RECEIPT},
{"NOTIFYS", MF_NOTIFYS},
{"", static_cast<MemoFlag>(-1)}
};
#define MYSQLPP_MYSQL_HEADERS_BURIED
#include <mysql++/mysql++.h>
inline std::string SQLAssign(const mysqlpp::String& s) { return s.c_str(); }
class DBMySQL;
static DBMySQL *me;
bool ExecuteQuery(mysqlpp::Query& query)
{
Alog(LOG_DEBUG) << "MySQL: " << query.str();
if (!query.execute())
{
Alog() << "MySQL: error executing query: " << query.error();
return false;
}
return true;
}
mysqlpp::StoreQueryResult StoreQuery(mysqlpp::Query& query)
{
Alog(LOG_DEBUG) << "MySQL: " << query.str();
mysqlpp::StoreQueryResult result = query.store();
if (!result)
{
Alog() << "MySQL: error executing query: " << query.error();
}
return result;
}
class DBMySQL : public Module
{
private:
bool LoadConfig()
{
ConfigReader config;
Database = config.ReadValue("mysql", "database", "anope", 0);
Server = config.ReadValue("mysql", "server", "127.0.0.1", 0);
SQLUser = config.ReadValue("mysql", "username", "anope", 0);
Password = config.ReadValue("mysql", "password", "", 0);
Port = config.ReadInteger("mysql", "port", "3306", 0, true);
Delay = config.ReadInteger("mysql", "updatedelay", "60", 0, true);
return !Password.empty();
}
public:
mysqlpp::Connection *Con;
mysqlpp::NoExceptions *Ne;
std::string Database;
std::string Server;
std::string SQLUser;
std::string Password;
unsigned int Port;
unsigned int Delay;
DBMySQL(const std::string &modname, const std::string &creator) : Module(modname, creator)
{
me = this;
this->SetAuthor("Anope");
this->SetVersion(VERSION_STRING);
this->SetType(DATABASE);
if (!LoadConfig())
throw ModuleException("Couldn't load config");
Con = new mysqlpp::Connection(false);
Ne = new mysqlpp::NoExceptions(Con);
if (!Con->connect(Database.c_str(), Server.c_str(), SQLUser.c_str(), Password.c_str(), Port))
{
std::string Error = "MySQL: Error connecting to SQL server: ";
Error += Con->error();
delete Con;
throw ModuleException(Error.c_str());
}
mysqlpp::Query query(Con);
query << "SET NAMES 'utf8'";
ExecuteQuery(query);
}
virtual ~DBMySQL()
{
delete Ne;
delete Con;
}
};
|