… | |
… | |
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 | |
1438 | Register a callback for execution when the client sends the user command |
1438 | Register 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 | |
1454 | Register a callback for execution when the client sends an (synchronous) |
1454 | Register a callback for execution when the client sends an (synchronous) |
1455 | extcmd packet. Ext commands will be processed in the order they are |
1455 | extcmd packet. Ext commands will be processed in the order they are |
1456 | received by the server, like other user commands. The first argument is |
1456 | received by the server, like other user commands. The first argument is |
1457 | the logged-in player. Ext commands can only be processed after a player |
1457 | the logged-in player. Ext commands can only be processed after a player |
1458 | has logged in successfully. |
1458 | has logged in successfully. |
1459 | |
1459 | |
1460 | If the callback returns something, it is sent back as if reply was being |
1460 | If the callback returns something, it is sent back as if reply was being |
1461 | called. |
1461 | called. |
1462 | |
1462 | |
1463 | =item cf::register_exticmd $name => \&callback($ns,$packet); |
1463 | =item cf::register_exticmd $name => \&callback($ns,$packet) |
1464 | |
1464 | |
1465 | Register a callback for execution when the client sends an (asynchronous) |
1465 | Register a callback for execution when the client sends an (asynchronous) |
1466 | exticmd packet. Exti commands are processed by the server as soon as they |
1466 | exticmd packet. Exti commands are processed by the server as soon as they |
1467 | are received, i.e. out of order w.r.t. other commands. The first argument |
1467 | are received, i.e. out of order w.r.t. other commands. The first argument |
1468 | is a client socket. Exti commands can be received anytime, even before |
1468 | is 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 | |
1913 | Expand deliantra pod fragments into protocol xml. |
1913 | Expand deliantra pod fragments into protocol xml. |
1914 | |
|
|
1915 | =item $player->ext_reply ($msgid, @msg) |
|
|
1916 | |
|
|
1917 | Sends an ext reply to the player. |
|
|
1918 | |
|
|
1919 | =cut |
|
|
1920 | |
|
|
1921 | sub 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 | |
1929 | Sends an ext event to the client. |
1917 | Sends 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 | |
|
|
3245 | Sends an ext reply to the client. |
|
|
3246 | |
|
|
3247 | =cut |
|
|
3248 | |
|
|
3249 | sub 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 | |
3257 | Queues a query to the client, calling the given callback with |
3233 | Queues a query to the client, calling the given callback with |
3258 | the reply text on a reply. flags can be C<cf::CS_QUERY_YESNO>, |
3234 | the reply text on a reply. flags can be C<cf::CS_QUERY_YESNO>, |
3259 | C<cf::CS_QUERY_SINGLECHAR> or C<cf::CS_QUERY_HIDEINPUT> or C<0>. |
3235 | C<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 | } |