--- deliantra/server/ext/help.ext 2007/04/18 17:32:06 1.2 +++ deliantra/server/ext/help.ext 2008/09/08 11:39:47 1.13 @@ -2,8 +2,15 @@ our $TOPIC; -sub load_topics($) { - my ($path) = @_; +our $HELP_CHANNEL = { + id => "help", + title => "Help", + reply => "help ", + tooltip => "Online Help", +}; + +sub load_topics($$) { + my ($type, $path) = @_; my $paragraphs = cf::pod::load_pod "$PODDIR/$path.pod" or die "unable to load $path"; @@ -12,10 +19,10 @@ my $level = 1e9; for my $par (@$paragraphs) { - Coro::cede; + cf::cede_to_tick; if ($par->{type} eq "head2") { if ($par->{markup} =~ /^(\S+)/) { - push @topics, $1 => [$par]; + push @topics, $1 => [$type => $par]; $level = $par->{level}; } } elsif ($par->{level} > $level) { @@ -28,26 +35,66 @@ sub reload() { $TOPIC = { - load_topics "dmcommand_help", - load_topics "emote_help", - load_topics "command_help", - load_topics "generic_help", + (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 { + $Coro::current->{desc} = "help loader"; reload; undef $guard; }; }; -cf::register_command xhelp => sub { +# 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"); + $pl->send_msg ($HELP_CHANNEL => "help files are being loaded currently, try again in a few seconds.", cf::NDI_REPLY | cf::NDI_CLEAR); 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:>\n" . (join " ", sort @$v) . "\n\n"; + } + + $pl->send_msg ($HELP_CHANNEL => $res, cf::NDI_REPLY | cf::NDI_CLEAR); + + } elsif (my $item = $TOPIC->{$topic}) { + my ($type, @pars) = @$item; + $pl->send_msg ($HELP_CHANNEL => (cf::pod::as_cfpod \@pars), cf::NDI_REPLY | cf::NDI_CLEAR); + + } else { + $pl->send_msg ($HELP_CHANNEL => "'$topic' no such help topic, try just 'help' to get a list of topics.", cf::NDI_REPLY); + } }; +