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