… | |
… | |
17 | use Carp (); |
17 | use Carp (); |
18 | |
18 | |
19 | our $VERSION; |
19 | our $VERSION; |
20 | |
20 | |
21 | BEGIN { |
21 | BEGIN { |
22 | $VERSION = '2.02'; |
22 | $VERSION = '3.0'; |
23 | |
23 | |
24 | use XSLoader; |
24 | use XSLoader; |
25 | XSLoader::load "Deliantra::Client", $VERSION; |
25 | XSLoader::load "Deliantra::Client", $VERSION; |
26 | } |
26 | } |
27 | |
27 | |
… | |
… | |
34 | use Pod::POM (); |
34 | use Pod::POM (); |
35 | use File::Path (); |
35 | use File::Path (); |
36 | use Storable (); # finally |
36 | use Storable (); # finally |
37 | use Fcntl (); |
37 | use Fcntl (); |
38 | use JSON::XS qw(encode_json decode_json); |
38 | use JSON::XS qw(encode_json decode_json); |
|
|
39 | use Guard qw(guard); |
39 | |
40 | |
40 | =item guard { BLOCK } |
41 | # modules to support other DC::* packages |
|
|
42 | use List::Util (); |
|
|
43 | use IO::AIO (); |
|
|
44 | use Coro::AIO (); |
|
|
45 | use AnyEvent::AIO (); |
41 | |
46 | |
42 | Returns an object that executes the given block as soon as it is destroyed. |
47 | use Deliantra::Util (); |
43 | |
48 | use Deliantra::Protocol::Constants (); |
44 | =cut |
|
|
45 | |
|
|
46 | sub guard(&) { |
|
|
47 | bless \(my $cb = $_[0]), "DC::Guard" |
|
|
48 | } |
|
|
49 | |
|
|
50 | sub DC::Guard::DESTROY { |
|
|
51 | ${$_[0]}->() |
|
|
52 | } |
|
|
53 | |
49 | |
54 | =item shorten $string[, $maxlength] |
50 | =item shorten $string[, $maxlength] |
55 | |
51 | |
56 | =cut |
52 | =cut |
57 | |
53 | |
… | |
… | |
65 | local $_ = $_[0]; |
61 | local $_ = $_[0]; |
66 | |
62 | |
67 | s/&/&/g; |
63 | s/&/&/g; |
68 | s/>/>/g; |
64 | s/>/>/g; |
69 | s/</</g; |
65 | s/</</g; |
|
|
66 | |
|
|
67 | $_ |
|
|
68 | } |
|
|
69 | |
|
|
70 | sub sanitise_cfxml($) { |
|
|
71 | local $_ = shift; |
|
|
72 | |
|
|
73 | # we now weed out all tags we do not support |
|
|
74 | s{ <(?! /?i> | /?u> | /?b> | /?big | /?small | /?s | /?tt | fg\ | /fg>) |
|
|
75 | }{ |
|
|
76 | "<" |
|
|
77 | }gex; |
|
|
78 | |
|
|
79 | # now all entities |
|
|
80 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
|
|
81 | |
|
|
82 | # handle some elements |
|
|
83 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
|
|
84 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
|
|
85 | |
|
|
86 | s/\s+$//; |
70 | |
87 | |
71 | $_ |
88 | $_ |
72 | } |
89 | } |
73 | |
90 | |
74 | sub background(&;&) { |
91 | sub background(&;&) { |
… | |
… | |
154 | sub find_rcfile($) { |
171 | sub find_rcfile($) { |
155 | my $path; |
172 | my $path; |
156 | |
173 | |
157 | for (@RC_PATH, "") { |
174 | for (@RC_PATH, "") { |
158 | $path = "$RC_BASE/$_/$_[0]"; |
175 | $path = "$RC_BASE/$_/$_[0]"; |
159 | return $path if -r $path; |
176 | return $path if -e $path; |
160 | } |
177 | } |
161 | |
178 | |
162 | die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n"; |
179 | die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n"; |
163 | } |
180 | } |
164 | |
181 | |
… | |
… | |
167 | |
184 | |
168 | open my $fh, $file |
185 | open my $fh, $file |
169 | or return; |
186 | or return; |
170 | |
187 | |
171 | local $/; |
188 | local $/; |
172 | JSON::XS->new->utf8->relaxed->decode (<$fh>) |
189 | eval { JSON::XS->new->utf8->relaxed->decode (<$fh>) } |
173 | } |
190 | } |
174 | |
191 | |
175 | sub set_theme($) { |
192 | sub set_theme($) { |
176 | return if $RC_THEME eq $_[0]; |
193 | return if $RC_THEME eq $_[0]; |
177 | $RC_THEME = $_[0]; |
194 | $RC_THEME = $_[0]; |
… | |
… | |
192 | |
209 | |
193 | %THEME = ( %$theme, %THEME ); |
210 | %THEME = ( %$theme, %THEME ); |
194 | } |
211 | } |
195 | } |
212 | } |
196 | |
213 | |
197 | sub read_cfg { |
214 | sub read_cfg($) { |
198 | my ($file) = @_; |
215 | my ($file) = @_; |
199 | |
216 | |
200 | $::CFG = (load_json $file) || (load_json "$file.bak"); |
217 | $::CFG = (load_json $file) || (load_json "$file.bak"); |
201 | } |
218 | } |
202 | |
219 | |
203 | sub write_cfg { |
220 | sub write_cfg($) { |
204 | my $file = "$Deliantra::VARDIR/client.cf"; |
221 | my $file = "$Deliantra::VARDIR/client.cf"; |
205 | |
222 | |
206 | $::CFG->{VERSION} = $::VERSION; |
223 | $::CFG->{VERSION} = $::VERSION; |
207 | $::CFG->{layout} = DC::UI::get_layout (); |
224 | $::CFG->{layout} = DC::UI::get_layout (); |
208 | |
225 | |
… | |
… | |
211 | print $fh JSON::XS->new->utf8->pretty->encode ($::CFG); |
228 | print $fh JSON::XS->new->utf8->pretty->encode ($::CFG); |
212 | close $fh; |
229 | close $fh; |
213 | |
230 | |
214 | rename $file, "$file.bak"; |
231 | rename $file, "$file.bak"; |
215 | rename "$file~", $file; |
232 | rename "$file~", $file; |
|
|
233 | } |
|
|
234 | |
|
|
235 | sub load_cfg() { |
|
|
236 | if (-e "$Deliantra::VARDIR/client.cf") { |
|
|
237 | DC::read_cfg "$Deliantra::VARDIR/client.cf"; |
|
|
238 | } else { |
|
|
239 | $::CFG = { cfg_schema => 1, db_schema => 1 }; |
|
|
240 | } |
|
|
241 | } |
|
|
242 | |
|
|
243 | sub save_cfg() { |
|
|
244 | write_cfg "$Deliantra::VARDIR/client.cf"; |
|
|
245 | } |
|
|
246 | |
|
|
247 | sub upgrade_cfg() { |
|
|
248 | my %DEF_CFG = ( |
|
|
249 | config_autosave => 1, |
|
|
250 | sdl_mode => undef, |
|
|
251 | fullscreen => 1, |
|
|
252 | fast => 0, |
|
|
253 | force_opengl11 => undef, |
|
|
254 | disable_alpha => 0, |
|
|
255 | smooth_movement => 1, |
|
|
256 | smooth_transitions => 1, |
|
|
257 | texture_compression => 1, |
|
|
258 | map_scale => 1, |
|
|
259 | fow_enable => 1, |
|
|
260 | fow_intensity => 0, |
|
|
261 | fow_texture => 0, |
|
|
262 | map_smoothing => 1, |
|
|
263 | gui_fontsize => 1, |
|
|
264 | log_fontsize => 0.7, |
|
|
265 | gauge_fontsize => 1, |
|
|
266 | gauge_size => 0.35, |
|
|
267 | stat_fontsize => 0.7, |
|
|
268 | mapsize => 100, |
|
|
269 | audio_enable => 1, |
|
|
270 | audio_hw_channels => 0, |
|
|
271 | audio_hw_frequency => 0, |
|
|
272 | audio_hw_chunksize => 0, |
|
|
273 | audio_mix_channels => 8, |
|
|
274 | effects_enable => 1, |
|
|
275 | effects_volume => 1, |
|
|
276 | bgm_enable => 1, |
|
|
277 | bgm_volume => 0.5, |
|
|
278 | output_rate => "", |
|
|
279 | pickup => Deliantra::Protocol::Constants::PICKUP_SPELLBOOK |
|
|
280 | | Deliantra::Protocol::Constants::PICKUP_SKILLSCROLL |
|
|
281 | | Deliantra::Protocol::Constants::PICKUP_VALUABLES, |
|
|
282 | inv_sort => "mtime", |
|
|
283 | default => "profile", # default profile |
|
|
284 | show_tips => 1, |
|
|
285 | logview_max_par => 1000, |
|
|
286 | shift_fire_stop => 0, |
|
|
287 | uitheme => "wood", |
|
|
288 | map_shift_x => -24, # arbitrary |
|
|
289 | map_shift_y => +24, # arbitrary |
|
|
290 | ); |
|
|
291 | |
|
|
292 | while (my ($k, $v) = each %DEF_CFG) { |
|
|
293 | $::CFG->{$k} = $v unless exists $::CFG->{$k}; |
|
|
294 | } |
|
|
295 | |
|
|
296 | if ($::CFG->{cfg_schema} < 1) { |
|
|
297 | for my $profile (values %{ $::CFG->{profile} }) { |
|
|
298 | $profile->{password} = unpack "H*", Deliantra::Util::hash_pw $profile->{password}; |
|
|
299 | } |
|
|
300 | $::CFG->{cfg_schema} = 1; |
|
|
301 | } |
216 | } |
302 | } |
217 | |
303 | |
218 | sub http_proxy { |
304 | sub http_proxy { |
219 | my @proxy = win32_proxy_info; |
305 | my @proxy = win32_proxy_info; |
220 | |
306 | |