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.192 by root, Wed Sep 3 10:36:25 2008 UTC vs.
Revision 1.212 by root, Wed Jan 4 11:23:23 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.9975'; 22 $VERSION = '2.11';
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
41 42use List::Util ();
42Returns an object that executes the given block as soon as it is destroyed. 43use IO::AIO ();
43 44use Coro::AIO ();
44=cut 45use AnyEvent::AIO ();
45
46sub guard(&) {
47 bless \(my $cb = $_[0]), "DC::Guard"
48}
49
50sub DC::Guard::DESTROY {
51 ${$_[0]}->()
52}
53 46
54=item shorten $string[, $maxlength] 47=item shorten $string[, $maxlength]
55 48
56=cut 49=cut
57 50
69 s/</&lt;/g; 62 s/</&lt;/g;
70 63
71 $_ 64 $_
72} 65}
73 66
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(&;&) { 67sub background(&;&) {
82 my ($bg, $cb) = @_; 68 my ($bg, $cb) = @_;
83 69
84 my ($fh_r, $fh_w) = DC::socketpipe; 70 my ($fh_r, $fh_w) = AnyEvent::Util::portable_socketpair
71 or die "unable to create background socketpair: $!";
85 72
86 my $pid = fork; 73 my $pid = fork;
87 74
88 if (defined $pid && !$pid) { 75 if (defined $pid && !$pid) {
89 local $SIG{__DIE__}; 76 local $SIG{__DIE__};
160sub find_rcfile($) { 147sub find_rcfile($) {
161 my $path; 148 my $path;
162 149
163 for (@RC_PATH, "") { 150 for (@RC_PATH, "") {
164 $path = "$RC_BASE/$_/$_[0]"; 151 $path = "$RC_BASE/$_/$_[0]";
165 return $path if -r $path; 152 return $path if -e $path;
166 } 153 }
167 154
168 die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n"; 155 die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n";
169} 156}
170 157
173 160
174 open my $fh, $file 161 open my $fh, $file
175 or return; 162 or return;
176 163
177 local $/; 164 local $/;
178 JSON::XS->new->utf8->relaxed->decode (<$fh>) 165 eval { JSON::XS->new->utf8->relaxed->decode (<$fh>) }
179} 166}
180 167
181sub set_theme($) { 168sub set_theme($) {
182 return if $RC_THEME eq $_[0]; 169 return if $RC_THEME eq $_[0];
183 $RC_THEME = $_[0]; 170 $RC_THEME = $_[0];
201} 188}
202 189
203sub read_cfg { 190sub read_cfg {
204 my ($file) = @_; 191 my ($file) = @_;
205 192
206 $::CFG = load_json $file; 193 $::CFG = (load_json $file) || (load_json "$file.bak");
207} 194}
208 195
209sub write_cfg { 196sub write_cfg {
210 my $file = "$Deliantra::VARDIR/client.cf"; 197 my $file = "$Deliantra::VARDIR/client.cf";
211 198
212 $::CFG->{VERSION} = $::VERSION; 199 $::CFG->{VERSION} = $::VERSION;
200 $::CFG->{layout} = DC::UI::get_layout ();
213 201
214 open my $fh, ">:utf8", $file 202 open my $fh, ">:utf8", "$file~"
215 or return; 203 or return;
216 print $fh JSON::XS->new->utf8->pretty->encode ($::CFG); 204 print $fh JSON::XS->new->utf8->pretty->encode ($::CFG);
205 close $fh;
206
207 rename $file, "$file.bak";
208 rename "$file~", $file;
217} 209}
218 210
219sub http_proxy { 211sub http_proxy {
220 my @proxy = win32_proxy_info; 212 my @proxy = win32_proxy_info;
221 213

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines