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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines