… | |
… | |
352 | # remove extcmds |
352 | # remove extcmds |
353 | for my $name (grep $extcmd{$_}[1] eq $pkg, keys %extcmd) { |
353 | for my $name (grep $extcmd{$_}[1] eq $pkg, keys %extcmd) { |
354 | delete $extcmd{$name}; |
354 | delete $extcmd{$name}; |
355 | } |
355 | } |
356 | |
356 | |
357 | if (my $cb = $pkg->can ("on_unload")) { |
357 | if (my $cb = $pkg->can ("unload")) { |
358 | eval { |
358 | eval { |
359 | $cb->($pkg); |
359 | $cb->($pkg); |
360 | 1 |
360 | 1 |
361 | } or warn "$pkg unloaded, but with errors: $@"; |
361 | } or warn "$pkg unloaded, but with errors: $@"; |
362 | } |
362 | } |
… | |
… | |
466 | |
466 | |
467 | ############################################################################# |
467 | ############################################################################# |
468 | # extcmd framework, basically convert ext <msg> |
468 | # extcmd framework, basically convert ext <msg> |
469 | # into pkg::->on_extcmd_arg1 (...) while shortcutting a few |
469 | # into pkg::->on_extcmd_arg1 (...) while shortcutting a few |
470 | |
470 | |
471 | sub on_extcmd { |
471 | attach_global |
|
|
472 | on_extcmd => sub { |
472 | my ($pl, $buf) = @_; |
473 | my ($pl, $buf) = @_; |
473 | |
474 | |
474 | my $msg = eval { from_json $buf }; |
475 | my $msg = eval { from_json $buf }; |
475 | |
476 | |
476 | if (ref $msg) { |
477 | if (ref $msg) { |
477 | if (my $cb = $extcmd{$msg->{msgtype}}) { |
478 | if (my $cb = $extcmd{$msg->{msgtype}}) { |
478 | if (my %reply = $cb->[0]->($pl, $msg)) { |
479 | if (my %reply = $cb->[0]->($pl, $msg)) { |
479 | $pl->ext_reply ($msg->{msgid}, %reply); |
480 | $pl->ext_reply ($msg->{msgid}, %reply); |
|
|
481 | } |
480 | } |
482 | } |
|
|
483 | } else { |
|
|
484 | warn "player " . ($pl->ob->name) . " sent unparseable ext message: <$buf>\n"; |
481 | } |
485 | } |
482 | } else { |
486 | |
483 | warn "player " . ($pl->ob->name) . " sent unparseable ext message: <$buf>\n"; |
487 | cf::override; |
484 | } |
488 | }, |
485 | |
489 | ; |
486 | 1 |
|
|
487 | } |
|
|
488 | |
490 | |
489 | ############################################################################# |
491 | ############################################################################# |
490 | # load/save/clean perl data associated with a map |
492 | # load/save/clean perl data associated with a map |
491 | |
493 | |
492 | *cf::mapsupport::on_clean = sub { |
494 | *cf::mapsupport::on_clean = sub { |