Unconf Command

Wrote new code? Fixed a bug? Want to discuss technical stuff? Feel free to post it here.

Moderator: Moderators

Message
Author
sli
Perl Monk
Perl Monk
Posts: 810
Joined: 04 Apr 2008, 17:26
Noob?: No

Unconf Command

#1 Post by sli »

Handy for unsetting lockMap, which I find myself needing to do from time to time, or any other config variable, of course. I also cleaned up what configModify says (try unconf'ing then conf'ing a variable to see what I mean).

Code: Select all

Index: src/Commands.pm
===================================================================
--- src/Commands.pm	(revision 6342)
+++ src/Commands.pm	(working copy)
@@ -76,6 +76,7 @@
 	cl                 => \&cmdChatLogClear,
 	closeshop          => \&cmdCloseShop,
 	conf               => \&cmdConf,
+	unconf             => \&cmdUnconf,
 	damage             => \&cmdDamage,
 	deal               => \&cmdDeal,
 	debug              => \&cmdDebug,
@@ -1063,6 +1064,22 @@
 	main::closeShop();
 }
 
+sub cmdUnconf {
+	my (undef, $args) = @_;
+	my ($arg1) = $args =~ /^(\w*\.*\w+)/;
+
+	if (exists $config{$arg1}) {
+		Plugins::callHook('Commands::cmdConf', {
+			key => $arg1,
+			val => ''
+		});
+		configModify($arg1, '');
+		Log::initLogFiles();
+	} else {
+		error TF("Config variable %s doesn't exist\n", $arg1);
+	}
+}
+
 sub cmdConf {
 	my (undef, $args) = @_;
 	my ($arg1) = $args =~ /^(\w*\.*\w+)/;
Index: src/Misc.pm
===================================================================
--- src/Misc.pm	(revision 6342)
+++ src/Misc.pm	(working copy)
@@ -289,7 +289,13 @@
 
 	if (!$args{silent} && $key !~ /password/i) {
 		my $oldval = $config{$key};
-		message TF("Config '%s' set to %s (was %s)\n", $key, $val, $oldval), "info";
+		if ($val ne '' && $oldval ne '') {
+			message TF("Config '%s' set to %s (was %s)\n", $key, $val, $oldval), "info";
+		} elsif ($oldval eq '') {
+			message TF("Config '%s' set to %s\n", $key, $val), "info";
+		} else {
+			message TF("Config '%s' unset (was %s)\n", $key, $oldval), "info";
+		}
 	}
 	if ($args{autoCreate} && !exists $config{$key}) {
 		my $f;
cs : ee : realist

Kissa2k
Human
Human
Posts: 46
Joined: 27 Apr 2008, 12:52
Noob?: No
Location: Russia

Re: Unconf Command

#2 Post by Kissa2k »

You can do this with conf command too. For example:
conf lockMap none

sli
Perl Monk
Perl Monk
Posts: 810
Joined: 04 Apr 2008, 17:26
Noob?: No

Re: Unconf Command

#3 Post by sli »

I like typing less than that. Plus, there's my whole... aversion towards using arbitrary strings to represent internal stuff (like "none" representing a null value instead of... just using a null value).
Last edited by sli on 06 May 2008, 13:07, edited 1 time in total.
cs : ee : realist

darkfate
Super Moderators
Super Moderators
Posts: 61
Joined: 22 Apr 2008, 02:22
Noob?: No
Location: Zurich, Switzerland

Re: Unconf Command

#4 Post by darkfate »

sli wrote:I like typing less than that.
how lazy can a human actually become?
You can't make people smarter. You can expose them to information, but your responsibility stops there.
- Mark Rippetoe

sli
Perl Monk
Perl Monk
Posts: 810
Joined: 04 Apr 2008, 17:26
Noob?: No

Re: Unconf Command

#5 Post by sli »

darkfate wrote:
sli wrote:I like typing less than that.
how lazy can a human actually become?
Pretty damn lazy. Some of us are college students, you know.
cs : ee : realist

Cozzie
Spam Generator
Spam Generator
Posts: 499
Joined: 04 Apr 2008, 09:30
Noob?: No
Location: Melbourne, City of beer and awful sushis

Re: Unconf Command

#6 Post by Cozzie »

isnt that the whole point of computers? to make lives easier? lol
Make Openkore Awesome. Join the team.

Kissa2k
Human
Human
Posts: 46
Joined: 27 Apr 2008, 12:52
Noob?: No
Location: Russia

Re: Unconf Command

#7 Post by Kissa2k »

I remember that quote from Futurama:
Bender: You humans think that robots are just machines made to make people's lives easier.
Fry: Well, aren't they?
Bender: I've never made anyone's life easier and you know it!

sli
Perl Monk
Perl Monk
Posts: 810
Joined: 04 Apr 2008, 17:26
Noob?: No

Re: Unconf Command

#8 Post by sli »

Yeah, but that's Bender. He hit a busted light bulb and it scrambled his AI, causing him to not benefit humans like he should. But then again, Hedonismbot doesn't really benefit anyone, either. But I think he was just made that way.
cs : ee : realist

Kissa2k
Human
Human
Posts: 46
Joined: 27 Apr 2008, 12:52
Noob?: No
Location: Russia

Re: Unconf Command

#9 Post by Kissa2k »

lol :D

isieo
Kami-Sama Desu~
Kami-Sama Desu~
Posts: 195
Joined: 04 Apr 2008, 09:24
Noob?: Yes
Location: 31th Dimension
Contact:

Re: Unconf Command

#10 Post by isieo »

it could even get shorter if you use alias =P

Post Reply