ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/help.ext
(Generate patch)

Comparing deliantra/server/ext/help.ext (file contents):
Revision 1.2 by root, Wed Apr 18 17:32:06 2007 UTC vs.
Revision 1.21 by root, Tue Nov 20 14:40:01 2012 UTC

1#! perl 1#! perl # mandatory depends=doclet
2 2
3our $TOPIC; 3our $TOPIC;
4our %DOCLET;
4 5
6our $HELP_CHANNEL = {
7 id => "help",
8 title => "Help",
9 reply => "help ",
10 tooltip => "Online Help",
11};
12
13# considerable duplication between load_doclets and load_topics
14sub load_doclets {
15 %DOCLET = ();
16
17 my %command_list;
18
19 for (
20 [standard => "command_help"],
21 [emote => "emote_help"],
22 [dm => "dmcommand_help"],
23 ) {
24 my ($type, $path) = @$_;
25
26 my $paragraphs = cf::pod::load_pod "$PODDIR/$path.pod"
27 or die "unable to load $path";
28
29 my $level = 1e9;
30 my $rpar;
31
32 for my $par (@$paragraphs) {
33 if ($par->{type} eq "head2") {
34 # this code taken almost verbatim from DC/Protocol.pm
35
36 if ($par->{markup} =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x) {
37 my $cmd = $1;
38 my @args = split /\|/, $2;
39 @args = (".*") unless @args;
40
41 $_ = $_ eq ".*" ? "" : " $_"
42 for @args;
43
44 my @variants = map "$cmd$_", sort { (length $a) <=> (length $b) } @args;
45
46 $rpar = \($DOCLET{$cmd} = &cf::pod::as_cfpod ([$par]));
47
48 push @{ $command_list{$type} }, @variants;
49 $level = $par->{level};
50 } else {
51 cf::error "$par->{markup}: unparsable command heading";
52 }
53 } elsif ($par->{level} > $level) {
54 $$rpar .= &cf::pod::as_cfpod ([$par]);
55 }
56
57 cf::cede_to_tick;
58 }
59 }
60
61 cf::cede_to_tick;
62
63 while (my ($k, $v) = each %command_list) {
64 cf::client::set_command_face $k, $v
65 }
66}
67
68our $DOCLET_HANDLER = ext::doclet::register command => sub {
69 my ($pl, $category, $command) = @_;
70
71 my $guard = cf::lock_acquire "ext::help::loading";
72
73 $DOCLET{$command}
74 || "B<No documentation available for '$category/$command'>"
75};
76
5sub load_topics($) { 77sub load_topics($$) {
6 my ($path) = @_; 78 my ($type, $path) = @_;
7 79
8 my $paragraphs = cf::pod::load_pod "$PODDIR/$path.pod" 80 my $paragraphs = cf::pod::load_pod "$PODDIR/$path.pod"
9 or die "unable to load $path"; 81 or die "unable to load $path";
10 82
11 my @topics; 83 my @topics;
12 my $level = 1e9; 84 my $level = 1e9;
13 85
14 for my $par (@$paragraphs) { 86 for my $par (@$paragraphs) {
15 Coro::cede; 87 cf::cede_to_tick;
16 if ($par->{type} eq "head2") { 88 if ($par->{type} eq "head2") {
17 if ($par->{markup} =~ /^(\S+)/) { 89 if ($par->{markup} =~ /^(\S+)/) {
18 push @topics, $1 => [$par]; 90 push @topics, $1 => [$type => $par];
19 $level = $par->{level}; 91 $level = $par->{level};
20 } 92 }
21 } elsif ($par->{level} > $level) { 93 } elsif ($par->{level} > $level) {
22 push @{ $topics[-1] }, $par; 94 push @{ $topics[-1] }, $par;
23 } 95 }
25 97
26 @topics 98 @topics
27} 99}
28 100
29sub reload() { 101sub reload() {
102 my $guard1 = cf::lock_acquire "ext::help::loading";
103 my $guard2 = cf::lock_acquire "ext::resource";
104
105 local $Coro::current->{desc} = "help loader";
106
30 $TOPIC = { 107 $TOPIC = {
31 load_topics "dmcommand_help", 108 (load_topics "DM Commands" => "dmcommand_help"),
32 load_topics "emote_help", 109 (load_topics "Emotes" => "emote_help"),
33 load_topics "command_help", 110 (load_topics "Commands" => "command_help"),
34 load_topics "generic_help", 111 (load_topics "Generic Help Topics" => "generic_help"),
35 }; 112 };
113
114 load_doclets;
115
116 ()
36} 117}
37 118
38cf::sync_job { 119cf::post_init {
39 my $guard = cf::lock_acquire "ext::help::loading";
40 cf::async_ext { 120 cf::async_ext { reload };
41 reload; 121 Coro::cede; # make sure reload acquires the lock(s)
42 undef $guard;
43 };
44}; 122};
45 123
46cf::register_command xhelp => sub { 124cf::register_command help => sub {
47 my ($pl, $topic) = @_; 125 my ($pl, $topic) = @_;
48 126
49 if (cf::lock_active "ext::help::loading") { 127 if (cf::lock_active "ext::help::loading") {
50 $pl->reply (undef, "help files are being loaded currently, try again in a few seconds"); 128 $pl->send_msg ($HELP_CHANNEL => "help files are being loaded currently, try again in a few seconds.", cf::NDI_REPLY | cf::NDI_CLEAR);
51 return; 129 return;
52 } 130 }
131
132 $topic = $1 if $topic =~ /(\S+)/;
133
134 if (!length $topic) {
135 # sort..
136
137 my %topics;
138 while (my ($k, $v) = each %$TOPIC) {
139 push @{$topics{$v->[0]}}, $k;
140 }
141
142 my $res;
143 while (my ($k, $v) = each %topics) {
144 $res .= "T<$k:>\n\n" . (join " ", sort @$v) . "\n\n";
145 }
146
147 $pl->send_msg ($HELP_CHANNEL => $res, cf::NDI_REPLY | cf::NDI_CLEAR);
148
149 } elsif (my $item = $TOPIC->{$topic}) {
150 my ($type, @pars) = @$item;
151 $pl->send_msg ($HELP_CHANNEL => (cf::pod::as_cfpod \@pars), cf::NDI_REPLY | cf::NDI_CLEAR);
152
153 } else {
154 $pl->send_msg ($HELP_CHANNEL => "'$topic' no such help topic, try just 'help' to get a list of topics.", cf::NDI_REPLY);
155 }
53}; 156};
157

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines