ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/commands.ext
Revision: 1.3
Committed: Thu Sep 14 19:39:09 2006 UTC (17 years, 8 months ago) by root
Branch: MAIN
Changes since 1.2: +0 -4 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3     # miscellaneous commands
4    
5     sub rename_to($$$) {
6     my ($ob, $from, $to) = @_;
7    
8     $to =~ /^[a-zA-Z0-9.,=#\/%$!^]*$/
9     or return $ob->message ("rename: name must consist only of letters, digits, spaces and a few other things.");
10    
11     127 >= length $to
12     or return $ob->message ("rename: new name must be <= 127 characters.");
13    
14     my $item;
15    
16     if (length $from) {
17     $item = $ob->find_best_object_match ($from)
18     or return $ob->message ("rename: could not find a matching item to rename.");
19     } else {
20     $item = $ob->find_marked_object ()
21     or return $ob->message ("rename: no from name and no marked item found to rename.");
22     }
23    
24     $item->custom_name (length $to ? $to : undef);
25    
26     if (length $to) {
27     $item->custom_name ($to);
28     $ob->message ("Your " . $item->base_name . " will now be called $to.");
29     } else {
30     $item->custom_name (undef);
31     $ob->message ("You stop calling your " . $item->base_name . " with weird names.");
32     }
33    
34     $ob->esrv_update_item (cf::UPD_NAME, $item);
35    
36     return 1;
37     }
38    
39     cf::register_command rename => 0, sub {
40     my ($ob, $arg) = @_;
41    
42 root 1.2 if ($arg =~ /^\s* (?: <([^>]+)> \s+)? to \s+ <([^>]+)> \s*$/x) {
43     # compatibility syntax
44 root 1.1 rename_to $ob, $1, $2;
45     } elsif ($arg =~ /
46     ^\s*
47     (?:
48     (?: "((?:[^"]+|\\.)*)" | (\S+) )
49     \s+)?
50     to \s+
51     (?: "((?:[^"]+|\\.)*)" | (\S+) )
52     \s*$
53     /x) {
54     # does not unquote $1 or $3
55     rename_to $ob, $2||$1, $4||$3;
56     } else {
57     $ob->message ('Syntax error. Rename usage: rename ["oldname"] to "newname"');
58     }
59     };