ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/setup.ext
(Generate patch)

Comparing deliantra/server/ext/setup.ext (file contents):
Revision 1.20 by root, Mon Oct 18 09:33:10 2010 UTC vs.
Revision 1.25 by root, Sun Nov 4 02:23:30 2012 UTC

1#! perl # mandatory 1#! perl # mandatory
2 2
3# the setup command 3# the setup command
4 4
5use JSON::XS ();
5use List::Util qw(min max); 6use List::Util qw(min max);
6 7
7sub send_capabilities { 8sub do_setup {
8 my ($ns) = @_; 9 my ($ns, $setup) = @_;
9 10
10 return unless $ns->extcmd; 11 my %orig = %$setup;
11 12
12 $ns->ext_msg (capabilities =>
13 # id, name, flags (1 == 2d), edge length
14 tileset => [[1, "default 64x64 faceset", 1, 64], [0, "default 32x32 faceset", 1, 32], [2, "default text faceset", 2, 1]],
15 );
16}
17
18cf::client->attach (on_setup => sub {
19 my ($ns, $args) = @_;
20
21 # run through the cmds of setup
22 # syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ...
23 #
24 # we send the status of the cmd back, or a FALSE is the cmd if the server unknown
25 # the client then must sort this out
26
27 my %setup = split / +/, $args;
28 while (my ($k, $v) = each %setup) { 13 while (my ($k, $v) = each %$setup) {
29 if ($k eq "sound") { 14 if ($k eq "sound") {
30 $ns->sound ($v); 15 $ns->sound ($v);
31 16
32 } elsif ($k eq "spellmon") { 17 } elsif ($k eq "spellmon") {
33 $ns->monitor_spells ($v); 18 $ns->monitor_spells ($v);
35 } elsif ($k eq "mapinfocmd") { 20 } elsif ($k eq "mapinfocmd") {
36 $ns->mapinfocmd ($v); 21 $ns->mapinfocmd ($v);
37 22
38 } elsif ($k eq "extcmd") { 23 } elsif ($k eq "extcmd") {
39 $ns->extcmd (min 2, $v); 24 $ns->extcmd (min 2, $v);
40 send_capabilities $ns;
41 25
42 } elsif ($k eq "faceset") { 26 } elsif ($k eq "faceset") {
43 $ns->faceset (0); 27 $ns->faceset (0);
44 $setup{$k} = 0; 28 $setup->{$k} = 0;
45 # $ns->image2 (1) 29 # $ns->image2 (1)
46 30
47 } elsif ($k eq "tileset") { 31 } elsif ($k eq "tileset") {
48 $setup{$k} = $ns->faceset (int cf::clamp $v, 0, 2); 32 $setup->{$k} = $ns->faceset (int cf::clamp $v, 0, 2);
49 33
50 } elsif ($k eq "itemcmd") { 34 } elsif ($k eq "itemcmd") {
51 # Version of the item protocol command to use. Currently, 35 # Version of the item protocol command to use. Currently,
52 # only supported versions are 1 and 2. Using a numeric 36 # only supported versions are 1 and 2. Using a numeric
53 # value will make it very easy to extend this in the future. 37 # value will make it very easy to extend this in the future.
54 $ns->itemcmd ($v) if $v >= 1 && $v <= 2; 38 $ns->itemcmd ($v) if $v >= 1 && $v <= 2;
55 39
56 $setup{$k} = $ns->itemcmd; 40 $setup->{$k} = $ns->itemcmd;
57 41
58 } elsif ($k eq "mapsize") { 42 } elsif ($k eq "mapsize") {
59 my ($x, $y) = split /x/, $v; 43 my ($x, $y) = split /x/, $v;
60 44
61 # we *need* to make sure we use an odd map size, as the remaining 45 # we *need* to make sure we use an odd map size, as the remaining
62 # code relies on this. 46 # code relies on this.
63 $ns->mapx ($x = max 9, min +(cf::MAP_CLIENT_X - 1) | 1, ($x - 1) | 1); 47 $ns->mapx ($x = max 9, min +(cf::MAP_CLIENT_X - 1) | 1, ($x - 1) | 1);
64 $ns->mapy ($y = max 9, min +(cf::MAP_CLIENT_Y - 1) | 1, ($y - 1) | 1); 48 $ns->mapy ($y = max 9, min +(cf::MAP_CLIENT_Y - 1) | 1, ($y - 1) | 1);
65 49
66 $setup{$k} = "${x}x${y}"; 50 $setup->{$k} = "${x}x${y}";
67 51
68 } elsif ($k eq "extendedTextInfos") { 52 } elsif ($k eq "extendedTextInfos") {
69 $ns->has_readable_type ($v); 53 $ns->has_readable_type ($v);
70 54
71 } elsif ($k eq "smoothing") { # cfplus-style smoothing 55 } elsif ($k eq "smoothing") { # cfplus-style smoothing
74 } elsif ($k eq "widget") { 58 } elsif ($k eq "widget") {
75 # server-side widgets 59 # server-side widgets
76 $v = $v > 1; 60 $v = $v > 1;
77 $ns->{can_widget} = $v; 61 $ns->{can_widget} = $v;
78 $ns->fx_want (6 => 1); # need support for RSRC 62 $ns->fx_want (6 => 1); # need support for RSRC
79 $setup{$k} = $v ? 2 : 0; 63 $setup->{$k} = $v ? 2 : 0;
80 64
81 } elsif ($k eq "lzf") { 65 } elsif ($k eq "lzf") {
82 # the lzf packet simply contains an lzf-compressed packet as argument 66 # the lzf packet simply contains an lzf-compressed packet as argument
83 $ns->{can_lzf} = $v == 1; 67 $ns->{can_lzf} = $v == 1;
84 68
93 } else { 77 } else {
94 # other commands: 78 # other commands:
95 # sexp: no idea, probably for oudated servers 79 # sexp: no idea, probably for oudated servers
96 # tick: more stupidity, server should send a tick per tick 80 # tick: more stupidity, server should send a tick per tick
97 81
98 $setup{$k} = "FALSE"; 82 $setup->{$k} = "FALSE";
99 } 83 }
100 } 84 }
101 85
102 # force some mandatory protocol options, most of these 86 # force some mandatory protocol options, most of these
103 # are for obsolete clients only 87 # are for obsolete clients only
104 $setup{darkness} = 1; 88# $setup->{darkness} = 1;
105 $setup{exp64} = 1; 89# $setup->{exp64} = 1;
106 $setup{extmap} = 1; 90 $setup->{extmap} = 1 if exists $setup->{extmap};
107 $setup{facecache} = 1; 91# $setup->{facecache} = 1;
108 $setup{fxix} = 3; 92 $setup->{fxix} = 3 if exists $setup->{fxix};
109 $setup{map1acmd} = 1; 93 $setup->{map1acmd} = 1 if exists $setup->{map1acmd};
110 $setup{map1cmd} = 0; 94 $setup->{map1cmd} = 0 if exists $setup->{map1cmd};
111 $setup{msg} = 1; 95 $setup->{msg} = 1 if exists $setup->{msg};
112 $setup{newmapcmd} = 1;
113
114
115 $ns->send_packet (join " ", setup => %setup);
116 96
117 cf::datalog setup => 97 cf::datalog setup =>
118 request => $args, 98 request => \%orig,
119 reply => \%setup, 99 reply => $setup,
120 ; 100 ;
101}
102
103cf::client->attach (on_setup => sub {
104 my ($ns, $args) = @_;
105
106 # run through the cmds of setup
107 # syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ...
108 # or setup json-object
109 #
110 # we send the status of the cmd back, or a FALSE is the cmd if the server unknown
111 # the client then must sort this out
112
113 if ($args =~ /^\s*\{/) {
114 my $setup = eval { JSON::XS::decode_json $args } || {};
115 do_setup $ns, $setup;
116 $ns->send_packet ("setup " . JSON::XS::encode_json $setup);
117 } else {
118 my %setup = split / +/, $args;
119 do_setup $ns, \%setup;
120 $ns->send_packet (join " ", setup => %setup);
121 }
121}); 122});
122 123

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines