diff options
author | George Hazan <ghazan@miranda.im> | 2017-12-10 00:39:55 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-12-10 00:39:55 +0300 |
commit | 90674ba62902b7aaeceeb4c326469a74a32a259d (patch) | |
tree | f7f6889e14bd882da1c4f477ccb9555db43744fa /plugins/StopSpamPlus/src/settings.h | |
parent | 002c6191a3cda8db182f2ca26bb182d3274ab960 (diff) |
StopSpam moved to CMOption<> instead of custom code
Diffstat (limited to 'plugins/StopSpamPlus/src/settings.h')
-rw-r--r-- | plugins/StopSpamPlus/src/settings.h | 92 |
1 files changed, 10 insertions, 82 deletions
diff --git a/plugins/StopSpamPlus/src/settings.h b/plugins/StopSpamPlus/src/settings.h index e52ec472b2..b1e735e88d 100644 --- a/plugins/StopSpamPlus/src/settings.h +++ b/plugins/StopSpamPlus/src/settings.h @@ -1,90 +1,18 @@ -class db_usage
-{
-public:
- //reading from database
- static tstring DBGetPluginSetting(std::string const &name, tstring const &defValue);
- static std::string DBGetPluginSetting(std::string const &name, std::string const &defValue);
- static bool DBGetPluginSetting(std::string const &name, bool const &defValue);
- static DWORD DBGetPluginSetting(std::string const &name, DWORD const &defValue);
- //writting to database
- static void DBSetPluginSetting(std::string const &name, tstring const &value);
- static void DBSetPluginSetting(std::string const &name, std::string const &value);
- static void DBSetPluginSetting(std::string const &name, bool const &value);
- static void DBSetPluginSetting(std::string const &name, DWORD const &value);
-
-};
-template <typename T>
-class db_setting
+struct Settings
{
- std::string m_name;
- T m_defValue;
- T m_value;
-public:
- db_setting(std::string const &name, T const &defValue):m_name(name),m_defValue(defValue)
- {
- m_value=db_usage::DBGetPluginSetting(m_name, m_defValue);
- }
- const T & GetDefault()const{return m_defValue;}
- void Set(T const &value)
- {
- m_value=value;
- db_usage::DBSetPluginSetting(m_name, m_value);
- }
- const T & Get()const{return m_value;}
- db_setting<T>& operator=(T const &value)
- {
- m_value=value;
- db_usage::DBSetPluginSetting(m_name, m_value);
- return *this;
- }
- operator T(){return m_value;}
- void SetResident(BOOL bResident){
- db_set_resident(pluginName, m_name.c_str(), bResident);
- }
-};
+ Settings();
-class Settings
-{
-public:
- db_setting<tstring> Question;
- db_setting<tstring> AuthRepl;
- db_setting<tstring> Answer;
- db_setting<tstring> Congratulation;
- db_setting<std::string> DisabledProtoList;
- db_setting<bool> InfTalkProtection;
- db_setting<bool> AddPermanent;
- db_setting<DWORD> MaxQuestCount;
- db_setting<bool> HandleAuthReq;
- db_setting<bool> AnswNotCaseSens;
- db_setting<tstring> AnswSplitString;
- db_setting<bool> RemTmpAll;
- db_setting<bool> HistLog;
-
- Settings():
- Question("Question", TranslateW(L"Spammers made me to install small anti-spam system you are now speaking with. Please reply \"nospam\" without quotes and spaces if you want to contact me.")),
- AuthRepl("AuthReply", TranslateW(L"StopSpam: send a message and reply to an anti-spam bot question.")),
- Answer("Answer", L"nospam"),
- Congratulation("Congratulation", TranslateW(L"Congratulations! You just passed human/robot test. Now you can write me a message.")),
- DisabledProtoList("DisabledProtoList", "MetaContacts RSSNews"),
- InfTalkProtection("InfTalkProtection", 1),
- AddPermanent("AddPermanent", 0),
- HandleAuthReq("HandleAuthReq", 0),
- MaxQuestCount("MaxQuestCount", 2),
- AnswNotCaseSens("AnswNotCaseSens", 1),
- AnswSplitString("AnswSplitString", L"|"),
- RemTmpAll("RemTmpAll", 1),
- HistLog("HistLog", 0)
- {
- const std::string &str = DisabledProtoList.Get();
- if (!str.empty() && *(str.rbegin()) != ' ')
- DisabledProtoList = DisabledProtoList.Get() + ' ';
- }
+ CMOption<bool> InfTalkProtection, AddPermanent, HandleAuthReq, AnswNotCaseSens, RemTmpAll, HistLog;
+ CMOption<wchar_t*> Question, AuthRepl, Answer, Congratulation, AnswSplitString;
+ CMOption<char*> DisabledProtoList;
+ CMOption<DWORD> MaxQuestCount;
- bool ProtoDisabled(std::string proto)
+ bool ProtoDisabled(const char *proto)
{
- return std::string::npos != DisabledProtoList.Get().find(proto + " ");
+ std::string temp(proto); temp += ' ';
+ return strstr(DisabledProtoList, temp.c_str()) != nullptr;
}
};
-extern Settings *plSets;
+extern Settings g_sets;
|