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 |
$ns->ext_msg (capabilities => |
13 |
# id, name, flags (1 == 2d), edge length |
14 |
tileset => [[1, "default 64x64 faceset", 1, 64], [0, "default 32x32 faceset", 1, 32], [2, "default text faceset", 2, 1]], |
15 |
); |
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 |
# we send the status of the cmd back, or a FALSE is the cmd is the server unknown |
25 |
# The client then must sort this out |
26 |
|
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 "exp64") { |
33 |
$setup{$k} = 1; |
34 |
|
35 |
} elsif ($k eq "spellmon") { |
36 |
$ns->monitor_spells ($v); |
37 |
|
38 |
} elsif ($k eq "darkness") { |
39 |
$setup{$k} = 1; |
40 |
|
41 |
} elsif ($k eq "map1cmd") { |
42 |
$ns->mapmode (cf::Map1Cmd) if $v > 0; |
43 |
|
44 |
} elsif ($k eq "map1acmd") { |
45 |
$ns->mapmode (cf::Map1aCmd) if $v > 0; |
46 |
|
47 |
} elsif ($k eq "newmapcmd") { |
48 |
$ns->newmapcmd ($v); |
49 |
|
50 |
} elsif ($k eq "mapinfocmd") { |
51 |
$ns->mapinfocmd ($v); |
52 |
|
53 |
} elsif ($k eq "extcmd") { |
54 |
$ns->extcmd (min 2, $v); |
55 |
send_capabilities $ns; |
56 |
|
57 |
} elsif ($k eq "extmap") { |
58 |
$setup{$k} = 1; |
59 |
|
60 |
} elsif ($k eq "facecache") { |
61 |
$setup{$k} = 1; |
62 |
|
63 |
} elsif ($k eq "faceset") { |
64 |
$v = int cf::clamp $v, 0, 2; |
65 |
$ns->faceset ($v); |
66 |
$setup{$k} = $v; |
67 |
# $ns->image2 (1) |
68 |
|
69 |
} elsif ($k eq "tileset") { |
70 |
$setup{$k} = $ns->faceset ($v & 1); |
71 |
|
72 |
} elsif ($k eq "itemcmd") { |
73 |
# Version of the item protocol command to use. Currently, |
74 |
# only supported versions are 1 and 2. Using a numeric |
75 |
# value will make it very easy to extend this in the future. |
76 |
$ns->itemcmd ($v) if $v >= 1 && $v <= 2; |
77 |
|
78 |
$setup{$k} = $ns->itemcmd; |
79 |
|
80 |
} elsif ($k eq "mapsize") { |
81 |
my ($x, $y) = split /x/, $v; |
82 |
|
83 |
# we *need* to make sure we use an odd map size, as the remaining |
84 |
# code relies on this. |
85 |
$ns->mapx ($x = max 9, min +(cf::MAP_CLIENT_X - 1) | 1, ($x - 1) | 1); |
86 |
$ns->mapy ($y = max 9, min +(cf::MAP_CLIENT_Y - 1) | 1, ($y - 1) | 1); |
87 |
|
88 |
$setup{$k} = "${x}x${y}"; |
89 |
|
90 |
} elsif ($k eq "extendedTextInfos") { |
91 |
$ns->has_readable_type ($v); |
92 |
|
93 |
} elsif ($k eq "smoothing") { # cfplus-style smoothing |
94 |
$ns->smoothing ($v); |
95 |
|
96 |
} elsif ($k eq "fxix") { |
97 |
$setup{$k} = 3; |
98 |
|
99 |
} elsif ($k eq "msg") { |
100 |
$setup{$k} = 1; |
101 |
|
102 |
} elsif ($k eq "widget") { |
103 |
# server-side widgets |
104 |
$v = $v > 1; |
105 |
$ns->{can_widget} = $v; |
106 |
$ns->fx_want (6 => 1); # need support for RSRC |
107 |
$setup{$k} = $v ? 2 : 0; |
108 |
|
109 |
} elsif ($k eq "lzf") { |
110 |
# the lzf packet simply contains an lzf-compressed packet as argument |
111 |
$ns->{can_lzf} = $v == 1; |
112 |
|
113 |
} elsif ($k eq "frag") { |
114 |
# the frag packet contains data which gets appended to the existing packet buffer. |
115 |
# empty frag packet means end of packet. |
116 |
$ns->{can_frag} = $v == 1; |
117 |
|
118 |
} elsif ($k eq "excmd") { |
119 |
# we support it |
120 |
|
121 |
} else { |
122 |
# other commands: |
123 |
# sexp: no idea, probably for oudated servers |
124 |
# tick: more stupidity, server should send a tick per tick |
125 |
|
126 |
$setup{$k} = "FALSE"; |
127 |
} |
128 |
} |
129 |
|
130 |
$ns->send_packet (join " ", setup => %setup); |
131 |
|
132 |
cf::datalog setup => |
133 |
request => $args, |
134 |
reply => \%setup, |
135 |
; |
136 |
}); |
137 |
|