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.
* `unset <option>`
Allows you to reset a configuration option back to the default value.
* `status`
Check the status of current conditions.

View File

@ -47,6 +47,7 @@ class CNotifoMod : public CModule
// Configuration options
MCString options;
MCString defaults;
public:
@ -69,15 +70,15 @@ class CNotifoMod : public CModule
user = GetUser();
// Notifo user account and secret
options["username"] = "";
options["secret"] = "";
defaults["username"] = "";
defaults["secret"] = "";
// Notification conditions
options["client_count_less_than"] = "0";
defaults["client_count_less_than"] = "0";
// Notification settings
options["message_length"] = "100";
options["message_uri"] = "";
defaults["message_length"] = "100";
defaults["message_uri"] = "";
}
virtual ~CNotifoMod() {}
@ -237,13 +238,17 @@ class CNotifoMod : public CModule
*/
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);
if (value != "")
{
options[i->first] = value;
}
else
{
options[i->first] = defaults[i->first];
}
}
authencode();
@ -377,6 +382,30 @@ class CNotifoMod : public CModule
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
else if (action == "get")
{