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.1 by pippijn, Thu Mar 1 13:35:39 2007 UTC vs.
Revision 1.14 by root, Mon Sep 22 01:33:09 2008 UTC

1#! perl 1#! perl
2 2
3#-------------------------------------------------- 3our $TOPIC;
4
5our $HELP_CHANNEL = {
6 id => "help",
7 title => "Help",
8 reply => "help ",
9 tooltip => "Online Help",
10};
11
12sub 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
36sub reload() {
37 $TOPIC = {
38 (load_topics "DM Commands" => "dmcommand_help"),
39 (load_topics "Emotes" => "emote_help"),
40 (load_topics "Commands" => "command_help"),
41 (load_topics "Generic Help Topics" => "generic_help"),
42 };
43
44 ()
45}
46
47cf::sync_job {
48 my $guard = cf::lock_acquire "ext::help::loading";
49 cf::async_ext {
50 $Coro::current->{desc} = "help loader";
51 reload;
52 undef $guard;
53 };
54};
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
4# cf::register_command help => sub { 67cf::register_command help => sub {
5# my ($pl, $topic) = @_; 68 my ($pl, $topic) = @_;
6# 69
7# $pl->reply (undef, "Help on $topic"); 70 if (cf::lock_active "ext::help::loading") {
8# }; 71 $pl->send_msg ($HELP_CHANNEL => "help files are being loaded currently, try again in a few seconds.", cf::NDI_REPLY | cf::NDI_CLEAR);
9#-------------------------------------------------- 72 return;
73 }
74
75 $topic = $1 if $topic =~ /(\S+)/;
76
77 if (!length $topic) {
78 # sort..
79
80 my %topics;
81 while (my ($k, $v) = each %$TOPIC) {
82 push @{$topics{$v->[0]}}, $k;
83 }
84
85 my $res;
86 while (my ($k, $v) = each %topics) {
87 $res .= "T<$k:>\n\n" . (join " ", sort @$v) . "\n\n";
88 }
89
90 $pl->send_msg ($HELP_CHANNEL => $res, cf::NDI_REPLY | cf::NDI_CLEAR);
91
92 } elsif (my $item = $TOPIC->{$topic}) {
93 my ($type, @pars) = @$item;
94 $pl->send_msg ($HELP_CHANNEL => (cf::pod::as_cfpod \@pars), cf::NDI_REPLY | cf::NDI_CLEAR);
95
96 } else {
97 $pl->send_msg ($HELP_CHANNEL => "'$topic' no such help topic, try just 'help' to get a list of topics.", cf::NDI_REPLY);
98 }
99};
100

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines