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.592 by root, Fri Nov 9 00:11:49 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 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines