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.591 by root, Tue Nov 6 23:33:15 2012 UTC vs.
Revision 1.593 by root, Fri Nov 9 01:59:33 2012 UTC

1431=cut 1431=cut
1432 1432
1433############################################################################# 1433#############################################################################
1434# command handling &c 1434# command handling &c
1435 1435
1436=item cf::register_command $name => \&callback($ob,$args); 1436=item cf::register_command $name => \&callback($ob,$args)
1437 1437
1438Register a callback for execution when the client sends the user command 1438Register a callback for execution when the client sends the user command
1439$name. 1439$name.
1440 1440
1441=cut 1441=cut
1447 #warn "registering command '$name/$time' to '$caller'"; 1447 #warn "registering command '$name/$time' to '$caller'";
1448 1448
1449 push @{ $COMMAND{$name} }, [$caller, $cb]; 1449 push @{ $COMMAND{$name} }, [$caller, $cb];
1450} 1450}
1451 1451
1452=item cf::register_extcmd $name => \&callback($pl,$packet); 1452=item cf::register_extcmd $name => \&callback($pl,$packet)
1453 1453
1454Register a callback for execution when the client sends an (synchronous) 1454Register a callback for execution when the client sends an (synchronous)
1455extcmd packet. Ext commands will be processed in the order they are 1455extcmd packet. Ext commands will be processed in the order they are
1456received by the server, like other user commands. The first argument is 1456received by the server, like other user commands. The first argument is
1457the logged-in player. Ext commands can only be processed after a player 1457the logged-in player. Ext commands can only be processed after a player
1458has logged in successfully. 1458has logged in successfully.
1459 1459
1460If the callback returns something, it is sent back as if reply was being 1460If the callback returns something, it is sent back as if reply was being
1461called. 1461called.
1462 1462
1463=item cf::register_exticmd $name => \&callback($ns,$packet); 1463=item cf::register_exticmd $name => \&callback($ns,$packet)
1464 1464
1465Register a callback for execution when the client sends an (asynchronous) 1465Register a callback for execution when the client sends an (asynchronous)
1466exticmd packet. Exti commands are processed by the server as soon as they 1466exticmd packet. Exti commands are processed by the server as soon as they
1467are received, i.e. out of order w.r.t. other commands. The first argument 1467are received, i.e. out of order w.r.t. other commands. The first argument
1468is a client socket. Exti commands can be received anytime, even before 1468is a client socket. Exti commands can be received anytime, even before
1512 1512
1513 if (my $cb = $EXTCMD{$type}) { 1513 if (my $cb = $EXTCMD{$type}) {
1514 @reply = $cb->($pl, @payload); 1514 @reply = $cb->($pl, @payload);
1515 } 1515 }
1516 1516
1517 $pl->ext_reply ($reply, @reply) 1517 $pl->ext_msg ("reply-$reply", @reply)
1518 if $reply; 1518 if $reply;
1519 1519
1520 } else { 1520 } else {
1521 error "player " . ($pl->ob->name) . " sent unparseable ext message: <$buf>\n"; 1521 error "player " . ($pl->ob->name) . " sent unparseable ext message: <$buf>\n";
1522 } 1522 }
1909} 1909}
1910 1910
1911=item $protocol_xml = $player->expand_cfpod ($cfpod) 1911=item $protocol_xml = $player->expand_cfpod ($cfpod)
1912 1912
1913Expand deliantra pod fragments into protocol xml. 1913Expand deliantra pod fragments into protocol xml.
1914
1915=item $player->ext_reply ($msgid, @msg)
1916
1917Sends an ext reply to the player.
1918
1919=cut
1920
1921sub ext_reply($$@) {
1922 my ($self, $id, @msg) = @_;
1923
1924 $self->ns->ext_reply ($id, @msg)
1925}
1926 1914
1927=item $player->ext_msg ($type, @msg) 1915=item $player->ext_msg ($type, @msg)
1928 1916
1929Sends an ext event to the client. 1917Sends an ext event to the client.
1930 1918
3238 my ($self, $type, @msg) = @_; 3226 my ($self, $type, @msg) = @_;
3239 3227
3240 $self->send_big_packet ("ext " . $self->{json_coder}->encode ([$type, @msg])); 3228 $self->send_big_packet ("ext " . $self->{json_coder}->encode ([$type, @msg]));
3241} 3229}
3242 3230
3243=item $client->ext_reply ($msgid, @msg)
3244
3245Sends an ext reply to the client.
3246
3247=cut
3248
3249sub cf::client::ext_reply($$@) {
3250 my ($self, $id, @msg) = @_;
3251
3252 $self->send_big_packet ("ext " . $self->{json_coder}->encode (["reply-$id", @msg]));
3253}
3254
3255=item $success = $client->query ($flags, "text", \&cb) 3231=item $success = $client->query ($flags, "text", \&cb)
3256 3232
3257Queues a query to the client, calling the given callback with 3233Queues a query to the client, calling the given callback with
3258the reply text on a reply. flags can be C<cf::CS_QUERY_YESNO>, 3234the reply text on a reply. flags can be C<cf::CS_QUERY_YESNO>,
3259C<cf::CS_QUERY_SINGLECHAR> or C<cf::CS_QUERY_HIDEINPUT> or C<0>. 3235C<cf::CS_QUERY_SINGLECHAR> or C<cf::CS_QUERY_HIDEINPUT> or C<0>.
3320 3296
3321 if (my $cb = $EXTICMD{$type}) { 3297 if (my $cb = $EXTICMD{$type}) {
3322 @reply = $cb->($ns, @payload); 3298 @reply = $cb->($ns, @payload);
3323 } 3299 }
3324 3300
3325 $ns->ext_reply ($reply, @reply) 3301 $ns->ext_msg ("reply-$reply", @reply)
3326 if $reply; 3302 if $reply;
3327 3303
3328 } else { 3304 } else {
3329 error "client " . ($ns->pl ? $ns->pl->ob->name : $ns->host) . " sent unparseable exti message: <$buf>\n"; 3305 error "client " . ($ns->pl ? $ns->pl->ob->name : $ns->host) . " sent unparseable exti message: <$buf>\n";
3330 } 3306 }
3701 my $face = cf::face::find "sound/$v"; 3677 my $face = cf::face::find "sound/$v";
3702 cf::sound::set $k => $face; 3678 cf::sound::set $k => $face;
3703 } 3679 }
3704} 3680}
3705 3681
3682#d# move docstuff to help or so
3683our %DOCSTRING;
3684
3706sub reload_pod { 3685sub reload_pod {
3707 trace "loading pods $PODDIR\n"; 3686 trace "loading pods $PODDIR\n";
3708 3687
3688 %DOCSTRING = ();
3709 my @command_help; 3689 my @command_list;
3710 3690
3711 for ( 3691 for (
3712 [0, "command_help"], 3692 [0, "command_help"],
3713 [1, "emote_help"], 3693 [1, "emote_help"],
3714 [2, "dmcommand_help"], 3694 [2, "dmcommand_help"],
3717 3697
3718 my $paragraphs = &cf::pod::load_pod ("$PODDIR/$path.pod") 3698 my $paragraphs = &cf::pod::load_pod ("$PODDIR/$path.pod")
3719 or die "unable to load $path"; 3699 or die "unable to load $path";
3720 3700
3721 my $level = 1e9; 3701 my $level = 1e9;
3702 my $rpar;
3722 3703
3723 for my $par (@$paragraphs) { 3704 for my $par (@$paragraphs) {
3724 if ($par->{type} eq "head2") { 3705 if ($par->{type} eq "head2") {
3725 # this code taken almost verbatim from DC/Protocol.pm 3706 # this code taken almost verbatim from DC/Protocol.pm
3726 3707
3732 $_ = $_ eq ".*" ? "" : " $_" 3713 $_ = $_ eq ".*" ? "" : " $_"
3733 for @args; 3714 for @args;
3734 3715
3735 my @variants = map "$cmd$_", sort { (length $a) <=> (length $b) } @args; 3716 my @variants = map "$cmd$_", sort { (length $a) <=> (length $b) } @args;
3736 3717
3737 push @command_help, [$type, \@variants, &cf::pod::as_cfpod ([$par])]; 3718 $rpar = \($DOCSTRING{"command/$cmd"} = &cf::pod::as_cfpod ([$par]));
3719
3720 push @command_list, [$type, \@variants];
3738 $level = $par->{level}; 3721 $level = $par->{level};
3739 } else { 3722 } else {
3740 error "$par->{markup}: unparsable command heading"; 3723 error "$par->{markup}: unparsable command heading";
3741 } 3724 }
3742 } elsif ($par->{level} > $level) { 3725 } elsif ($par->{level} > $level) {
3743 $command_help[-1][2] .= &cf::pod::as_cfpod ([$par]); 3726 $$rpar .= &cf::pod::as_cfpod ([$par]);
3744 } 3727 }
3745 3728
3746 cf::cede_to_tick; 3729 cf::cede_to_tick;
3747 } 3730 }
3748 } 3731 }
3749 3732
3750 @command_help = sort { 3733 @command_list = sort {
3751 $a->[0] <=> $b->[0] 3734 $a->[0] <=> $b->[0]
3752 or $a->[1] cmp $b->[1] 3735 or $a->[1] cmp $b->[1]
3753 } @command_help; 3736 } @command_list;
3754 3737
3755 cf::cede_to_tick; 3738 cf::cede_to_tick;
3756 3739
3757 add_face "res/command_help" => FT_RSRC, 3740 add_face "res/command_list" => FT_RSRC,
3758 JSON::XS->new->utf8->encode (\@command_help); 3741 JSON::XS->new->utf8->encode (\@command_list);
3759} 3742}
3760 3743
3761sub reload_resources { 3744sub reload_resources {
3762 trace "reloading resource files...\n"; 3745 trace "reloading resource files...\n";
3763 3746

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines