ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/setup.ext
Revision: 1.25
Committed: Sun Nov 4 02:23:30 2012 UTC (11 years, 6 months ago) by root
Branch: MAIN
Changes since 1.24: +5 -5 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #! perl # mandatory
2
3 # the setup command
4
5 use JSON::XS ();
6 use List::Util qw(min max);
7
8 sub do_setup {
9 my ($ns, $setup) = @_;
10
11 my %orig = %$setup;
12
13 while (my ($k, $v) = each %$setup) {
14 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 $ns->extcmd (min 2, $v);
25
26 } elsif ($k eq "faceset") {
27 $ns->faceset (0);
28 $setup->{$k} = 0;
29 # $ns->image2 (1)
30
31 } elsif ($k eq "tileset") {
32 $setup->{$k} = $ns->faceset (int cf::clamp $v, 0, 2);
33
34 } elsif ($k eq "itemcmd") {
35 # Version of the item protocol command to use. Currently,
36 # only supported versions are 1 and 2. Using a numeric
37 # value will make it very easy to extend this in the future.
38 $ns->itemcmd ($v) if $v >= 1 && $v <= 2;
39
40 $setup->{$k} = $ns->itemcmd;
41
42 } elsif ($k eq "mapsize") {
43 my ($x, $y) = split /x/, $v;
44
45 # we *need* to make sure we use an odd map size, as the remaining
46 # code relies on this.
47 $ns->mapx ($x = max 9, min +(cf::MAP_CLIENT_X - 1) | 1, ($x - 1) | 1);
48 $ns->mapy ($y = max 9, min +(cf::MAP_CLIENT_Y - 1) | 1, ($y - 1) | 1);
49
50 $setup->{$k} = "${x}x${y}";
51
52 } elsif ($k eq "extendedTextInfos") {
53 $ns->has_readable_type ($v);
54
55 } elsif ($k eq "smoothing") { # cfplus-style smoothing
56 $ns->smoothing ($v);
57
58 } elsif ($k eq "widget") {
59 # server-side widgets
60 $v = $v > 1;
61 $ns->{can_widget} = $v;
62 $ns->fx_want (6 => 1); # need support for RSRC
63 $setup->{$k} = $v ? 2 : 0;
64
65 } elsif ($k eq "lzf") {
66 # the lzf packet simply contains an lzf-compressed packet as argument
67 $ns->{can_lzf} = $v == 1;
68
69 } elsif ($k eq "frag") {
70 # the frag packet contains data which gets appended to the existing packet buffer.
71 # empty frag packet means end of packet.
72 $ns->{can_frag} = $v == 1;
73
74 } elsif ($k eq "excmd") {
75 # we support it
76
77 } else {
78 # other commands:
79 # sexp: no idea, probably for oudated servers
80 # tick: more stupidity, server should send a tick per tick
81
82 $setup->{$k} = "FALSE";
83 }
84 }
85
86 # force some mandatory protocol options, most of these
87 # are for obsolete clients only
88 # $setup->{darkness} = 1;
89 # $setup->{exp64} = 1;
90 $setup->{extmap} = 1 if exists $setup->{extmap};
91 # $setup->{facecache} = 1;
92 $setup->{fxix} = 3 if exists $setup->{fxix};
93 $setup->{map1acmd} = 1 if exists $setup->{map1acmd};
94 $setup->{map1cmd} = 0 if exists $setup->{map1cmd};
95 $setup->{msg} = 1 if exists $setup->{msg};
96
97 cf::datalog setup =>
98 request => \%orig,
99 reply => $setup,
100 ;
101 }
102
103 cf::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 }
122 });
123