ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/help.ext
Revision: 1.15
Committed: Tue Sep 23 04:29:11 2008 UTC (15 years, 8 months ago) by root
Branch: MAIN
Changes since 1.14: +6 -7 lines
Log Message:
*** empty log message ***

File Contents

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