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.14 by root, Fri Mar 31 22:47:35 2006 UTC vs.
Revision 1.17 by root, Mon Jun 19 10:20:07 2006 UTC

65 65
66my %ext_pkg; 66my %ext_pkg;
67my @exts; 67my @exts;
68my @hook; 68my @hook;
69my %command; 69my %command;
70my %extcmd;
70 71
71sub inject_event { 72sub inject_event {
72 my $extension = shift; 73 my $extension = shift;
73 my $event_code = shift; 74 my $event_code = shift;
74 75
99 100
100sub register_command { 101sub register_command {
101 my ($name, $time, $cb) = @_; 102 my ($name, $time, $cb) = @_;
102 103
103 my $caller = caller; 104 my $caller = caller;
104
105 warn "registering command '$name/$time' to '$caller'"; 105 #warn "registering command '$name/$time' to '$caller'";
106 106
107 push @{ $command{$name} }, [$time, $cb, $caller]; 107 push @{ $command{$name} }, [$time, $cb, $caller];
108 $COMMAND{"$name\000"} = List::Util::max map $_->[0], @{ $command{$name} }; 108 $COMMAND{"$name\000"} = List::Util::max map $_->[0], @{ $command{$name} };
109} 109}
110 110
111sub register_extcmd {
112 my ($name, $cb) = @_;
113
114 my $caller = caller;
115 #warn "registering extcmd '$name' to '$caller'";
116
117 $extcmd{$name} = [$cb, $caller];
118}
119
111sub register { 120sub register {
112 my ($base, $pkg) = @_; 121 my ($base, $pkg) = @_;
113 122
114 for my $idx (0 .. $#EVENT) { 123 for my $idx (0 .. $#EVENT) {
115 if (my $ref = $pkg->can ("on_$EVENT[$idx]")) { 124 if (my $ref = $pkg->can ("on_$EVENT[$idx]")) {
116 warn "registering $EVENT[$idx] hook to '$pkg'\n"; 125 #warn "registering $EVENT[$idx] hook to '$pkg'\n";
117 $hook[$idx]{$base} = $ref; 126 $hook[$idx]{$base} = $ref;
118 } 127 }
119 } 128 }
120} 129}
121 130
172 delete $command{$name}; 181 delete $command{$name};
173 delete $COMMAND{"$name\000"}; 182 delete $COMMAND{"$name\000"};
174 } 183 }
175 } 184 }
176 185
186 # remove extcmds
187 for my $name (grep $extcmd{$_}[1] eq $pkg, keys %extcmd) {
188 delete $extcmd{$name};
189 }
190
177 Symbol::delete_package $pkg; 191 Symbol::delete_package $pkg;
178} 192}
179 193
180sub load_extensions { 194sub load_extensions {
181 my $LIBDIR = maps_directory "perl"; 195 my $LIBDIR = maps_directory "perl";
214 $who->message ("Intruder Alert!"); 228 $who->message ("Intruder Alert!");
215 } 229 }
216}; 230};
217 231
218############################################################################# 232#############################################################################
233# extcmd framework, basically convert ext <id> <pkg> arg1 args
234# into pkg::->on_extcmd_arg1 (...) while shortcutting a few
235
236sub on_extcmd {
237 my ($pl, $buf) = @_;
238
239 my ($type) = $buf =~ s/^(\S+) // ? $1 : "";
240
241 $extcmd{$type}[0]->($pl, $buf)
242 if $extcmd{$type};
243}
244
245#############################################################################
219# load/save/clean perl data associated with a map 246# load/save/clean perl data associated with a map
220 247
221*on_mapclean = sub { 248*on_mapclean = sub {
222 my ($map) = @_; 249 my ($map) = @_;
223 250
309 unlink "$path.cfperl";#d##TODO#remove 336 unlink "$path.cfperl";#d##TODO#remove
310}; 337};
311 338
312register "<global>", __PACKAGE__; 339register "<global>", __PACKAGE__;
313 340
341unshift @INC, maps_directory "perl";
342
314load_extensions; 343load_extensions;
315 344
3161 3451
317 346

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines