ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC.pm (file contents):
Revision 1.193 by root, Fri Sep 5 15:24:10 2008 UTC vs.
Revision 1.214 by root, Wed Jan 18 00:51:22 2012 UTC

10 10
11=over 4 11=over 4
12 12
13=cut 13=cut
14 14
15package Deliantra::Client; # work around CPAN breakage
16package App::Deliantra; # try to reserve namespace
17package DC; 15package DC;
18 16
19use Carp (); 17use Carp ();
20 18
21our $VERSION; 19our $VERSION;
22 20
23BEGIN { 21BEGIN {
24 $VERSION = '0.9976'; 22 $VERSION = '3.0';
25 23
26 use XSLoader; 24 use XSLoader;
27 XSLoader::load "Deliantra::Client", $VERSION; 25 XSLoader::load "Deliantra::Client", $VERSION;
28} 26}
29 27
30use utf8; 28use utf8;
31use strict qw(vars subs); 29use strict qw(vars subs);
32 30
31use Socket ();
33use AnyEvent (); 32use AnyEvent ();
33use AnyEvent::Util ();
34use Pod::POM (); 34use Pod::POM ();
35use File::Path (); 35use File::Path ();
36use Storable (); # finally 36use Storable (); # finally
37use Fcntl (); 37use Fcntl ();
38use JSON::XS qw(encode_json decode_json); 38use JSON::XS qw(encode_json decode_json);
39use Guard qw(guard);
39 40
40=item guard { BLOCK } 41# modules to support other DC::* packages
42use List::Util ();
43use IO::AIO ();
44use Coro::AIO ();
45use AnyEvent::AIO ();
41 46
42Returns an object that executes the given block as soon as it is destroyed. 47use Deliantra::Protocol::Constants ();
43
44=cut
45
46sub guard(&) {
47 bless \(my $cb = $_[0]), "DC::Guard"
48}
49
50sub DC::Guard::DESTROY {
51 ${$_[0]}->()
52}
53 48
54=item shorten $string[, $maxlength] 49=item shorten $string[, $maxlength]
55 50
56=cut 51=cut
57 52
69 s/</&lt;/g; 64 s/</&lt;/g;
70 65
71 $_ 66 $_
72} 67}
73 68
74sub socketpipe() {
75 socketpair my $fh1, my $fh2, &Socket::AF_UNIX, &Socket::SOCK_STREAM, &Socket::PF_UNSPEC
76 or die "cannot establish bidirectional pipe: $!\n";
77
78 ($fh1, $fh2)
79}
80
81sub background(&;&) { 69sub background(&;&) {
82 my ($bg, $cb) = @_; 70 my ($bg, $cb) = @_;
83 71
84 my ($fh_r, $fh_w) = DC::socketpipe; 72 my ($fh_r, $fh_w) = AnyEvent::Util::portable_socketpair
73 or die "unable to create background socketpair: $!";
85 74
86 my $pid = fork; 75 my $pid = fork;
87 76
88 if (defined $pid && !$pid) { 77 if (defined $pid && !$pid) {
89 local $SIG{__DIE__}; 78 local $SIG{__DIE__};
160sub find_rcfile($) { 149sub find_rcfile($) {
161 my $path; 150 my $path;
162 151
163 for (@RC_PATH, "") { 152 for (@RC_PATH, "") {
164 $path = "$RC_BASE/$_/$_[0]"; 153 $path = "$RC_BASE/$_/$_[0]";
165 return $path if -r $path; 154 return $path if -e $path;
166 } 155 }
167 156
168 die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n"; 157 die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n";
169} 158}
170 159
173 162
174 open my $fh, $file 163 open my $fh, $file
175 or return; 164 or return;
176 165
177 local $/; 166 local $/;
178 JSON::XS->new->utf8->relaxed->decode (<$fh>) 167 eval { JSON::XS->new->utf8->relaxed->decode (<$fh>) }
179} 168}
180 169
181sub set_theme($) { 170sub set_theme($) {
182 return if $RC_THEME eq $_[0]; 171 return if $RC_THEME eq $_[0];
183 $RC_THEME = $_[0]; 172 $RC_THEME = $_[0];
201} 190}
202 191
203sub read_cfg { 192sub read_cfg {
204 my ($file) = @_; 193 my ($file) = @_;
205 194
206 $::CFG = load_json $file; 195 $::CFG = (load_json $file) || (load_json "$file.bak");
207} 196}
208 197
209sub write_cfg { 198sub write_cfg {
210 my $file = "$Deliantra::VARDIR/client.cf"; 199 my $file = "$Deliantra::VARDIR/client.cf";
211 200
212 $::CFG->{VERSION} = $::VERSION; 201 $::CFG->{VERSION} = $::VERSION;
202 $::CFG->{layout} = DC::UI::get_layout ();
213 203
214 open my $fh, ">:utf8", $file 204 open my $fh, ">:utf8", "$file~"
215 or return; 205 or return;
216 print $fh JSON::XS->new->utf8->pretty->encode ($::CFG); 206 print $fh JSON::XS->new->utf8->pretty->encode ($::CFG);
207 close $fh;
208
209 rename $file, "$file.bak";
210 rename "$file~", $file;
211}
212
213sub upgrade_cfg() {
214 my %DEF_CFG = (
215 config_autosave => 1,
216 sdl_mode => undef,
217 fullscreen => 1,
218 fast => 0,
219 force_opengl11 => undef,
220 disable_alpha => 0,
221 smooth_movement => 1,
222 smooth_transitions => 1,
223 texture_compression => 1,
224 map_scale => 1,
225 fow_enable => 1,
226 fow_intensity => 0,
227 fow_texture => 0,
228 map_smoothing => 1,
229 gui_fontsize => 1,
230 log_fontsize => 0.7,
231 gauge_fontsize => 1,
232 gauge_size => 0.35,
233 stat_fontsize => 0.7,
234 mapsize => 100,
235 audio_enable => 1,
236 audio_hw_channels => 0,
237 audio_hw_frequency => 0,
238 audio_hw_chunksize => 0,
239 audio_mix_channels => 8,
240 effects_enable => 1,
241 effects_volume => 1,
242 bgm_enable => 1,
243 bgm_volume => 0.5,
244 output_rate => "",
245 pickup => Deliantra::Protocol::Constants::PICKUP_SPELLBOOK
246 | Deliantra::Protocol::Constants::PICKUP_SKILLSCROLL
247 | Deliantra::Protocol::Constants::PICKUP_VALUABLES,
248 inv_sort => "mtime",
249 default => "profile", # default profile
250 show_tips => 1,
251 logview_max_par => 1000,
252 shift_fire_stop => 0,
253 uitheme => "wood",
254 map_shift_x => -24, # arbitrary
255 map_shift_y => +24, # arbitrary
256 #db_schema => 0,
257 );
258
259 while (my ($k, $v) = each %DEF_CFG) {
260 $::CFG->{$k} = $v unless exists $::CFG->{$k};
261 }
217} 262}
218 263
219sub http_proxy { 264sub http_proxy {
220 my @proxy = win32_proxy_info; 265 my @proxy = win32_proxy_info;
221 266

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines