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.184 by root, Mon Jul 7 12:56:07 2008 UTC vs.
Revision 1.200 by root, Sun Jan 4 10:22:19 2009 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
19our $VERSION;
20
21BEGIN { 21BEGIN {
22 $VERSION = '0.9973'; 22 $VERSION = '2.02';
23 23
24 use XSLoader; 24 use XSLoader;
25 XSLoader::load "Deliantra::Client", $VERSION; 25 XSLoader::load "Deliantra::Client", $VERSION;
26} 26}
27 27
28use utf8; 28use utf8;
29use strict qw(vars subs);
29 30
31use Socket ();
30use AnyEvent (); 32use AnyEvent ();
33use AnyEvent::Util ();
31use Pod::POM (); 34use Pod::POM ();
32use File::Path (); 35use File::Path ();
33use Storable (); # finally 36use Storable (); # finally
34use Fcntl (); 37use Fcntl ();
35use JSON::XS qw(encode_json decode_json); 38use JSON::XS qw(encode_json decode_json);
66 s/</&lt;/g; 69 s/</&lt;/g;
67 70
68 $_ 71 $_
69} 72}
70 73
71sub socketpipe() {
72 socketpair my $fh1, my $fh2, Socket::AF_UNIX, Socket::SOCK_STREAM, Socket::PF_UNSPEC
73 or die "cannot establish bidirectional pipe: $!\n";
74
75 ($fh1, $fh2)
76}
77
78sub background(&;&) { 74sub background(&;&) {
79 my ($bg, $cb) = @_; 75 my ($bg, $cb) = @_;
80 76
81 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: $!";
82 79
83 my $pid = fork; 80 my $pid = fork;
84 81
85 if (defined $pid && !$pid) { 82 if (defined $pid && !$pid) {
86 local $SIG{__DIE__}; 83 local $SIG{__DIE__};
142 print $msg, "\n"; 139 print $msg, "\n";
143} 140}
144 141
145package DC; 142package DC;
146 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
147sub find_rcfile($) { 154sub find_rcfile($) {
148 my $path; 155 my $path;
149 156
150 for (grep !ref, @INC) { 157 for (@RC_PATH, "") {
151 $path = "$_/Deliantra/Client/private/resources/$_[0]"; 158 $path = "$RC_BASE/$_/$_[0]";
152 return $path if -r $path; 159 return $path if -r $path;
153 } 160 }
154 161
155 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 }
156} 195}
157 196
158sub read_cfg { 197sub read_cfg {
159 my ($file) = @_; 198 my ($file) = @_;
160 199
161 open my $fh, $file 200 $::CFG = load_json $file;
162 or return;
163
164 local $/;
165 my $CFG = <$fh>;
166
167 $::CFG = decode_json $CFG;
168} 201}
169 202
170sub write_cfg { 203sub write_cfg {
171 my $file = "$Deliantra::VARDIR/client.cf"; 204 my $file = "$Deliantra::VARDIR/client.cf";
172 205

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines