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.15 by root, Sun Jun 11 15:02:16 2006 UTC vs.
Revision 1.16 by root, Mon Jun 12 13:25:27 2006 UTC

100 100
101sub register_command { 101sub register_command {
102 my ($name, $time, $cb) = @_; 102 my ($name, $time, $cb) = @_;
103 103
104 my $caller = caller; 104 my $caller = caller;
105
106 warn "registering command '$name/$time' to '$caller'"; 105 #warn "registering command '$name/$time' to '$caller'";
107 106
108 push @{ $command{$name} }, [$time, $cb, $caller]; 107 push @{ $command{$name} }, [$time, $cb, $caller];
109 $COMMAND{"$name\000"} = List::Util::max map $_->[0], @{ $command{$name} }; 108 $COMMAND{"$name\000"} = List::Util::max map $_->[0], @{ $command{$name} };
110} 109}
111 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
112sub register { 120sub register {
113 my ($base, $pkg) = @_; 121 my ($base, $pkg) = @_;
114 122
115 for my $idx (0 .. $#EVENT) { 123 for my $idx (0 .. $#EVENT) {
116 if (my $ref = $pkg->can ("on_$EVENT[$idx]")) { 124 if (my $ref = $pkg->can ("on_$EVENT[$idx]")) {
117 warn "registering $EVENT[$idx] hook to '$pkg'\n"; 125 #warn "registering $EVENT[$idx] hook to '$pkg'\n";
118 $hook[$idx]{$base} = $ref; 126 $hook[$idx]{$base} = $ref;
119 } 127 }
120 } 128 }
121} 129}
122 130
174 delete $COMMAND{"$name\000"}; 182 delete $COMMAND{"$name\000"};
175 } 183 }
176 } 184 }
177 185
178 # remove extcmds 186 # remove extcmds
179 for my $name (keys %command) { 187 for my $name (grep $extcmd{$_}[1] eq $pkg, keys %extcmd) {
180 my @cb = grep $_->[2] ne $pkg, @{ $command{$name} };
181
182 if (@cb) {
183 $command{$name} = \@cb;
184 $COMMAND{"$name\000"} = List::Util::max map $_->[0], @cb;
185 } else {
186 delete $command{$name}; 188 delete $extcmd{$name};
187 delete $COMMAND{"$name\000"};
188 }
189 } 189 }
190
191 190
192 Symbol::delete_package $pkg; 191 Symbol::delete_package $pkg;
193} 192}
194 193
195sub load_extensions { 194sub load_extensions {
235# into pkg::->on_extcmd_arg1 (...) while shortcutting a few 234# into pkg::->on_extcmd_arg1 (...) while shortcutting a few
236 235
237sub on_extcmd { 236sub on_extcmd {
238 my ($pl, $buf) = @_; 237 my ($pl, $buf) = @_;
239 238
240 my ($id, $pkg, $name, $data) = split / /, $buf, 4; 239 my ($type) = $buf =~ s/^(\S+) // ? $1 : "";
241 240
242 if (my $method = "cf::ext::$pkg"->can ("on_extcmd_$name")) { 241 $extcmd{$type}[0]->($pl, $buf)
243 $method->($pl, $id, $buf); 242 if $extcmd{$type};
244 }
245} 243}
246 244
247############################################################################# 245#############################################################################
248# load/save/clean perl data associated with a map 246# load/save/clean perl data associated with a map
249 247

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines