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.182 by root, Thu May 22 20:45:20 2008 UTC vs.
Revision 1.200 by root, Sun Jan 4 10:22:19 2009 UTC

14 14
15package DC; 15package DC;
16 16
17use Carp (); 17use Carp ();
18 18
19our $VERSION;
20
19BEGIN { 21BEGIN {
20 $VERSION = '0.9972'; 22 $VERSION = '2.02';
21 23
22 use XSLoader; 24 use XSLoader;
23 XSLoader::load "Deliantra::Client", $VERSION; 25 XSLoader::load "Deliantra::Client", $VERSION;
24} 26}
25 27
26use utf8; 28use utf8;
29use strict qw(vars subs);
27 30
31use Socket ();
28use AnyEvent (); 32use AnyEvent ();
33use AnyEvent::Util ();
29use Pod::POM (); 34use Pod::POM ();
30use File::Path (); 35use File::Path ();
31use Storable (); # finally 36use Storable (); # finally
32use Fcntl (); 37use Fcntl ();
33use JSON::XS qw(encode_json decode_json); 38use JSON::XS qw(encode_json decode_json);
64 s/</&lt;/g; 69 s/</&lt;/g;
65 70
66 $_ 71 $_
67} 72}
68 73
69sub socketpipe() {
70 socketpair my $fh1, my $fh2, Socket::AF_UNIX, Socket::SOCK_STREAM, Socket::PF_UNSPEC
71 or die "cannot establish bidirectional pipe: $!\n";
72
73 ($fh1, $fh2)
74}
75
76sub background(&;&) { 74sub background(&;&) {
77 my ($bg, $cb) = @_; 75 my ($bg, $cb) = @_;
78 76
79 my ($fh_r, $fh_w) = DC::socketpipe; 77 my ($fh_r, $fh_w) = AnyEvent::Util::portable_socketpair
78 or die "unable to create background socketpair: $!";
80 79
81 my $pid = fork; 80 my $pid = fork;
82 81
83 if (defined $pid && !$pid) { 82 if (defined $pid && !$pid) {
84 local $SIG{__DIE__}; 83 local $SIG{__DIE__};
140 print $msg, "\n"; 139 print $msg, "\n";
141} 140}
142 141
143package DC; 142package DC;
144 143
144our $RC_THEME;
145our %THEME;
146our @RC_PATH;
147our $RC_BASE;
148
149for (grep !ref, @INC) {
150 $RC_BASE = "$_/Deliantra/Client/private/resources";
151 last if -d $RC_BASE;
152}
153
145sub find_rcfile($) { 154sub find_rcfile($) {
146 my $path; 155 my $path;
147 156
148 for (grep !ref, @INC) { 157 for (@RC_PATH, "") {
149 $path = "$_/Deliantra/Client/private/resources/$_[0]"; 158 $path = "$RC_BASE/$_/$_[0]";
150 return $path if -r $path; 159 return $path if -r $path;
151 } 160 }
152 161
153 die "FATAL: can't find required file $_[0]\n"; 162 die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n";
163}
164
165sub load_json($) {
166 my ($file) = @_;
167
168 open my $fh, $file
169 or return;
170
171 local $/;
172 JSON::XS->new->utf8->relaxed->decode (<$fh>)
173}
174
175sub set_theme($) {
176 return if $RC_THEME eq $_[0];
177 $RC_THEME = $_[0];
178
179 # kind of hacky, find the main theme file, then load all theme files and merge them
180
181 %THEME = ();
182 @RC_PATH = "theme-$RC_THEME";
183
184 my $theme = load_json find_rcfile "theme.json"
185 or die "FATAL: theme resource file not found";
186
187 @RC_PATH = @{ $theme->{path} } if $theme->{path};
188
189 for (@RC_PATH, "") {
190 my $theme = load_json "$RC_BASE/$_/theme.json"
191 or next;
192
193 %THEME = ( %$theme, %THEME );
194 }
154} 195}
155 196
156sub read_cfg { 197sub read_cfg {
157 my ($file) = @_; 198 my ($file) = @_;
158 199
159 open my $fh, $file 200 $::CFG = load_json $file;
160 or return;
161
162 local $/;
163 my $CFG = <$fh>;
164
165 $::CFG = decode_json $CFG;
166} 201}
167 202
168sub write_cfg { 203sub write_cfg {
169 my $file = "$Deliantra::VARDIR/client.cf"; 204 my $file = "$Deliantra::VARDIR/client.cf";
170 205

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines