--- deliantra/server/ext/help.ext 2007/03/01 13:35:39 1.1 +++ deliantra/server/ext/help.ext 2007/04/23 19:17:16 1.7 @@ -1,9 +1,90 @@ #! perl -#-------------------------------------------------- -# cf::register_command help => sub { -# my ($pl, $topic) = @_; -# -# $pl->reply (undef, "Help on $topic"); -# }; -#-------------------------------------------------- +our $TOPIC; + +sub load_topics($$) { + my ($type, $path) = @_; + + my $paragraphs = cf::pod::load_pod "$PODDIR/$path.pod" + or die "unable to load $path"; + + my @topics; + my $level = 1e9; + + for my $par (@$paragraphs) { + Coro::cede; + if ($par->{type} eq "head2") { + if ($par->{markup} =~ /^(\S+)/) { + push @topics, $1 => [$type => $par]; + $level = $par->{level}; + } + } elsif ($par->{level} > $level) { + push @{ $topics[-1] }, $par; + } + } + + @topics +} + +sub reload() { + $TOPIC = { + (load_topics "DM Commands" => "dmcommand_help"), + (load_topics "Emotes" => "emote_help"), + (load_topics "Commands" => "command_help"), + (load_topics "Generic Help Topics" => "generic_help"), + }; +} + +cf::sync_job { + my $guard = cf::lock_acquire "ext::help::loading"; + cf::async_ext { + reload; + undef $guard; + }; +}; + +# 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) = @_; + + if (cf::lock_active "ext::help::loading") { + $pl->reply (undef, "help files are being loaded currently, try again in a few seconds."); + return; + } + + $topic = $1 if $topic =~ /(\S+)/; + + if (!length $topic) { + # sort.. + + my %topics; + while (my ($k, $v) = each %$TOPIC) { + push @{$topics{$v->[0]}}, $k; + } + + my $res; + while (my ($k, $v) = each %topics) { + $res .= "[b]$k:[/b]\n" . (join " ", sort @$v) . "\n\n"; + } + + $pl->reply (undef, $res); + + } elsif (my $item = $TOPIC->{$topic}) { + my ($type, @pars) = @$item; + $pl->reply (undef, cf::pod::as_text \@pars); + + } else { + $pl->reply (undef, "'$topic' no such help topic, try just 'help' to get a list of topics."); + } +}; +