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 |
root |
1.27 |
# 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 |
root |
1.1 |
|
22 |
|
|
} elsif ($k eq "mapinfocmd") { |
23 |
|
|
$ns->mapinfocmd ($v); |
24 |
|
|
|
25 |
|
|
} elsif ($k eq "extcmd") { |
26 |
root |
1.3 |
$ns->extcmd (min 2, $v); |
27 |
root |
1.1 |
|
28 |
|
|
} elsif ($k eq "tileset") { |
29 |
root |
1.26 |
$setup->{$k} = $ns->tileset (int cf::clamp $v, 0, 2); |
30 |
root |
1.1 |
|
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 |
root |
1.22 |
$setup->{$k} = $ns->itemcmd; |
38 |
root |
1.1 |
|
39 |
|
|
} elsif ($k eq "mapsize") { |
40 |
|
|
my ($x, $y) = split /x/, $v; |
41 |
|
|
|
42 |
root |
1.10 |
# 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 |
root |
1.1 |
|
47 |
root |
1.22 |
$setup->{$k} = "${x}x${y}"; |
48 |
root |
1.1 |
|
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 |
root |
1.7 |
} elsif ($k eq "widget") { |
56 |
|
|
# server-side widgets |
57 |
|
|
$v = $v > 1; |
58 |
|
|
$ns->{can_widget} = $v; |
59 |
root |
1.8 |
$ns->fx_want (6 => 1); # need support for RSRC |
60 |
root |
1.22 |
$setup->{$k} = $v ? 2 : 0; |
61 |
root |
1.1 |
|
62 |
root |
1.9 |
} 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 |
root |
1.1 |
} 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 |
root |
1.22 |
$setup->{$k} = "FALSE"; |
80 |
root |
1.1 |
} |
81 |
root |
1.19 |
} |
82 |
|
|
|
83 |
|
|
# force some mandatory protocol options, most of these |
84 |
|
|
# are for obsolete clients only |
85 |
root |
1.24 |
# $setup->{darkness} = 1; |
86 |
|
|
# $setup->{exp64} = 1; |
87 |
root |
1.25 |
$setup->{extmap} = 1 if exists $setup->{extmap}; |
88 |
root |
1.24 |
# $setup->{facecache} = 1; |
89 |
root |
1.25 |
$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 |
root |
1.19 |
|
94 |
|
|
cf::datalog setup => |
95 |
root |
1.22 |
request => \%orig, |
96 |
|
|
reply => $setup, |
97 |
root |
1.19 |
; |
98 |
root |
1.22 |
} |
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 |
root |
1.1 |
}); |
120 |
|
|
|