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.14 by root, Mon Sep 22 01:33:09 2008 UTC vs.
Revision 1.21 by root, Tue Nov 20 14:40:01 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 [standard => "command_help"],
21 [emote => "emote_help"],
22 [dm => "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 while (my ($k, $v) = each %command_list) {
64 cf::client::set_command_face $k, $v
65 }
66}
67
68our $DOCLET_HANDLER = ext::doclet::register command => sub {
69 my ($pl, $category, $command) = @_;
70
71 my $guard = cf::lock_acquire "ext::help::loading";
72
73 $DOCLET{$command}
74 || "B<No documentation available for '$category/$command'>"
10}; 75};
11 76
12sub load_topics($$) { 77sub load_topics($$) {
13 my ($type, $path) = @_; 78 my ($type, $path) = @_;
14 79
32 97
33 @topics 98 @topics
34} 99}
35 100
36sub reload() { 101sub reload() {
102 my $guard1 = cf::lock_acquire "ext::help::loading";
103 my $guard2 = cf::lock_acquire "ext::resource";
104
105 local $Coro::current->{desc} = "help loader";
106
37 $TOPIC = { 107 $TOPIC = {
38 (load_topics "DM Commands" => "dmcommand_help"), 108 (load_topics "DM Commands" => "dmcommand_help"),
39 (load_topics "Emotes" => "emote_help"), 109 (load_topics "Emotes" => "emote_help"),
40 (load_topics "Commands" => "command_help"), 110 (load_topics "Commands" => "command_help"),
41 (load_topics "Generic Help Topics" => "generic_help"), 111 (load_topics "Generic Help Topics" => "generic_help"),
42 }; 112 };
113
114 load_doclets;
43 115
44 () 116 ()
45} 117}
46 118
47cf::sync_job { 119cf::post_init {
48 my $guard = cf::lock_acquire "ext::help::loading";
49 cf::async_ext { 120 cf::async_ext { reload };
50 $Coro::current->{desc} = "help loader"; 121 Coro::cede; # make sure reload acquires the lock(s)
51 reload;
52 undef $guard;
53 };
54}; 122};
55
56# for lack of a better place: "media tags"
57# b bold
58# i italic
59# ul underlined
60# fixed font
61# arcane font
62# hand font
63# strange font
64# print font (default)
65# color=xxx
66 123
67cf::register_command help => sub { 124cf::register_command help => sub {
68 my ($pl, $topic) = @_; 125 my ($pl, $topic) = @_;
69 126
70 if (cf::lock_active "ext::help::loading") { 127 if (cf::lock_active "ext::help::loading") {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines