--- deliantra/server/ext/setup.ext 2008/08/31 10:05:26 1.9 +++ deliantra/server/ext/setup.ext 2012/11/21 13:22:34 1.27 @@ -2,82 +2,31 @@ # the setup command +use JSON::XS (); use List::Util qw(min max); -sub send_capabilities { - my ($ns) = @_; +sub do_setup { + my ($ns, $setup) = @_; - return unless $ns->extcmd; + my %orig = %$setup; - $ns->ext_msg (capabilities => - # id, name, flags (1 == 2d), edge length - tileset => [[1, "default 64x64 faceset", 1, 64], [0, "default 32x32 faceset", 1, 32]], - ); -} - -cf::client->attach (on_setup => sub { - my ($ns, $args) = @_; - - # run through the cmds of setup - # syntax is setup ... - # - # we send the status of the cmd back, or a FALSE is the cmd is the server unknown - # The client then must sort this out - - my %setup = split / +/, $args; - while (my ($k, $v) = each %setup) { + while (my ($k, $v) = each %$setup) { if ($k eq "sound") { $ns->sound ($v); - } elsif ($k eq "exp64") { - $setup{$k} = 1; - } elsif ($k eq "spellmon") { - $ns->monitor_spells ($v); - - } elsif ($k eq "darkness") { - $ns->darkness ($v); - - } elsif ($k eq "map1cmd") { - $ns->mapmode (cf::Map1Cmd) if $v > 0; - - } elsif ($k eq "map1acmd") { - $ns->mapmode (cf::Map1aCmd) if $v > 0; - - } elsif ($k eq "map2cmd") { - # gcfclient bug, map1acmd is sent too late - $ns->mapmode (cf::Map1aCmd); - $setup{$k} = "FALSE"; - - } elsif ($k eq "newmapcmd") { - $ns->newmapcmd ($v); + # version 1 - enable addspell etc. + # version 2 - no documentation in addspell + $setup->{$k} = $ns->monitor_spells (int cf::clamp $v, 0, 2); } elsif ($k eq "mapinfocmd") { $ns->mapinfocmd ($v); } elsif ($k eq "extcmd") { $ns->extcmd (min 2, $v); - send_capabilities $ns; - - } elsif ($k eq "extmap") { - $ns->extmap ($v); - - } elsif ($k eq "facecache") { - if (!$v) { - $v = 1; - $setup{$k} = $v; - $ns->send_drawinfo ("(trying to forcefully enable facecaching)", cf::NDI_RED); - } - - $ns->facecache ($v); - - } elsif ($k eq "faceset") { - $ns->faceset (0); - $setup{$k} = 0; - # $ns->image2 (1) } elsif ($k eq "tileset") { - $setup{$k} = $ns->faceset ($v & 1); + $setup->{$k} = $ns->tileset (int cf::clamp $v, 0, 2); } elsif ($k eq "itemcmd") { # Version of the item protocol command to use. Currently, @@ -85,18 +34,17 @@ # value will make it very easy to extend this in the future. $ns->itemcmd ($v) if $v >= 1 && $v <= 2; - $setup{$k} = $ns->itemcmd; + $setup->{$k} = $ns->itemcmd; } elsif ($k eq "mapsize") { my ($x, $y) = split /x/, $v; - $ns->mapx ($x = max 9, min cf::MAP_CLIENT_X, ($x - 1) | 1); - $ns->mapy ($y = max 9, min cf::MAP_CLIENT_Y, ($y - 1) | 1); + # we *need* to make sure we use an odd map size, as the remaining + # code relies on this. + $ns->mapx ($x = max 9, min +(cf::MAP_CLIENT_X - 1) | 1, ($x - 1) | 1); + $ns->mapy ($y = max 9, min +(cf::MAP_CLIENT_Y - 1) | 1, ($y - 1) | 1); - $setup{$k} = "${x}x${y}"; - - } elsif ($k eq "extendedMapInfos") { - $ns->ext_mapinfos ($v); + $setup->{$k} = "${x}x${y}"; } elsif ($k eq "extendedTextInfos") { $ns->has_readable_type ($v); @@ -104,18 +52,12 @@ } elsif ($k eq "smoothing") { # cfplus-style smoothing $ns->smoothing ($v); - } elsif ($k eq "fxix") { - $ns->fxix ($setup{$k} = min 3, $v); - - } elsif ($k eq "msg") { - $ns->can_msg ($setup{$k} = min 2, $v); - } elsif ($k eq "widget") { # server-side widgets $v = $v > 1; $ns->{can_widget} = $v; $ns->fx_want (6 => 1); # need support for RSRC - $setup{$k} = $v ? 2 : 0; + $setup->{$k} = $v ? 2 : 0; } elsif ($k eq "lzf") { # the lzf packet simply contains an lzf-compressed packet as argument @@ -134,17 +76,45 @@ # sexp: no idea, probably for oudated servers # tick: more stupidity, server should send a tick per tick - $setup{$k} = "FALSE"; + $setup->{$k} = "FALSE"; } - } + } + + # force some mandatory protocol options, most of these + # are for obsolete clients only +# $setup->{darkness} = 1; +# $setup->{exp64} = 1; + $setup->{extmap} = 1 if exists $setup->{extmap}; +# $setup->{facecache} = 1; + $setup->{fxix} = 3 if exists $setup->{fxix}; + $setup->{map1acmd} = 1 if exists $setup->{map1acmd}; + $setup->{map1cmd} = 0 if exists $setup->{map1cmd}; + $setup->{msg} = 1 if exists $setup->{msg}; + + cf::datalog setup => + request => \%orig, + reply => $setup, + ; +} - $ns->send_packet (join " ", setup => %setup); +cf::client->attach (on_setup => sub { + my ($ns, $args) = @_; - cf::datalog setup => - request => $args, - reply => \%setup, - client => $ns->version, - ; + # run through the cmds of setup + # syntax is setup ... + # or setup json-object + # + # we send the status of the cmd back, or a FALSE is the cmd if the server unknown + # the client then must sort this out + + if ($args =~ /^\s*\{/) { + my $setup = eval { JSON::XS::decode_json $args } || {}; + do_setup $ns, $setup; + $ns->send_packet ("setup " . JSON::XS::encode_json $setup); + } else { + my %setup = split / +/, $args; + do_setup $ns, \%setup; + $ns->send_packet (join " ", setup => %setup); + } }); -