ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.5 by root, Wed Feb 8 03:46:15 2006 UTC vs.
Revision 1.7 by root, Tue Mar 7 13:44:43 2006 UTC

1package cf; 1package cf;
2 2
3use Symbol; 3use Symbol;
4use List::Util; 4use List::Util;
5use Storable;
5 6
6use strict; 7use strict;
7 8
8our %COMMAND; 9our %COMMAND;
9our @EVENT; 10our @EVENT;
102 103
103 warn "registering command '$name/$time' to '$caller'"; 104 warn "registering command '$name/$time' to '$caller'";
104 105
105 push @{ $command{$name} }, [$time, $cb, $caller]; 106 push @{ $command{$name} }, [$time, $cb, $caller];
106 $COMMAND{"$name\000"} = List::Util::max map $_->[0], @{ $command{$name} }; 107 $COMMAND{"$name\000"} = List::Util::max map $_->[0], @{ $command{$name} };
108}
109
110sub register {
111 my ($base, $pkg) = @_;
112
113 for my $idx (0 .. $#EVENT) {
114 if (my $ref = $pkg->can ("on_$EVENT[$idx]")) {
115 warn "registering $EVENT[$idx] hook to '$pkg'\n";
116 $hook[$idx]{$base} = $ref;
117 }
118 }
107} 119}
108 120
109sub load_extension { 121sub load_extension {
110 my ($path) = @_; 122 my ($path) = @_;
111 123
130 or die "$path: $@"; 142 or die "$path: $@";
131 143
132 push @exts, $pkg; 144 push @exts, $pkg;
133 $ext_pkg{$base} = $pkg; 145 $ext_pkg{$base} = $pkg;
134 146
135 no strict 'refs'; 147# no strict 'refs';
136
137# @{"$pkg\::ISA"} = cf::ext::; 148# @{"$pkg\::ISA"} = cf::ext::;
138 149
139 for my $idx (0 .. $#EVENT) { 150 register $base, $pkg;
140 if (my $ref = $pkg->can ("on_$EVENT[$idx]")) {
141 warn "registering $EVENT[$idx] hook\n";
142 $hook[$idx]{$base} = $ref;
143 }
144 }
145} 151}
146 152
147sub unload_extension { 153sub unload_extension {
148 my ($pkg) = @_; 154 my ($pkg) = @_;
149 155
206 } else { 212 } else {
207 $who->message ("Intruder Alert!"); 213 $who->message ("Intruder Alert!");
208 } 214 }
209}; 215};
210 216
217*on_mapclean = sub {
218 my $map = shift->{map};
219
220 my $path = $map->tmpname;
221 defined $path or return;
222
223 unlink "$path.cfperl";
224};
225
226*on_mapin =
227*on_mapload = sub {
228 my $map = shift->{map};
229
230 my $path = $map->tmpname;
231 $path = $map->path unless defined $path;
232
233 open my $fh, "<:raw", "$path.cfperl"
234 or return; # no perl data
235
236 my $data = Storable::thaw do { local $/; <$fh> };
237
238 $data->{version} <= 1
239 or return; # too new
240
241 $map->_set_obs ($data->{obs});
242};
243
244*on_mapout = sub {
245 my $map = shift->{map};
246
247 my $path = $map->tmpname;
248 $path = $map->path unless defined $path;
249
250 my $obs = $map->_get_obs;
251
252 if (defined $obs) {
253 open my $fh, ">:raw", "$path.cfperl"
254 or die "$path.cfperl: $!";
255
256 print $fh Storable::nfreeze {
257 version => 1,
258 obs => $obs,
259 };
260
261 chmod SAVE_MODE, "$path.cfperl"; # very racy, but cf-compatible *g*
262 } else {
263 unlink "$path.cfperl";
264 }
265};
266
267register "<global>", __PACKAGE__;
268
211load_extensions; 269load_extensions;
212 270
2131 2711
214 272

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines