ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/help.ext
Revision: 1.10
Committed: Wed Sep 19 21:56:30 2007 UTC (16 years, 8 months ago) by root
Branch: MAIN
CVS Tags: rel-2_4, rel-2_3, rel-2_32, rel-2_42, rel-2_41
Changes since 1.9: +1 -0 lines
Log Message:
name your coroutines

File Contents

# User Rev Content
1 pippijn 1.1 #! perl
2    
3 root 1.2 our $TOPIC;
4    
5 root 1.3 sub load_topics($$) {
6     my ($type, $path) = @_;
7 root 1.2
8     my $paragraphs = cf::pod::load_pod "$PODDIR/$path.pod"
9     or die "unable to load $path";
10    
11     my @topics;
12     my $level = 1e9;
13    
14     for my $par (@$paragraphs) {
15     Coro::cede;
16     if ($par->{type} eq "head2") {
17     if ($par->{markup} =~ /^(\S+)/) {
18 root 1.3 push @topics, $1 => [$type => $par];
19 root 1.2 $level = $par->{level};
20     }
21     } elsif ($par->{level} > $level) {
22     push @{ $topics[-1] }, $par;
23     }
24     }
25    
26     @topics
27     }
28    
29     sub reload() {
30     $TOPIC = {
31 root 1.3 (load_topics "DM Commands" => "dmcommand_help"),
32     (load_topics "Emotes" => "emote_help"),
33     (load_topics "Commands" => "command_help"),
34     (load_topics "Generic Help Topics" => "generic_help"),
35 root 1.2 };
36     }
37    
38     cf::sync_job {
39     my $guard = cf::lock_acquire "ext::help::loading";
40     cf::async_ext {
41 root 1.10 $Coro::current->{desc} = "help loader";
42 root 1.2 reload;
43     undef $guard;
44     };
45     };
46    
47 root 1.6 # for lack of a better place: "media tags"
48     # b bold
49     # i italic
50     # ul underlined
51     # fixed font
52     # arcane font
53     # hand font
54     # strange font
55     # print font (default)
56     # color=xxx
57    
58 root 1.3 cf::register_command help => sub {
59 root 1.2 my ($pl, $topic) = @_;
60    
61     if (cf::lock_active "ext::help::loading") {
62 root 1.3 $pl->reply (undef, "help files are being loaded currently, try again in a few seconds.");
63 root 1.2 return;
64     }
65 root 1.3
66     $topic = $1 if $topic =~ /(\S+)/;
67    
68     if (!length $topic) {
69     # sort..
70    
71     my %topics;
72     while (my ($k, $v) = each %$TOPIC) {
73     push @{$topics{$v->[0]}}, $k;
74     }
75    
76     my $res;
77     while (my ($k, $v) = each %topics) {
78 root 1.8 $res .= "B<$k:>\n" . (join " ", sort @$v) . "\n\n";
79 root 1.3 }
80    
81     $pl->reply (undef, $res);
82    
83 root 1.7 } elsif (my $item = $TOPIC->{$topic}) {
84     my ($type, @pars) = @$item;
85 root 1.9 $pl->reply (undef, cf::pod::as_cfpod \@pars);
86 root 1.3
87     } else {
88     $pl->reply (undef, "'$topic' no such help topic, try just 'help' to get a list of topics.");
89     }
90 root 1.2 };
91 root 1.3