--- deliantra/server/ext/help.ext 2008/09/22 01:33:09 1.14 +++ deliantra/server/ext/help.ext 2012/11/20 14:40:01 1.21 @@ -1,6 +1,7 @@ -#! perl +#! perl # mandatory depends=doclet our $TOPIC; +our %DOCLET; our $HELP_CHANNEL = { id => "help", @@ -9,6 +10,70 @@ tooltip => "Online Help", }; +# considerable duplication between load_doclets and load_topics +sub load_doclets { + %DOCLET = (); + + my %command_list; + + for ( + [standard => "command_help"], + [emote => "emote_help"], + [dm => "dmcommand_help"], + ) { + my ($type, $path) = @$_; + + my $paragraphs = cf::pod::load_pod "$PODDIR/$path.pod" + or die "unable to load $path"; + + my $level = 1e9; + my $rpar; + + for my $par (@$paragraphs) { + if ($par->{type} eq "head2") { + # this code taken almost verbatim from DC/Protocol.pm + + if ($par->{markup} =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x) { + my $cmd = $1; + my @args = split /\|/, $2; + @args = (".*") unless @args; + + $_ = $_ eq ".*" ? "" : " $_" + for @args; + + my @variants = map "$cmd$_", sort { (length $a) <=> (length $b) } @args; + + $rpar = \($DOCLET{$cmd} = &cf::pod::as_cfpod ([$par])); + + push @{ $command_list{$type} }, @variants; + $level = $par->{level}; + } else { + cf::error "$par->{markup}: unparsable command heading"; + } + } elsif ($par->{level} > $level) { + $$rpar .= &cf::pod::as_cfpod ([$par]); + } + + cf::cede_to_tick; + } + } + + cf::cede_to_tick; + + while (my ($k, $v) = each %command_list) { + cf::client::set_command_face $k, $v + } +} + +our $DOCLET_HANDLER = ext::doclet::register command => sub { + my ($pl, $category, $command) = @_; + + my $guard = cf::lock_acquire "ext::help::loading"; + + $DOCLET{$command} + || "B" +}; + sub load_topics($$) { my ($type, $path) = @_; @@ -34,36 +99,28 @@ } sub reload() { + my $guard1 = cf::lock_acquire "ext::help::loading"; + my $guard2 = cf::lock_acquire "ext::resource"; + + local $Coro::current->{desc} = "help loader"; + $TOPIC = { (load_topics "DM Commands" => "dmcommand_help"), (load_topics "Emotes" => "emote_help"), (load_topics "Commands" => "command_help"), (load_topics "Generic Help Topics" => "generic_help"), }; + + load_doclets; () } -cf::sync_job { - my $guard = cf::lock_acquire "ext::help::loading"; - cf::async_ext { - $Coro::current->{desc} = "help loader"; - reload; - undef $guard; - }; +cf::post_init { + cf::async_ext { reload }; + Coro::cede; # make sure reload acquires the lock(s) }; -# for lack of a better place: "media tags" -# b bold -# i italic -# ul underlined -# fixed font -# arcane font -# hand font -# strange font -# print font (default) -# color=xxx - cf::register_command help => sub { my ($pl, $topic) = @_;