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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines