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