ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/setup.ext
(Generate patch)

Comparing deliantra/server/ext/setup.ext (file contents):
Revision 1.9 by root, Sun Aug 31 10:05:26 2008 UTC vs.
Revision 1.27 by root, Wed Nov 21 13:22:34 2012 UTC

1#! perl # mandatory 1#! perl # mandatory
2 2
3# the setup command 3# the setup command
4 4
5use JSON::XS ();
5use List::Util qw(min max); 6use List::Util qw(min max);
6 7
7sub send_capabilities { 8sub do_setup {
8 my ($ns) = @_; 9 my ($ns, $setup) = @_;
9 10
10 return unless $ns->extcmd; 11 my %orig = %$setup;
11 12
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]],
15 );
16}
17
18cf::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) { 13 while (my ($k, $v) = each %$setup) {
29 if ($k eq "sound") { 14 if ($k eq "sound") {
30 $ns->sound ($v); 15 $ns->sound ($v);
31 16
32 } elsif ($k eq "exp64") {
33 $setup{$k} = 1;
34
35 } elsif ($k eq "spellmon") { 17 } elsif ($k eq "spellmon") {
36 $ns->monitor_spells ($v); 18 # version 1 - enable addspell etc.
37 19 # version 2 - no documentation in addspell
38 } elsif ($k eq "darkness") { 20 $setup->{$k} = $ns->monitor_spells (int cf::clamp $v, 0, 2);
39 $ns->darkness ($v);
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 "map2cmd") {
48 # gcfclient bug, map1acmd is sent too late
49 $ns->mapmode (cf::Map1aCmd);
50 $setup{$k} = "FALSE";
51
52 } elsif ($k eq "newmapcmd") {
53 $ns->newmapcmd ($v);
54 21
55 } elsif ($k eq "mapinfocmd") { 22 } elsif ($k eq "mapinfocmd") {
56 $ns->mapinfocmd ($v); 23 $ns->mapinfocmd ($v);
57 24
58 } elsif ($k eq "extcmd") { 25 } elsif ($k eq "extcmd") {
59 $ns->extcmd (min 2, $v); 26 $ns->extcmd (min 2, $v);
60 send_capabilities $ns;
61
62 } elsif ($k eq "extmap") {
63 $ns->extmap ($v);
64
65 } elsif ($k eq "facecache") {
66 if (!$v) {
67 $v = 1;
68 $setup{$k} = $v;
69 $ns->send_drawinfo ("(trying to forcefully enable facecaching)", cf::NDI_RED);
70 }
71
72 $ns->facecache ($v);
73
74 } elsif ($k eq "faceset") {
75 $ns->faceset (0);
76 $setup{$k} = 0;
77 # $ns->image2 (1)
78 27
79 } elsif ($k eq "tileset") { 28 } elsif ($k eq "tileset") {
80 $setup{$k} = $ns->faceset ($v & 1); 29 $setup->{$k} = $ns->tileset (int cf::clamp $v, 0, 2);
81 30
82 } elsif ($k eq "itemcmd") { 31 } elsif ($k eq "itemcmd") {
83 # Version of the item protocol command to use. Currently, 32 # Version of the item protocol command to use. Currently,
84 # only supported versions are 1 and 2. Using a numeric 33 # only supported versions are 1 and 2. Using a numeric
85 # value will make it very easy to extend this in the future. 34 # value will make it very easy to extend this in the future.
86 $ns->itemcmd ($v) if $v >= 1 && $v <= 2; 35 $ns->itemcmd ($v) if $v >= 1 && $v <= 2;
87 36
88 $setup{$k} = $ns->itemcmd; 37 $setup->{$k} = $ns->itemcmd;
89 38
90 } elsif ($k eq "mapsize") { 39 } elsif ($k eq "mapsize") {
91 my ($x, $y) = split /x/, $v; 40 my ($x, $y) = split /x/, $v;
92 41
42 # we *need* to make sure we use an odd map size, as the remaining
43 # code relies on this.
93 $ns->mapx ($x = max 9, min cf::MAP_CLIENT_X, ($x - 1) | 1); 44 $ns->mapx ($x = max 9, min +(cf::MAP_CLIENT_X - 1) | 1, ($x - 1) | 1);
94 $ns->mapy ($y = max 9, min cf::MAP_CLIENT_Y, ($y - 1) | 1); 45 $ns->mapy ($y = max 9, min +(cf::MAP_CLIENT_Y - 1) | 1, ($y - 1) | 1);
95 46
96 $setup{$k} = "${x}x${y}"; 47 $setup->{$k} = "${x}x${y}";
97
98 } elsif ($k eq "extendedMapInfos") {
99 $ns->ext_mapinfos ($v);
100 48
101 } elsif ($k eq "extendedTextInfos") { 49 } elsif ($k eq "extendedTextInfos") {
102 $ns->has_readable_type ($v); 50 $ns->has_readable_type ($v);
103 51
104 } elsif ($k eq "smoothing") { # cfplus-style smoothing 52 } elsif ($k eq "smoothing") { # cfplus-style smoothing
105 $ns->smoothing ($v); 53 $ns->smoothing ($v);
106 54
107 } elsif ($k eq "fxix") {
108 $ns->fxix ($setup{$k} = min 3, $v);
109
110 } elsif ($k eq "msg") {
111 $ns->can_msg ($setup{$k} = min 2, $v);
112
113 } elsif ($k eq "widget") { 55 } elsif ($k eq "widget") {
114 # server-side widgets 56 # server-side widgets
115 $v = $v > 1; 57 $v = $v > 1;
116 $ns->{can_widget} = $v; 58 $ns->{can_widget} = $v;
117 $ns->fx_want (6 => 1); # need support for RSRC 59 $ns->fx_want (6 => 1); # need support for RSRC
118 $setup{$k} = $v ? 2 : 0; 60 $setup->{$k} = $v ? 2 : 0;
119 61
120 } elsif ($k eq "lzf") { 62 } elsif ($k eq "lzf") {
121 # the lzf packet simply contains an lzf-compressed packet as argument 63 # the lzf packet simply contains an lzf-compressed packet as argument
122 $ns->{can_lzf} = $v == 1; 64 $ns->{can_lzf} = $v == 1;
123 65
132 } else { 74 } else {
133 # other commands: 75 # other commands:
134 # sexp: no idea, probably for oudated servers 76 # sexp: no idea, probably for oudated servers
135 # tick: more stupidity, server should send a tick per tick 77 # tick: more stupidity, server should send a tick per tick
136 78
137 $setup{$k} = "FALSE"; 79 $setup->{$k} = "FALSE";
138 } 80 }
139 } 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}
140 99
141 $ns->send_packet (join " ", setup => %setup); 100cf::client->attach (on_setup => sub {
101 my ($ns, $args) = @_;
142 102
143 cf::datalog setup => 103 # run through the cmds of setup
144 request => $args, 104 # syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ...
145 reply => \%setup, 105 # or setup json-object
146 client => $ns->version, 106 #
147 ; 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 }
148}); 119});
149 120
150

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines