ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/setup.ext
Revision: 1.26
Committed: Sun Nov 11 05:53:11 2012 UTC (11 years, 6 months ago) by root
Branch: MAIN
Changes since 1.25: +1 -6 lines
Log Message:
move face blob manegemnt fully to perl

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