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.8 by root, Tue Jun 26 23:09:30 2007 UTC vs.
Revision 1.19 by root, Sun Nov 11 05:53:11 2012 UTC

1#! perl 1#! perl # mandatory depends=doclet
2 2
3our $TOPIC; 3our $TOPIC;
4our %DOCLET;
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 [0, "command_help"],
21 [1, "emote_help"],
22 [2, "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 @command_list = sort {
62 $a->[0] <=> $b->[0]
63 or $a->[1] cmp $b->[1]
64 } @command_list;
65
66 cf::cede_to_tick;
67
68 cf::face::set
69 "res/command_list" => cf::FT_RSRC,
70 JSON::XS->new->utf8->encode (\@command_list);
71}
72
73our $DOCLET_HANDLER = ext::doclet::register command => sub {
74 my ($pl, $category, $command) = @_;
75
76 my $guard = cf::lock_acquire "ext::help::loading";
77
78 $DOCLET{$command}
79 || "B<No documentation available for '$category/$command'>"
80};
4 81
5sub load_topics($$) { 82sub load_topics($$) {
6 my ($type, $path) = @_; 83 my ($type, $path) = @_;
7 84
8 my $paragraphs = cf::pod::load_pod "$PODDIR/$path.pod" 85 my $paragraphs = cf::pod::load_pod "$PODDIR/$path.pod"
10 87
11 my @topics; 88 my @topics;
12 my $level = 1e9; 89 my $level = 1e9;
13 90
14 for my $par (@$paragraphs) { 91 for my $par (@$paragraphs) {
15 Coro::cede; 92 cf::cede_to_tick;
16 if ($par->{type} eq "head2") { 93 if ($par->{type} eq "head2") {
17 if ($par->{markup} =~ /^(\S+)/) { 94 if ($par->{markup} =~ /^(\S+)/) {
18 push @topics, $1 => [$type => $par]; 95 push @topics, $1 => [$type => $par];
19 $level = $par->{level}; 96 $level = $par->{level};
20 } 97 }
25 102
26 @topics 103 @topics
27} 104}
28 105
29sub reload() { 106sub reload() {
107 my $guard1 = cf::lock_acquire "ext::help::loading";
108 my $guard2 = cf::lock_acquire "ext::resource";
109
110 local $Coro::current->{desc} = "help loader";
111
30 $TOPIC = { 112 $TOPIC = {
31 (load_topics "DM Commands" => "dmcommand_help"), 113 (load_topics "DM Commands" => "dmcommand_help"),
32 (load_topics "Emotes" => "emote_help"), 114 (load_topics "Emotes" => "emote_help"),
33 (load_topics "Commands" => "command_help"), 115 (load_topics "Commands" => "command_help"),
34 (load_topics "Generic Help Topics" => "generic_help"), 116 (load_topics "Generic Help Topics" => "generic_help"),
35 }; 117 };
118
119 load_doclets;
120
121 ()
36} 122}
37 123
38cf::sync_job { 124cf::post_init {
39 my $guard = cf::lock_acquire "ext::help::loading";
40 cf::async_ext { 125 cf::async_ext { reload };
41 reload; 126 Coro::cede; # make sure reload acquires the lock(s)
42 undef $guard;
43 };
44}; 127};
45
46# for lack of a better place: "media tags"
47# b bold
48# i italic
49# ul underlined
50# fixed font
51# arcane font
52# hand font
53# strange font
54# print font (default)
55# color=xxx
56 128
57cf::register_command help => sub { 129cf::register_command help => sub {
58 my ($pl, $topic) = @_; 130 my ($pl, $topic) = @_;
59 131
60 if (cf::lock_active "ext::help::loading") { 132 if (cf::lock_active "ext::help::loading") {
61 $pl->reply (undef, "help files are being loaded currently, try again in a few seconds."); 133 $pl->send_msg ($HELP_CHANNEL => "help files are being loaded currently, try again in a few seconds.", cf::NDI_REPLY | cf::NDI_CLEAR);
62 return; 134 return;
63 } 135 }
64 136
65 $topic = $1 if $topic =~ /(\S+)/; 137 $topic = $1 if $topic =~ /(\S+)/;
66 138
72 push @{$topics{$v->[0]}}, $k; 144 push @{$topics{$v->[0]}}, $k;
73 } 145 }
74 146
75 my $res; 147 my $res;
76 while (my ($k, $v) = each %topics) { 148 while (my ($k, $v) = each %topics) {
77 $res .= "B<$k:>\n" . (join " ", sort @$v) . "\n\n"; 149 $res .= "T<$k:>\n\n" . (join " ", sort @$v) . "\n\n";
78 } 150 }
79 151
80 $pl->reply (undef, $res); 152 $pl->send_msg ($HELP_CHANNEL => $res, cf::NDI_REPLY | cf::NDI_CLEAR);
81 153
82 } elsif (my $item = $TOPIC->{$topic}) { 154 } elsif (my $item = $TOPIC->{$topic}) {
83 my ($type, @pars) = @$item; 155 my ($type, @pars) = @$item;
84 $pl->reply (undef, cf::pod::as_text \@pars); 156 $pl->send_msg ($HELP_CHANNEL => (cf::pod::as_cfpod \@pars), cf::NDI_REPLY | cf::NDI_CLEAR);
85 157
86 } else { 158 } else {
87 $pl->reply (undef, "'$topic' no such help topic, try just 'help' to get a list of topics."); 159 $pl->send_msg ($HELP_CHANNEL => "'$topic' no such help topic, try just 'help' to get a list of topics.", cf::NDI_REPLY);
88 } 160 }
89}; 161};
90 162

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines