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 "faceset") { |
27 |
root |
1.18 |
$ns->faceset (0); |
28 |
root |
1.22 |
$setup->{$k} = 0; |
29 |
root |
1.1 |
# $ns->image2 (1) |
30 |
|
|
|
31 |
|
|
} elsif ($k eq "tileset") { |
32 |
root |
1.22 |
$setup->{$k} = $ns->faceset (int cf::clamp $v, 0, 2); |
33 |
root |
1.1 |
|
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 |
root |
1.22 |
$setup->{$k} = $ns->itemcmd; |
41 |
root |
1.1 |
|
42 |
|
|
} elsif ($k eq "mapsize") { |
43 |
|
|
my ($x, $y) = split /x/, $v; |
44 |
|
|
|
45 |
root |
1.10 |
# 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 |
root |
1.1 |
|
50 |
root |
1.22 |
$setup->{$k} = "${x}x${y}"; |
51 |
root |
1.1 |
|
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 |
root |
1.7 |
} elsif ($k eq "widget") { |
59 |
|
|
# server-side widgets |
60 |
|
|
$v = $v > 1; |
61 |
|
|
$ns->{can_widget} = $v; |
62 |
root |
1.8 |
$ns->fx_want (6 => 1); # need support for RSRC |
63 |
root |
1.22 |
$setup->{$k} = $v ? 2 : 0; |
64 |
root |
1.1 |
|
65 |
root |
1.9 |
} 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 |
root |
1.1 |
} 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 |
root |
1.22 |
$setup->{$k} = "FALSE"; |
83 |
root |
1.1 |
} |
84 |
root |
1.19 |
} |
85 |
|
|
|
86 |
|
|
# force some mandatory protocol options, most of these |
87 |
|
|
# are for obsolete clients only |
88 |
root |
1.24 |
# $setup->{darkness} = 1; |
89 |
|
|
# $setup->{exp64} = 1; |
90 |
root |
1.22 |
$setup->{extmap} = 1; |
91 |
root |
1.24 |
# $setup->{facecache} = 1; |
92 |
root |
1.22 |
$setup->{fxix} = 3; |
93 |
|
|
$setup->{map1acmd} = 1; |
94 |
|
|
$setup->{map1cmd} = 0; |
95 |
|
|
$setup->{msg} = 1; |
96 |
root |
1.19 |
|
97 |
|
|
cf::datalog setup => |
98 |
root |
1.22 |
request => \%orig, |
99 |
|
|
reply => $setup, |
100 |
root |
1.19 |
; |
101 |
root |
1.22 |
} |
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 |
root |
1.1 |
}); |
123 |
|
|
|