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.12 by root, Fri Apr 11 01:15:49 2008 UTC vs.
Revision 1.20 by root, Tue Nov 20 14:30:22 2012 UTC

1#! perl 1#! perl # mandatory depends=doclet
2 2
3our $TOPIC; 3our $TOPIC;
4our %DOCLET;
4 5
5our $HELP_CHANNEL = { 6our $HELP_CHANNEL = {
6 id => "help", 7 id => "help",
7 title => "Help", 8 title => "Help",
8 reply => "help ", 9 reply => "help ",
9 tooltip => "Online 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 cf::cede_to_tick;
62
63 use Data::Dump; ddx \@command_list;#d#
64
65 cf::client::set_command_faces
66 map {
67 cf::face::set
68 "command_list/$_" => cf::FT_RSRC,
69 JSON::XS->new->utf8->encode ([ sort @{ $command_list[$_] } ])
70 }
71 0..$#command_list;
72}
73
74our $DOCLET_HANDLER = ext::doclet::register command => sub {
75 my ($pl, $category, $command) = @_;
76
77 my $guard = cf::lock_acquire "ext::help::loading";
78
79 $DOCLET{$command}
80 || "B<No documentation available for '$category/$command'>"
10}; 81};
11 82
12sub load_topics($$) { 83sub load_topics($$) {
13 my ($type, $path) = @_; 84 my ($type, $path) = @_;
14 85
32 103
33 @topics 104 @topics
34} 105}
35 106
36sub reload() { 107sub reload() {
108 my $guard1 = cf::lock_acquire "ext::help::loading";
109 my $guard2 = cf::lock_acquire "ext::resource";
110
111 local $Coro::current->{desc} = "help loader";
112
37 $TOPIC = { 113 $TOPIC = {
38 (load_topics "DM Commands" => "dmcommand_help"), 114 (load_topics "DM Commands" => "dmcommand_help"),
39 (load_topics "Emotes" => "emote_help"), 115 (load_topics "Emotes" => "emote_help"),
40 (load_topics "Commands" => "command_help"), 116 (load_topics "Commands" => "command_help"),
41 (load_topics "Generic Help Topics" => "generic_help"), 117 (load_topics "Generic Help Topics" => "generic_help"),
42 }; 118 };
119
120 load_doclets;
121
122 ()
43} 123}
44 124
45cf::sync_job { 125cf::post_init {
46 my $guard = cf::lock_acquire "ext::help::loading";
47 cf::async_ext { 126 cf::async_ext { reload };
48 $Coro::current->{desc} = "help loader"; 127 Coro::cede; # make sure reload acquires the lock(s)
49 reload;
50 undef $guard;
51 };
52}; 128};
53
54# for lack of a better place: "media tags"
55# b bold
56# i italic
57# ul underlined
58# fixed font
59# arcane font
60# hand font
61# strange font
62# print font (default)
63# color=xxx
64 129
65cf::register_command help => sub { 130cf::register_command help => sub {
66 my ($pl, $topic) = @_; 131 my ($pl, $topic) = @_;
67 132
68 if (cf::lock_active "ext::help::loading") { 133 if (cf::lock_active "ext::help::loading") {
80 push @{$topics{$v->[0]}}, $k; 145 push @{$topics{$v->[0]}}, $k;
81 } 146 }
82 147
83 my $res; 148 my $res;
84 while (my ($k, $v) = each %topics) { 149 while (my ($k, $v) = each %topics) {
85 $res .= "B<$k:>\n" . (join " ", sort @$v) . "\n\n"; 150 $res .= "T<$k:>\n\n" . (join " ", sort @$v) . "\n\n";
86 } 151 }
87 152
88 $pl->send_msg ($HELP_CHANNEL => $res, cf::NDI_REPLY | cf::NDI_CLEAR); 153 $pl->send_msg ($HELP_CHANNEL => $res, cf::NDI_REPLY | cf::NDI_CLEAR);
89 154
90 } elsif (my $item = $TOPIC->{$topic}) { 155 } elsif (my $item = $TOPIC->{$topic}) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines