ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/commands.ext
Revision: 1.13
Committed: Sun Nov 26 02:37:53 2006 UTC (17 years, 5 months ago) by root
Branch: MAIN
Changes since 1.12: +16 -11 lines
Log Message:
show irc users, HACK

File Contents

# Content
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 1
37 }
38
39 sub ext::schmorp_irc::users; # HACK: TODO: replace by signal
40
41 sub who_listing(;$) {
42 my ($privileged) = @_;
43
44 my ($numwiz, $numafk) = (0, 0);
45 my @pl;
46
47 foreach my $pl (cf::player::list) {
48 my $ob = $pl->ob;
49
50 next unless $ob->map
51 && ($privileged || !$pl->hidden);
52
53 $numwiz++ if $ob->flag (cf::FLAG_WIZ);
54 $numafk++ if $ob->flag (cf::FLAG_AFK);
55
56 push @pl, $pl;
57 }
58
59 (
60 "Total Players in The World. (" . (scalar @pl) . ") -- WIZ($numwiz) AFK($numafk) BOT(0)",
61 (
62 map {
63 my ($pl, $ob) = ($_, $_->ob);
64
65 "* " . $ob->name . "/" . $ob->level . " " . (length $pl->own_title ? $pl->own_title : "the " . $pl->title)
66 . ($pl->peaceful ? " [peaceful]" : " [HOSTILE]")
67 . ($ob->flag (cf::FLAG_AFK) ? " [AFK]" : "")
68 . ($ob->flag (cf::FLAG_WIZ) ? " [WIZ]" : "")
69 . " [" . $pl->client . "]"
70 . " [" . ($pl->peaceful || $privileged ? $ob->map->path : $ob->map->region ? $ob->map->region->name : "the unknown") . "]"
71 . ($privileged ? " " . $pl->host : "")
72 } sort { (lc $a->ob->name) cmp (lc $b->ob->name) } @pl
73 ),
74 eval { "* IRC: " . join ", ", ext::schmorp_irc::users },
75 )
76 }
77
78 cf::register_command who => $cf::TICK, sub {
79 my ($ob, $arg) = @_;
80
81 $ob->reply (undef, (join "\n", who_listing $ob->may ("extended_who")), cf::NDI_UNIQUE | cf::NDI_DK_ORANGE);
82
83 1
84 };
85
86 cf::register_command rename => $cf::TICK, sub {
87 my ($ob, $arg) = @_;
88
89 if ($arg =~ /^\s* (?: <([^>]+)> \s+)? to \s+ <([^>]*)> \s*$/x) {
90 # compatibility syntax
91 rename_to $ob, $1, $2;
92 } elsif ($arg =~ /
93 ^\s*
94 (?:
95 (?: "((?:[^"]+|\\.)*)" | (\S+) )
96 \s+)?
97 to \s+
98 (?: "((?:[^"]+|\\.)*)" | (\S+) )
99 \s*$
100 /x) {
101 # does not unquote $1 or $3
102 rename_to $ob, $2||$1, $4||$3;
103 } else {
104 $ob->reply (undef, 'Syntax error. Rename usage: rename ["oldname"] to "newname"');
105 }
106
107 1
108 };
109