ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/setup.ext
Revision: 1.22
Committed: Tue Oct 30 15:05:27 2012 UTC (11 years, 6 months ago) by root
Branch: MAIN
Changes since 1.21: +43 -28 lines
Log Message:
setup JSONOBJECT

File Contents

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