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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines