… | |
… | |
90 | my %ext_pkg; |
90 | my %ext_pkg; |
91 | my @exts; |
91 | my @exts; |
92 | my @hook; |
92 | my @hook; |
93 | my %command; |
93 | my %command; |
94 | my %extcmd; |
94 | my %extcmd; |
|
|
95 | |
|
|
96 | ############################################################################# |
|
|
97 | # object support |
|
|
98 | |
|
|
99 | sub reattach { |
|
|
100 | warn "reattach<@_>\n"; |
|
|
101 | } |
|
|
102 | |
|
|
103 | sub instantiate { |
|
|
104 | warn "instantiate<@_>\n"; |
|
|
105 | } |
|
|
106 | |
|
|
107 | sub clone { |
|
|
108 | warn "clone<@_>\n"; |
|
|
109 | } |
95 | |
110 | |
96 | ############################################################################# |
111 | ############################################################################# |
97 | # "new" plug-in system |
112 | # "new" plug-in system |
98 | |
113 | |
99 | =item cf::object::attach ... # NYI |
114 | =item cf::object::attach ... # NYI |
… | |
… | |
352 | # remove extcmds |
367 | # remove extcmds |
353 | for my $name (grep $extcmd{$_}[1] eq $pkg, keys %extcmd) { |
368 | for my $name (grep $extcmd{$_}[1] eq $pkg, keys %extcmd) { |
354 | delete $extcmd{$name}; |
369 | delete $extcmd{$name}; |
355 | } |
370 | } |
356 | |
371 | |
357 | if (my $cb = $pkg->can ("on_unload")) { |
372 | if (my $cb = $pkg->can ("unload")) { |
358 | eval { |
373 | eval { |
359 | $cb->($pkg); |
374 | $cb->($pkg); |
360 | 1 |
375 | 1 |
361 | } or warn "$pkg unloaded, but with errors: $@"; |
376 | } or warn "$pkg unloaded, but with errors: $@"; |
362 | } |
377 | } |
… | |
… | |
466 | |
481 | |
467 | ############################################################################# |
482 | ############################################################################# |
468 | # extcmd framework, basically convert ext <msg> |
483 | # extcmd framework, basically convert ext <msg> |
469 | # into pkg::->on_extcmd_arg1 (...) while shortcutting a few |
484 | # into pkg::->on_extcmd_arg1 (...) while shortcutting a few |
470 | |
485 | |
471 | sub on_extcmd { |
486 | attach_to_players |
|
|
487 | on_extcmd => sub { |
472 | my ($pl, $buf) = @_; |
488 | my ($pl, $buf) = @_; |
473 | |
489 | |
474 | my $msg = eval { from_json $buf }; |
490 | my $msg = eval { from_json $buf }; |
475 | |
491 | |
476 | if (ref $msg) { |
492 | if (ref $msg) { |
477 | if (my $cb = $extcmd{$msg->{msgtype}}) { |
493 | if (my $cb = $extcmd{$msg->{msgtype}}) { |
478 | if (my %reply = $cb->[0]->($pl, $msg)) { |
494 | if (my %reply = $cb->[0]->($pl, $msg)) { |
479 | $pl->ext_reply ($msg->{msgid}, %reply); |
495 | $pl->ext_reply ($msg->{msgid}, %reply); |
|
|
496 | } |
480 | } |
497 | } |
|
|
498 | } else { |
|
|
499 | warn "player " . ($pl->ob->name) . " sent unparseable ext message: <$buf>\n"; |
481 | } |
500 | } |
482 | } else { |
501 | |
483 | warn "player " . ($pl->ob->name) . " sent unparseable ext message: <$buf>\n"; |
502 | cf::override; |
484 | } |
503 | }, |
485 | |
504 | ; |
486 | 1 |
|
|
487 | } |
|
|
488 | |
505 | |
489 | ############################################################################# |
506 | ############################################################################# |
490 | # load/save/clean perl data associated with a map |
507 | # load/save/clean perl data associated with a map |
491 | |
508 | |
492 | *cf::mapsupport::on_clean = sub { |
509 | *cf::mapsupport::on_clean = sub { |