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.2 by root, Fri Feb 3 21:22:53 2006 UTC vs.
Revision 1.5 by root, Wed Feb 8 03:46:15 2006 UTC

58# guessed hierarchies 58# guessed hierarchies
59 59
60@cf::object::player::ISA = 'cf::object'; 60@cf::object::player::ISA = 'cf::object';
61@cf::object::map::ISA = 'cf::object'; 61@cf::object::map::ISA = 'cf::object';
62 62
63my %ext_pkg;
63my @exts; 64my @exts;
64my @hook; 65my @hook;
65my %command; 66my %command;
66 67
67sub inject_event { 68sub inject_event {
68 my ($data) = @_; 69 my ($data) = @_;
69 70
71 my $cb = $hook[$data->{event_code}]{$data->{extension}}
72 or return;
73
74 $cb->($data)
75}
76
77sub inject_global_event {
78 my ($data) = @_;
79
70 my $cb = $hook[$data->{event_code}] 80 my $cb = $hook[$data->{event_code}]
71 or return; 81 or return;
72 82
73 $_->($data) for values %$cb; 83 $_->($data) for values %$cb;
74 84
88sub register_command { 98sub register_command {
89 my ($name, $time, $cb) = @_; 99 my ($name, $time, $cb) = @_;
90 100
91 my $caller = caller; 101 my $caller = caller;
92 102
103 warn "registering command '$name/$time' to '$caller'";
104
93 push @{ $command{$name} }, [$time, $cb, $caller]; 105 push @{ $command{$name} }, [$time, $cb, $caller];
94 $COMMAND{"$name\000"} = List::Util::max map $_->[0], @{ $command{$name} }; 106 $COMMAND{"$name\000"} = List::Util::max map $_->[0], @{ $command{$name} };
95} 107}
96 108
97sub load_extension { 109sub load_extension {
98 my ($path) = @_; 110 my ($path) = @_;
99 111
100 $path =~ /([^\/\\]+)\.ext$/ or die "$path"; 112 $path =~ /([^\/\\]+)\.ext$/ or die "$path";
113 my $base = $1;
101 my $pkg = $1; 114 my $pkg = $1;
102 $pkg =~ s/[^[:word:]]/_/g; 115 $pkg =~ s/[^[:word:]]/_/g;
103 $pkg = "cf::ext::$pkg"; 116 $pkg = "cf::ext::$pkg";
104 117
105 warn "loading '$path' into '$pkg'\n"; 118 warn "loading '$path' into '$pkg'\n";
115 128
116 eval $source 129 eval $source
117 or die "$path: $@"; 130 or die "$path: $@";
118 131
119 push @exts, $pkg; 132 push @exts, $pkg;
133 $ext_pkg{$base} = $pkg;
120 134
121 no strict 'refs'; 135 no strict 'refs';
122 136
123# @{"$pkg\::ISA"} = cf::ext::; 137# @{"$pkg\::ISA"} = cf::ext::;
124 138
125 for my $idx (0 .. $#EVENT) { 139 for my $idx (0 .. $#EVENT) {
126 if (my $ref = $pkg->can ("on_$EVENT[$idx]")) { 140 if (my $ref = $pkg->can ("on_$EVENT[$idx]")) {
127 warn "registering $EVENT[$idx] hook\n"; 141 warn "registering $EVENT[$idx] hook\n";
128 $hook[$idx]{$pkg} = $ref; 142 $hook[$idx]{$base} = $ref;
129 } 143 }
130 } 144 }
131} 145}
132 146
133sub unload_extension { 147sub unload_extension {
158 172
159sub load_extensions { 173sub load_extensions {
160 my $LIBDIR = maps_directory "perl"; 174 my $LIBDIR = maps_directory "perl";
161 175
162 for my $ext (<$LIBDIR/*.ext>) { 176 for my $ext (<$LIBDIR/*.ext>) {
177 next unless -r $ext;
163 eval { 178 eval {
164 load_extension $ext; 179 load_extension $ext;
165 1 180 1
166 } or warn "$ext not loaded: $@"; 181 } or warn "$ext not loaded: $@";
167 } 182 }
169 184
170register_command "perl-reload", 0, sub { 185register_command "perl-reload", 0, sub {
171 my ($who, $arg) = @_; 186 my ($who, $arg) = @_;
172 187
173 if ($who->flag (FLAG_WIZ)) { 188 if ($who->flag (FLAG_WIZ)) {
189 $who->message ("reloading...");
190
174 warn "reloading...\n"; 191 warn "reloading...\n";
192 eval {
175 unload_extension $_ for @exts; 193 unload_extension $_ for @exts;
176 @exts = 0; 194 delete $INC{"cf.pm"};
177 load_extensions; 195
196 # don't, removes xs symbols, too
197 #Symbol::delete_package $pkg;
198
199 require cf;
200 };
201 warn $@ if $@;
202 $who->message ($@) if $@;
178 warn "reloaded\n"; 203 warn "reloaded\n";
204
205 $who->message ("reloaded");
206 } else {
207 $who->message ("Intruder Alert!");
179 } 208 }
180}; 209};
181 210
182load_extensions; 211load_extensions;
183 212

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines