summaryrefslogtreecommitdiff
path: root/plugins/StopSpamPlus/src/settings.h
blob: 22c005649e5544260f3e16bf97f788f830f20ac9 (plain)
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
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
{
	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);
	}
};

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",TranslateTS(L"Spammers made me to install small anti-spam system you are now speaking with. "
		L"Please reply \"nospam\" without quotes and spaces if you want to contact me.\r\n"
		L"Âíèìàíèå! Àíòèñïàì çàùèòà. Îòâåòüòå \"nospam\" áåç êàâû÷åê è ïðîáåëîâ, åñëè õîòèòå ñâÿçàòüñÿ ñî ìíîé."))
	,AuthRepl("AuthReply",TranslateTS(L"StopSpam: send a message and reply to a anti-spam bot question.\r\n"
		L"Àíòèñïàì: îòïðàâüòå ñîîáùåíèå è îòâåòüòå íà âîïðîñ àíòèñïàì ñèñòåìû."))
	,Answer("Answer",L"nospam")
	,Congratulation("Congratulation",TranslateTS(L"Congratulations! You just passed human/robot test. Now you can write me a message.\r\n"
		L"Ïîçäðàâëÿþ! Âû ïðîøëè àíòèñïàì ïðîâåðêó. Òåïåðü âû ìîæåòå ïèñàòü ìíå."))
	,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()+' ';
	}
	bool ProtoDisabled(std::string proto)
	{
		return std::string::npos != DisabledProtoList.Get().find(proto + " ");
	}
};

extern Settings *plSets;