ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/board.ext
(Generate patch)

Comparing deliantra/maps/perl/board.ext (file contents):
Revision 1.7 by root, Sun Aug 27 18:01:38 2006 UTC vs.
Revision 1.8 by root, Tue Sep 12 22:43:50 2006 UTC

12} 12}
13 13
14sub do_write { 14sub do_write {
15 my ($board, $msg, $who, $npc) = @_; 15 my ($board, $msg, $who, $npc) = @_;
16 if ($msg =~ /\S/) { 16 if ($msg =~ /\S/) {
17 CFBoard::write ($board, $who->name, $msg); 17 CFBoard::put_entry ($board, $who->name, $msg);
18 $who->reply ($npc, "Added entry."); 18 $who->reply ($npc, "Added entry.");
19 } else { 19 } else {
20 $who->reply ($npc, "Usage: write <message>\n"); 20 $who->reply ($npc, "Usage: write <message>\n");
21 } 21 }
22 1 22 1
24 24
25sub do_list { 25sub do_list {
26 my ($board, $who, $npc) = @_; 26 my ($board, $who, $npc) = @_;
27 my $cont = CFBoard::get ($board); 27 my $cont = CFBoard::get ($board);
28 if (@{$cont || []}) { 28 if (@{$cont || []}) {
29 $who->message ("$board content:", cf::NDI_BROWN | cf::NDI_UNIQUE); 29 $who->reply ($npc, "$board content:");
30 my $idx = 0; 30 my $idx = 0;
31 for (@$cont) { 31 for (@$cont) {
32 $who->message ("<$idx> $_->[0]: $_->[1]", cf::NDI_BROWN | cf::NDI_UNIQUE); 32 $who->reply ($npc, "<$idx> $_->[0]: $_->[1]");
33 $idx++; 33 $idx++;
34 } 34 }
35 } else { 35 } else {
36 $who->message ("$board is empty.", cf::NDI_BROWN | cf::NDI_UNIQUE); 36 $who->reply ($npc, "$board is empty.");
37 } 37 }
38 1 38 1
39} 39}
40 40
41sub do_remove { 41sub do_remove {
42 my ($board, $idx, $who, $npc) = @_; 42 my ($board, $idx, $who, $npc) = @_;
43 43
44 my $entry = CFBoard::get_idx ($board, $idx); 44 my $entry = CFBoard::get_entry ($board, $idx);
45 unless (defined $entry) { 45 unless (defined $entry) {
46 $who->reply ($npc, "No such entry."); 46 $who->reply ($npc, "No such entry.");
47 return 1; 47 return 1;
48 } 48 }
49 49
50 if ($entry->[0] eq $who->name or $who->flag (cf::FLAG_WIZ)) { 50 if ($entry->[0] eq $who->name or $who->flag (cf::FLAG_WIZ)) {
51 my $e = CFBoard::remove_idx ($board, $idx); 51 my $e = CFBoard::remove_entry ($board, $idx);
52 $who->reply ($npc, "Removed entry $idx ($e->[0]: $e->[1])."); 52 $who->reply ($npc, "Removed entry $idx ($e->[0]: $e->[1]).");
53 } else { 53 } else {
54 $who->reply ($npc, "Access denied."); 54 $who->reply ($npc, "Access denied.");
55 } 55 }
56 56
87package CFBoard; 87package CFBoard;
88 88
89use POSIX qw/strftime/; 89use POSIX qw/strftime/;
90use CFDB; 90use CFDB;
91 91
92my $BOARDDB = CFDB->new (db_file => cf::localdir . "/crossfireboard.perl"); 92my $BOARDDB = cf::db_get "board";
93 93
94sub get { 94sub get {
95 my ($board) = @_; 95 my ($board) = @_;
96 $BOARDDB->get ($board); 96
97 $BOARDDB->{"msg_$board"} ||= []
97} 98}
98 99
99sub get_idx { 100sub get_entry {
100 my ($board, $idx) = @_; 101 my ($board, $idx) = @_;
101 $board = $BOARDDB->get ($board); 102
102 return $board->[$idx]; 103 $BOARDDB->{"msg_$board"}[$idx]
103} 104}
104 105
105sub remove_idx { 106sub remove_entry {
106 my ($boardname, $idx) = @_; 107 my ($board, $idx) = @_;
107 my $board = $BOARDDB->get ($boardname); 108
108 my $e = splice @$board, $idx, 1; 109 my $entry = splice @{ $BOARDDB->{"msg_$board"} ||= [] }, $idx, 1;
109 $BOARDDB->set ($boardname, $board); 110 cf::db_dirty;
110 $e 111 $entry
111} 112}
112 113
113sub clear { 114sub clear {
114 my ($board) = @_; 115 my ($board) = @_;
115 $BOARDDB->clear ($board); 116
117 delete $BOARDDB->{"msg_$board"};
118 cf::db_dirty;
116} 119}
117 120
118sub write { 121sub put_entry {
119 my ($board, $from, $message) = @_; 122 my ($board, $from, $message) = @_;
120 my $boardentrys = $BOARDDB->get ($board); 123
124 my $entries = $BOARDDB->{"msg_$board"} ||= [];
121 push @$boardentrys, [$from, $message]; 125 push @$entries, [$from, $message];
122 $BOARDDB->set ($board, $boardentrys); 126 cf::db_dirty;
123} 127}
124 128
1251; 1291;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines