Implemented UNSET command to restore default values

This commit is contained in:
John Reese 2011-01-13 22:52:50 -05:00
parent 6c191f6471
commit 3aaafb7ffb
2 changed files with 39 additions and 6 deletions

View File

@ -49,6 +49,10 @@ Commands
Allows you to see current configuration values. Allows you to see current configuration values.
* `unset <option>`
Allows you to reset a configuration option back to the default value.
* `status` * `status`
Check the status of current conditions. Check the status of current conditions.

View File

@ -47,6 +47,7 @@ class CNotifoMod : public CModule
// Configuration options // Configuration options
MCString options; MCString options;
MCString defaults;
public: public:
@ -69,15 +70,15 @@ class CNotifoMod : public CModule
user = GetUser(); user = GetUser();
// Notifo user account and secret // Notifo user account and secret
options["username"] = ""; defaults["username"] = "";
options["secret"] = ""; defaults["secret"] = "";
// Notification conditions // Notification conditions
options["client_count_less_than"] = "0"; defaults["client_count_less_than"] = "0";
// Notification settings // Notification settings
options["message_length"] = "100"; defaults["message_length"] = "100";
options["message_uri"] = ""; defaults["message_uri"] = "";
} }
virtual ~CNotifoMod() {} virtual ~CNotifoMod() {}
@ -237,13 +238,17 @@ class CNotifoMod : public CModule
*/ */
bool OnLoad(const CString& args, CString& message) bool OnLoad(const CString& args, CString& message)
{ {
for (MCString::iterator i = options.begin(); i != options.end(); i++) for (MCString::iterator i = defaults.begin(); i != defaults.end(); i++)
{ {
CString value = GetNV(i->first); CString value = GetNV(i->first);
if (value != "") if (value != "")
{ {
options[i->first] = value; options[i->first] = value;
} }
else
{
options[i->first] = defaults[i->first];
}
} }
authencode(); authencode();
@ -377,6 +382,30 @@ class CNotifoMod : public CModule
authencode(); authencode();
} }
} }
// UNSET command
else if (action == "unset")
{
if (token_count != 2)
{
PutModule("Usage: unset <option>");
return;
}
CString option = tokens[1].AsLower();
MCString::iterator pos = options.find(option);
if (pos == options.end())
{
PutModule("Error: invalid option name");
}
else
{
options[option] = defaults[option];
DelNV(option);
authencode();
}
}
// GET command // GET command
else if (action == "get") else if (action == "get")
{ {