--- deliantra/server/ext/cfplus.ext 2007/06/19 18:14:36 1.7 +++ deliantra/server/ext/cfplus.ext 2010/04/11 04:52:07 1.17 @@ -21,13 +21,11 @@ =cut cf::register_extcmd cfplus_support => sub { - my ($pl, $msg) = @_; + my ($pl, %msg) = @_; - # $msg->{version} + $pl->ns->{cfplus_ext} = $msg{version}; - ( - version => 2, - ) + (version => $msg{version} >= 2 ? 2 : 0) }; sub dialog_tell { @@ -37,9 +35,9 @@ my ($reply, @kw) = $dialog->tell ($msg); $reply = "..." unless defined $reply; - return if $reply eq ""; # NPC doesn't want to say, or wants to say something later - $pl->ext_reply ($id => msgtype => "reply", msg => $reply, add_topics => \@kw); + $pl->ext_msg ($id, update => msg => $pl->expand_cfpod ($reply), add_topics => \@kw) + if $reply ne ""; # NPC might not want to say, or wants to say something later } =item ... = extcmd lookat { dx => $dx, dy => $dy } @@ -55,8 +53,7 @@ =cut cf::register_extcmd lookat => sub { - my ($pl, $msg) = @_; - my ($dx, $dy) = @$msg{qw(dx dy)}; + my ($pl, $dx, $dy) = @_; return unless $pl->ob && $pl->ob->map; @@ -66,8 +63,8 @@ if ($pl->cell_visible ($dx, $dy)) { for my $ob ($pl->ob->map->at ($pl->ob->x + $dx, $pl->ob->y + $dy)) { - $res{npc_dialog} = $ob->name - if $near && NPC_Dialogue::has_dialogue $ob && !$pl->{npc_dialog}; + $res{npc_dialog} = [$ob->name, $dx, $dy] + if $near && $ob->has_dialogue && !$pl->{npc_dialog}; } } @@ -87,16 +84,21 @@ =cut cf::register_extcmd npc_dialog_begin => sub { - my ($pl, $msg) = @_; - my ($id, $dx, $dy) = @$msg{qw(msgid dx dy)}; + my ($pl, $id, $token) = @_; + + #TODO: + # this is not a request, so returning does no good: make it a request and die on error return unless $pl->ob && $pl->ob->map; - return unless (abs $dx) <= 2 && (abs $dy) <= 2; - return unless $pl->cell_visible ($dx, $dy); - return if $pl->{npc_dialog}; # only one dialog at a time + + my ($name, $dx, $dy) = @$token; + + return (error => "too far away") unless (abs $dx) <= 2 && (abs $dy) <= 2; + return (error => "nothing to talk there") unless $pl->cell_visible ($dx, $dy); + return (error => "only one dialog can be open at a time") if $pl->{npc_dialog}; # only one dialog at a time for my $npc ($pl->ob->map->at ($pl->ob->x + $dx, $pl->ob->y + $dy)) { - if (NPC_Dialogue::has_dialogue $npc) { + if ($npc->has_dialogue) { $pl->attach ("npc_dialog_active"); $pl->{npc_dialog} = new NPC_Dialogue pl => $pl, npc => $npc, id => $id; dialog_tell $id, $pl->{npc_dialog}, "hi"; @@ -104,7 +106,7 @@ } } - (msgtype => "error", msg => "nothing to talk to found") + (error => "nothing to talk to to found") }; =item ... = extcmd npc_dialog_tell { msgid => $id, msg => $text } @@ -112,7 +114,6 @@ Tells the NPC the given $text message and returns a reply structure which can have the following keys: - msgtype => "reply" msg => $reply_text, add_topics => [additional topic strings] del_topics => [invalidated topic strings] @@ -120,13 +121,11 @@ =cut cf::register_extcmd npc_dialog_tell => sub { - my ($pl, $msg) = @_; + my ($pl, $id, $msg) = @_; if (my $dialog = $pl->{npc_dialog}) { - dialog_tell $msg->{msgid}, $dialog, $msg->{msg}; + dialog_tell $id, $dialog, $msg; } - - () }; =item extcmd npc_dialog_end { msgid => $id } @@ -136,13 +135,11 @@ =cut cf::register_extcmd npc_dialog_end => sub { - my ($pl, $msg) = @_; + my ($pl, $id) = @_; if (my $dialog = delete $pl->{npc_dialog}) { - $pl->detach ("ncpa_dialog_active"); + $pl->detach ("ncp_dialog_active"); } - - () }; =item ... = extcmd editor_support @@ -154,7 +151,7 @@ gameserver => the hostname:port of the normal game server testserver => the hostname:port of the test server the maps can be tested on cvs_root => the (http) url where the cvs root for downloading is located - lib_root => the (http) url where crossfire.0 and archetypes can be found + lib_root => the (http) url where archetypes data can be found upload => the (http) url where clients can upload maps If those values are not supplied or empty strings, the server does not @@ -168,22 +165,28 @@ mapdir: the cvs root url originally used to download the map revision: cvs-revision originally used to download the map comment: a comment supplied by the user that documents the changes - cf_login: crossfire server login - cf_password: crossfire server password, optionally used for authentication purposes + login: deliantra server login + password: deliantra server password, optionally used for authentication purposes =cut cf::register_extcmd editor_support => sub { - my ($pl, $msg) = @_; + my ($pl, %msg) = @_; - map +($_ => $cf::CFG{"editor_$_"}), qw(servertype gameserver testserver cvs_root lib_root builder_ui) + my %cfg = map +($_ => $cf::CFG{"editor_$_"}), qw(servertype servertypes gameserver testserver cvs_root lib_root builder_ui); + + # clients 2.10 and below check for type and "nameserver" :/ + $cfg{type} = $cfg{servertype}; + $cfg{nameserver} = $cfg{gameserver}; + + %cfg }; sub unload { for my $pl (cf::player::list) { if (my $dialog = delete $pl->{npc_dialog}) { $pl->detach ("npc_dialog_active"); - $pl->ext_reply ($dialog->{id} => msgtype => "error", msg => "npc dialogue module was reloaded"); + $pl->ext_msg ($dialog->{id} => error => "npc dialogue module was reloaded"); } } } @@ -195,26 +198,33 @@ delete $pl->{npc_dialog}; $pl->detach ("npc_dialog_active"); }, - on_move => sub { - my ($pl, $dir) = @_; - - if (my $dialog = $pl->{npc_dialog}) { - warn "on_move<@_>\n";#d# - warn $pl->ob; - warn $dialog; - warn $dialog->{npc}; - warn $dialog->{npc}->is_valid; - - my (undef, $dx, $dy) = $pl->ob->rangevector ($dialog->{npc}); - - return if (abs $dx) <= 2 && (abs $dy) <= 2; + on_map_change => sub { + my ($pl) = @_; - $pl->ext_reply ($dialog->{id} => msgtype => "error", msg => "out of range"); - } + my $dialog = delete $pl->{npc_dialog} + or return; - delete $pl->{npc_dialog}; + $pl->ext_msg ($dialog->{id} => error => "out of range"); $pl->detach ("npc_dialog_active"); }, + on_move => sub { + my ($pl, $dir) = @_; + + # must delay a bit :/ + my $delay; $delay = AE::timer 0, 0, sub { + undef $delay; + + if (my $dialog = $pl->{npc_dialog}) { + my (undef, $dx, $dy) = $pl->ob->rangevector ($dialog->{npc}); + + return if (abs $dx) <= 2 && (abs $dy) <= 2; + + delete $pl->{npc_dialog}; + $pl->ext_msg ($dialog->{id} => error => "out of range"); + $pl->detach ("npc_dialog_active"); + } + }; + }, ; cf::player->attach (