From 90674ba62902b7aaeceeb4c326469a74a32a259d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 10 Dec 2017 00:39:55 +0300 Subject: StopSpam moved to CMOption<> instead of custom code --- plugins/StopSpamPlus/src/settings.h | 92 ++++--------------------------------- 1 file changed, 10 insertions(+), 82 deletions(-) (limited to 'plugins/StopSpamPlus/src/settings.h') 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 -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& 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 Question; - db_setting AuthRepl; - db_setting Answer; - db_setting Congratulation; - db_setting DisabledProtoList; - db_setting InfTalkProtection; - db_setting AddPermanent; - db_setting MaxQuestCount; - db_setting HandleAuthReq; - db_setting AnswNotCaseSens; - db_setting AnswSplitString; - db_setting RemTmpAll; - db_setting 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 InfTalkProtection, AddPermanent, HandleAuthReq, AnswNotCaseSens, RemTmpAll, HistLog; + CMOption Question, AuthRepl, Answer, Congratulation, AnswSplitString; + CMOption DisabledProtoList; + CMOption 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; -- cgit v1.2.3